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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> P;

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int y;
string ans = "No";

int main() { // TODO
  int x;
  cin >> x >> y;
  for (int i = 0; i <= x; i++) {
    if ((i * 2) + ((x - i) * 4) == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> P;

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int y;
string ans = "No";

void dfs(int xi, int yi) {
  if (xi == 0) {
    if (y == yi)
      ans = "Yes";
    return;
  }
  dfs(xi - 1, yi + 4);
  dfs(xi - 1, yi + 2);
}

int main() { // TODO
  int x;
  cin >> x >> y;
  dfs(x, 0);
  cout << ans << endl;

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

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

int main() {
  int X, N, pi;
  cin >> X >> N;
  set<int> S;
  for (int i = 0; i < N; i++) {
    cin >> pi;
    S.insert(pi);
  }

  for (int i = 0; i < 100; i++) {
    if (!S.count(X - i)) {
      cout << X - i << endl;
      break;
    }
    if (!S.count(X + i)) {
      cout << X + i << endl;
      break;
    }
  }
}

Error: 0

Fixed submission:

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

int main() {
  int X, N, pi;
  cin >> X >> N;
  vector<int> suuretu(100);
  for (int i = 0; i < 100; i++) {
    suuretu.at(i) = i;
  }
  for (int i = 0; i < N; i++) {
    cin >> pi;
    suuretu.at(pi) = 0;
  }
  bool ok = true;
  int z = 1;
  int ans = 0;
  /*
   for(int x : suuretu){
   cout << x << endl;
   }
  */
  if (N == 0 or suuretu.at(X) != 0) {
    ans = X;
    ok = false;
  }
  while (ok) {
    if (!(X - z < 0)) {
      if (suuretu.at(X - z) != 0) {
        ans = suuretu.at(X - z);
        ok = false;
        break;
      }
    }
    if (!(X + z > 100)) {
      if (suuretu.at(X + z) != 0) {
        ans = suuretu.at(X + z);
        ok = false;
        break;
      }
    }
    z++;
  }
  cout << ans << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int x, n;
vector<int> vec;

int test(int i, int j) {
  // int a = find(vec.begin(), vec.end(), i);
  // int b = find(vec.begin(), vec.end(), j);
  if (find(vec.begin(), vec.end(), j) == vec.end()) {
    return j;
  } else if (find(vec.begin(), vec.end(), i) == vec.end()) {
    return i;
  } else {
    i++;
    j--;
    return test(i, j);
  }
}
int main() {
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    vec.push_back(s);
  }

  cout << test(x, x) << endl;
  ;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int x, n;
vector<int> vec;

int test(int i, int j) {
  // int a = find(vec.begin(), vec.end(), i);
  // int b = find(vec.begin(), vec.end(), j);
  if (find(vec.begin(), vec.end(), j) == vec.end()) {
    return j;
  } else if (find(vec.begin(), vec.end(), i) == vec.end()) {
    return i;
  } else {
    i++;
    j--;
    test(i, j);
  }
}
int main() {
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    vec.push_back(s);
  }
  cout << test(x, x) << endl;
  ;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++)
    cin >> p.at(i);

  vector<int> x(102);
  for (int i = 0; i < 102; i++)
    x.at(i) = i;

  for (int i = 0; i < N; i++)
    x.erase(remove(x.begin(), x.end(), p.at(i)), x.end());

  vector<int> sa(x.size());
  for (int i = 0; i < x.size(); i++)
    sa.at(i) = abs(X - x.at(i));

  sort(sa.begin(), sa.end());

  int a = 0;
  for (int i = 0; i < x.size(); i++) {
    if (x.at(i) == X - sa.at(0)) {
      cout << x.at(i) << endl;
      a = 1;
      break;
    }
  }
  if (a == 0)
    cout << X + sa.at(0) << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int X, N;
  cin >> X >> N;

  vector<int> p(N);
  for (int i = 0; i < N; i++)
    cin >> p.at(i);

  vector<int> x(100);
  for (int i = 0; i < 100; i++)
    x.at(i) = i + 1;

  for (int i = 0; i < N; i++)
    x.erase(remove(x.begin(), x.end(), p.at(i)), x.end());
  vector<int> sa(x.size());
  for (int i = 0; i < x.size(); i++)
    sa.at(i) = abs(X - x.at(i));
  sort(sa.begin(), sa.end());
  int a = 0;
  for (int i = 0; i < x.size(); i++) {
    if (x.at(i) == X - sa.at(0)) {
      cout << x.at(i) << endl;
      a = 1;
      break;
    }
  }
  if (a == 0)
    cout << X + sa.at(0) << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int x, n, ans = -1;
  cin >> x >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ans = x;
  if (n > 0) {
    int mx = *max_element(arr.begin(), arr.end());
    int mn = *min_element(arr.begin(), arr.end());
    int p[100];
    int count = 0;
    for (int i = mn - 1; i <= mx + 1; i++) {
      if (find(arr.begin(), arr.end(), i) == arr.end()) {
        p[count++] = i;
      }
    }
    int d = abs(x - p[0]);
    ans = p[0];
    for (int i = 1; i < count; i++) {
      if (d > abs(x - p[i])) {
        d = abs(x - p[i]);
        ans = p[i];
      }
    }
  }
  cout << ans << "\\n";
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int x, n, ans = -1;
  cin >> x >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ans = x;
  if (n > 0) {
    int mx = *max_element(arr.begin(), arr.end());
    int mn = *min_element(arr.begin(), arr.end());
    vector<int> p;
    int count = 0;
    for (int i = mn; i <= mx; i++) {
      if (find(arr.begin(), arr.end(), i) == arr.end()) {
        p.push_back(i);
        count++;
      }
    }
    int d = abs(x - p[0]);
    ans = p[0];
    for (int i = 1; i < count; i++) {
      if (d > abs(x - p[i])) {
        d = abs(x - p[i]);
        ans = p[i];
      }
    }
  }
  cout << ans << "\\n";
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int x, n, ans, a, b;
  cin >> x >> n;
  if (n == 0) {
    ans = x;
  } else {
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
      cin >> p.at(i);
    }
    for (int i = x; i <= 101; i++) {
      int h = 0;
      for (int j = 0; j < n; j++) {
        if (p.at(j) == i) {
          h = 1;
          break;
        }
      }
      if (h == 0) {
        a = i;
        break;
      }
    }
    for (int i = x; i >= -100; i--) {
      int h = 0;
      for (int j = 0; j < n; j++) {
        if (p.at(j) == i) {
          h = 1;
          break;
        }
      }
      if (h == 0) {
        b = i;
        break;
      }
    }
    if (a - x >= x - b)
      ans = b;
    else
      ans = a;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int x, n, ans;
  bool finished = false;
  cin >> x >> n;
  vector<int> a(n);
  if (n != 0) {
    for (int i = 0; i < n; i++) {
      cin >> a.at(i);
    }
    for (int i = 0; i < 100; i++) {
      auto itr = a.begin();
      for (;;) {
        itr = find(itr, a.end(), x - i);
        if (itr == a.end()) {
          ans = x - i;
          finished = true;
          break;
        }
      }
      for (;;) {
        itr = find(itr, a.end(), x + i);
        if (itr == a.end()) {
          ans = x + i;
          finished = true;
          break;
        }
      }
      if (finished) {
        break;
      }
    }
  } else {
    ans = x;
  }
  cout << ans << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n;
  cin >> x >> n;
  int p;
  int b[401] = {0};
  for (int i = 0; i < n; i++) {
    cin >> p;
    b[p + 100]++;
  }
  if (n == 0)
    cout << x << endl;
  else {
    int pr = x + 100;
    int aag = x + 100;
    while (1) {
      if (b[pr] != 0 && b[aag] == 0) {
        cout << aag - 100 << endl;
        break;
      } else if (b[pr] == 0 && b[aag] != 0) {
        cout << pr - 100 << endl;
        break;
      } else if ((b[pr] == 1 && b[aag] == 1)) {
        pr--;
        aag++;
      } else if (b[pr] == 0 && b[aag] == 0) {
        cout << pr - 100 << endl;
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n;
  cin >> x >> n;
  int p;
  int b[101] = {0};
  for (int i = 0; i < n; i++) {
    cin >> p;
    b[p]++;
  }
  if (n == 0)
    cout << x << endl;
  else {
    int pr = x;
    int aag = x;
    while (1) {
      if (b[pr] != 0 && b[aag] == 0) {
        cout << aag << endl;
        break;
      } else if (b[pr] == 0 && b[aag] != 0) {
        cout << pr << endl;
        break;
      } else if ((b[pr] == 1 && b[aag] == 1)) {
        pr--;
        aag++;
      } else if (b[pr] == 0 && b[aag] == 0) {
        cout << pr << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
using namespace std;

void forbidden_list(vector<int> v, int x);
int main() {
  int x, n;
  vector<int> v;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    v.push_back(l);
  }
  forbidden_list(v, x);

  return 0;
}

void forbidden_list(vector<int> v, int x) {
  auto it = find(v.begin(), v.end(), x);
  if (it == v.end())
    cout << x << endl;

  else {
    int min = 100;
    vector<pair<int, int>> p;
    for (int i = 0; i <= 101; i++) {

      auto it = find(v.begin(), v.end(), i);
      if (it == v.end()) {
        int ab = abs(x - i);

        if (ab < min) {
          min = ab;
          p.push_back(make_pair(min, i));
        }
      } else
        v.erase(it);
    }

    sort(p.begin(), p.end());
    auto it = p.begin();
    cout << it->second << endl;
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
using namespace std;

void forbidden_list(vector<int> v, int x);
int main() {
  int x, n;
  vector<int> v;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    v.push_back(l);
  }
  forbidden_list(v, x);

  return 0;
}

void forbidden_list(vector<int> v, int x) {
  auto it = find(v.begin(), v.end(), x);
  if (it == v.end())
    cout << x << endl;

  else {
    int min = 100;
    vector<pair<int, int>> p;
    for (int i = 1; i < 100; i++) {

      auto it = find(v.begin(), v.end(), i);
      if (it == v.end()) {
        int ab = abs(x - i);

        if (ab < min) {
          min = ab;
          p.push_back(make_pair(min, i));
        }
      } else
        v.erase(it);
    }

    sort(p.begin(), p.end());
    auto it = p.begin();
    cout << it->second << endl;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> p(N);
  int now;
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  int len = max(X, 100 - X);
  int checks = 0;
  int checkl = 0;
  for (int i = 0; i < len + 1; i++) {
    checks = 0;
    checkl = 0;
    for (int j = 0; j < N; j++) {
      if (X - i == p.at(j)) {
        checks = 1;
      }
      if (X + i == p.at(j)) {
        checkl = 1;
      }
    }
    if (checks == 0) {
      X = X - i;
      break;
    }
    if (checks != 0 && checkl == 0) {
      X = X + i;
      break;
    }
  }
  cout << X << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int X, N;
  cin >> X >> N;

  bool easy = true;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
    if (p.at(i) == X)
      easy = false;
  }
  int a, b;

  if (easy)
    cout << X << endl;
  else {
    for (int i = 1; i < 110; i++) {
      a = 0, b = 0;
      for (int j = 0; j < N; j++) {
        if (p.at(j) == X - i) {
          a = 1;
        }
        if (p.at(i) == X + i) {
          b = 1;
        }
      }
      if (a == 0) {
        cout << X - i << endl;
        a = 2;
        break;
      }
      if (b == 0) {
        cout << X + i << endl;
        b = 2;
        break;
      }
    }
  }
  if (a != 2 && b != 2) {
    if (X <= 50)
      cout << 0 << endl;
    else
      cout << 101 << endl;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  // your code goes here
  int x, n; // a+b=x;2*a + 4*b=y;
  cin >> x >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  set<int> st;
  for (int i = 0; i < n; i++)
    st.insert(a[i]);
  int dif = 0;
  while (1) {
    if (st.find(x - dif) == st.end()) {
      cout << x - dif << endl;
      break;
    }
    if (st.find(x + dif) == st.end()) {
      cout << x + dif << endl;
      break;
    }
    dif++;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  // your code goes here
  int x, n; // a+b=x;2*a + 4*b=y;
  cin >> x >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  set<int> st;
  for (int i = 0; i < n; i++)
    st.insert(a[i]);
  int dif = 0;
  while (1) {
    if (st.find(x - dif) == st.end()) {
      cout << x - dif << endl;
      break;
    }
    if (st.find(x + dif) == st.end()) {
      cout << x + dif << endl;
      break;
    }
  }
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int X, N;
  cin >> X >> N;

  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }

  int diff = 1000;
  int ans = X;
  for (int x = 0; x <= 101; x++) {
    bool flag = false;

    for (int i = 0; i < N; i++) {
      if (x == p.at(i)) {
        flag = true;
        break;
      }
    }
    if (flag)
      continue;

    int new_diff = abs(x - X);
    if (diff > new_diff) {
      diff = new_diff;
      ans = x;
    }
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  // 初期化
  int X = 0;
  int N = 0;
  cin >> X >> N;
  if (N == 0) {
    cout << X << endl;
    return 0;
  }

  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
    p.at(i) = p.at(i) - X;
  }

  // p-Xが小さい順に並べ替え
  sort(p.begin(), p.end());

  // p-Xがマイナスとプラスで分けて考える
  int X_ele = 0;
  for (int i = 0; i < N; i++) {
    if (p.at(i) > 0) {
      X_ele = i;
      break;
    }
  }

  // Xより小さい整数で答えを求める
  int ans1 = X;
  for (int i = X_ele; i >= 0; i--) {
    if (i == 0) {
      ans1 = p.at(0) - 1 + X;
      break;
    }
    if (p.at(i) - p.at(i - 1) > 1) {
      ans1 = p.at(i) - 1 + X;
      break;
    }
  }

  // Xより大きい整数で答えを求める
  int ans2 = X;
  for (int i = X_ele; i < N; i++) {
    if (i == N) {
      ans2 = p.at(N) + 1 + X;
      break;
    }
    if (p.at(i + 1) - p.at(i) > 1) {
      ans2 = p.at(i) + 1 + X;
      break;
    }
  }

  // より差が小さい方を答えとする。
  // 差が同じ場合は値が小さい方を採用
  if (ans1 == X && ans2 == X) {
    cout << X << endl;
  } else if (ans1 != X && ans2 != X) {
    if (abs(ans1 - X) > abs(ans2 - X)) {
      cout << ans2 << endl;
    } else {
      cout << ans1 << endl;
    }
  } else if (ans1 == X && ans2 != X) {
    cout << ans2 << endl;
  } else {
    cout << ans1 << endl;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll X, N;
  vector<ll> v(101, 0);

  cin >> X >> N;
  for (ll i = 0; i < N; i++) {
    ll x;
    cin >> x;
    v[x]++;
  }

  if (v[X] == 0)
    cout << X << endl;

  else {
    ll j = X, k = X;
    while (1) {
      j--;
      if (v[j] == 0 && j >= 0) {
        cout << j << endl;
        return 0;
      } else if (j < 0) {
        cout << j << endl;
        return 0;
      }
      k++;
      if (v[k] == 0 && k <= 100) {
        cout << k << endl;
        return 0;
      } else if (k > 100) {
        cout << k << endl;
        return 0;
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll X, N;
  vector<ll> v(101, 0);

  cin >> X >> N;
  for (ll i = 0; i < N; i++) {
    ll x;
    cin >> x;
    v[x]++;
  }

  if (v[X] == 0)
    cout << X << endl;

  else {
    ll j = X, k = X;
    while (1) {
      j--;
      if (v[j] == 0 && j >= 1) {
        cout << j << endl;
        return 0;
      }
      k++;
      if (v[k] == 0 && k <= 100) {
        cout << k << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int a, x, n;
  cin >> x >> n;
  unordered_map<int, int> p;
  for (int i = 0; i < n; i++) {
    cin >> a;
    p[a] = 1;
  }
  for (int d = 0; d <= x; d++) {
    if (!p[x - d]) {
      cout << x - d << '\\n';
      break;
    } else if (!p[x + d]) {
      cout << x + d << '\\n';
      break;
    }
  }
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, x, n;
  cin >> x >> n;
  bool p[101] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a;
    p[a] = 1;
  }
  int d = 0;
  while (p[max(1, x - d)] || p[min(100, x + d)])
    d++;
  if (p[max(1, x - d)])
    cout << min(100, x + d) << endl;
  else
    cout << max(1, x - d) << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rb(a, b, c) for (int a = b; a <= c; ++a)
#define rl(a, b, c) for (int a = b; a >= c; --a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a, b) make_pair(a, b)
#define FIR first
#define SEC second
#define FREO freopen("check.out", "w", stdout)
#define rep(a, b) for (int a = 0; a < b; ++a)
#define KEEP while (1)
#define SRAND                                                                  \\
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng() % a
#define ALL(a) a.begin(), a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr << A.FIR << " " << A.SEC << endl;
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> mp;
typedef pair<mp, mp> superpair;
int ap[101];
int main() {
  fastio;
  int x, n;
  cin >> x >> n;
  rb(i, 1, n) {
    int ai;
    cin >> ai;
    ap[ai] = 1;
  }
  int l = x, r = x;
  while (1) {
    if (!ap[l]) {
      cout << l << endl;
      return 0;
    }
    if (!ap[r]) {
      cout << r << endl;
      return 0;
    }
    l--;
    r++;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x, n;
  cin >> x >> n;
  int a[102], b, l = x, r = x;
  for (int i = 0; i <= 100; i++)
    a[i] = 0;
  for (int i = 0; i < n; i++) {
    cin >> b;
    a[b] = 1;
  }
  while (true) {
    if (a[l] == 0 && l > 0) {
      cout << l;
      break;
    }
    if (a[r] == 0 && r < 101) {
      cout << r;
      break;
    }
    l--;
    r++;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int x, n, o;
  cin >> x >> n;
  vector<int> v;
  if (n == 0) {
    cout << x << endl;
  } else if (n == 100) {
    int z = x;
    if (z > 50) {
      cout << 101 << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    for (int p = -200; p < 301; p++) {
      v.push_back(p);
    }
    for (int i = 0; i < n; i++) {
      int y;
      cin >> y;
      vector<int>::iterator e = remove(v.begin(), v.end(), y);
    }
    for (int i = 0; i < n; i++) {
      v.pop_back();
    }
    int a = 300, b, c;
    for (int i = 0; i < 500 - n; i++) {
      b = v.at(i);
      c = abs(x - b);
      if (a > c) {
        o = v.at(i);
      }
      a = c;
    }
    cout << o << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int x, n, o;
  cin >> x >> n;
  vector<int> v;
  if (n == 0) {
    cout << x << endl;
  } else {
    for (int p = 1; p < 101; p++) {
      v.push_back(p);
    }
    for (int i = 0; i < n; i++) {
      int y;
      cin >> y;
      vector<int>::iterator e = remove(v.begin(), v.end(), y);
    }
    for (int i = 0; i < 5; i++) {
      v.pop_back();
    }
    int a = 200, b, c;
    for (int i = 0; i < 100 - n; i++) {
      b = v.at(i);
      c = abs(x - b);
      if (a > c) {
        o = v.at(i);
      }
      a = c;
    }
    cout << o << endl;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int X, N;
  vector<int> p;
  vector<pair<int, int>> q;
  cin >> X >> N;
  int y;
  rep(i, N) {
    cin >> y;
    p.push_back(y);
  }
  for (int i = 0; i <= 101; i++) {
    auto result = find(p.begin(), p.end(), i);
    if (result == p.end()) {
      q.push_back(make_pair((X - i) * (X - i), i));
    }
  }
  sort(q.begin(), q.end());
  cout << q[0].second << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int X, N;
  vector<int> p;
  vector<pair<int, int>> q;
  cin >> X >> N;
  int y;
  rep(i, N) {
    cin >> y;
    p.push_back(y);
  }
  for (int i = 1; i <= 100; i++) {
    auto result = find(p.begin(), p.end(), i);
    if (result == p.end()) {
      q.push_back(make_pair((X - i) * (X - i), i));
    }
  }
  sort(q.begin(), q.end());
  cout << q[0].second << endl;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, s, e) for (int64_t i = s; i < e; i++)
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int X, N, i = 0;
  cin >> X >> N;
  vector<int> p(N);
  rep(i, 0, N) { cin >> p[i]; }
  while (true) {
    int A = X - i, B = X + i;
    bool a = true, b = true;
    rep(i, 0, N) {
      if (A == p[i]) {
        a = false;
      }
    }
    if (a) {
      cout << A << endl;
      return 0;
    }
    rep(i, 0, N) {
      if (B == p[i]) {
        b = false;
      }
    }
    if (b) {
      cout << B << endl;
      return 0;
    }
    i++;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, s, e) for (int64_t i = s; i < e; i++)
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int X, N, i = 0;
  cin >> X >> N;
  vector<int> p(N);
  rep(i, 0, N) { cin >> p[i]; }
  while (true) {
    int A = X - i, B = X + i;
    bool a = true, b = true;
    rep(i, 0, N) {
      if (A == p[i]) {
        a = false;
      }
    }
    if (a) {
      cout << A << endl;
    }
    rep(i, 0, N) {
      if (B == p[i]) {
        b = false;
      }
    }
    if (b) {
      cout << B << endl;
    }
    i++;
  }
}