alexjercan/bugnet huggingface dataset:
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

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

int main() {
  int A[10000 + 10], key, q, n;
  int sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> A[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> key;
    if (searcher(A, n, key))
      sum++;
  }
  cout << sum << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

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

int main() {
  int A[1000 + 1], key, q, n;
  int sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> A[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> key;
    if (searcher(A, n, key))
      sum++;
  }
  cout << sum << endl;
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int linearSearch(int S[], int T[], int n, int q) {
  int k = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (T[i] == S[j]) {
        k++;
        break;
      }
    }
  }
  return k;
}

int main() {
  int n, q;
  int S[10000], T[500];
  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]);
  }
  printf("%d\\n", linearSearch(S, T, n, q));
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int linearSearch(int S[], int T[], int n, int q) {
  int k = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (T[i] == S[j]) {
        k++;
        break;
      }
    }
  }
  return k;
}

int main() {
  int n, q;
  int S[10000], T[500];
  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]);
  }
  printf("%d\\n", linearSearch(S, T, n, q));
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

#define ms(a, x) memset(a, x, sizeof(a))
using namespace std;

typedef long long ll;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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 i, n, a[100001], q, key, ans = 0;

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

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> key;
    if (search(a, n, key))
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>

#define ms(a, x) memset(a, x, sizeof(a))
using namespace std;

typedef long long ll;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
ll a[100000010];
int main() {
  int n, q, x;

  int ans = 0;
  cin >> n;
  ms(a, 0);
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[x] = 1;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> x;
    if (a[x] == 1) {
      a[x] -= 1;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n2;
  int n1, S[100000];
  int T[100000], sum = 0;
  cin >> n1;

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

  cin >> n2;
  for (int i = 0; i < n2; i++) {
    int y = max(n1, n2);
    cin >> T[i];
    for (int j = 0; j < y; j++) {
      if (T[i] == S[j]) {
        sum++;
        break;
      }
    }
  }

  cout << sum << endl;

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n2;
  int n1, S[100000000];
  int T[100000000], sum = 0;
  cin >> n1;

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

  cin >> n2;
  for (int i = 0; i < n2; i++) {
    int y = min(n1, n2);
    cin >> T[i];
    for (int j = 0; j < y; j++) {
      if (T[i] == S[j]) {
        sum++;
        break;
      }
    }
  }

  cout << sum << endl;
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main(void) {
  int S[10005], T[505], n, q;

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

    int count = 0;

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

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
using namespace std;

int a[10005], b[505];
int a1[10005], b1[505];

int main() {
  int n, q, x = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a1[a[i]]++;
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &b[i]);
    b1[b[i]]++;
  }
  for (int i = 0; i < n; i++) {
    if (b1[a[i]])
      x++;
  }
  printf("%d\\n", x);
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
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 i, n, A[10000 + 1], q, key, 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", &key);
    if (search(A, n, key))
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
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 i, n, A[10000 + 1], q, key, 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", &key);
    if (search(A, n, key))
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
using namespace std;
long long int N[10001] = {};
int main() {

  int n, q;

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

  // sort(N,N+1000000);

  int c = 0, w[50001] = {};
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> y;
    for (int j = 0; j < n; j++)
      if (N[j] == y) {
        c++;
        break;
      }
  }
  cout << c << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
long long int N[100001] = {};
int main() {

  int n, q;

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

  // sort(N,N+1000000);

  int c = 0, w[50001] = {};
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> y;
    if (N[y] > 0)
      c++;
  }
  cout << c << endl;

  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, p;
  int s[1000000];
  int t[1000000];
  int i, j;
  int c = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> p;
  for (i = 0; i < p; i++) {
    cin >> t[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < p; j++) {
      if (s[i] == t[j]) {
        t[j] = -1;
        c++;
      }
    }
  }
  cout << c << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, p;
  int s[1000];
  int t[1000];
  int i, j;
  int c = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  cin >> p;
  for (i = 0; i < p; i++) {
    cin >> t[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < p; j++) {
      if (s[i] == t[j]) {
        t[j] = -1;
        c++;
      }
    }
  }
  cout << c << endl;
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>

typedef long long int lli;
lli s[20000], t[2000];

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

  std::sort(s, s + n);
  std::sort(t, t + q);

  lli *ps = s, *pt = t;
  int res = 0;
  while (ps < s + n && pt < t + q) {
    if (*ps == *pt)
      res++, ps++, pt++;
    else if (*ps < *pt)
      ps++;
    else
      pt++;
  }
  printf("%d\\n", res);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>

typedef long long int lli;
lli s[20000], t[2000];

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

  std::sort(s, s + n);
  std::sort(t, t + q);

  lli *ps = s, *pt = t;
  int res = 0;
  while (ps < s + n, pt < t + q) {
    if (*ps == *pt)
      res++, ps++, pt++;
    else if (*ps < *pt)
      ps++;
    else
      pt++;
  }
  printf("%d\\n", res);

  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main(void) {
  int n, q;
  cin >> n;
  int s[n];

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

  cin >> q;
  int t[q];

  for (int i = 0; i < q; i++) {
    cin >> t[i];
  }
  int count = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (t[i] == s[j]) {
        count++;
        break;
      } else
        continue;
    }
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

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

int main(void) {
  int n, q;
  cin >> n;
  int s[n];

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

  for (int i = 0; i < q; i++) {
    cin >> t[i];
  }
  sort(s, s + n);
  int count = 0;
  for (int i = 0; i < q; i++) {
    int low = 0;
    int high = n - 1;
    while (low <= high) {
      int mid = low + high / 2;
      if (t[i] == s[mid]) {
        count++;
        break;
      } else if (t[i] > s[mid]) {
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
  }
  cout << count << endl;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

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

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

int linearSearch(int *array, int n, int key) {
  *(array + n) = key;
  int i = 0;
  while (array[i] != key) {
    i++;
  }
  return i == n ? -1 : i;
}

int main(int argc, const char *argv[]) {
  int n = 0;
  int S[10000 + 1] = {0};
  int q = 0;
  int sum = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", S + i);
  }

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int key = 0;
    scanf("%d", &key);
    if (-1 != linearSearch(S, n, key)) {
      sum++;
    }
  }
  printf("%d\\n", sum);

  return 0;
}


Error: 0

Fixed submission:

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

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

int linearSearch(int *array, int n, int key) {
  *(array + n) = key;
  int i = 0;
  while (array[i] != key) {
    i++;
  }
  return i == n ? -1 : i;
}

int main(int argc, const char *argv[]) {
  int n = 0;
  int S[10 ^ 5] = {0};
  int q = 0;
  int sum = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", S + i);
  }

  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int key = 0;
    scanf("%d", &key);
    if (-1 != linearSearch(S, n, key)) {
      sum++;
    }
  }
  printf("%d\\n", sum);

  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int a[10001], b[10001], sum = 0;
  int n, z;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> z;
    a[i] = z;
  }
  int m, x;
  cin >> m;
  for (int j = 0; j < m; j++) {
    cin >> x;
    b[j] = x;
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        sum++;
        break;
      }
    }
  }

  cout << sum << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[1000000001] = {0}, sum = 0;
  int n, z;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> z;
    a[z] = 1;
  }
  int m, x;
  cin >> m;
  for (int j = 0; j < m; j++) {
    cin >> x;
    if (a[x] == 1)
      sum++;
  }
  cout << sum << endl;
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

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

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

  int count = 0;
  for (int i = 0; i < q; ++i) {
    for (int j = 0; j < n; j++) {
      if (T[i] == S[j]) {
        count++;
        break;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Error: -11

Fixed submission:

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

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

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < q; j++) {
      if (S[i] == T[j]) {
        count++;
        break;
      }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, q, s[10000], t[500];
  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 count = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (s[j] == t[i]) {
        count++;
        break;
      }
    }
  }
  printf("%d\\n", count);
}


Error: -11

Fixed submission:

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

int main() {
  int n, q, s[10000], tmp;
  scanf("%d", n);
  for (int i = 0; i < n; i++)
    scanf("%d", s + i);
  scanf("%d", q);
  int count = 0;
  for (int i = 0; i < q; i++) {
    scanf("%d", &tmp);
    for (int j = 0; j < n; j++) {
      if (s[j] == tmp) {
        count++;
        break;
      }
    }
  }
  printf("%d\\n", count);
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

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 i, n, A[10000 + 1], q, key, 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", &key);
    if (search(A, n, key))
      sum++;
  }
  printf("%d\\n", sum);

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>

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 i, n, A[1000 + 1], q, key, 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", &key);
    if (search(A, n, key))
      sum++;
  }
  printf("%d\\n", sum);

  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

  return result;
}

int main() {
  int S[10000], T[1000];
  int n, q, result;

  cin >> n;

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

  cin >> q;

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

  result = Linear_Search(S, T, n, q);

  cout << result << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

  return result;
}

int main() {
  int S[1000], T[1000];
  int n, q, result;

  cin >> n;

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

  cin >> q;

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

  result = Linear_Search(S, T, n, q);

  cout << result << endl;

  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

#define MAX 100000

using namespace std;

int collisionSearch(int *array, int key, int num) {

  int i;

  for (i = 0; i < num; i++) {
    if (array[i] == key) {
      return -1;
    }
  }

  return 0;
}

int main() {

  int i;
  int j;
  int k;
  int n;
  int q;
  int S[MAX];
  int T[MAX];
  int alr[MAX];
  int cnt = 0;
  int flag = 0;
  int temp;

  cin >> n;

  i = 0;
  // origin array
  while (i != n) {
    cin >> temp;
    if (collisionSearch(S, temp, i) != 0) {
      n--;
      continue;
    }
    S[i] = temp;
    i++;
  }

  cin >> q;

  i = 0;
  // cmp array
  while (i != q) {
    cin >> temp;
    if (collisionSearch(T, temp, i) != 0) {
      q--;
      continue;
    }
    T[i] = temp;
    i++;
  }

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

  cout << cnt << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>

#define MAX 10000000

using namespace std;

int main() {

  int i;
  int j;
  int n;
  int q;
  int S[MAX];
  int T[MAX];
  int cnt = 0;

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

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

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

  cout << cnt << endl;

  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

int main(int argc, char *argv[]) {
  vector<int> S;
  int q = 0;
  int t = 0;
  int C = 0;
  int n = 0;
  int s = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    S.push_back(s);
  }
  sort(S.begin(), S.end());

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> s;
    int start = 0;
    int end = S.size();
    while (start < end) {
      // cout << start <<" "<< end << "\\n";
      if (S[(int)((end + start) / 2)] < s) {
        start = (int)((end + start) / 2) + 1;
      } else if (S[(int)((end + start) / 2)] > s) {
        end = (int)((end + start) / 2);
      } else {
        C++;
        break;
      }
    }
  }
  cout << C << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
#define NMAX 10000
int main(int argc, char *argv[]) {
  int n_max = 10000;
  int answer = 0;
  int S[NMAX] = {0};
  int n = 0;
  int q = 0;
  int ns = 0;
  int qs = 0;
  cin >> n;

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

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> qs;
    if (S[qs] == 1) {
      answer++;
    }
  }

  cout << answer << "\\n";
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;

std::vector<std::string> &split(const std::string &s, char delim,
                                std::vector<std::string> &elems) {
  std::stringstream ss(s);
  std::string item;
  while (std::getline(ss, item, delim)) {
    elems.push_back(item);
  }
  return elems;
}

std::vector<std::string> split(const std::string &s, char delim) {
  std::vector<std::string> elems;
  split(s, delim, elems);
  return elems;
}

int _stoi(string s) { return atoi(s.c_str()); }

int popValue(stack<int> *S) {
  int retVal = S->top();
  S->pop();
  return retVal;
}

int main(int argc, const char *argv[]) {
  vector<int> S;
  vector<int> T;
  string s;
  int n = -1;
  int q = -1;
  while (cin >> s) {
    if (n == -1) {
      n = _stoi(s);
    } else if (n > 0) {
      n--;
      S.push_back(_stoi(s));
    } else if (q == -1) {
      q = _stoi(s);
    } else if (q > 0) {
      q--;
      T.push_back(_stoi(s));
    }
  }

  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  int j = 0;
  int total = 0;
  for (int i = 0; i < T.size(); i++) {
    int t = T[i];
    while (j < S.size() && S[j] <= t) {
      if (S[j] == t) {
        total++;
        break;
      }
      j++;
    }
  }

  cout << total << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;

std::vector<std::string> &split(const std::string &s, char delim,
                                std::vector<std::string> &elems) {
  std::stringstream ss(s);
  std::string item;
  while (std::getline(ss, item, delim)) {
    elems.push_back(item);
  }
  return elems;
}

std::vector<std::string> split(const std::string &s, char delim) {
  std::vector<std::string> elems;
  split(s, delim, elems);
  return elems;
}

int _stoi(string s) { return atoi(s.c_str()); }

int popValue(stack<int> *S) {
  int retVal = S->top();
  S->pop();
  return retVal;
}

int main(int argc, const char *argv[]) {
  vector<int> S;
  vector<int> T;
  string s;
  int n = -1;
  int q = -1;
  while (cin >> s) {
    if (n == -1) {
      n = _stoi(s);
    } else if (n > 0) {
      n--;
      S.push_back(_stoi(s));
    } else if (q == -1) {
      q = _stoi(s);
    } else if (q > 0) {
      q--;
      T.push_back(_stoi(s));
    }
  }

  sort(S.begin(), S.end());
  sort(T.begin(), T.end());
  int j = 0;
  int total = 0;
  for (int i = 0; i < T.size(); i++) {
    int t = T[i];
    while (j < S.size()) {
      if (S[j] < t) {
        j++;
      } else if (S[j] == t) {
        total++;
        j++;
        break;
      }
    }
  }

  cout << total << endl;

  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

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 A[10000 + 1], n, i, q, sum = 0, key;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    if (search(A, n, key))
      sum++;
  }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

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 A[10000 + 1], n, i, q, sum = 0, key;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    while (search(A, n, key))
      sum++;
  }

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

  return 0;
}