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

#include <iostream>
using namespace std;

int LSearch(int A[], unsigned int q, int x) {
  A[q] = x;
  for (int i = 0;; i++) {
    if (A[i] == x)
      if (i != q)
        return 0;
      else
        return -1;
  }
}
int main() {
  unsigned int n, q;
  unsigned int counter = 0;
  int S[10000000], T;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> T;
    if (LSearch(S, n, T) == 0)
      counter++;
  }
  cout << counter << endl;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int LSearch(int A[], unsigned int q, int x) {
  A[q] = x;
  for (int i = 0;; i++) {
    if (A[i] == x)
      if (i != q)
        return 0;
      else
        return -1;
  }
}
int main() {
  unsigned int n, q;
  unsigned int counter = 0;
  int S[1000000000], T;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> T;
    if (LSearch(S, n, T) == 0)
      counter++;
  }
  cout << counter << endl;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

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

// 番兵により比較回数の削減
int isin_Lsearch(std::vector<int> A, int n, int key) {
  int i = 0;
  A.push_back(key);
  while (A[i] != key)
    i++;
  return i != n;
}

int main(int argc, char const *argv[]) {
  int n, tmp, key, cnt = 0;
  std::cin >> n;

  std::vector<int> S;
  S.reserve(10001);

  for (size_t i = 0; i < n; i++) {
    std::cin >> tmp;
    S.push_back(tmp);
  }

  int q;
  std::cin >> q;

  for (size_t i = 0; i < q; i++) {
    std::cin >> key;
    if (isin_Lsearch(S, n, key))
      cnt++;
  }

  std::cout << cnt << '\\n';

  return 0;
}


Error: -11

Fixed submission:

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

// 番兵により比較回数の削減
int isin_Lsearch(std::vector<int> S, int n, int key) {
  int i = 0;
  S[n] = key;
  while (S[i] != key)
    i++;
  return i != n;
}

int main(int argc, char const *argv[]) {
  int n, key, cnt = 0;
  std::cin >> n;

  std::vector<int> S;
  S.reserve(10001);

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

  int q;
  std::cin >> q;

  for (size_t i = 0; i < q; i++) {
    std::cin >> key;
    if (isin_Lsearch(S, n, key))
      cnt++;
  }

  std::cout << cnt << '\\n';

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

#include <algorithm>
#include <cstdio>
#include <vector>

#define rep(i, N) for (int i = 0; i < N; ++i)

using namespace std;

bool linerSearch(vector<int> vec, int key) {
  auto itr = std::find(vec.begin(), vec.end(), key);
  size_t index = std::distance(vec.begin(), itr);
  return index != vec.size();
}

int main() {
  int n, q, key;
  scanf("%d", &n);
  vector<int> S(n);
  rep(i, n) scanf("%d", &S[i]);

  int ans = 0;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d", &key);
    if (linerSearch(S, key))
      ++ans;
  }

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


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>

#define rep(i, N) for (int i = 0; i < N; ++i)

using namespace std;

bool linerSearch(vector<int> vec, int key) {
  for (int &v : vec)
    if (v == key)
      return true;
  return false;
}

int main() {
  int n, q, key;
  scanf("%d", &n);
  vector<int> S(n);
  rep(i, n) scanf("%d", &S[i]);

  int ans = 0;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d", &key);
    if (linerSearch(S, key))
      ++ans;
  }

  printf("%d\\n", ans);
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>

int s[10000];

int main() {
  int n;
  int q;
  int cnt = 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 t;
    scanf("%d", &t);
    for (int i2 = 0; i2 < n; ++i2) {
      if (t == s[i2]) {
        ++cnt;
        break;
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <stdio.h>

int s[10000];

int main() {
  int n;
  int q;
  int cnt = 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 t;
    scanf("%d", &t);
    for (int i2 = 0; i2 < n; ++i) {
      if (t == s[i2]) {
        ++cnt;
        break;
      }
    }
  }

  printf("%d", cnt);
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;
int Check(int ni, vector<int> Li, int inh) {
  Li.resize(ni + 1);
  Li[ni] = inh;
  int ih = 0;
  while (Li[ih] != inh) {
    ih++;
  }
  if (ih == ni) {
    return -1;
  } else {
    return ih;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> L(n);

  int count = 0;
  for (int i = 0; i < n; ++i) {
    cin >> L[i];
  }
  int q;
  cin >> q;
  while (q > 0) {
    q--;
    int l;
    cin >> l;

    if (Check(n, L, l) != -1) {

      ++count;
    } else {
    }
  }

  cout << count << endl;
}


Error: -11

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
int Check(vector<int> Li, int inh) {
  int n = Li.size();
  Li.push_back(inh);
  int i = 0;
  while (Li[i] != inh) {
    i++;
  }
  if (i == n) {
    return 0;
  } else {
    return i;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> L;
  cout << n;
  int count = 0;
  for (int i = 0; i < n; ++i) {
    cin >> L[i];
  }
  int q;
  cin >> q;
  for (int j = 0; j < q; ++q) {
    int l;
    cin >> l;
    if (Check(L, l) != 0) {
      ++count;
    }
  }

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

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> s;
  int s_done[10000] = {0}, t_done[500] = {0};
  for (int i = 0; i < n; i++) {
    int kari;
    cin >> kari;
    if (s_done[kari] == 0) {
      s_done[kari] = 1;
      s.push_back(kari);
    }
  }
  int q;
  cin >> q;
  vector<int> t;
  for (int i = 0; i < q; i++) {
    int kari;
    cin >> kari;
    if (t_done[kari] == 0) {
      t_done[kari] = 1;
      t.push_back(kari);
    }
  }
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i] == t[j]) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int linear(int a[], int key, int n);
int main() {
  int i, j, n, q, c = 0;
  int s[100000], t[100000];

  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 < q; i++) {
    c = c + linear(s, t[i], n);
  }
  cout << c << endl;
}
int linear(int a[], int key, int n) {
  int i = 0;
  a[n] = key;
  while (a[i] != key) {
    i++;
  }
  if (i >= n) {
    return 0;
  } else {
    return 1;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int linear(int a[], int key, int n);
int main() {
  int i, j, n, q, c = 0;
  int s[1000], t[1000];

  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 < q; i++) {
    c = c + linear(s, t[i], n);
  }
  cout << c << endl;
}
int linear(int a[], int key, int n) {
  int i = 0;
  a[n] = key;
  while (a[i] != key) {
    i++;
  }
  if (i >= n) {
    return 0;
  } else {
    return 1;
  }
}
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>
using namespace std;

int main() {
  int n, q, S[10010], T[510], 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) {
    for (int j = 0; j < n; ++j) {
      if (T[i] == S[j]) {
        ++C;
        break;
      }
    }
  }

  cout << C << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

  cout << C << endl;

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

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> s;
  for (int i = 0; i < n; ++i) {
    int ss;
    cin >> ss;
    s.push_back(ss);
  }
  int q;
  cin >> q;
  int count{0};
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (find(begin(s), end(s), t) != end(s)) {
      ++count;
    }
  }
  cout << count << endl;
}

Error: 0

Fixed submission:

#include <bitset>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  bitset<100000> b;
  for (int i = 0; i < n; ++i) {
    int s;
    cin >> s;
    b[s] = true;
  }
  int q;
  cin >> q;
  int count{0};
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (b[t]) {
      ++count;
    }
  }
  cout << count << endl;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  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];
  }
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  int ans = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (t[i] == s[j]) {
        ans++;
        i++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  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];
  }
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  int ans = 0, p = 0;
  for (int i = 0; i < n; i++) {
    if (t[p] == s[i]) {
      ans++;
      p++;
    } else if (t[p] < s[i]) {
      p++;
      i--;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  bool c = false;
  int n, q, ans = 0;
  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }
  cin >> q;
  vector<int> T(q);
  for (int i = 0; i < q; i++) {
    cin >> T.at(i);
  }
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (T.at(i) == S.at(j))
        c = true;
    }
    if (c)
      ans++;
    c = false;
  }
  cout << ans << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {
  bool c = false;
  int n, q, ans;
  vector<int> S, T;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }
  cin >> q;
  for (int i = 0; i < n; i++) {
    cin >> T.at(i);
  }
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (T.at(i) == S.at(j))
        c = true;
    }
    if (c)
      ans++;
  }
  cout << ans;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
using namespace std;

int linearSearch(int A[], int n, int key) {
  int i = 0;
  A[n] = key; //???????¨????
  while (A[i] != key)
    i++;
  return i != n;
}

int main() {
  int n, q;
  int S[10000 + 1], T;
  int i, j, same = 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", &T);
    if (linearSearch(S, n, T))
      same++;
  }

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

Error: 0

Fixed submission:

#include <cstdio>
using namespace std;

int main() {
  int n, q;
  int S[10000], T[100];
  int i, j, same = 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", &T[i]);
  }

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

  printf("%d\\n", same);
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define pout(n) printf("%d\\n", n)

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};

#define MAX_N (int)2e5 + 20
#define INF 1e12 + 20

typedef long long ll;
using namespace std;

int n, m, b, j;
int main() {
  cin >> n;

  int a[n];
  rep(i, 0, n) { cin >> a[i]; }
  cin >> m;
  int cnt = 0;
  rep(i, 0, m) {
    cin >> b;
    a[n] = b;
    for (j = 0; a[j] != b; j++)
      ;
    if (j != n)
      cnt++;
  }
  pout(cnt);
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>

#define pout(n) printf("%d\\n", n)

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};

#define MAX_N (int)2e5 + 20
#define INF 1e12 + 20

typedef long long ll;
using namespace std;

int n, m, b, j;
int main() {
  cin >> n;
  int a[n];

  rep(i, 0, n) { cin >> a[i]; }
  cin >> m;
  int cnt = 0;
  rep(i, 0, m) {
    cin >> b;
    a[n] = b;
    for (j = 0; a[j] != j; j++)
      ;
    if (j != n)
      cnt++;
  }
  pout(cnt);
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

  int n;
  cin >> n;
  int mx = 0;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mx = max(mx, v[i]);
  }
  sort(v.begin(), v.end());

  int q;
  cin >> q;
  int key;
  int cnt = 0;
  for (int i = 0; i < q; i++) {
    cin >> key;
    if (key > mx)
      continue;
    else {
      auto it = lower_bound(v.begin(), v.end(), key);
      if (*it == key)
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int n;
bool my_search(int key, vector<int> v) {
  int up = n;
  int down = 0;
  while (down < up) {
    int mid = (up + down) / 2;
    if (v[mid] > key) {
      up = mid;
    } else if (v[mid] == key) {
      return 1;
    } else {
      down = mid + 1;
    }
  }
  cerr << 1 << endl;
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());

  int q;
  cin >> q;
  int t;
  int cnt = 0;
  for (int i = 0; i < q; i++) {
    cin >> t;
    if (my_search(t, v)) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02267 (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 CLR(a) memset((a), 0, sizeof(a))
#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;

const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};
const double EPS = 1e-10;
const double PI = acos(-1.0);

int liner_Search(vector<int> s, vector<int> t) {
  int res = 0;
  REP(i, (int)t.size()) {
    for (int s : s) {
      if (s == t[i]) {
        res++;
        break;
      }
    }
  }

  return res;
}

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

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

  int q;
  cin >> q;
  // vector<int> t;
  int count = 0;
  REP(_, q) {
    int num;
    cin >> num;
    REP(i, n) {
      if (s[i] == num) {
        count++;
        break;
      }
    }
  }

  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 CLR(a) memset((a), 0, sizeof(a))
#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;

const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};
const double EPS = 1e-10;
const double PI = acos(-1.0);

int liner_Search(vector<int> s, vector<int> t) {
  int res = 0;
  REP(i, (int)t.size()) {
    for (int s : s) {
      if (s == t[i]) {
        res++;
        break;
      }
    }
  }

  return res;
}

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

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

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

  cout << liner_Search(s, t) << endl;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int S[10000];

int main() {

  int n, q;
  int tmp;
  int count = 0;

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

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

  cout << count << "\\n";

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int S[10000];

int main() {

  int n, q;
  int min, max, mid;
  int tmp;
  int count;

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

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

  cout << count + "\\n";

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

#include <stdio.h>

#define rep(i, n) for (i = 0; i < n; i++)
#define size 100000

int main() {
  int n, s[size], q, t[size];
  int i, j, k;
  int count = 0;

  scanf("%d", &n);
  rep(i, n) scanf("%d", &s[i]);
  scanf("%d", &q);
  rep(i, q) scanf("%d", &t[i]);

  rep(i, q) {
    rep(j, n) {
      if (s[j] == t[i]) {
        count++;
        break;
      }
    }
  }
  printf("%d\\n", count);
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

#define rep(i, n) for (i = 0; i < n; i++)

int main() {
  int n, s[1000000000], q, t[1000000000];
  int i, j, k;
  int count = 0;

  scanf("%d", &n);
  rep(i, n) scanf("%d", &s[i]);
  scanf("%d", &q);
  rep(i, q) scanf("%d", &t[i]);

  rep(i, q) {
    rep(j, n) {
      if (s[j] == t[i]) {
        count++;
        break;
      }
    }
  }
  printf("%d\\n", count);
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

#define N 10000

int check(int);
int i, j, n, q, S[N], T[N], count = 0;

int main() {

  scanf("%d", &n);

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

  scanf("%d", &q);

  for (j = 0; j < q; j++) {
    scanf("%d", &T[j]);
    for (i = 0; i < n; i++) {
      if (S[i] == T[j]) {
        count++;
        break;
      }
    }
  }

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

  return 0;
}

Error: -11

Fixed submission:

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

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

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

  printf("%d\\n", count);
  return 0;
}
Problem p02267 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

  C = 0;
  for (i = 0; i < q; i++) {
    j = 0;
    S[n] = T[i];
    while (S[j] != S[n])
      j++;
    if (j < n)
      C++;
  }
  cout << C << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

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

  C = 0;
  for (i = 0; i < q; i++) {
    j = 0;
    S[n] = T[i];
    while (S[j] != S[n])
      j++;
    if (j < n)
      C++;
  }
  cout << C << endl;

  return 0;
}