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: Time Limit Exceeded)

#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

static bool binary_search(int32_t data[], size_t size, int32_t f)
{
  if (size == 0) {
    return false;
  } else {
    int32_t mid = size / 2;
    int32_t pivot = data[size / 2];
    if (f < pivot) {
      return binary_search(data, mid, f);
    } else if (pivot < f) {
      return binary_search(&data[mid], size - mid, f);
    } else {
      return true;
    }
  }

  return false;
}
size_t binary_search_find(int32_t data[], size_t data_size, int32_t find[], size_t find_size)
{
  if ((data == NULL) || (find == NULL)) {
    return 0;
  }

  size_t found = 0;
  int32_t i;
  for (i = 0; i < find_size; i++) {
    int32_t f = find[i];
    if (binary_search(data, data_size, f)) {
      found++;
    }
  }

  return found;
}

#if !defined(TEST)

#include <stdio.h>
static int32_t data[100000];
static int32_t find[50000];

int32_t main(void)
{
  int32_t num1;
  scanf("%d", &num1);
  int32_t i;
  for (i = 0; i < num1; i++) {
    scanf("%d", &data[i]);
  }

  int32_t num2;
  scanf("%d", &num2);

  for (i = 0; i < num2; i++) {
    scanf("%d", &find[i]);
  }

  size_t n = binary_search_find(data, num1, find, num2);

  printf("%lu\n", n);

  return 0;
}
#endif