1 #include<stdio.h>
2 #include<stdlib.h>
3 #define N 10002
4
5 int cmp(const void *a,const void *b)
6 {
7 return *(int *)a - *(int *)b;
8 }
9
10 int main()
11 {
12 int i,a[N], b[N],j;
13 int n, m, count;
14
15 while(scanf("%d %d", &n, &m) != EOF)
16 {
17 for(i=0; i<n; i++)
18 {
19 scanf("%d", &a[i]);
20 }
21 qsort(a,n,sizeof(a[0]),cmp);
22
23 for (j=0; j<m; j++)
24 {
25 scanf("%d", &b[j]);
26 }
27 qsort(b,m,sizeof(b[0]),cmp);
28
29 count = 0;
30 i = 0;
31 j = 0;
32 while(i != n && j != m)
33 {
34 if(a[i] == b[j])
35 {
36 count++;
37 i++;
38 j++;
39 }
40 if(a[i] < b[j])
41 {
42 i++;
43 }
44 if(a[i] > b[j])
45 {
46 j++;
47 }
48 }
49 printf("%d\n", count);
50 }
51 return 0;
52 }
53
54