#include <iostream>
#include <vector>

bool includeNum(int fig, std::vector<int> S) {
  int left = 0;
  int right = S.size() - 1;
  int center;

  do {
    center = (right + left) / 2;
    if (S[center] < fig) {
      left = center;
    } else if (S[center] > fig) {
      right = center;
    } else {
      return true;
    }
  } while (right - left > 0);

  return false;
}

int main(int argc, char const *argv[]) {

  int N, fig;
  int cnt = 0;

  std::vector<int> S;
  std::cin >> N;
  for (int i = 0; i < N; ++i) {
    std::cin >> fig;
    S.push_back(fig);
  }

  std::cin >> N;
  for (int i = 0; i < N; ++i) {
    std::cin >> fig;
    if (includeNum(fig, S))
      cnt++;
  }

  std::cout << cnt << std::endl;
  return 0;
}

#include <iostream>
#include <vector>

bool includeNum(int fig, std::vector<int> S) {
  int left = 0;
  int right = S.size();
  int center;

  while (right > left) {
    center = (right + left) / 2;
    if (S[center] < fig) {
      left = center + 1;
    } else if (S[center] > fig) {
      right = center;
    } else {
      return true;
    }
  }

  return false;
}

int main(int argc, char const *argv[]) {

  int N, fig;
  int cnt = 0;

  std::vector<int> S;
  std::cin >> N;
  for (int i = 0; i < N; ++i) {
    std::cin >> fig;
    S.push_back(fig);
  }
  std::cin >> N;
  for (int i = 0; i < N; ++i) {
    std::cin >> fig;
    if (includeNum(fig, S))
      cnt++;
  }

  std::cout << cnt << std::endl;
  return 0;
}


#include <algorithm>
#include <assert.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (i = a; i < b; i++)
#define rloop(i, a, b) for (i = a; i >= b; i--)
const int inf = 1e8;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009

int search(int *s, int t, int left, int right) {

  while (left < right) {
    int k = (right + left) / 2;
    if (s[k] == t) {
      return 1;
    } else if (s[k] > t) {
      right = k;
    } else {
      left = k;
    }
  }
  return 0;
}

int main() {
  int n, q, i, j;
  cin >> n;
  int s[n];
  int cnt = 0;
  loop(i, 0, n) { cin >> s[i]; }
  cin >> q;
  int t;
  loop(i, 0, q) {
    cin >> t;
    if (search(s, t, 0, n) != 0) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

#include <algorithm>
#include <assert.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (i = a; i < b; i++)
#define rloop(i, a, b) for (i = a; i >= b; i--)
const int inf = 1e8;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009

int search(int *s, int t, int left, int right) {
  while (left < right) {
    int k = (right + left) / 2;
    if (s[k] == t) {
      return 1;
    } else if (s[k] > t) {
      right = k;
    } else {
      left = k + 1;
    }
  }
  return 0;
}

int main() {
  int n, q, i, j;
  cin >> n;
  int s[n];
  int cnt = 0;
  loop(i, 0, n) { cin >> s[i]; }
  cin >> q;
  int t;
  loop(i, 0, q) {
    cin >> t;
    if (search(s, t, 0, n) != 0) {
      cnt++;
    }
  }
  cout << cnt << endl;
}


#include <cstdio>

using namespace std;

int count = 0;

int binary_search(int A[], int n, int key) {

  int j, count, length;

  int origin = 0;

  length = n;

  if (n % 2 == 0) {

    j = n / 2;

    while (length > 0) {

      if (A[j - 1] == key) {

        count++;

        break;

      } else if (A[j - 1] > key) {

        length = length / 2;

        j = origin + length / 2;

      } else {

        length = length / 2;

        origin = j;

        j += length / 2;
      }
    }

  } else {

    j = n / 2;

    while (length > 0) {

      if (A[j - 1] == key) {

        count++;

        break;

      } else if (A[j - 1] > key) {

        length = length / 2;

        j = origin + length / 2;

      } else {

        length = length / 2 + 1;

        origin = j;

        j += length / 2;
      }
    }
  }

  return count;
}

int main() {

  int i, n, count;

  scanf("%d", &n);

  int S[n];

  for (i = 0; i < n; i++) {

    scanf("%d", &S[i]);
  }

  int m;

  scanf("%d", &m);

  int key;

  count = 0;

  for (i = 0; i < m; i++) {

    scanf("%d", &key);

    count += binary_search(S, n, key);
  }

  printf("%d\\n", count);
}

#include <cstdio>

using namespace std;

int count = 0;

int binary_search(int A[], int n, int key) {

  int left, right, j;

  int origin = 0;

  left = 0;
  right = n;

  while (left < right) {

    j = (left + right) / 2;

    if (A[j] == key)
      return 1;

    else if (A[j] > key)
      right = j;

    else
      left = j + 1;
  }

  return 0;
}

int main() {

  int i, n, count;

  scanf("%d", &n);

  int S[n];

  for (i = 0; i < n; i++) {

    scanf("%d", &S[i]);
  }

  int m;

  scanf("%d", &m);

  int key;

  count = 0;

  for (i = 0; i < m; i++) {

    scanf("%d", &key);

    count += binary_search(S, n, key);
  }

  printf("%d\\n", count);
}


#include <iostream>
int main() {
  using namespace std;
  int len1, len2;
  cin >> len1;
  int *arr1 = new int[len1];
  for (int i = 0; i < len1; i++)
    cin >> arr1[i];
  cin >> len2;
  int *arr2 = new int[len2];
  for (int i = 0; i < len2; i++)
    cin >> arr2[i];
  int cnt = 0;
  for (int i = 0; i < len2; i++) {
    int l = 0;
    int r = len1 - 1;
    int m = (l + r) / 2;
    while (l != r) {
      if (arr1[m] == arr2[i]) {
        cnt++;
        break;
      } else if (arr1[m] < arr2[i]) {
        l = m + 1;
        m = (l + r) / 2;
      } else {
        r = m - 1;
        m = (l + r) / 2;
      }
    }
    if (arr1[l] == arr1[r] && arr1[l] == arr2[i])
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

#include <iostream>
int main() {
  using namespace std;
  int len1, len2;
  cin >> len1;
  int *arr1 = new int[len1];
  for (int i = 0; i < len1; i++)
    cin >> arr1[i];
  cin >> len2;
  int *arr2 = new int[len2];
  for (int i = 0; i < len2; i++)
    cin >> arr2[i];
  int cnt = 0;
  for (int i = 0; i < len2; i++) {
    int l = 0;
    int r = len1 - 1;
    int m = (l + r) / 2;
    while (l < r) {
      if (arr1[m] == arr2[i]) {
        cnt++;
        break;
      } else if (arr1[m] < arr2[i]) {
        l = m + 1;
        m = (l + r) / 2;
      } else {
        r = m - 1;
        m = (l + r) / 2;
      }
    }
    if (arr1[l] == arr1[r] && arr1[l] == arr2[i] && l == r)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


#include <iostream>

using namespace std;
bool search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while (A[i] != key)
    i++;
  return i < n;
}
int main() {
  int n, m;
  cin >> n;
  int *S = new int[n + 1];
  for (int i = 0; i < n; ++i)
    cin >> S[i];
  cin >> m;
  int *T = new int[m];
  for (int i = 0; i < m; ++i)
    cin >> T[i];
  int sum = 0;
  for (int j = 0; j < m; ++j)
    if (search(S, n, T[j]))
      sum++;
  cout << sum << endl;
  return 0;
}

#include <iostream>

using namespace std;
bool search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while (A[i] != key)
    i++;
  return i < n;
}
int BinarySearch(int A[], int n, int key) {
  int left = 0;
  int right = n;
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (A[mid] == key)
      return 1;
    if (A[mid] > key)
      right = mid;
    else
      left = mid + 1;
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n;
  int *S = new int[n + 1];
  for (int i = 0; i < n; ++i)
    cin >> S[i];
  cin >> m;
  int *T = new int[m];
  for (int i = 0; i < m; ++i)
    cin >> T[i];
  int sum = 0;
  for (int j = 0; j < m; ++j)
    if (BinarySearch(S, n, T[j]))
      sum++;
  cout << sum << endl;
  return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int get_middle(int head, int tail) {
  if ((tail - head) % 2) {
    return (tail + head) / 2;
  } else {
    return (tail + head + 1) / 2;
  }
}

bool binary_search(vector<int> s, int num, int head, int tail) {
  if (head == tail) {
    if (s[head] == num) {
      return true;
    } else {
      return false;
    }
  } else if (tail - head == 1) {
    if (s[head] == num || s[tail] == num) {
      return true;
    } else {
      return false;
    }
  }
  int middle = get_middle(head, tail);
  if (s[middle] == num) {
    return true;
  } else if (s[middle] > num) {
    return binary_search(s, num, head, middle - 1);
  } else if (s[middle] < num) {
    return binary_search(s, num, middle + 1, tail);
  }
  printf("error\\n");
  return false;
}

int main(void) {
  int n;
  scanf("%d", &n);

  vector<int> s;
  for (int i = 0; i < n; i++) {
    int s_;
    scanf("%d", &s_);
    s.push_back(s_);
  }

  int q;
  scanf("%d", &q);

  int t[50000];
  for (int i = 0; i < q; i++) {
    scanf("%d", &t[i]);
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    if (binary_search(s, t[i], 0, s.size() - 1)) {
      cnt++;
    }
  }

  printf("%d\\n", cnt);
}

#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int get_middle(int head, int tail) {
  if ((tail - head) % 2) {
    return (tail + head) / 2;
  } else {
    return (tail + head + 1) / 2;
  }
}

bool binary_search(int *s, int num, int head, int tail) {
  if (head == tail) {
    if (s[head] == num) {
      return true;
    } else {
      return false;
    }
  } else if (tail - head == 1) {
    if (s[head] == num || s[tail] == num) {
      return true;
    } else {
      return false;
    }
  }
  int middle = get_middle(head, tail);
  if (s[middle] == num) {
    return true;
  } else if (s[middle] > num) {
    return binary_search(s, num, head, middle - 1);
  } else if (s[middle] < num) {
    return binary_search(s, num, middle + 1, tail);
  }
  printf("error\\n");
  return false;
}

int main(void) {
  int n;
  scanf("%d", &n);

  int s[100000];
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }

  int q;
  scanf("%d", &q);

  int t[50000];
  for (int i = 0; i < q; i++) {
    scanf("%d", &t[i]);
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    if (binary_search(s, t[i], 0, n - 1)) {
      cnt++;
    }
  }

  printf("%d\\n", cnt);
}


#include <iostream>
using namespace std;

int BSearch(int x, int A[], int N) {
  int left = 0;
  int right = N;

  while (left <= right) {
    int mid = (left + right) / 2;

    if (A[mid] == x) {
      return mid;
    } else if (x < A[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return -1;
}

int main() {
  int n;
  cin >> n;
  int S[n];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  int q;
  cin >> q;
  int T[q];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  int ans = 0;

  for (int i = 0; i < q; i++) {
    if (BSearch(T[i], S, n) != -1) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

#include <iostream>
using namespace std;

int BSearch(int x, int A[], int N) {
  int left = 0;
  int right = N;

  while (left < right) {
    int mid = (left + right) / 2;

    if (A[mid] == x) {
      return mid;
    } else if (x < A[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return -1;
}

int main() {
  int n;
  cin >> n;
  int S[n];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  int q;
  cin >> q;
  int T[q];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  int ans = 0;

  for (int i = 0; i < q; i++) {
    if (BSearch(T[i], S, n) != -1) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int search(int first, int last, int k, std::vector<int> S) {
  if (first == last) {
    if (S[first] == k) {
      return 1;
    } else {
      return 0;
    }
  } else {
    int m;
    m = (first + last) / 2;
    if (S[m] == k) {
      return 1;
    } else if (S[m] > k) {
      return search(first, m, k, S);
    } else {
      return search(m + 1, last, k, S);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int i, j, n, q;
  int count = 0;

  cin >> n;
  vector<int> S(n);
  for (i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  int T[q];
  for (i = 0; i < q; i++) {
    cin >> T[i];
  }

  for (j = 0; j < q; j++) {
    count += search(0, n - 1, T[j], S);
  }

  cout << count << endl;

  return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int search(int first, int last, int k, int *S) {
  if (first == last) {
    if (S[first] == k) {
      return 1;
    } else {
      return 0;
    }
  } else {
    int m;
    m = (first + last) / 2;
    if (S[m] == k) {
      return 1;
    } else if (S[m] > k) {
      return search(first, m, k, S);
    } else {
      return search(m + 1, last, k, S);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int i, j, n, q;
  int count = 0;

  cin >> n;
  int S[n];
  for (i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  int T[q];
  for (i = 0; i < q; i++) {
    cin >> T[i];
  }

  for (j = 0; j < q; j++) {
    count += search(0, n - 1, T[j], S);
  }

  cout << count << endl;

  return 0;
}


#include <algorithm>
#include <iostream>
#include <list>
using namespace std;
int main() {
  // declairring
  int n, q, c = 0, tmp;
  list<int> S;
  list<int>::iterator it;
  // inputting
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    S.push_back(tmp);
  }
  cin >> q;
  for (int i = 0; i < q; i++) { // inputting&searching&counting
    cin >> tmp;
    if (binary_search(S.begin(), S.end(), tmp))
      c++;
  }
  // outputting
  cout << c << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  // declairring
  int n, q, c = 0, tmp;
  // inputting
  cin >> n;
  int S[n];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) { // inputting&searching&counting
    cin >> tmp;
    if (binary_search(S, S + n, tmp))
      c++;
  }
  // outputting
  cout << c << endl;
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int s[100000], n;

int binsearch(int key) {
  int left = 0, right = n, mid = (left + right) / 2;
  while (left < right) {
    if (s[mid] == key)
      return 1;
    else if (s[mid] > key) {
      right = mid;
      mid = (left + right) / 2;
    } else if (s[mid] < key) {
      left = mid;
      mid = (left + right) / 2;
    }
  }
  return 0;
}

int main() {
  int m, count = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    count += binsearch(t);
  }
  cout << count << endl;
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int s[100000], n;

int binsearch(int key) {
  int left = 0, right = n, mid = (left + right) / 2;
  while (left < right) {
    if (s[mid] == key)
      return 1;
    else if (s[mid] > key) {
      right = mid;
      mid = (left + right) / 2;
    } else if (s[mid] < key) {
      left = mid + 1;
      mid = (left + right) / 2;
    }
  }
  return 0;
}

int main() {
  int m, count = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    count += binsearch(t);
  }
  cout << count << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, q;
  cin >> n;
  int *S = new int[n];
  int number;
  for (int i; i < n; ++i) {
    cin >> number;
    S[i] = number;
  }
  cin >> q;
  int *T = new int[q];
  for (int i = 0; i < q; ++i) {
    cin >> number;
    T[i] = number;
  }
  int cnt = 0;

  for (int i = 0; i < q; ++i) {
    int left = 0, right = n;
    while (left < right) {
      int mid = (left + right) / 2;
      if (S[mid] == T[i]) {
        cnt++;
        break;
      } else if (S[mid] > T[i]) {
        right = mid;
      } else if (S[mid] < T[i]) {
        left = mid;
      }
    }
  }

  cout << cnt << "\\n";
  delete[] T;
  delete[] S;
}

#include <iostream>
using namespace std;

int main() {
  int n, q;
  cin >> n;
  int *S = new int[n];
  int number;
  for (int i; i < n; ++i) {
    cin >> number;
    S[i] = number;
  }
  cin >> q;
  int *T = new int[q];
  for (int i = 0; i < q; ++i) {
    cin >> number;
    T[i] = number;
  }
  int cnt = 0;

  for (int i = 0; i < q; ++i) {
    int left = 0, right = n;
    while (left < right) {
      int mid = (left + right) / 2;
      if (S[mid] == T[i]) {
        cnt++;
        break;
      } else if (S[mid] > T[i]) {
        right = mid;
      } else if (S[mid] < T[i]) {
        left = mid + 1;
      }
    }
  }

  cout << cnt << "\\n";
  delete[] T;
  delete[] S;
}


#include <stdio.h>

#define MAX_N 100000
#define MAX_Q 50000

int binary_search(int *s, int n, int x) {
  int p = n / 2;
  int searched = -1;
  while (true) {
    if (s[p] < x) {
      p = (n + p) / 2;
    } else if (s[p] > x) {
      p = p / 2;
    } else {
      return p;
    }

    if (searched == p) {
      return -1;
    }

    searched = p;
  }
}

int main() {
  int n, q;
  int s[MAX_N], t[MAX_Q];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &t[i]);
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    if (binary_search(s, n, t[i]) != -1) {
      cnt++;
    }
  }

  printf("%d\\n", cnt);

  return 0;
}

#include <stdio.h>

#define MAX_N 100000
#define MAX_Q 50000

int binary_search(int *s, int n, int x) {
  int max = n - 1;
  int min = 0;

  int avg = 0;
  int avg_ = -1;
  while (avg != avg_) {
    avg_ = avg;
    avg = (max + min) / 2;

    if (s[avg] > x) {
      max = avg;
    } else if (s[avg] < x) {
      min = avg;
    } else {
      return avg;
    }
  }

  if (s[avg + 1] == x) {
    return avg + 1;
  }
  return -1;
}

int main() {
  int n, q;
  int s[MAX_N], t[MAX_Q];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &t[i]);
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    if (binary_search(s, n, t[i]) != -1)
      cnt++;
  }

  printf("%d\\n", cnt);

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

bool binarySearch(int, int[], int, int);

bool binarySearch(int key, int arr[], int l, int r) {
  if (arr[(l + r) / 2] == key)
    return true;
  if (l == r)
    return false;

  if (arr[(l + r) / 2] < key)
    return binarySearch(key, arr, (l + r) / 2 + 1, r);
  if (arr[(l + r) / 2] > key)
    return binarySearch(key, arr, l, (l + r) / 2 - 1);

  return false;
}

int main(void) {
  int n, q;
  int *S;
  int T;
  int i;
  int result = 0;

  cin >> n;
  S = new int[n];
  for (i = 0; i < n; i++)
    cin >> S[i];

  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> T;
    if (binarySearch(T, S, 0, n))
      result++;
  }

  cout << result << endl;
  delete[] S;
  S = 0;
  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
  int n, q;
  int *S;
  int T;
  int i;
  int result = 0;
  int l, r;

  cin >> n;
  S = new int[n];
  for (i = 0; i < n; i++)
    cin >> S[i];

  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> T;
    l = 0;
    r = n;
    while (l <= r) {
      if (S[(l + r) / 2] == T) {
        result++;
        break;
      } else if (S[(l + r) / 2] < T) {
        l = (l + r) / 2 + 1;
      } else {
        r = (l + r) / 2 - 1;
      }
    }
  }

  cout << result << endl;
  delete[] S;
  S = 0;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

bool binarySearch(vector<int> vi, int t) {
  int right = vi.size() - 1;
  int left = 0;
  bool flg = true;
  while (flg) {
    if (right == left)
      flg = false;
    int center = (left + right) / 2;
    if (vi[center] < t) {
      left = center;
    } else if (vi[center] > t) {
      right = center;
    } else {
      return true;
    }
  }
  return false;
}

int main() {
  vector<int> vi;
  int n, q;
  int count = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    vi.push_back(s);
  }
  sort(vi.begin(), vi.end());
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    count += binarySearch(vi, t);
  }
  cout << count << endl;
  return 0;
};

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

bool binarySearch(vector<int> vi, int t) {
  int right = vi.size() - 1;
  int left = 0;
  bool flg = true;
  while (flg) {
    if (right == left)
      flg = false;
    int center = (left + right) / 2;
    if (vi[center] < t) {
      left = center + 1;
    } else if (vi[center] > t) {
      right = center;
    } else {
      return true;
    }
  }
  return false;
}

int main() {
  vector<int> vi;
  int n, q;
  int count = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    vi.push_back(s);
  }
  sort(vi.begin(), vi.end());
  cin >> q;
  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    count += binarySearch(vi, t);
  }
  cout << count << endl;
  return 0;
};


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define fori(i, k, n) for (int i = k; i < (int)n; i++)
using namespace std;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const int dX[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          dY[8] = {1, 1, 0, -1, -1, -1, 0, 1};
struct XY {
  int x;
  int y;
};

/*
(char)'1' - (int)48 = (int)1;

*/

int main() {
  int n, q;
  vector<int> s;
  cin >> n;
  int j;
  rep(i, n) {
    cin >> j;
    s.push_back(j);
  }
  cin >> q;
  int ans = 0;
  rep(i, q) {
    cin >> j;
    int l = 0, r = n;
    while (l != r) {
      bool ri = true;
      if (s[(l + r) / 2] > j) {
        r = (l + r) / 2 - 1;
      } else if (s[(l + r) / 2] < j) {
        l = (l + r) / 2 + 1;
      } else
        break;
    }
    if (s[(l + r) / 2] == j)
      ans++;
  }
  cout << ans << endl;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define fori(i, k, n) for (int i = k; i < (int)n; i++)
using namespace std;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const int dX[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          dY[8] = {1, 1, 0, -1, -1, -1, 0, 1};
struct XY {
  int x;
  int y;
};

/*
(char)'1' - (int)48 = (int)1;

*/

int main() {
  int n, q;
  vector<int> s;
  cin >> n;
  int j;
  rep(i, n) {
    cin >> j;
    s.push_back(j);
  }
  cin >> q;
  int ans = 0;
  rep(i, q) {
    cin >> j;
    int l = 0, r = n;
    if (binary_search(s.begin(), s.end(), j))
      ans++;
  }
  cout << ans << endl;
}


#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int A[100001];

int main() {
  int n, q, k, count;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    scanf("%d", &k);
    for (int j = 0; j < n; j++) {
      if (A[j] == k) {
        count++;
        break;
      }
    }
  }
  cout << count << endl;
}

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

int S[100001];
int N;

bool binary(int q, int left, int right) {
  int mid = (left + right) / 2;
  if (right - left == 1)
    return (S[left] == q);

  // if (S[mid] == q) return true;
  else if (S[mid] > q) {
    return binary(q, left, mid);
  } else {
    return binary(q, mid, right);
  }
}

int main() {
  int q, Noq;
  cin >> N;

  for (int i = 0; i < N; i++)
    scanf("%d", &S[i]);

  cin >> Noq;
  int count = 0;

  for (int i = 0; i < Noq; i++) {
    scanf("%d", &q);
    if (binary(q, 0, N))
      count++;
  }

  printf("%d\\n", count);

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, q, S[100010], T, C = 0;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> S[i];
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> T;
    int a = 0, b = n;
    while (b - a >= 0) {
      if (T == S[(a + b) / 2]) {
        ++C;
        break;
      } else if (T > S[(a + b) / 2]) {
        a = (a + b) / 2;
      } else {
        b = (a + b) / 2;
      }
    }
  }

  cout << C << endl;

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n, q, S[100010], T[50010], C = 0;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> S[i];
  cin >> q;
  for (int i = 0; i < q; ++i)
    cin >> T[i];

  for (int i = 0; i < q; ++i) {
    int a = 0, b = n - 1;
    while (a <= b) {
      int m = (a + b) / 2;
      if (T[i] == S[m]) {
        ++C;
        break;
      } else if (T[i] > S[m])
        a = m + 1;
      else
        b = m - 1;
    }
  }

  cout << C << endl;

  return 0;
}


#include <iostream>
using namespace std;
int main() {

  int n, a[100000], m, b, result = 0, i;

  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> b;
    if (b < a[0] || a[n - 1] < b)
      continue;
    int l = 0, r = n, m;
    while (r - l > 0) {
      m = (r + l) / 2;
      if (b == a[m]) {
        result++;
        break;
      } else if (b > a[m])
        l = m;
      else
        r = m - 1;
    }
  }
  cout << result << endl;
  return 0;
}

#include <iostream>
using namespace std;
int main() {

  int n, a[100000], m, b, result = 0, i;

  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> b;
    if (b < a[0] || a[n - 1] < b)
      continue;
    int l = 0, r = n, m;
    while (r - l) {
      m = (r + l) / 2;
      if (b == a[m]) {
        result++;
        break;
      } else if (b > a[m])
        l = m + 1;
      else
        r = m;
    }
  }
  cout << result << endl;
  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

std::vector<int> Create_input_vector() {

  std::vector<int> vector;
  int size;

  cin >> size;
  vector.reserve(size);

  while (size--) {
    int value;
    cin >> value;
    vector.emplace_back(value);
  }

  return std::move(vector);
}

bool Exist_element(const std::vector<int> &list, int value) {

  if (value < list.front() || list.back() < value) {
    return false;
  }

  int begin = 0;
  int end = list.size() - 1;
  int now;
  while (now = (begin + end) / 2, begin != end) {
    int element = list.at(now);
    if (element < value) {
      begin = now;
      continue;
    }
    if (element > value) {
      end = now;
      continue;
    }
    return true;
  }

  return false;
}

int Count_same_element(const std::vector<int> &base,
                       const std::vector<int> &other) {

  int count = 0;
  for (const auto base_element : base) {
    if (Exist_element(other, base_element)) {
      ++count;
    }
  }

  return count;
}

int main() {

  std::vector<int> S{Create_input_vector()};
  std::vector<int> T{Create_input_vector()};

  cout << Count_same_element(T, S) << endl;

  return 0;
}

#include <iostream>
#include <vector>

using namespace std;

std::vector<int> Create_input_vector() {

  std::vector<int> vector;
  int size;

  cin >> size;
  vector.reserve(size);

  while (size--) {
    int value;
    cin >> value;
    vector.emplace_back(value);
  }

  return std::move(vector);
}

bool Exist_element(const std::vector<int> &list, int value) {

  if (value < list.front() || list.back() < value) {
    return false;
  }

  int begin = 0;
  int end = list.size() - 1;
  int now;
  while (now = (begin + end) / 2, begin != end) {
    int element = list.at(now);
    if (begin + 1 == end) {
      if (value == list.at(begin) || value == list.at(end)) {
        return true;
      }
      return false;
    }
    if (element < value) {
      begin = now;
      continue;
    }
    if (element > value) {
      end = now;
      continue;
    }
    return true;
  }

  return false;
}

int Count_same_element(const std::vector<int> &base,
                       const std::vector<int> &other) {

  int count = 0;
  for (const auto element : base) {
    if (Exist_element(other, element)) {
      ++count;
    }
  }

  return count;
}

int main() {

  std::vector<int> S{Create_input_vector()};
  std::vector<int> T{Create_input_vector()};

  cout << Count_same_element(T, S) << endl;

  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;

int search(int);

int n, S[100000];

int main() {

  int q, T[50000], counter = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> S[i];

  cin >> q;
  for (int i = 0; i < q; i++)
    cin >> T[i];

  sort(S, S + n);

  for (int i = 0; i < q; i++)
    counter += search(T[i]);

  cout << counter << endl;

  return 0;
}

int search(int t) {

  int left = 0;
  int right = n;

  while (left <= right) {
    int mid = (left + right) / 2;
    if (S[mid] == t) {
      return 1;
    } else if (t < S[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;

int search(int);

int n, S[100000];

int main() {

  int q, T[50000], counter = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> S[i];

  cin >> q;
  for (int i = 0; i < q; i++)
    cin >> T[i];

  sort(S, S + n);

  for (int i = 0; i < q; i++)
    counter += search(T[i]);

  cout << counter << endl;

  return 0;
}

int search(int t) {

  int left = 0;
  int right = n;

  while (left < right) {
    int mid = (left + right) / 2;
    if (S[mid] == t) {
      return 1;
    } else if (t < S[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }

  return 0;
}


#include <iostream>
using namespace std;

int a[10000], b[10000];
int binary(int l, int r, int c) {
  while (l <= r) {
    int p = (l + r) / 2, x, y;
    if (a[p] == c)
      return 1;
    else if (c < a[p])
      r = p - 1;
    else
      l = p + 1;
  }
  return 0;
}

int ar(int n) {
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    for (int j = 0; j < i; j++)
      if (b[i] == b[j])
        i--, n--;
  }
  return n;
}

int main() {
  int p, q, n = 0;
  cin >> p;
  for (int i = 0; i < p; i++)
    cin >> a[i];
  cin >> q, q = ar(q);
  for (int i = 0; i < q; i++)
    n += binary(0, p - 1, b[i]);
  cout << n << endl;

  return 0;
}

#include <iostream>
using namespace std;

int a[100000], b[100000];
int binary(int l, int r, int c) {
  while (l <= r) {
    int p = (l + r) / 2, x, y;
    if (a[p] == c)
      return 1;
    else if (c < a[p])
      r = p - 1;
    else
      l = p + 1;
  }
  return 0;
}

int ar(int n) {
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    for (int j = 0; j < i; j++)
      if (b[i] == b[j])
        i--, n--;
  }
  return n;
}

int main() {
  int p, q, n = 0;
  cin >> p;
  for (int i = 0; i < p; i++)
    cin >> a[i];
  cin >> q, q = ar(q);
  for (int i = 0; i < q; i++)
    n += binary(0, p - 1, b[i]);
  cout << n << endl;

  return 0;
}


#include <iostream>
using namespace std;

int n, S[10010], q, key, cnt = 0;

int search() {
  int left = 0, right = n, med;
  while (left < right) {
    med = (left + right) / 2;
    if (S[med] == key)
      return 1;
    else if (S[med] < key)
      left = med + 1;
    else
      right = med;
  }
  return 0;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> S[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> key;
    cnt += search();
  }
  cout << cnt << endl;
  return 0;
}

#include <iostream>
using namespace std;

int n, S[100010], q, key, cnt = 0;

int search() {
  int left = 0, right = n, med;
  while (left < right) {
    med = (left + right) / 2;
    if (S[med] == key)
      return 1;
    else if (S[med] < key)
      left = med + 1;
    else
      right = med;
  }
  return 0;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> S[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> key;
    cnt += search();
  }
  cout << cnt << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, q;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]); // cin >> ;
  }
  cin >> q;
  int b[q];
  int ans = 0;
  for (int i = 0; i < q; i++) {
    scanf("%d", &b[i]); // cin >> b[i];
    int l = 0, r = n;
    while (l < r) {
      int j = (l + r) / 2;
      if (b[i] == a[j]) {
        ans++;
        break;
      } else if (b[i] > a[j]) {
        l = j;
      } else if (b[i] < a[j]) {
        r = j - 1;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, q;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]); // cin >> ;
  }
  cin >> q;
  int b[q];
  int ans = 0;
  for (int i = 0; i < q; i++) {
    scanf("%d", &b[i]); // cin >> b[i];
    int l = 0, r = n;
    while (l < r) {
      int j = (l + r) / 2;
      if (b[i] == a[j]) {
        ans++;
        break;
      } else if (b[i] > a[j]) {
        l = j + 1;
      } else if (b[i] < a[j]) {
        r = j;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int s[n];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  int q;
  cin >> q;
  int t[q];
  for (int i = 0; i < q; i++)
    cin >> t[i];
  int ans = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (s[j] == t[i]) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int s[n];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  int q;
  cin >> q;
  int t[q];
  for (int i = 0; i < q; i++)
    cin >> t[i];
  int ans = 0;
  for (int i = 0; i < q; i++) {
    int left = 0, right = n, mid;
    while (left < right) {
      mid = (left + right) / 2;
      if (s[mid] == t[i]) {
        ans++;
        break;
      }
      if (t[i] < s[mid])
        right = mid;
      else
        left = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}


#include <stdio.h>

#define N 10000

int n, A[N];

int binSearch(int num) {
  int first = 0, last = n, middle;

  while (first < last) {
    middle = (first + last) / 2;
    if (A[middle] == num)
      return 1;
    else if (A[middle] < num)
      first = middle + 1;
    else
      last = middle;
  }

  return 0;
}

int main(void) {
  int i, q, num;
  int cnt = 0;

  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", A + i);

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &num);
    if (binSearch(num))
      cnt++;
  }
  printf("%d\\n", cnt);

  return 0;
}

#include <stdio.h>

#define N 1000000

int A[N], n;

int binSearch(int key) {
  int first = 0, last = n, middle;

  while (first < last) {
    middle = (first + last) / 2;
    if (key == A[middle])
      return 1;
    if (key > A[middle])
      first = middle + 1;
    else if (key < A[middle])
      last = middle;
  }

  return 0;
}

int main() {
  int i, q, num, cnt = 0;

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

  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    scanf("%d", &num);
    if (binSearch(num))
      cnt++;
  }

  printf("%d\\n", cnt);
  return 0;
}


#include <iostream>
#include <vector>

#define ll long long

using namespace std;

bool search(vector<ll> v, ll n) {
  ll top = 0, btm = v.size() - 1, mid;

  while (top <= btm) {
    mid = (top + btm) / 2;

    if (v[mid] == n) {
      return true;
    } else if (v[mid] < n) {
      top = mid;
    } else {
      btm = mid - 1;
    }
  }

  return false;
}

ll count(vector<ll> s, vector<ll> t) {
  ll cnt = 0;

  for (ll i = 0; i < t.size(); i++) {
    if (search(s, t[i]))
      ++cnt;
  }

  return cnt;
}

int main() {
  ll n, q;
  vector<ll> vs, vt;

  cin >> n;

  vs.resize(n);

  for (ll i = 0; i < n; ++i) {
    cin >> vs[i];
  }

  cin >> q;

  vt.resize(n);

  for (ll i = 0; i < q; ++i) {
    cin >> vt[i];
  }

  cout << count(vs, vt) << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int n, q;

  cin >> n;
  vector<ll> s(n);

  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  cin >> q;
  vector<ll> t(q);

  for (int i = 0; i < q; i++) {
    cin >> t[i];
  }

  unique(s.begin(), s.end());
  unique(t.begin(), t.end());

  int cnt = 0;
  int left, right, mid;

  for (int i = 0; i < q; i++) {
    left = 0;
    right = s.size();

    while (left <= right) {
      mid = (left + right) / 2;

      if (s[mid] == t[i]) {
        cnt++;
        break;
      } else if (s[mid] < t[i]) {
        left = mid + 1;
      } else {
        right = mid - 1;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


#include <cstdio>
#include <iostream>

using namespace std;

int binSearch(int A[], int n, int key) {
  int left = 0, right = n, mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid])
      return 1;
    if (key < A[mid])
      right = mid;
    if (key > A[mid])
      left = mid + 1;
  }
  return 0;
}

int main(int argc, char const *argv[]) {
  int i, n, q, A[10001], key, sum = 0;

  cin >> n;
  for (i = 0; i < n; i++)
    scanf("%d", &A[i]);

  cin >> q;
  for (int i = 0; i < q; ++i) {
    scanf("%d", &key);
    sum += binSearch(A, n, key);
  }
  cout << sum << endl;
  return 0;
}

#include <cstdio>
#include <iostream>

using namespace std;

int binSearch(int A[], int n, int key) {
  int left = 0, right = n, mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid])
      return 1;
    if (key < A[mid])
      right = mid;
    if (key > A[mid])
      left = mid + 1;
  }
  return 0;
}

int main(int argc, char const *argv[]) {
  int i, n, q, A[100001], key, sum = 0;

  cin >> n;
  for (i = 0; i < n; i++)
    scanf("%d", &A[i]);

  cin >> q;
  for (int i = 0; i < q; ++i) {
    scanf("%d", &key);
    sum += binSearch(A, n, key);
  }
  cout << sum << endl;
  return 0;
}


/*
 * ALDS1_4_A.cpp
 *
 *  Created on: Apr 26, 2018
 *      Author: 13743
 */

#include <iostream>

using namespace std;

// bool binarySearch(int* a, int l, int r, int x) {
//	if(l == r) return false;
//	int mid = (r - l) / 2;
//	if(a[mid] == x) return true;
//	if(x < a[mid]) binarySearch(a, l, mid, x);
//	else binarySearch(a, mid, r, x);
//
// }

int main() {
  int cnt = 0;
  int n, q;
  int S[100000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    int l = 0;
    int r = n;
    int mid;
    while (l < r) {
      mid = (l + r) / 2;
      if (S[mid] == x) {
        cnt++;
        break;
      } else if (S[mid] < x) {
        l = mid;
      } else {
        r = mid;
      }
    }
  }
  cout << cnt << endl;
}

/*
 * ALDS1_4_A.cpp
 *
 *  Created on: Apr 26, 2018
 *      Author: 13743
 */

#include <iostream>

using namespace std;

bool binarySearch(int *a, int l, int r, int x) {
  if (l == r)
    return false;
  int mid = (r - l) / 2;
  if (a[mid] == x)
    return true;
  if (x < a[mid])
    binarySearch(a, l, mid, x);
  else
    binarySearch(a, mid, r, x);
}

int main() {
  int cnt = 0;
  int n, q;
  int S[100000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    int l = 0;
    int r = n;
    while (l < r) {
      int mid = (l + r) / 2;
      if (S[mid] == x) {
        cnt++;
        break;
      } else if (S[mid] < x) {
        l = mid + 1;
      } else {
        r = mid;
      }
    }
  }
  cout << cnt << endl;
}


#include <iostream>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
  int n, p, S[100000], T[100000];
  bool exist;
  cin >> n;
  rep(i, n) cin >> S[i];
  cin >> p;
  rep(i, p) cin >> T[i];

  int h;
  rep(i, n) {
    int ch = i;
    REP(j, i, n) {
      if (S[ch] > S[j])
        ch = j;
    }
    h = S[ch];
    S[ch] = S[i];
    S[i] = h;
  }

  int count = 0;

  rep(i, p) {
    int lef = 0, rig = n;
    exist = false;
    while (lef < rig) {
      int index = (lef + rig) / 2;
      if (T[i] == S[index]) {
        exist = true;
        break;
      } else if (T[i] < S[index]) {
        rig = index;
      } else {
        lef = index + 1;
      }
    }
    if (exist) {
      count++;
    }
  }
  cout << count << endl;
}

#include <iostream>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;

int main() {
  int n, p, S[100000], T[100000];
  bool exist;
  cin >> n;
  rep(i, n) cin >> S[i];
  cin >> p;
  rep(i, p) cin >> T[i];

  int count = 0;

  rep(i, p) {
    int lef = 0, rig = n;
    exist = false;
    while (lef < rig) {
      int index = (lef + rig) / 2;
      if (T[i] == S[index]) {
        exist = true;
        break;
      } else if (T[i] < S[index]) {
        rig = index;
      } else {
        lef = index + 1;
      }
    }
    if (exist) {
      count++;
    }
  }
  cout << count << endl;
}


#include <algorithm>
#include <cstdio>
#include <iostream>

#define NMAX 100000
#define QMAX 50000p
using namespace std;

int main(void) {

  int n, q;
  long long S[NMAX], T;
  int cnt = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> T;
    for (int j = 0; j < n; j++) {
      if (S[j] == T) {
        cnt++;
        break;
      }
      if (S[j] > T)
        break;
    }
  }

  cout << cnt << endl;

  return 0;
}

#include <algorithm>
#include <cstdio>
#include <iostream>

#define NMAX 100000
#define QMAX 50000p
using namespace std;

int main(void) {

  int n, q;
  long long S[NMAX], T;
  int cnt = 0;
  int min, max;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> T;
    min = 0, max = n - 1;
    while (1) {
      if (S[(max + min) / 2] == T) {
        cnt++;
        break;
      } else if (S[(max + min) / 2] < T) {
        if (min == (max + min) / 2) {
          if (min + 1 < n) {
            if (S[min + 1] == T)
              cnt++;
          }
          break;
        } else
          min = (max + min) / 2;
      } else if (S[(max + min) / 2] > T) {
        if (max == (max + min) / 2)
          break;
        else
          max = (max + min) / 2;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


#include <iostream>
using namespace std;

int BinarySearch(int S[], int D[], int n, int q) {
  int C = 0;
  for (int i = 0; i < q; i++) {
    int B = 0;
    int T = q - 1;
    while (B <= T) {
      int mid = (B + T) / 2;
      if (S[mid] == D[i]) {
        C++;
      } else if (S[mid] > D[i]) {
        T = mid - 1;
      } else {
        B = mid + 1;
      }
    }
  }
  return C;
}

int main() {
  int n, m;
  cin >> n;
  int S[n];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> m;
  int T[m];
  for (int i = 0; i < m; i++) {
    cin >> T[i];
  }
  cout << BinarySearch(S, T, n, m) << endl;
}

#include <iostream>
using namespace std;

const int f = -1;

int binarySearch(int key, int A[], int n) {
  int l = 0;
  int r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    if (A[mid] == key) {
      return mid;
    } else if (key < A[mid]) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  return f;
}

int main() {
  int n;
  cin >> n;

  int S[100000];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  int q;
  cin >> q;
  int T[50000];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }
  int C = 0;
  for (int i = 0; i < q; i++) {
    if (binarySearch(T[i], S, n) != f) {
      C++;
    }
  }
  cout << C << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

int binSearch(int A[], int n, int key) {
  int left = 0, right = n, mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (A[mid] == key)
      return 1;
    else if (A[mid] < key)
      left = mid + 1; //+1???????????¨???????????§?????£??????
    else
      right = mid; // left<right
  }
  return 0;
}

int main() {
  int n, sum = 0, q, S[10000], T[50000];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> S[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> T[i];
    if (binSearch(S, n, T[i]))
      sum++;
  }
  cout << sum << endl;
}

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

int binSearch(int A[], int n, int key) {
  int left = 0, right = n, mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (A[mid] == key)
      return 1;
    else if (A[mid] < key)
      left = mid + 1; //+1???????????¨???????????§?????£??????
    else
      right = mid; // left<right
  }
  return 0;
}

int main() {
  int n, sum = 0, q, S[100000], T[50000];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> S[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> T[i];
    if (binSearch(S, n, T[i]))
      sum++;
  }
  cout << sum << endl;
}


//
//  main.cpp
//  ALDS1_4_B
//
//  Created by ptyuan on 2018/10/23.
//  Copyright © 2018 YY. All rights reserved.
//

#include <cstdio>
#include <iostream>
static const int kNotFound = -1;

int binarySearch(int *array, int n, int key) {
  int low = 0;
  int hight = n - 1;

  while (low <= hight) {
    int middle = (low + hight) * 0.5;
    int middleValue = array[middle];
    if (middleValue == key) {
      return middle;
    } else if (key > middleValue) {
      low = middle + 1;
    } else {
      hight = middle - 1;
    }
  }

  return kNotFound;
}

int main(int argc, const char *argv[]) {
  int n = 0;
  int s[10001] = {0};
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", s + i);
  }

  int q = 0;
  int sum = 0;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int temp = 0;
    scanf("%d", &temp);
    if (kNotFound != binarySearch(s, n, temp)) {
      sum++;
    }
  }
  printf("%d\\n", sum);
  return 0;
}

//
//  main.cpp
//  ALDS1_4_B
//
//  Created by ptyuan on 2018/10/23.
//  Copyright © 2018 YY. All rights reserved.
//

#include <cstdio>
#include <iostream>
static const int kNotFound = -1;

int binarySearch(int *array, int n, int key) {
  int low = 0;
  int hight = n - 1;

  while (low <= hight) {
    int middle = (low + hight) * 0.5;
    int middleValue = array[middle];
    if (middleValue == key) {
      return middle;
    } else if (key > middleValue) {
      low = middle + 1;
    } else {
      hight = middle - 1;
    }
  }

  return kNotFound;
}

int main(int argc, const char *argv[]) {
  int n = 0;
  int s[100010] = {0};
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", s + i);
  }

  int q = 0;
  int sum = 0;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int temp = 0;
    scanf("%d", &temp);
    if (kNotFound != binarySearch(s, n, temp)) {
      sum++;
    }
  }
  printf("%d\\n", sum);
  return 0;
}


#include <stdio.h>

int A[1000000], n;

// A[]が昇順にソートされていることを前提とする
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid])
      return 1;
    else if (key > A[mid])
      left = mid;
    else
      right = mid - 1;
  }
  return 0;
}

int main() {
  int i, q, k, sum = 0;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &k);
    if (binarySearch(k))
      sum++;
  }
  printf("%d\\n", sum);

  return 0;
}

#include <stdio.h>

int A[1000000], n;

// A[]が昇順にソートされていることを前提とする
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid])
      return 1;
    else if (key > A[mid])
      left = mid + 1;
    else
      right = mid;
  }
  return 0;
}

int main() {
  int i, q, k, sum = 0;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &k);
    if (binarySearch(k))
      sum++;
  }
  printf("%d\\n", sum);

  return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;

int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while (A[i] != key)
    i++;
  return i != n;
}

int main() {
  int n;
  scanf("%d", &n);
  int S[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  int q;
  scanf("%d", &q);
  int T[q];
  for (int i = 0; i < q; i++) {
    scanf("%d", &T[i]);
  }
  int cnt = 0;
  for (int i = 0; i < q; i++) {
    cnt += search(S, n, T[i]);
  }

  printf("%d\\n", cnt);
  return 0;
}

#include <iostream>
#include <stdio.h>
using namespace std;

int search(int A[], int n, int key) {
  int left = 0;
  int right = n;
  while (left < right) {
    int mid = (left + right) / 2;
    if (A[mid] == key) {
      return 1;
    } else if (key < A[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return 0;
}

int main() {
  int n;
  scanf("%d", &n);
  int S[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  int q;
  scanf("%d", &q);
  int T[q];
  for (int i = 0; i < q; i++) {
    scanf("%d", &T[i]);
  }
  int cnt = 0;
  for (int i = 0; i < q; i++) {
    cnt += search(S, n, T[i]);
  }

  printf("%d\\n", cnt);
  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

bool binarySearch(vector<int> vec, int target) {
  int l = 0;
  int r = vec.size();
  while (l < r) {
    int mid = (l + r) / 2;
    if (vec[mid] == target) {
      return (true);
    } else if (vec[mid] < target) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  return (false);
}

void solve() {
  int n;
  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
  }
  int q;
  cin >> q;
  vector<int> T(q);
  for (int i = 0; i < q; ++i) {
    cin >> T[i];
  }
  int ans = 0;
  for (int i = 0; i < q; ++i) {
    for (int j = 0; j < n; ++j) {
      if (binarySearch(S, T[i])) {
        ++ans;
        break;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return (0);
}

#include <iostream>
#include <vector>

using namespace std;

bool binarySearch(vector<int> vec, int target) {
  int l = 0;
  int r = vec.size();
  while (l < r) {
    int mid = (l + r) / 2;
    if (vec[mid] == target) {
      return (true);
    } else if (vec[mid] < target) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  return (false);
}

void solve() {
  int n;
  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
  }
  int q;
  cin >> q;
  vector<int> T(q);
  for (int i = 0; i < q; ++i) {
    cin >> T[i];
  }
  int ans = 0;
  for (int i = 0; i < q; ++i) {
    if (binarySearch(S, T[i])) {
      ++ans;
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return (0);
}


#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define mp make_pair
signed main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n) cin >> v[i];
  int m;
  cin >> m;
  int ans = 0;
  rep(i, m) {
    int t;
    cin >> t;
    int imax = n;
    int imin = 0;
    int mid;
    while (imax > imin) {
      mid = (imax + imin) / 2;
      if (v[mid] > t)
        imax = mid;
      else if (v[mid] < t)
        imin += 1;
      else {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define mp make_pair
signed main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n) cin >> v[i];
  int m;
  cin >> m;
  int ans = 0;
  rep(i, m) {
    int t;
    cin >> t;
    int imax = n;
    int imin = 0;
    int mid;
    while (imax > imin) {
      mid = (imax + imin) / 2;
      if (v[mid] > t)
        imax = mid;
      else if (v[mid] < t)
        imin = mid + 1;
      else {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define mp make_pair
signed main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n) cin >> v[i];
  int m;
  cin >> m;
  int ans = 0;
  rep(i, m) {
    int t;
    cin >> t;
    int imax = n - 1;
    int imin = 0;
    int mid;
    while (imax >= imin) {
      mid = (imax + imin) / 2;
      if (v[mid] > t)
        imax = mid + 1;
      else if (v[mid] < t)
        imin = mid - 1;
      else {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define mp make_pair
signed main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n) cin >> v[i];
  int m;
  cin >> m;
  int ans = 0;
  rep(i, m) {
    int t;
    cin >> t;
    int imax = n - 1;
    int imin = 0;
    int mid;
    while (imax >= imin) {
      mid = (imax + imin) / 2;
      if (v[mid] > t)
        imax = mid - 1;
      else if (v[mid] < t)
        imin = mid + 1;
      else {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define mp make_pair
signed main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n) cin >> v[i];
  int m;
  cin >> m;
  int ans = 0;
  rep(i, m) {
    int t;
    cin >> t;
    int imax = n - 1;
    int imin = 0;
    int mid;
    while (imax - imin > 1) {
      mid = (imax + imin) / 2;
      if (v[mid] > t)
        imax = mid;
      else if (v[mid] < t)
        imin = mid;
    }
    if (v[imin] == t)
      ans++;
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define mp make_pair
signed main() {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n) cin >> v[i];
  int m;
  cin >> m;
  int ans = 0;
  rep(i, m) {
    int t;
    cin >> t;
    int imax = n;
    int imin = -1;
    int mid;
    while (imax - imin > 1) {
      mid = (imax + imin) / 2;
      if (v[mid] > t)
        imax = mid;
      else
        imin = mid;
    }
    if (v[imin] == t)
      ans++;
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
// #define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define mp make_pair
signed main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  int ans = 0;
  int a;
  cin >> a;
  vector<int> u(a);
  rep(i, a) cin >> u[i];
  rep(i, a) {
    int f = u[i];
    int imin = 0;
    int imax = n - 1;
    while (imax > imin) {
      int mid = (imax + imin) / 2;
      if (v[mid] > f)
        imax = mid + 1;
      else
        imin = mid - 1;
    }
    if (v[imin] == f)
      ans++;
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
// #define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define mp make_pair
signed main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  int ans = 0;
  int a;
  cin >> a;
  vector<int> u(a);
  rep(i, a) cin >> u[i];
  rep(i, a) {
    int f = u[i];
    int imin = 0;
    int imax = n;
    while (imax - imin > 1) {
      int mid = (imax + imin) / 2;
      if (v[mid] > f)
        imax = mid;
      else
        imin = mid;
    }
    if (v[imin] == f)
      ans++;
  }
  cout << ans << endl;
}


#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int S[n];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  int q;
  cin >> q;
  int T[q];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  int cnt = 0;
  for (int ti = 0; ti < q; ti++) {
    int left = 0, right = n, mid;
    while (left < right) {
      mid = (left + right) / 2;
      if (S[mid] == T[ti]) {
        cnt++;
        break;
      } else if (T[ti] < S[mid])
        right = mid;
      else
        left = mid - 1;
    }
  }
  cout << cnt << endl;
  return 0;
}

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int S[n];
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  int q;
  cin >> q;
  int T[q];
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  int cnt = 0;
  for (int ti = 0; ti < q; ti++) {
    int left = 0, right = n, mid;
    while (left < right) {
      mid = (left + right) / 2;
      if (S[mid] == T[ti]) {
        cnt++;
        break;
      } else if (T[ti] < S[mid])
        right = mid;
      else
        left = mid + 1;
    }
  }
  cout << cnt << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

  int n, q, t, cnt = 0;

  cin >> n;

  int s[n];

  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }

  cin >> q;

  for (int i = 0; i < q; ++i) {
    cin >> t;

    int l = 0, r = n, m;
    while (1) {
      m = (l + r) / 2;
      if (s[m] == t) {
        // cout << "found" << endl;
        ++cnt;
        break;
      } else if (l == r) {
        break;
      } else if (s[m] < t) {
        l = m + 1;
      } else if (s[m] > t) {
        r = m - 1;
      }
      // cout << m << ' ' << l << ' ' << r << endl;
    }
  }

  cout << cnt << endl;
}

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n, q, t, size, cnt = 0;

  cin >> n;

  int s[n];

  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }

  cin >> q;

  for (int i = 0; i < q; ++i) {
    cin >> t;

    int l = 0, r = n, m;
    while (l <= r) {
      m = (l + r) / 2;
      if (s[m] == t) {
        ++cnt;
        break;
      } else if (s[m] < t) {
        l = m + 1;
      } else if (s[m] > t) {
        r = m - 1;
      }
    }
  }

  cout << cnt << endl;
}


#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;

vector<int> merge_sort_merge(vector<int> v1, vector<int> v2) {
  vector<int> ret;
  int i = 0, j = 0;
  while (i < v1.size() && j < v2.size()) {
    if (v1[i] < v2[j]) {
      ret.push_back(v1[i++]);
    } else {
      ret.push_back(v2[j++]);
    }
  }
  while (i < v1.size()) {
    ret.push_back(v1[i++]);
  }
  while (j < v2.size()) {
    ret.push_back(v2[j++]);
  }
  return ret;
}

void merge_sort(vector<int> &vec) {
  if (vec.size() < 2) {
    return;
  }
  vector<int> v1(vec.size() / 2 + vec.size() % 2);
  vector<int> v2(vec.size() / 2);
  for (int i = 0; i < vec.size(); i++) {
    if (i < vec.size() / 2 + vec.size() % 2) {
      v1[i] = vec[i];
    } else {
      v2[i - vec.size() / 2 - vec.size() % 2] = vec[i];
    }
  }
  merge_sort(v1);
  merge_sort(v2);
  vec = merge_sort_merge(v1, v2);
}

bool binary_search(vector<int> vec, int target, int l, int r) {
  int mid = (l + r) / 2;
  // cout<<target<<" "<<l<<" "<<r<<endl;
  if (vec[mid] == target) {
    return true;
  }
  if (vec[mid] > target) {
    r = mid - 1;
  }
  if (vec[mid] < target) {
    l = mid + 1;
  }
  if (l > vec.size() - 1 || r < 0 || l > r) {
    return false;
  }
  return binary_search(vec, target, l, r);
  ;
}

int main() {
  int n;

  vector<int> S, T;
  int q;
  cin >> n;
  S.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  // merge_sort(S);

  cin >> q;
  T.resize(q);
  int ans = 0;
  for (int i = 0; i < q; i++) {
    cin >> T[i];
    if (binary_search(S, T[i], 0, n - 1)) {
      ans++;
    }
    //   cout<<i<<endl;
  }
  cout << ans << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

vector<int> merge_sort_merge(vector<int> v1, vector<int> v2) {
  vector<int> ret;
  int i = 0, j = 0;
  while (i < v1.size() && j < v2.size()) {
    if (v1[i] < v2[j]) {
      ret.push_back(v1[i++]);
    } else {
      ret.push_back(v2[j++]);
    }
  }
  while (i < v1.size()) {
    ret.push_back(v1[i++]);
  }
  while (j < v2.size()) {
    ret.push_back(v2[j++]);
  }
  return ret;
}

void merge_sort(vector<int> &vec) {
  if (vec.size() < 2) {
    return;
  }
  vector<int> v1(vec.size() / 2 + vec.size() % 2);
  vector<int> v2(vec.size() / 2);
  for (int i = 0; i < vec.size(); i++) {
    if (i < vec.size() / 2 + vec.size() % 2) {
      v1[i] = vec[i];
    } else {
      v2[i - vec.size() / 2 - vec.size() % 2] = vec[i];
    }
  }
  merge_sort(v1);
  merge_sort(v2);
  vec = merge_sort_merge(v1, v2);
}
int S[100000];
int n;
bool binary_search(int target, int l, int r) {
  int mid = (l + r) / 2;
  // cout<<target<<" "<<l<<" "<<r<<endl;
  if (S[mid] == target) {
    return true;
  }
  if (S[mid] > target) {
    r = mid - 1;
  }
  if (S[mid] < target) {
    l = mid + 1;
  }
  if (l > n - 1 || r < 0 || l > r) {
    return false;
  }
  return binary_search(target, l, r);
  ;
}

int main() {
  int q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", S + i);
  }
  cin >> q;
  int t;
  int ans = 0;
  for (int i = 0; i < q; i++) {
    cin >> t;
    if (binary_search(t, 0, n - 1)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int n, q, *S, *T, c = 0, i, j;

  scanf("%d", &n);
  S = new int[n];
  for (i = 0; i < n; ++i)
    scanf("%d", S + i);

  scanf("%d", &q);
  T = new int[q];
  for (i = 0; i < q; ++i)
    scanf("%d", T + i);

  for (i = q; i; --i)
    for (j = n; j; --j)
      if (S[j - 1] == T[i - 1]) {
        ++c;
        break;
      }

  cout << c << endl;

  delete[] S;
  delete[] T;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int *S;
  int n, q, t;
  int cnt;

  cin >> n;
  S = new int[n];
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
  }
  cin >> q;
  cnt = 0;
  for (int i = 0; i < q; ++i) {
    cin >> t;
    int st = 0, ed = n - 1, mid;
    if (S[st] == t || S[ed] == t)
      ++cnt;
    else {
      while (ed - st > 1) {
        mid = (st + ed) / 2;
        if (S[mid] == t) {
          ++cnt;
          break;
        } else if (S[mid] > t) {
          ed = mid;
        } else {
          st = mid;
        }
      }
    }
  }
  cout << cnt << endl;

  return 0;
}


#include <iostream>

using namespace std;

int ans = 0;

bool answer(int n, long num[], int p) {
  if (n == num[p]) {
    ans++;
    return true;
  }
  return false;
}

int main() {
  int s, t, n;

  cin >> s;
  long num[s];

  for (int i = 0; i < s; i++)
    cin >> num[i];

  cin >> t;
  for (int i = 0; i < t; i++) {
    int p = 0, pp = s;
    bool br = false;
    cin >> n;
    while (true) {
      int a = p + ((pp - p) / 2);
      if (answer(n, num, a))
        break;
      else if (n > num[a]) {
        if (answer(n, num, a + 1))
          break;
        p = a;
        if (p >= s)
          break;
      } else if (answer(n, num, a - 1))
        break;
      else {
        pp = a - 2;
        if (pp <= p)
          break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

#include <iostream>

using namespace std;

int ans = 0;

bool answer(int n, long num[], int p) {
  if (n == num[p]) {
    ans++;
    return true;
  }
  return false;
}

int main() {
  int s, t, n;

  cin >> s;
  long num[s];

  for (int i = 0; i < s; i++)
    cin >> num[i];

  cin >> t;
  for (int i = 0; i < t; i++) {
    int p = 0, pp = s;
    bool br = false;
    cin >> n;
    while (true) {
      int a = p + ((pp - p) / 2);
      if (answer(n, num, a))
        break;
      else if (n > num[a]) {
        if (answer(n, num, a + 1))
          break;
        p = a + 1;
        if (p == pp)
          break;
      } else if (answer(n, num, a - 1))
        break;
      else {
        pp = a - 2;
        if (pp <= p)
          break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


#include <stdio.h>

int BsearchQ(int A[], int n, int key) {
  int l = 0;
  int r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    if (A[mid] == key) {
      return 1;
    } else if (A[mid] < key) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  return 0;
}

int main() {
  int n, A[10000 + 1], q, key, sum = 0;

  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &A[i]);

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &key);
    sum += BsearchQ(A, n, key);
  }
  printf("%d\\n", sum);
  return 0;
}

#include <stdio.h>

int BsearchQ(int A[], int n, int key) {
  int l = 0;
  int r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    if (A[mid] == key) {
      return 1;
    } else if (A[mid] < key) {
      l = mid + 1;
    } else {
      r = mid;
    }
  }
  return 0;
}

int main() {
  int n, A[100000 + 5], q, key, sum = 0;

  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &A[i]);

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &key);
    sum += BsearchQ(A, n, key);
  }
  printf("%d\\n", sum);
  return 0;
}


#include <cstdlib>
#include <iostream>
#include <vector>
/*与えられた数列Sの中に含まれている数列Tの要素の数を出力する*/
using namespace std;
int main() {
  vector<int> s, t;
  int n, n2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  cin >> n2;
  for (int i = 0; i < n2; i++) {
    int tmp;
    cin >> tmp;
    t.push_back(tmp);
  }
  int ans = 0;
  for (int t_i = 0; t_i < n2; t_i++) {
    int first = 0, last = n, middle = last / s.size();
    while (first <= last) {
      if (s[middle] == t[t_i]) {
        ans++;
        break;
      } else if (s[middle] > t[t_i]) {
        first = middle + 1;
      } else if (s[middle] < t[t_i]) {
        last = middle - 1;
      }
    }
  }
  cout << ans << endl;
}

#include <cstdlib>
#include <iostream>
#include <vector>
/*与えられた数列Sの中に含まれている数列Tの要素の数を出力する*/
using namespace std;
int main() {
  vector<int> s, t;
  int n, n2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  cin >> n2;
  for (int i = 0; i < n2; i++) {
    int tmp;
    cin >> tmp;
    t.push_back(tmp);
  }
  int ans = 0;
  for (int t_i = 0; t_i < n2; t_i++) {
    int first = 0, last = n, middle;
    while (first < last) {
      middle = (first + last) / 2;
      if (s[middle] == t[t_i]) {
        ans++;
        break;
      } else if (s[middle] > t[t_i]) {
        last = middle;
      } else {
        first = middle + 1;
      }
    }
  }
  cout << ans << endl;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <list>
using namespace std;

#define PB push_back

int main(int argc, char *argv[]) {
  int n, q;
  list<int> lis, lit;
  int i, x, ans = 0;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    lis.PB(x);
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> x;
    lit.PB(x);
  }
  // 重複要素を削除
  lis.sort();
  lis.unique();
  lit.sort();
  lit.unique();

  list<int>::iterator itlit;
  for (itlit = lit.begin(); itlit != lit.end(); itlit++) {
    if (find(lis.begin(), lis.end(), *itlit) != lis.end())
      ans++;
  }

  cout << ans << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#define PB push_back

int main(int argc, char *argv[]) {
  int n, q, x, ans = 0, i;
  vector<int> vis, vit;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    vis.PB(x);
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> x;
    vit.PB(x);
  }

  sort(vis.begin(), vis.end());
  sort(vit.begin(), vit.end());

  vector<int>::iterator itvis, itvit;
  itvis = vis.begin();
  itvit = vit.begin();

  while (itvis != vis.end() && itvit != vit.end()) {
    if (*itvis == *itvit) {
      ans++;
      itvis++;
      itvit++;
    } else if (*itvis > *itvit) {
      itvit++;
    } else if (*itvis < *itvit) {
      itvis++;
    }
  }

  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

bool binary_search(vector<int> &v, int &n) {
  int left = 0;
  int right = v.size() - 1;
  int middle = (right - left) / 2;
  while (true) {
    if (v[middle] == n)
      return true;
    if (v[middle] < n) {
      left = middle;
      middle = (right + left + 1) / 2;
    } else {
      right = middle;
      middle = (right + left) / 2;
    }
    if (left == right)
      break;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
  }

  int q;
  cin >> q;

  int count = 0;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (binary_search(S, t))
      ++count;
  }
  cout << count << endl;

  return 0;
}

#include <iostream>
#include <vector>

using namespace std;

bool binary_search(vector<int> &v, int &n) {
  int left = 0;
  int right = v.size();
  while (left < right) {
    int middle = (left + right) / 2;
    if (v[middle] == n)
      return true;
    if (n < v[middle]) {
      right = middle;
    } else {
      left = middle + 1;
    }
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
  }

  int q;
  cin >> q;

  int count = 0;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (binary_search(S, t))
      ++count;
  }
  cout << count << endl;

  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int n, q, s[100001], t, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t;
    int l = 0, r = n, m;
    while (l < r) {
      m = (l + r) / 2;
      if (t < s[m])
        r = m;
      else if (t > s[m])
        l = m;
      else {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int n, q, s[100001], t, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t;
    int l = 0, r = n, m;
    while (l < r) {
      m = (l + r) / 2;
      if (t < s[m])
        r = m;
      else if (t > s[m])
        l = m + 1;
      else {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> o1(100000, 0);
  vector<int> o2(50000, 0);
  int n1;
  int n2;
  int count = 0;
  cin >> n1;
  for (int i = 0; i < n1; i++) {
    cin >> o1[i];
  }
  cin >> n2;
  for (int j = 0; j < n2; j++) {
    cin >> o2[j];
  }
  for (int i = 0; i < n2; i++) {
    for (int j = 0; j < n1; j++) {
      if (o2[i] == o1[j]) {
        count++;
        break;
      }
    }
  }
  cout << count << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<int> o1(100000);
  vector<int> o2(50000);
  int n1;
  int n2;
  int count = 0;
  int n;
  cin >> n1;
  for (int i = 0; i < n1; i++) {
    cin >> o1[i];
  }
  sort(o1.begin(), o1.end());
  cin >> n2;
  for (int j = 0; j < n2; j++) {
    cin >> o2[j];
  }
  for (int i = 0; i < n2; i++) {
    if (binary_search(o1.begin(), o1.end(), o2[i])) {
      count++;
    }
  }
  cout << count << endl;

  return 0;
}


#include <cstdio>
#include <vector>
using namespace std;

bool binary_search(int target, int low, int high, vector<int> &S) {
  int mid = low + (high - low) / 2;
  if (S.at(mid) == target) {
    return true;
  }
  if (low == high)
    return false;
  if (S.at(mid) > target) {
    return binary_search(target, low, mid - 1, S);
  } else {
    return binary_search(target, mid + 1, high, S);
  }
}

int main() {
  int n, q, a, c = 0, i, j;
  vector<int> S;
  scanf("%d", &n);
  S.resize(n);
  for (i = 0; i < n; ++i) {
    scanf("%d", &S[i]);
  }

  scanf("%d", &q);
  for (j = 0; j < q; ++j) {
    scanf("%d", &a);
    if (binary_search(a, 0, n - 1, S))
      ++c;
  }
  printf("%d\\n", c);
  return 0;
}

#include <cstdio>
#include <vector>
using namespace std;

bool binary_search(int target, int low, int high, vector<int> &S) {
  int mid = low + (high - low) / 2;
  if (S.at(mid) == target) {
    return true;
  }
  if (low >= high)
    return false;
  if (S.at(mid) > target) {
    return binary_search(target, low, mid - 1, S);
  } else {
    return binary_search(target, mid + 1, high, S);
  }
}

int main() {
  int n, q, a, c = 0, i, j;
  vector<int> S;
  scanf("%d", &n);
  S.resize(n);
  for (i = 0; i < n; ++i) {
    scanf("%d", &S[i]);
  }

  scanf("%d", &q);
  for (j = 0; j < q; ++j) {
    scanf("%d", &a);
    if (binary_search(a, 0, n - 1, S))
      ++c;
  }
  printf("%d\\n", c);
  return 0;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long

int binarysearch(int A[], int n, int key) {
  int left = 0, right = n;
  while (left < right) {
    int mid = (left + right) / 2;
    if (A[mid] == key) {
      return 1;
    } else if (key < A[mid]) {
      right = mid - 1;
    } else {
      left = mid;
    }
  }
  return 0;
}

int main() {
  int s[100001];
  int n, q, key;

  cin >> n;
  REP(i, n) cin >> s[i];
  cin >> q;

  int sum = 0;
  REP(i, q) {
    cin >> key;
    if (binarysearch(s, n, key))
      sum++;
  }
  cout << sum << endl;
}

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long

int binarysearch(int A[], int n, int key) {
  int left = 0, right = n;
  while (left < right) {
    int mid = (left + right) / 2;
    if (A[mid] == key) {
      return 1;
    } else if (key < A[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return 0;
}

int main() {
  int s[100001];
  int n, q, key;

  cin >> n;
  REP(i, n) cin >> s[i];
  cin >> q;

  int sum = 0;
  REP(i, q) {
    cin >> key;
    if (binarysearch(s, n, key))
      sum++;
  }
  cout << sum << endl;
}


#include <iostream>
#include <vector>
using namespace std;

int main(void) {
  int n, q, Number, count;
  bool Exist;
  vector<int> S;

  std::cin >> n;
  S.clear();
  for (int i = 0; i < n; i++) {
    std::cin >> Number;
    if (S.empty()) {
      S.push_back(Number);
    } else {
      Exist = false;
      for (int j = 0; j < S.size(); j++) {
        if (Number == S[j])
          Exist = true;
      }
      if (Exist == false)
        S.push_back(Number);
    }
  }

  std::cin >> q;
  count = 0;
  for (int i = 0; i < q; i++) {
    std::cin >> Number;
    for (int j = 0; j < S.size(); j++) {
      if (Number == S[j])
        count++;
    }
  }

  std::cout << count << std::endl;
}

#include <iostream>
#include <vector>
using namespace std;

bool IsExist(vector<int> &S, int Number);

bool IsExist(vector<int> &S, int Number) {
  int left = 0;
  int right = S.size();

  while (left < right) {
    int Index = (left + right) / 2;
    if (S[Index] == Number) {
      return true;
    } else if (Number < S[Index]) {
      right = Index;
    } else {
      left = Index + 1;
    }
  }
  return false;
}

int main(void) {
  int n, q, Number, count;
  bool Exist;
  vector<int> S;

  std::cin >> n;
  S.clear();
  for (int i = 0; i < n; i++) {
    std::cin >> Number;
    if (S.empty()) {
      S.push_back(Number);
    } else {
      if (S[S.size() - 1] != Number)
        S.push_back(Number);
    }
  }

  std::cin >> q;
  count = 0;
  for (int i = 0; i < q; i++) {
    std::cin >> Number;
    if (IsExist(S, Number) == true)
      count++;
  }

  std::cout << count << std::endl;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>

int main() {
  int n, q;
  std::cin >> n;
  int *S = new int[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  std::cin >> q;
  int *T = new int[q];
  for (int i = 0; i < q; i++) {
    scanf("%d", &T[i]);
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    int head = 0;
    int tail = n - 1;
    int j = (head + tail) / 2;
    while (1) {
      if (S[j] == T[i]) {
        cnt++;
        break;
      } else if (head - tail == 1) {
        break;
      } else if (S[j] > T[i]) {
        tail = j;
        j = (head + tail) / 2;
      } else if (S[j] < T[i]) {
        head = j;
        j = (head + tail) / 2;
      }
    }
  }

  printf("%d\\n", cnt);
  return 0;
}

#include <cstdio>
#include <cstdlib>
#include <iostream>

int main() {
  int n, q;
  std::cin >> n;
  int *S = new int[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  std::cin >> q;
  int *T = new int[q];
  for (int i = 0; i < q; i++) {
    scanf("%d", &T[i]);
  }

  int cnt = 0;
  for (int i = 0; i < q; i++) {
    int head = 0;
    int tail = n - 1;
    int j = (head + tail) / 2;
    while (1) {
      if (S[j] == T[i]) {
        cnt++;
        break;
      } else if (tail - head == 1) {
        if (S[head] == T[i] || S[tail] == T[i]) {
          cnt++;
        }
        break;
      } else if (S[j] > T[i]) {
        tail = j;
        j = (head + tail) / 2;
      } else if (S[j] < T[i]) {
        head = j;
        j = (head + tail) / 2;
      }
    }
  }

  printf("%d\\n", cnt);
  return 0;
}


#include <iostream>
#include <vector>

const int N = 100000;
const int Q = 50000;

int main() {
  std::ios_base::sync_with_stdio(false);

  int n = 0;
  std::vector<int> S;

  S.reserve(N);

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    int x = 0;

    std::cin >> x;

    S.push_back(x);
  }

  int q = 0;
  std::vector<int> T;

  T.reserve(Q);

  std::cin >> q;

  for (int i = 0; i < q; i++) {
    int x = 0;

    std::cin >> x;

    T.push_back(x);
  }

  int count = 0;

  for (std::vector<int>::iterator i = S.begin(); i != S.end(); ++i) {
    std::vector<int>::iterator j = T.begin();

    while (j != T.end()) {
      int left = 0;
      int right = n - 1;

      bool found = false;

      while (left <= right) {
        int middle = (left + right) / 2;

        //	std::cout << middle << std::endl;

        if (S[middle] == *j) {
          count++;

          found = true;

          break;
        } else if (S[middle] < *j) {
          left = middle + 1;
        } else {
          right = middle - 1;
        }
      }

      if (found) {
        j = T.erase(j);
      } else {
        ++j;
      }
    }
  }

  std::cout << count << std::endl;

  return 0;
}

#include <iostream>
#include <vector>

const int N = 100000;
const int Q = 50000;

int main() {
  std::ios_base::sync_with_stdio(false);

  int n = 0;
  std::vector<int> S;

  S.reserve(N);

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    int x = 0;

    std::cin >> x;

    if (i == 0) {
      S.push_back(x);

      continue;
    }

    if ((i > 0) && (x != S[S.size() - 1])) {
      S.push_back(x);
    }
  }

  int q = 0;
  std::vector<int> T;

  T.reserve(Q);

  std::cin >> q;

  for (int i = 0; i < q; i++) {
    int x = 0;

    std::cin >> x;

    T.push_back(x);
  }

  int count = 0;

  std::vector<int>::iterator j = T.begin();

  while (j != T.end()) {
    int left = 0;
    int right = S.size() - 1;

    bool found = false;

    while (left <= right) {
      int middle = (left + right) / 2;

      if (S[middle] == *j) {
        count++;

        found = true;

        break;
      } else if (S[middle] < *j) {
        left = middle + 1;
      } else {
        right = middle - 1;
      }
    }

    if (found) {
      j = T.erase(j);
    } else {
      ++j;
    }
  }

  std::cout << count << std::endl;

  return 0;
}


#include <iostream>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int i, j, n, q, count = 0;
  int dataS[100000], dataT[50000];
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> dataS[i];
  }

  cin >> q;
  for (i = 0; i < q; ++i) {
    cin >> dataT[i];
  }
  for (int j = 0; j < q; ++j) {
    for (int i = 0; i < n; ++i) {
      if (dataT[j] == dataS[i]) {
        count++;
        break;
      }
    }
  }
  cout << count << "\\n";

  return 0;
}


#include <iostream>
using namespace std;

int LinearSearch(int n, int q, int S[], int T) {
  int i = 0;
  S[n] = T;
  while (S[i] != T)
    i++;

  return i != n;
}
int main() {

  int S[100000], T, n, q, i, c = 0;

  cin >> n;
  for (i = 0; i < n; i++)
    cin >> S[i];
  cin >> q;

  for (i = 0; i < q; i++) {
    cin >> T;

    if (LinearSearch(n, q, S, T))
      c++;
  }

  cout << c << endl;
}

#include <iostream>
using namespace std;

int binarySearch(int n, int q, int S[], int flag) {
  int left = 0;
  int right = n;
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (S[mid] == flag)
      return 1;
    else if (S[mid] > flag)
      right = mid;
    else if (S[mid] < flag)
      left = mid + 1;
  }
  return 0;
}
int main() {

  int S[100000], T, n, q, i, c = 0;

  cin >> n;
  for (i = 0; i < n; i++)
    cin >> S[i];
  cin >> q;

  for (i = 0; i < q; i++) {
    cin >> T;

    if (binarySearch(n, q, S, T))
      c++;
  }

  cout << c << endl;
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int n, q;
ll int data[100000];

bool mybinary_serach(int l, int r, ll int tg) { // left,right,target
  if (l == r)
    return false;
  int nowpos = (l + r) / 2;
  if (data[nowpos] == tg)
    return true;
  else if (data[nowpos] > tg)
    return mybinary_serach(l, nowpos, tg);
  else if (data[nowpos] < tg)
    return mybinary_serach(nowpos, r, tg);
}
int main() {
  ll int cnt = 0;
  cin >> n;
  REP(i, n) cin >> data[i];
  sort(data, data + n);
  cin >> q;
  REP(i, q) {
    ll int tmp;
    cin >> tmp;
    if (mybinary_serach(0, n, tmp))
      cnt++;
  }
  cout << cnt << endl;
}

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  // q=50000????????§????????????????????¨????????????
  // C++??????binary_search??¨?????????????????¢??°?????????
  // b2.cpp??§??????????????°??????????????????????£?
  int n, q;
  ll int cnt = 0;
  cin >> n;
  ll int data[100000];
  REP(i, n) cin >> data[i];
  sort(data, data + n);
  cin >> q;
  REP(i, q) {
    ll int tmp;
    cin >> tmp;
    if (binary_search(data, data + n, tmp))
      cnt++;
  }
  cout << cnt << endl;
}


#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int n, q, nk = 0, goukei = 0;
  cin >> n;
  int s[100000], t[50000];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < q; i++) {
    int right = n - 1, left = 0;
    ;
    while (left < right) {
      nk = right + left + 1;
      nk /= 2;
      /*if (nk == k) {
              cout << "ohmy" << endl;
              break;
      }*/
      if (s[nk] > t[i]) {
        right = nk;
      } else if (s[nk] == t[i]) {
        goukei++; /* cout << t[i] << " " << goukei<<endl;*/
        break;
      } else {
        left = nk;
      } // cout << left << "  " << right <<" "<<nk<< endl;
      int lk = left, rk = right;
    }
  }
  cout << goukei << endl;
  return 0;
}

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int n, q, nk = 0, goukei = 0;
  cin >> n;
  int s[100000], t[50000];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (s[i] == s[i - 1]) {
      i--;
      n--;
    }
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < q; i++) {
    int right = n - 1, left = 0, count = 0;
    while (left < right) {
      nk = right + left + count % 2 * 2;
      ;
      nk /= 2;

      if (s[nk] > t[i]) {
        if (right == nk) {
          count++;
          if (count == 2) {
            break;
          }
        } else {
          count = 0;
        }
        right = nk;
      } else if (s[nk] == t[i]) {
        goukei++;
        break;
      } else {
        if (left == nk) {
          count++;
          if (count == 2) {
            break;
          }
        } else {
          count = 0;
        }
        left = nk;
      }
    }
  }
  cout << goukei + 1 << endl;
  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int s[10000];
int main() {
  int n;
  scanf("%d", &n);
  rep(i, n) scanf("%d", &s[i]);
  int q;
  scanf("%d", &q);
  int cnt = 0;
  rep(i, q) {
    int t;
    scanf("%d", &t);
    if (binary_search(s, s + n, t))
      cnt++;
  }
  printf("%d\\n", cnt);
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int s[100000];
int main() {
  int n;
  scanf("%d", &n);
  rep(i, n) scanf("%d", &s[i]);
  int q;
  scanf("%d", &q);
  int cnt = 0;
  rep(i, q) {
    int t;
    scanf("%d", &t);
    if (binary_search(s, s + n, t))
      cnt++;
  }
  printf("%d\\n", cnt);
}


#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  const int MAX = 10000;
  int n, m, a[MAX], b, cnt = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> b;
    if (binary_search(a, a + n, b))
      cnt++;
  }
  cout << cnt << endl;
}

#include <algorithm>
#include <iostream>
using namespace std;

int main() {

  int n, m, cnt = 0;
  cin >> n;
  int a[n];

  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  sort(a, a + n);

  cin >> m;
  for (int i = 0; i < m; i++) {
    int v;
    scanf("%d", &v);
    if (binary_search(a, a + n, v))
      cnt++;
  }
  cout << cnt << endl;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++)
    scanf("%d", &a[i]);
  int Q;
  cin >> Q;
  int b[Q];
  for (int i = 0; i < Q; i++)
    scanf("%d", &b[i]);
  bool c[Q];
  for (int i = 0; i < Q; i++)
    c[i] = false;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < Q; j++) {
      if (a[i] == b[j] && !c[j])
        c[j] = true, ans++;
    }
  }
  printf("%d\\n", ans);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {

  int N;
  cin >> N;
  int a[N]; // sorted
  for (int i = 0; i < N; i++)
    scanf("%d", &a[i]);
  int Q;
  cin >> Q;
  int ans = 0;
  while (Q--) {
    int b;
    cin >> b;
    int l = 0, r = N;
    while (r - l > 1) {
      int m = (l + r) / 2;
      if (a[m] <= b) {
        l = m;
      } else {
        r = m;
      }
    }
    if (a[l] == b)
      ans++; // lower_bound
  }

  printf("%d\\n", ans);
  return 0;
}


#include <iostream>
#include <stdlib.h>
using namespace std;

bool binary_search(int *seq, int n, int key) {
  int left = 0, right = n, mid;
  int flag = false;
  while (left < right) {
    mid = (left + right) / 2;
    if (seq[mid] == key)
      flag = true;
    else if (seq[mid] > key)
      right = mid;
    else
      left = mid + 1;
  }
  return flag;
}

int main() {
  int seq[10000];
  int n;
  cin >> n;
  int i = 0;
  for (i; i < n; i++) {
    cin >> seq[i];
  }

  int q;
  cin >> q;

  int num = 0;
  int key = 0;
  for (i = 0; i < q; i++) {
    cin >> key;
    if (binary_search(seq, n, key))
      num += 1;
  }

  cout << num << endl;
  //	system("pause");
  return 0;
}

#include <iostream>
#include <stdlib.h>
using namespace std;

bool binary_search(int *seq, int n, int key) {
  int left = 0, right = n, mid;
  int flag = false;
  while (left < right) {
    mid = (left + right) / 2;
    if (seq[mid] == key) {
      flag = true;
      break;
    } else if (seq[mid] > key)
      right = mid;
    else
      left = mid + 1;
  }
  return flag;
}

int main() {
  int seq[100000];
  int n;
  cin >> n;
  int i = 0;
  for (i; i < n; i++) {
    cin >> seq[i];
  }

  int q;
  cin >> q;

  int num = 0;
  int key = 0;
  for (i = 0; i < q; i++) {
    cin >> key;
    if (binary_search(seq, n, key))
      num += 1;
  }

  cout << num << endl;
  //	system("pause");
  return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

void solve() {
  int n, q, a[100000], b[50000], i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> b[i];
  }
  int r, l;
  int ans = 0;
  for (i = 0; i < q; i++) {
    r = 0;
    l = n - 1;
    if (b[i] == a[0])
      ans++;
    else {
      while (l - r > 1) {
        int m;
        if ((l + r) % 2 == 1)
          m = (l + r + 1) / 2;
        else
          m = (l + r) / 2;
        if (a[m] >= b[i])
          l = a[m];
        else
          r = a[m];
      }
      if (b[i] == a[l])
        ans++;
    }
  }
  cout << ans;
}

int main() {
  solve();
  return 0;
}

#include <algorithm>
#include <iostream>

using namespace std;

void solve() {
  int n, q, a[100000], b[50000], i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> b[i];
  }
  int r, l;
  int ans = 0;
  for (i = 0; i < q; i++) {
    r = 0;
    l = n - 1;
    if (b[i] == a[0])
      ans++;
    else {
      while (l - r > 1) {
        int m;
        if ((l + r) % 2 == 1)
          m = (l + r + 1) / 2;
        else
          m = (l + r) / 2;
        if (a[m] >= b[i])
          l = m;
        else
          r = m;
      }
      if (b[i] == a[l])
        ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


#include <cstdio>
using namespace std;
int S[1000000], n;
int serch(int key) {
  int left = 0, right, mid;
  right = n;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == S[mid])
      return 1;
    if (key > S[mid])
      left = mid;
    else if (key < S[mid])
      right = mid;
  }
  return 0;
}
int main() {
  int q, key;
  int i, sum = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (serch(key))
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}

#include <cstdio>
using namespace std;
int S[1000000], n;
int serch(int key) {
  int left = 0, right, mid;
  right = n;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == S[mid])
      return 1;
    if (key > S[mid])
      left = mid + 1;
    else if (key < S[mid])
      right = mid;
  }
  return 0;
}
int main() {
  int q, key;
  int i, sum = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (serch(key))
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}


#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

bool BinarySerach(const vector<int> &S, int &key) {
  int start = 0;
  int end = S.size() - 1;
  int middle;

  while (1) {
    middle = ceil((end - start) / 2.) + start;
    if (S[middle] == key) {
      return true;
    } else if (start == end) {
      return false;
    } else if (S[middle] < key) {
      start = middle + 1;
    } else if (S[middle] > key) {
      end = middle;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, q;
  vector<int> S;

  cin >> n;
  S.resize(n);

  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  int count = 0;
  for (int i = 0; i < q; i++) {
    int key;
    cin >> key;
    if (BinarySerach(S, key)) {
      count++;
      //			cout << "key:" << key << endl;
    }
  }
  cout << count << endl;
}

#include <iostream>
#include <vector>

using namespace std;

bool BinarySerach(const vector<int> &S, int &key) {
  int start = 0;
  int end = S.size() - 1;
  int middle;

  while (1) {
    middle = (end - start) / 2 + start;
    if (S[middle] == key) {
      return true;
    } else if (start == end) {
      return false;
    } else if (S[middle] < key) {
      start = middle + 1;
    } else if (S[middle] > key) {
      end = middle;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, q;
  vector<int> S;

  cin >> n;
  S.resize(n);

  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  int count = 0;
  for (int i = 0; i < q; i++) {
    int key;
    cin >> key;
    if (BinarySerach(S, key)) {
      count++;
      //			cout << "key:" << key << endl;
    }
  }
  cout << count << endl;
}


#include <math.h>
#include <stdio.h>
#include <string.h>

int main() {
  long i, j;
  long n;
  long q;
  long cnt = 0;
  static long S[100001];
  static long T[50001];

  scanf("%ld", &n);
  for (i = 0; i < n; i++) {
    scanf("%ld", &S[i]);
  }

  scanf("%ld", &q);
  for (i = 0; i < q; i++) {
    scanf("%ld", &T[i]);
  }

  for (i = 0; i < q; i++) {
    for (j = 0; j < n; j++) {
      if (T[i] == S[j]) {
        cnt++;
        break;
      }
    }
  }

  printf("%ld\\n", cnt);

  return 0;
}

#include <math.h>
#include <stdio.h>
#include <string.h>

int main() {
  long i, j;
  long n;
  long q;
  long cnt = 0;
  long h;
  long left, right, mid;
  static long S[100001];
  static long T[50001];

  scanf("%ld", &n);
  for (i = 0; i < n; i++) {
    scanf("%ld", &S[i]);
  }

  scanf("%ld", &q);
  for (i = 0; i < q; i++) {
    scanf("%ld", &T[i]);
  }

  for (i = 0; i < q; i++) {
    left = 0;
    right = n;
    while (left < right) {
      mid = (left + right) / 2;
      if (S[mid] > T[i])
        right = mid;
      else if (T[i] > S[mid])
        left = mid + 1;
      else {
        cnt++;
        break;
      }
    }
  }
  printf("%ld\\n", cnt);

  return 0;
}