Problem:
Search II

You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S.

Input

In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given.

Output

Print C in a line.

Constraints

Elements in S is sorted in ascending order

n ≤ 100000

q ≤ 50000

0 ≤ an element in S ≤ 109

0 ≤ an element in T ≤ 109

Sample Input 1

5
1 2 3 4 5
3
3 4 1

Sample Output 1

3

Sample Input 2

3
1 2 3
1
5

Sample Output 2

0

Sample Input 3

5
1 1 2 2 3
2
1 2

Sample Output 3

2

Notes

Solution in C (judge verdict: Accepted)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}
// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000
#define QUERY_MAX 50000
#define INF ((1e+9)+1)

int asc(const void *a1, const void *a2) {
    return *(int*)a1 - *(int*)a2;
}

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX+1];
    fget_array(arr, num);
    int qs = get_int();
    static int queries[NUM_MAX+1];
    fget_array(queries, qs);
    qsort(queries, qs, sizeof(int), asc);
    arr[num] = queries[qs] = INF;

    int k;
    int nidx = 0;
    int qidx = 0;
    int size = num + qs;
    int ans = 0;
    int prev = -1;
    for(k = 0; k < size; k++) {
        ans += (prev != arr[nidx] && arr[nidx] == queries[qidx]);
        if(arr[nidx] < queries[qidx]) {
            prev = arr[nidx];
            nidx++;
        } else {
            qidx++;
        }
    }
    printf("%d\n", ans);
    return 0;
}