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

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n, q;
  long long S[1000000], T;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> S[i];
  cin >> q;

  int count = 0;

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


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

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

  int count = 0;

  for (int j = 0; j < q; j++) {
    cin >> T;
    int left = 0;
    int right = n;
    int mid = (left + right) / 2;
    while (left < right) {
      mid = (left + right) / 2;
      if (T == S[mid]) {
        count++;
        break;
      }
      if (T > S[mid]) {
        left = mid + 1;
      } else if (T < S[mid]) {
        right = mid;
      }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, A[100000];
  cin >> n;
  int *pos;
  int sum = 0;

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

  int a, B[50000];
  cin >> a;

  for (int i = 0; i < a; i++) {
    cin >> B[i];
    pos = lower_bound(A, A + n, B[i]);
    if (*pos == B[i]) {
      sum++;
    }
  }

  cout << sum << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n, A[100];
  cin >> n;
  int *pos;
  int sum = 0;

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

  int a, B[100];
  cin >> a;

  for (int i = 0; i < a; i++) {
    cin >> B[i];
    pos = lower_bound(A, A + n, B[i]);
    if (*pos == B[i]) {
      sum++;
    }
  }

  cout << sum << endl;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

class IntVector : public std::vector<int> {
public:
  void Input(int Count);
  bool Search(int Target) const;
};

void IntVector::Input(int Count) {
  for (int i = 0; i < Count; i++) {
    int Input;
    std::cin >> Input;
    push_back(Input);
  }
}

bool IntVector::Search(int Target) const {
  int left = 0;
  int right = size() - 1;
  int i = 0;
  while (left <= right) {
    i = left + (right - left) / 2;
    if (at(i) == Target)
      return true;
    if (at(i) < Target) {
      left = i + 1;
    } else {
      right = i - 1;
    }
  }
  return false;
}

int main() {
  int n = 0;
  std::cin >> n;
  IntVector S;
  S.Input(n);
  int q = 0;
  std::cin >> q;
  int Count = 0;
  for (int i = 0; i < q; i++) {
    int T;
    std::cin >> T;
    Count += S.Search(T);
  }

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

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

class IntVector : public std::vector<int> {
public:
  void Input(int Count);
  bool Search(int Target) const;
};

void IntVector::Input(int Count) {
  for (int i = 0; i < Count; i++) {
    int Input;
    std::cin >> Input;
    push_back(Input);
  }
}

bool IntVector::Search(int Target) const {
  int left = 0;
  int right = size() - 1;
  int i = left + (right - left) / 2;
  while (left < right) {
    if (at(i) == Target)
      return true;
    if (at(i) < Target) {
      left = i;
    } else {
      right = i;
    }
    i = left + (right - left) / 2;
  }
  return false;
}

int main() {
  int n = 0;
  std::cin >> n;
  IntVector S;
  S.Input(n);
  int q = 0;
  std::cin >> q;
  int Count = 0;
  for (int i = 0; i < q; i++) {
    int T;
    std::cin >> T;
    Count += S.Search(T);
  }

  std::cout << Count << std::endl;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

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

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

  int cnt = 0;

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

    int left = 0;
    int right = n;
    int mid = (right + left) / 2;

    while (left < right) {
      if (T > S[mid]) {
        left = mid + 1;
      } else if (T < S[mid]) {
        right = mid;
      } else {
        ++cnt;
        break;
      }
      mid = (right + left) / 2;
    }
  }

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

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

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

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

  int cnt = 0;

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

    int left = 0;
    int right = n - 1;
    int mid = right - left;

    while (1) {
      if (T > S[mid]) {
        if (mid + 1 > n - 1) {
          break;
        }
        left = mid + 1;
      } else if (T < S[mid]) {
        if (mid - 1 < 0) {
          break;
        }
        right = mid - 1;
      } else {
        ++cnt;
        break;
      }
      mid = right - left;
    }
  }

  cout << cnt << endl;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, q;

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

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

  cout << count << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, q;

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

  int count = 0;
  for (int j = 0; j < q; j++) {
    int left = 0;
    int right = n;
    while (left < right) {
      int mid = (left + right) / 2;
      if (S[mid] == T[j]) {
        count += 1;
      } else if (T[j] < S[mid]) {
        right = mid;
      } else {
        left = mid + 1;
      }
    }
  }

  cout << count << endl;

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
int NS;
int S[MAX_N];
int NT;
int T[MAX_N];

// not the most left
int binarySearch(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 mid;
    } else if (key < A[mid]) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return -1;
}

int main() {

  cin >> NS;
  rep(i, NS) { cin >> S[i]; }
  cin >> NT;
  rep(i, NT) { cin >> T[i]; }

  int ret = 0;
  rep(i, NT) {
    if (binarySearch(S, NS, T[i]) >= 0)
      ret++;
  }
  cout << ret << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
int NS;
int S[MAX_N];
int NT;
int T[MAX_N];

// not the most left
int binarySearch(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 mid;
    } else if (key < A[mid]) {
      right = mid;
    } else {
      left = mid;
    }
  }
  return -1;
}

int main() {

  cin >> NS;
  rep(i, NS) { cin >> S[i]; }
  cin >> NT;
  rep(i, NT) { cin >> T[i]; }

  int ret = 0;
  rep(i, NT) {
    if (binarySearch(S, NS, T[i]) >= 0)
      ret++;
  }
  cout << ret << endl;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int binarySearch(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 (A[mid] < key)
      left = mid + 1;
    else
      right = mid;
  }
  return 0;
}

int main() {
  int i, n, A[100000 + 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 (binarySearch(A, n, key))
      sum++;
  }
  printf("%d\\n", sum);

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

int binarySearch(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 (A[mid] < key)
      left = mid + 1;
    else
      right = mid;
  }
  return 0;
}

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 (binarySearch(A, n, key))
      sum++;
  }
  printf("%d\\n", sum);

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

#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];
  }
  int count = 0;
  for (int i = 0; i < q; i++) {
    int low = 0;
    int high = n;
    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;
}


Error: TLE

Fixed submission:

#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];
  }
  int count = 0;
  for (int i = 0; i < q; i++) {
    int low = 0;
    int high = n;
    int mid = (low + high) / 2;
    while (low <= high) {
      if (t[i] == s[mid]) {
        count++;
      } else if (t[i] > s[mid]) {
        low = mid + 1;
      } else {
        high = mid - 1;
      }
      int mid = (low + high) / 2;
    }
  }
  cout << count << endl;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

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

int main() {
  int n, q, count = 0;

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

  std::cin >> q;
  int T[q];
  for (int i = 0; i < q; i++) {
    std::cin >> T[i];
    if (binarySearch(T[i], S, n))
      count++;
  }

  /*	int flag=0,search,searchF,searchE;
    for(int k=0;k<q;k++){
          flag=0;
          search=n/2;
          searchF=0;
          searchE=n-1;
          */
  /*
  while(flag==0){

          if(S[searchF]==S[searchE]){
                  flag=1;
          }
          if(S[search]==T[k]){
                  count++;
                  break;

          }else if(S[search]>T[k]){
                  searchE=search-1;
                  search=(searchF+searchE)/2;
          }else{
                  searchF=search+1;
                  search=(searchF+searchE)/2;
          }

  }


}
  */
  std::cout << count << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
int main() {
  int n, q, count = 0;

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

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

  int flag = 0, search, searchF, searchE;
  for (int k = 0; k < q; k++) {
    flag = 0;
    search = n / 2;
    searchF = 0;
    searchE = n - 1;
    while (flag == 0) {

      if (S[searchF] == S[searchE]) {
        flag = 1;
      }
      if (S[search] == T[k]) {
        count++;
        break;

      } else if (S[search] > T[k]) {
        searchE = search - 1;
        search = (searchF + searchE) / 2;
      } else {
        searchF = search + 1;
        search = (searchF + searchE) / 2;
      }
    }
  }
  std::cout << count << "\\n";
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

int A[100000];

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

int main() {
  int n, q, key;
  int cnt = 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);
    if (search(key, n))
      cnt++;
  }
  printf("%d\\n", cnt);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

int A[100000];

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

int main() {
  int n, q, key;
  int cnt = 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);
    if (search(key, n))
      cnt++;
  }
  printf("%d\\n", cnt);
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int s[100100];
int linesearch(int a[], int n, int key) {
  for (int i = 0; i < n; i++) {
    if (a[i] == key)
      return 1;
  }
  return false;
}

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

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int linesearch(int a[], int n, int key) {
  for (int i = 0; i < n; i++) {
    if (a[i] == key)
      return 1;
  }
  return false;
}

int main() {
  int n, q, t, sum = 0;
  int s[10100];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i];
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> t;
    sum += linesearch(s, n, t);
  }
  cout << sum << endl;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

bool binary_search(vector<int> v, int kay, bool is_sorted) {
  if (!is_sorted)
    sort(ALL(v));

  int left = 0;
  int right = SZ(v);
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (v[mid] == kay)
      return true;
    else if (kay < v[mid])
      right = mid;
    else
      left = mid + 1;
  }
  return false;
}

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

  int n;
  cin >> n;

  vector<int> v;
  int t;
  REP(_, n) {
    cin >> t;
    v.PB(t);
  }

  cin >> n;
  int count = 0;
  REP(_, n) {
    cin >> t;
    if (binary_search(v, t, true))
      count++;
  }

  cout << count << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

using namespace std;

bool binary_search(vector<int> v, int kay, bool is_sorted) {
  if (is_sorted)
    sort(ALL(v));

  int left = 0;
  int right = SZ(v);
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (v[mid] == kay)
      return true;
    else if (kay < v[mid])
      right = mid;
    else
      left = mid + 1;
  }
  return false;
}

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

  int n;
  cin >> n;

  vector<int> v;
  int t;
  REP(_, n) {
    cin >> t;
    v.PB(t);
  }

  cin >> n;
  int count = 0;
  REP(_, n) {
    cin >> t;
    if (binary_search(v, t, true))
      count++;
  }

  cout << count << endl;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int x[100100], y[50010], z[150110];
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &x[i]);
  int a = unique(x, x + n) - x;
  scanf("%d", &m);
  for (int i = 0; i < m; i++)
    scanf("%d", &y[i]);
  sort(y, y + m);
  int b = unique(y, y + m) - y;
  for (int i = 0; i < a; i++)
    z[i] = x[i];
  for (int i = a; i < a + b; i++)
    z[i] = y[i - a];
  sort(z, z + a + b);
  int t = unique(z, z + a + b) - z;
  printf("%d\\n", a + b - t);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int a[100000], b[100000], c[50000];
int main() {
  int n, m;
  while (scanf("%d", &n) != EOF) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      b[a[i]]++;
    }
    sort(a, a + n);

    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      scanf("%d", &c[i]);
      for (int j = 0; j <= a[n - 1]; j++)
        if (b[c[i]] != 0)
          b[c[i]] = -1;
    }
    sort(c, c + m);
    int sum = 0, y;
    if (a[n - 1] >= c[m - 1])
      y = a[n - 1];
    else
      y = c[m - 1];
    for (int i = 0; i <= y; i++) {
      if (b[i] == -1)
        sum++;
    }
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1e6 + 10;
int a[N], n;
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;
    if (key > a[mid])
      left = mid + 1;
    else if (key < a[mid])
      right = mid;
  }
  return 0;
}
int main() {
  int i, q, key, sum = 0;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> key;
    if (binarysearch(key))
      sum++;
  }
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>
int a[100010];
int b[100010];
int c[100010];
int d[100010];
int main() {
  int t, n;
  while (~scanf("%d", &t)) {
    memset(c, 0, sizeof(c));

    for (int i = 0; i < t; i++) {
      scanf("%d", &a[i]);
      c[a[i]]++;
    }
    scanf("%d", &n);
    int l = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &b[i]);
      if (c[b[i]] != 0)
        d[l++] = b[i];
    }
    printf("%d\\n", l);
  }
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int n, A[1000010];

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

int main() {
#ifdef LOCAL
  freopen("E:\\\\Temp\\\\input.txt", "r", stdin);
  freopen("E:\\\\Temp\\\\output.txt", "w", stdout);
#endif

  int i, 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 (binarySearch(key))
      ++sum;
  }
  printf("%d\\n", sum);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int a[10005], n;
int binarySearch(int key) {
  int left = 0, right = n;
  int mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == a[mid])
      return 1;
    if (key > a[mid])
      left = mid + 1;
    if (key < a[mid])
      right = mid;
  }
  return 0;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int q;
  scanf("%d", &q);
  int sum = 0;
  for (int i = 0; i < q; i++) {
    int jie;
    scanf("%d", &jie);
    if (binarySearch(jie))
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}