alexjercan/bugnet huggingface dataset:
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}


Error: TLE

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: 0

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
 * 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;
}


Error: TLE

Fixed submission:

/*
 * 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;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}


Error: TLE

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

//
//  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;
}


Error: 0

Fixed submission:

//
//  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;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}


Error: TLE

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}


Error: TLE

Fixed submission:

#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;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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);
}

Error: TLE

Fixed submission:

#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);
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#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;
}

Error: TLE

Fixed submission:

#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;
}