alexjercan/bugnet huggingface dataset:
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> A(N);
  vector<bool> answer(300);
  if (N != 0) {
    for (int i = 0; i < N; i++) {
      cin >> A.at(i);
      answer.at(101 + A.at(i) - 1) = true;
    }
    for (int i = 0; i < 104; i++) {
      if (answer.at(101 + X - i - 1) == false) {
        cout << X - i << endl;
        break;
      } else if (answer.at(101 + X + i - 1) == false) {
        cout << X + i << endl;
        break;
      }
    }
  } else
    cout << X << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int X, N;
  cin >> X >> N;
  vector<int> A(N);
  vector<bool> answer(103);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    answer.at(A.at(i) - 1) = true;
  }
  for (int i = 0; i < 104; i++) {
    if (answer.at(X - i - 1) == false) {
      cout << X - i << endl;
      break;
    } else if (answer.at(X + i - 1) == false) {
      cout << X + i << endl;
      break;
    }
  }
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int x, n, i, j;
  cin >> x;
  cin >> n;
  int p[n];

  if (n == 0) {
    cout << x << endl;
    return 0;
  }

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

  i = 0;
  while (1) {
    for (j = 0; j < n; j++) {
      if (p[j] == x + i) {
        j = 0;
        break;
      }
    }
    if (j != 0) {
      cout << x + i << endl;
      return 0;
    }
    if (i >= 0) {
      i = i * (-1) - 1;
    } else {
      i = i * (-1);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int x, n, i, j;
  cin >> x;
  cin >> n;
  int p[n];

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

  i = 0;
  while (1) {
    for (j = 0; j < n; j++) {
      if (p[j] == x + i) {
        j = 0;
        break;
      }
    }
    if (j != 0) {
      cout << x + i << endl;
      return 0;
    }
    if (i >= 0) {
      i = i * (-1) - 1;
    } else {
      i = i * (-1);
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
int x, n, a[105], t[105];
int main() {
  cin >> x >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i], t[a[i]] = 1;
  if (t[x] == 0) {
    cout << x;
    return 0;
  }
  int dis = 1;
  while (1) {
    if (x - dis == 0) {
      cout << 0;
      break;
    }
    if (x + dis == 101) {
      if (t[x - dis] == 0)
        cout << x - dis;
      else
        cout << 101;
      break;
    }
    if (t[x - dis] == 0) {
      cout << x - dis;
      break;
    }
    if (t[x + dis] == 0) {
      cout << x + dis;
      break;
    }
    dis++;
  }
}


Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
using namespace std;
#define N 100007
#define pb push_back;
vector<ll> v[N];
vector<bool> vs(N);
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

int main() {
  ll x, n, i;
  cin >> x >> n;
  vector<ll> v;
  map<ll, ll> mp;
  for (i = 0; i < n; i++) {
    ll y;
    cin >> y;
    mp[y]++;
  }
  for (i = 0; i <= 107; i++) {
    if (mp[i] == 0) {
      v.push_back(i);
    }
  }
  ll ind = lower_bound(v.begin(), v.end(), x) - v.begin();
  if (ind == 0) {
    cout << v[ind];
  } else {
    if (abs(x - v[ind]) >= abs(x - v[ind - 1])) {
      cout << v[ind - 1];
    } else {
      cout << v[ind];
    }
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
using namespace std;
#define N 100007
#define pb push_back;
vector<ll> v[N];
vector<bool> vs(N);
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

int main() {
  ll x, n, i;
  cin >> x >> n;
  vector<ll> v;
  map<ll, ll> mp;
  for (i = 0; i < n; i++) {
    ll y;
    cin >> y;
    mp[y]++;
  }
  for (i = 1; i <= 100; i++) {
    if (mp[i] == 0) {
      v.push_back(i);
    }
  }
  ll ind = lower_bound(v.begin(), v.end(), x) - v.begin();
  if (ind == 0) {
    cout << v[ind];
  } else {
    if (abs(x - v[ind]) >= abs(x - v[ind - 1])) {
      cout << v[ind - 1];
    } else {
      cout << v[ind];
    }
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

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

int main(void) {
  int X, N;
  cin >> X >> N;
  int check = 0;
  vector<int> list(100);

  rep(i, N) {
    cin >> check;
    list.at(check - 1) = 1;
    check = 0;
  }
  for (int j = 0; j < 500; j++) {
    if (X - j - 1 >= 0) {
      if (list.at(X - j - 1) != 1) {
        cout << X - j;
        break;
      }
    } else {
      cout << X - j;
      break;
    }

    if (X + j - 1 <= 99) {
      if (list.at(X + j - 1) != 1) {
        cout << X + j;
        break;
      }
    } else {
      cout << X + j;
      break;
    }
  }
}

Error: WA

Fixed submission:

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

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

int main(void) {
  int X, N;
  cin >> X >> N;
  int check = 0;
  vector<int> list(100);

  rep(i, N) {
    cin >> check;
    list.at(check - 1) = 1;
    check = 0;
  }
  for (int j = 0; j < 500; j++) {
    if (X - j - 1 >= 0) {
      if (list.at(X - j - 1) != 1) {
        cout << X - j;
        break;
      }
    } else {
      cout << X - j;
      break;
    }

    if (X + j - 1 <= 100) {
      if (list.at(X + j - 1) != 1) {
        cout << X + j;
        break;
      }
    } else {
      cout << X + j;
      break;
    }
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k, i, n) for (ll i = k; i < n; ++i)
#define push_back pb
int main(void) {
  // Your code here!
  ll x, n;
  cin >> x >> n;
  vector<ll> a(n);
  rep(0, i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  ll m = 1e9, ans, c = 0;
  rep(0, i, 110) {
    if (c < n && a[c] == i) {
      ++c;
      continue;
    }
    ll d = abs(i - x);
    if (d < m) {
      m = d;
      ans = i;
    }
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k, i, n) for (ll i = k; i < n; ++i)
#define push_back pb
int main(void) {
  // Your code here!
  ll x, n;
  cin >> x >> n;
  vector<ll> a(n);
  rep(0, i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  ll m = 1e9, ans, c = 0;
  rep(0, i, 110) {
    if (a[c] == i && c < n) {
      ++c;
      continue;
    }
    ll d = abs(i - x);
    if (d < m) {
      m = d;
      ans = i;
    }
  }
  cout << ans;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
/* start */

int was[110];

signed main() {
  IOS;
  int x, n;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    int it;
    cin >> it;
    was[it] = 1;
  }
  vector<pair<int, int>> ans;
  for (int i = 0; i < 10000; i++) {
    if (i < 110) {
      if (!was[i])
        ans.push_back({abs(i - x), i});
    } else
      ans.push_back({abs(i - x), i});
  }
  sort(ans.begin(), ans.end());
  cout << ans[0].second << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)
/* start */

int was[110];

signed main() {
  IOS;
  int x, n;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    int it;
    cin >> it;
    was[it] = 1;
  }
  vector<pair<int, int>> ans;
  for (int i = 1; i <= 100; i++) {
    if (!was[i])
      ans.push_back({abs(i - x), i});
  }
  sort(ans.begin(), ans.end());
  cout << ans[0].second << "\\n";
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int X, N, sub;
  cin >> X >> N;
  vector<int> a(N), b;
  map<int, int> m;
  if (N == 0)
    cout << X << endl;
  else {
    for (int i = 0; i < N; i++) {
      cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    bool finish = false;
    for (int i = 0; i < N; i++) {
      if (a.at(i) == X) {
        finish = true;
      }
    }
    if (!finish) {
      cout << X << endl;
      return 0;
    }
    int sub;
    for (int i = 0; i <= 101; i++) {
      bool judge = false;
      for (int j = 0; j < N; j++) {
        if (i == a.at(j)) {
          judge = true;
          break;
        }
      }
      if (!judge)
        b.push_back(i);
    }
    for (int i = 0; i < b.size(); i++) {
      sub = b.at(i) - X;
      if (sub < 0)
        sub = -1 * sub;
      if (m.count(sub))
        m[sub] = min(m[sub], b.at(i));
      else
        m[sub] = b.at(i);
    }
    for (auto p : m) {
      auto k = p.first;
      auto v = p.second;
      cout << v << endl;
      return 0;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> a(N);
  if (N == 0)
    cout << X << endl;
  else {
    for (int i = 0; i < N; i++) {
      cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    vector<int> b;
    for (int i = 0; i <= 101; i++) {
      for (int j = 0; j < a.size(); j++) {
        if (a.at(j) == i) {
          break;
        } else if (a.at(j) > i) {
          b.push_back(i);
          break;
        }
      }
    }
    int v;
    map<int, int> m;
    for (int i = 0; i < b.size(); i++) {
      v = X - b.at(i);
      if (v < 0)
        v = v * (-1);
      m[v] = b.at(i);
    }
    vector<int> c(4);
    int count = 0;
    for (auto p : m) {
      c[count] = p.first;
      c[count + 1] = p.second;
      count = count + 2;
    }
    if (c.at(0) == c.at(2)) {
      cout << min(c.at(1), c.at(3)) << endl;
    } else
      cout << c.at(1) << endl;
  }
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int X, N;
  std::cin >> X >> N;
  std::vector<int> P(N);
  int Distance = 0;
  int ans;
  for (auto &p : P) {
    std::cin >> p;
  }
  while (1) {
    auto itr1 = std::find(P.begin(), P.end(), X - Distance);
    auto itr2 = std::find(P.begin(), P.end(), X + Distance);
    if (itr1 == P.end()) {
      ans = X - Distance;
      break;
    } else if (itr2 == P.end()) {
      ans = X + Distance;
      break;
    }
    Distance++;
  }
  std::cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int X, N;
  std::cin >> X >> N;
  std::vector<int> P(N);
  int Distance = 0;
  int ans;
  for (auto &p : P) {
    std::cin >> p;
  }
  while (1) {
    auto itr1 = std::find(P.begin(), P.end(), X - Distance);
    auto itr2 = std::find(P.begin(), P.end(), X + Distance);
    if (itr1 == P.end()) {
      ans = X - Distance;
      break;
    } else if (itr2 == P.end()) {
      ans = X + Distance;
      break;
    }
    Distance;
  }
  std::cout << ans;
  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;
  if (N == 0) {
    cout << X;
  } else {
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
      cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    bool check = false;
    int num = 0;
    for (int i = 0; i < N; i++) {
      if (p.at(i) == X) {
        check = true;
        num = i;
        break;
      }
    }
    if (!check) {
      cout << X;
    } else {
      if (num == 0) {
        cout << X - 1;
      } else if (num == N - 1) {
        if (p.at(N - 1) - p.at(N - 2) > 1) {
          cout << X - 1;
        } else {
          cout << X + 1;
        }
      } else {
        int small = p.at(0) - 1, large = p.at(N - 1) + 1;
        for (int i = num; i > 0; i--) {
          if (p.at(i) - p.at(i - 1) > 1) {
            small = p.at(i) - 1;
            break;
          }
        }
        for (int i = num; i < N - 1; i++) {
          if (p.at(i + 1) - p.at(i) > 1) {
            large = p.at(i) + 1;
            break;
          }
        }
        if (large - X < X - small) {
          cout << large;
        } else {
          cout << small;
        }
      }
    }
  }
}

Error: WA

Fixed submission:

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

int main() {
  int X, N;
  cin >> X >> N;
  if (N == 0) {
    cout << X;
  } else {
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
      cin >> p.at(i);
    }
    sort(p.begin(), p.end());
    if (p.at(N - 1) < X) {
      cout << X;
    } else if (X < p.at(0)) {
      cout << X;
    } else {
      int s = 0, l = N - 1;
      for (int i = 1; i < N - 1; i++) {
        if (p.at(i) <= X) {
          s = i;
        }
        if (p.at(i) >= X) {
          l = i;
          break;
        }
      }
      if (p.at(s) != X) {
        cout << X;
      } else {
        int small = p.at(0) - 1, large = p.at(N - 1) + 1;
        if (s == 0) {
          cout << X - 1;
        } else if (l == N - 1) {
          if (p.at(l) - p.at(l - 1) > 1) {
            cout << X - 1;
          } else {
            cout << X + 1;
          }
        } else {
          for (int i = s; i > 0; i--) {
            if (p.at(i) - p.at(i - 1) > 1) {
              small = p.at(i) - 1;
              break;
            }
          }
          for (int i = l; l < N - 1; i++) {
            if (p.at(i + 1) - p.at(i) > 1) {
              large = p.at(i) + 1;
              break;
            }
          }
          if (large - X < X - small) {
            cout << large;
          } else {
            cout << small;
          }
        }
      }
    }
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<int> a(102, 0);
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    a[p]++;
  }
  int tmp = 101;
  int ans = 0;
  for (int i = 101; i >= 0; i--) {
    if (a[i] == 0) {
      int buf = abs(x - i);
      if (buf <= tmp) {
        tmp = buf;
        ans = i;
      }
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> a(n);
  vector<int> b;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= 100; i++) {
    bool ok = true;
    for (int j = 0; j < n; j++) {
      if (i == a[j]) {
        ok = false;
      }
    }
    if (ok) {
      b.push_back(i);
    }
  }
  vector<pair<int, int>> ans(b.size());
  for (int i = 0; i < b.size(); i++) {
    ans[i].first = abs(b[i] - x);
    ans[i].second = b[i];
  }
  sort(ans.begin(), ans.end());
  cout << ans[0].second << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意！
using P = pair<int, int>;
#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！

int main() {
  int X, N;
  cin >> X >> N;
  vector<bool> ok(102);
  rep(i, 102) ok[i] = true;
  rep(i, N) {
    int p;
    cin >> p;
    ok[p] = false;
  }
  P ans(99999, -1);
  for (int i = 0; i <= 101; i++) {
    if (!ok[i])
      continue;
    int dis = abs(X - i);
    ans = min(ans, P(dis, i));
  }
  cout << ans.second << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; // intじゃ扱えないことに注意！
using P = pair<int, int>;
#define rep(i, n)                                                              \\
  for (int i = 0; i < (int)(n); i++) // 範囲外参照とループの初期化に注意！

int main() {
  int X, N;
  cin >> X >> N;
  vector<bool> ok(101);
  rep(i, 101) ok[i] = true;
  rep(i, N) {
    int p;
    cin >> p;
    ok[p] = false;
  }
  if (ok[X]) {
    cout << X << endl;
    return 0;
  }
  int k = 101;
  for (int i = 1; i <= 100; i++) {
    if (ok[i]) {
      int dis = abs(X - i);
      k = min(k, dis);
    }
  }
  int m, n;
  m = X - k;
  n = X + k;
  if (ok[m]) {
    cout << m << endl;
    return 0;
  }
  if (ok[n]) {
    cout << n << endl;
    return 0;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int x, n, z = 1000, ans = 0;
  cin >> x >> n;
  vector<int> p(n + 3);
  vector<int> a(10000);
  vector<int> b(10000);
  for (int i = 1; i <= n; i++) {
    cin >> p.at(i);
  }
  for (int i = 0; i <= 1000; i++) {
    a.at(i) = i;
  }
  for (int i = 0; i <= 1000; i++) {
    b.at(i) = i * (-1);
  }
  for (int i = 1; i <= 101; i++) {
    for (int j = 1; j <= n; j++) {
      if (p.at(j) == a.at(i))
        a.at(i) = 100000;
    }
  }
  for (int i = 1000; i >= 0; i--) {
    if (z >= abs(x - a.at(i))) {
      z = abs(x - a.at(i));
      ans = i;
    }
    if (z >= abs(x - b.at(i))) {
      z = abs(x - b.at(i));
      ans = i;
    }
  }
  cout << ans;
}


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


Fixed submission:

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

int main() {
  int x, n, z = 1000, ans = 0;
  cin >> x >> n;
  vector<int> p(n + 3);
  vector<int> a(10000);
  for (int i = 1; i <= n; i++) {
    cin >> p.at(i);
  }
  for (int i = 1; i <= 1000; i++) {
    a.at(i) = i;
  }
  for (int i = 1; i <= 101; i++) {
    for (int j = 1; j <= n; j++) {
      if (p.at(j) == a.at(i))
        a.at(i) = 100000;
    }
  }
  for (int i = 1000; i >= -200; i--) {
    if (z >= abs(x - a.at(i))) {
      z = abs(x - a.at(i));
      ans = i;
    }
  }
  cout << ans;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long
#define MOD 1000000007
#define MAX 1000000

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> in(102, 0);
  int p;
  for (int i = 0; i < n; i++) {
    cin >> p;
    in.at(p)++;
  }

  int dis = 99999;
  int ans;
  for (int i = 0; i <= 101; i++) {
    if (in.at(i) == 1)
      continue;
    if (dis > abs(x - i)) {
      dis = abs(x - i);
      ans = i;
    }
  }

  cout << ans << endl;
}


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


Fixed submission:

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

#define ll long long
#define MOD 1000000007
#define MAX 1000000

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> in(101, 0);
  int p;
  for (int i = 0; i < n; i++) {
    cin >> p;
    in.at(p)++;
  }

  int dis = 99999;
  int ans;
  for (int i = 0; i <= 101; i++) {
    if (in.at(i) == 1)
      continue;
    if (dis > abs(x - i)) {
      dis = abs(x - i);
      ans = i;
    }
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
  int x, n, min = 100, ans = 0;
  cin >> x >> n;
  if (n == 0)
    cout << x << endl;

  else {
    vector<int> p(n);
    rep(i, n) cin >> p.at(i);

    vector<int> con(102, 0);
    rep(i, n) con.at(p.at(i)) = 1;

    rep(i, 102) {
      if (con.at(i) == 0) {
        if (abs(x - i) < min) {
          min = abs(x - i);
          ans = i;
        }
      }
    }
    cout << ans << endl;
    return 0;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
  int x, n, min = 100, ans = 0;
  cin >> x >> n;
  if (n == 0)
    cout << x << endl;

  vector<int> p(n);
  rep(i, n) cin >> p.at(i);

  vector<int> con(100, 0);
  rep(i, n) con.at(p.at(i)) = 1;

  rep(i, 100) {
    if (con.at(i) == 0) {
      if (abs(x - i) < min) {
        min = abs(x - i);
        ans = i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define INX(x) (cin >> x)
#define INXV(vec, cnt)                                                         \\
  for (ll i; i < cnt; i++)                                                     \\
  INX(vec[i])
#define OUTX(x) (cout << x << endl)
#define OUTXV(vec)                                                             \\
  for (ll i; i < (ll)vec.size(); i++)                                          \\
  OUTX(vec[i])

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>

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

  vector<bool> pbl(102, false);
  for (ll i = 0; i < N; i++) {
    ll tmp;
    INX(tmp);

    pbl[tmp] = true;
  }

  for (ll i = 0; i <= 101; i++) {
    if (X - i >= 0 && !pbl[X - i]) {
      OUTX(X - i);
      break;
    }
    if (X + i <= 101 && !pbl[X + i]) {
      OUTX(X + i);
      break;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define INX(x) (cin >> x)
#define INXV(vec, cnt)                                                         \\
  for (ll i; i < cnt; i++)                                                     \\
  INX(vec[i])
#define OUTX(x) (cout << x << endl)
#define OUTXV(vec)                                                             \\
  for (ll i; i < (ll)vec.size(); i++)                                          \\
  OUTX(vec[i])

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>

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

  vector<bool> pbl(100, false);
  for (ll i = 0; i < N; i++) {
    ll tmp;
    INX(tmp);

    pbl[tmp - 1] = true;
  }

  X--;
  for (ll i = 0; i <= N; i++) {
    if (!pbl[X - i]) {
      OUTX(X - i + 1);
      break;
    }
    if (!pbl[X + i]) {
      OUTX(X + i + 1);
      break;
    }
  }

  return 0;
}