1 #include <iostream>
2 #include <string.h>
3 #include <algorithm>
4 #include <cstdio>
5
6 int a[100000], b[100000], c[100000];
7 int panduan=0;
8 int ff=0;
9 using namespace std;
10
11 void bijiao(int gps, int x, int n)
12 {
13 for (int i=gps+1; i<n; i++)
14 {
15 if (a[b[gps]]==b[i])
16 {
17 b[gps] = 0;
18 b[i] = 0;
19 }
20 }
21 }
22 void qiushu(int n)
23 {
24 for (int i=0; i<n; i++)
25 {
26 if (b[i]==0)
27 {
28 ff++;
29 }
30 }
31 }
32 void shuchu(int n)
33 {
34 qiushu(n);
35 //cout <<ff/2 <<endl;
36 cout <<n-ff <<endl;
37 sort (b, b+n/*,cmp*/);
38 int first = 0;
39 for (int i=0; i<n; i++)
40 {
41 if (b[i])
42 {
43 if (first)
44 {
45 cout <<" ";
46 }
47 printf("%05d",b[i]);
48 first = 1;
49 }
50 }
51
52 }
53 int main()
54 {
55 int N;
56 cin >>N;
57 for (int i=0; i<N; i++)
58 {
59 int x;
60 cin >>x;
61 cin >>a[x];
62 a[a[x]] = x;
63 }
64 int M;
65 cin >>M;
66 for (int i=0; i<M; i++)
67 {
68 cin >>b[i];
69 }
70
71 for (int i=0; i<M; i++)
72 {
73 bijiao(i, b[i], M);
74 }
75
76 shuchu(M);
77
78 return 0;
79 }