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

#pragma GCC optimize("O3")
#pragma GCC target("sse4") // wonderful

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

#define forn(i, a, n) for (int i = (a); i < (int)n; i++)
#define trav(x, arr) for (auto &x : arr)
#define sz(x) (int)x.size()
#define Matrix(m, h, w) = std::vector<vector<int>> m(h, vector<int>(w));
using ll = long long;

#define vi vector<int>
#define vl vector<long>
#define vll vector<ll>

// benq
const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;

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

  int x, n, p;
  cin >> x >> n;

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

  unordered_set<int> set{};

  forn(i, 0, n) {
    int a;
    cin >> a;
    set.insert(a);
  }

  if (set.find(x) == set.end()) {
    cout << x;
    return 0;
  }

  int b = 1;

  while (true) {

    if (set.find(abs(x - b)) == set.end()) {
      cout << x - b;
      break;
    } else if (set.find(abs(x + b)) == set.end()) {
      cout << x + b;
      break;
    }
    b++;
  }

  return 0;
}

Error: WA

Fixed submission:

#pragma GCC optimize("O3")
#pragma GCC target("sse4") // wonderful

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

#define forn(i, a, n) for (int i = (a); i < (int)n; i++)
#define trav(x, arr) for (auto &x : arr)
#define sz(x) (int)x.size()
#define Matrix(m, h, w) = std::vector<vector<int>> m(h, vector<int>(w));
using ll = long long;

#define vi vector<int>
#define vl vector<long>
#define vll vector<ll>

// benq
const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;

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

  int x, n, p;
  cin >> x >> n;

  if (n == 0) {
    return x;
  }

  unordered_set<int> set{};

  forn(i, 0, n) {
    int a;
    cin >> a;
    set.insert(a);
  }

  int b = 1;

  while (true) {

    if (set.find(abs(x - b)) == set.end()) {
      cout << x - b;
      break;
    } else if (set.find(abs(x + b)) == set.end()) {
      cout << x + b;
      break;
    }
    b++;
  }

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

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

int main() {
  int x, n;
  cin >> x >> n;
  if (n != 0) {
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    vector<int> p_;
    p_.push_back(p[0] - 1);
    rep(i, n) {
      if (p[i + 1] > p[i]) {
        rep(j, p[i + 1] - p[i] - 1) { p_.push_back(p[i] + j + 1); }
      }
    }
    p_.push_back(p[n - 1] + 1);
    int near = 0;
    rep(i, p_.size()) {
      if (p_[i] >= x) {
        near = i;
        break;
      }
    }
    if (p_[near] - x >= x - p_[near - 1])
      near--;
    cout << p_[near] << endl;
  } else {
    cout << x << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(p.begin(), p.end());
  vector<int> p_;
  p_.push_back(p[0] - 1);
  rep(i, n) {
    if (p[i + 1] > p[i]) {
      rep(j, p[i + 1] - p[i] - 1) { p_.push_back(p[i] + j + 1); }
    }
  }
  p_.push_back(p[n - 1] + 1);
  int near = 0;
  rep(i, p_.size()) {
    if (p_[i] >= x) {
      near = i;
      break;
    }
  }
  if (p_[near] - x >= x - p_[near - 1])
    near--;
  cout << p_[near] << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
/*#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<iterator>*/
#include <vector>

#define ll long long
#define uint unsigned int
#define ld long double
#define SAM                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define mod 1000000007
#define mxn 200005
#define pb push_back
#define pii pair<int, int>
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

using namespace std;

int main() {
  SAM;
  int x, n;
  cin >> x >> n;
  vector<int> v;
  FOR(i, 0, n) {
    int m;
    cin >> m;
    v.pb(m);
  }
  sort(all(v));
  int b = 1000;
  int c;
  vector<int>::iterator it;
  for (int i = 0; i <= 101; i++) {
    it = find(all(v), i);
    if (it != v.end())
      continue;
    else {
      int a = abs(x - i);
      if (a < b) {
        b = a;
        c = i;
      }
    }
  }
  cout << c;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <vector>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  int x, n, a;
  cin >> x >> n;
  vector<int> v;

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

  vector<int>::iterator lower, upper, find1, find2;
  lower = lower_bound(v.begin(), v.end(), x);
  upper = upper_bound(v.begin(), v.end(), x);

  while (1) {
    find1 = find(v.begin(), v.end(), *upper);
    find2 = find(v.begin(), v.end(), *lower);
    if (find1 == v.end() && find2 == v.end()) {
      if (abs(*upper - x) > abs(*lower - x)) {
        cout << *lower;
        return 0;
      } else if (abs(*upper - x) < abs(*lower - x)) {
        cout << *upper;
        return 0;
      } else if (abs(*upper - x) == abs(*lower - x)) {
        if (*upper > *lower) {
          cout << *lower;
          return 0;
        } else {
          cout << *upper;
          return 0;
        }
      }

    } else {
      if (find1 == v.end()) {
        *lower -= 1;
      } else {
        *upper += 1;
      }
    }
  }
}
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++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//------------------------------------------------------//

int main() {
  int x, n;
  cin >> x >> n;
  vec<bool> p(101, false);
  rep(i, n) {
    int y;
    cin >> y;
    p[y] = true;
  }
  int l = x, r = x;
  int ans = 0;
  while (ans == 0) {
    if (l == 0) {
      ans = 0;
      break;
    }
    if (p[l] == false && p[r] == false)
      ans = l;
    else if (p[l] == false && p[r] == true)
      ans = l;
    else if (p[l] == true && p[r] == false)
      ans = r;
    l--;
    r++;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//------------------------------------------------------//

int main() {
  int x, n;
  cin >> x >> n;
  vec<bool> p(101, false);
  rep(i, n) {
    int y;
    cin >> y;
    p[y] = true;
  }
  int l = x, r = x;
  int ans = 0;
  while (ans == 0) {
    if (p[l] == false && p[r] == false)
      ans = l;
    else if (p[l] == false && p[r] == true)
      ans = l;
    else if (p[l] == true && p[r] == false)
      ans = r;
    l--;
    r++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define prArr(Arr, n)                                                          \\
  for (int _ = 0; _ < n; _++)                                                  \\
    cout << (Arr)[_] << " ";
using namespace std;
const int INF = (int)0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
bool seen[101];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x, n, tmp, ans1, ans2;
  cin >> x >> n;
  for (int i = 0; i < n && cin >> tmp; i++)
    seen[tmp] = 1;
  for (int i = x; i < 200; i++)
    if (!seen[i]) {
      ans1 = i;
      break;
    }
  for (int i = x; i >= 0; i--)
    if (!seen[i]) {
      ans2 = i;
      break;
    }
  cout << (ans1 - x < x - ans2 ? ans1 : ans2);
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\\n"
#define MOD (int)1e9 + 7
#define inf (int)(1e18)

void solve() {
  int x, n;
  cin >> x >> n;
  vector<int> mp(101, 0);
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    mp[p]++;
  }
  int r = x, l = x;
  while (1) {
    if (l >= 0 && mp[l] == 0) {
      cout << l;
      return;
    }
    if (r <= 100 && mp[r] == 0) {
      cout << r;
      return;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long int t = 1;
  // cin >> t;
  for (long int tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
int INF = 1e14;
int mod = 1e9 + 7;

int power(int x, unsigned int y) {
  int temp;
  if (y == 0)
    return 1;
  temp = power(x, y / 2) % mod;
  if (y % 2 == 0)
    return (temp * temp) % mod;
  else
    return x * ((temp * temp) % mod) % mod;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  // cin >> t;
  t = 1;
  while (t--) {
    set<int> st;
    rep(i, 0, 102) st.insert(i);
    int n, x;
    cin >> x >> n;
    rep(i, 0, n) {
      int temp;
      cin >> temp;
      st.erase(temp);
    }
    auto key = st.lower_bound(x);
    if (key != st.begin()) {
      int curr = *key;
      int prev = *(--key);
      if (abs(prev - x) > abs(curr - x))
        cout << curr << endl;
      else
        cout << prev << endl;
    } else
      cout << *key << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define rep(i, a, b) for (int i = a; i < b; i++)
#define revrep(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
int INF = 1e14;
int mod = 1e9 + 7;

int power(int x, unsigned int y) {
  int temp;
  if (y == 0)
    return 1;
  temp = power(x, y / 2) % mod;
  if (y % 2 == 0)
    return (temp * temp) % mod;
  else
    return x * ((temp * temp) % mod) % mod;
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  // cin >> t;
  t = 1;
  while (t--) {
    set<int> st;
    rep(i, 1, 101) st.insert(i);
    int n, x;
    cin >> x >> n;
    rep(i, 0, n) {
      int temp;
      cin >> temp;
      st.erase(temp);
    }
    auto key = st.lower_bound(x);
    if (key == st.end()) {
      cout << *st.rbegin() << endl;
      continue;
    }
    if (key != st.begin()) {
      int curr = *key;
      int prev = *(--key);
      if (abs(prev - x) > abs(curr - x))
        cout << curr << endl;
      else
        cout << prev << endl;
    } else
      cout << *key << endl;
  }

  return 0;
}
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 = int64_t;

int main() {
  int x, n;
  cin >> x >> n;

  vector<int> p(n);
  rep(i, n) cin >> p[i];

  for (int i = 0; i < 100; ++i) {
    bool exist = true;
    for (int l : p)
      if (x - i == l)
        exist = false;

    if (exist) {
      cout << x - i << endl;
      exit(0);
    }

    for (int l : p)
      if (x + i == l)
        exist = true;

    if (!exist) {
      cout << x + i << endl;
      exit(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 = int64_t;

int main() {
  int x, n;
  cin >> x >> n;

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

  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(p.begin(), p.end());

  vector<int> b;
  int ref = 0;
  for (int i = 1; i <= 100; ++i) {
    if (p[ref] == i) {
      ++ref;
      if (ref == n)
        --ref;
      continue;
    }
    b.emplace_back(i);
  }

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

  int k = lower_bound(b.begin(), b.end(), x) - b.begin();

  if (k == 0)
    cout << b[0] << endl;
  else if (k == n)
    cout << b[n - 1] << endl;
  else {
    if (b[k] - x < x - b[k - 1])
      cout << b[k] << endl;
    else
      cout << b[k - 1] << endl;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
int main() {
  int x, n, k = 0, l, c = 0, i, u;
  cin >> x >> n;
  l = x;
  u = x;
  int p[n];

  for (i = 0; i < n; i++)
    cin >> p[i];
x:
  for (i = 0; i < n; i++) {
    if (p[i] == x) {
      x--;
      goto x;
      break;
    }
  }
y:
  for (i = 0; i < n; i++) {
    if (p[i] == l) {
      l++;
      goto y;
      break;
    }
  }
  if (abs(u - x) > abs(u - l))
    cout << l;
  else
    cout << x;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main() {
  int x, n, k = 0, l, c = 0, i;
  cin >> x >> n;
  l = x;
  int p[n];

  for (i = 0; i < n; i++)
    cin >> p[i];
xy:
  for (i = 0; i < n; i++) {
    if (x == p[i]) {
      k = 0;
      break;
    } else
      k = 1;
  }

  for (i = 0; i < n; i++) {
    if (l == p[i]) {
      c = 0;
      break;
    } else
      c = 1;
  }
  if (c == 0 && k == 0) {
    l++;
    x--;
    goto xy;
  }

  if (c == 1 && k == 1)
    cout << x;
  else if (c == 1)
    cout << l;
  else
    cout << x;
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>

using namespace std;

int main() {
  int X, N;

  cin >> X >> N;

  int *p;
  p = new int[N];

  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  bool found = true;
  int output = 0;

  for (int i = 0; i < N; i++) {
    if (p[i] == X) {
      found = true;
      i = N;
    } else {
      found = false;
      output = X;
    }
  }

  if (N == 0) {
    found = false;
    output = X;
  }

  int j = 1;
  while (found) {
    for (int i = 0; i < N; i++) {
      if (p[i] == X - j) {
        found = true;
        i = N;
      } else {
        found = false;
        output = X - j;
      }
    }

    if (found) {
      for (int i = 0; i < N; i++) {
        if (p[i] == X + j) {
          found = true;
          i = N;
        } else {
          found = false;
          output = X + j;
        }
      }
    }
    j++;
  }
  cout << output;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

using namespace std;

int main() {
  int X, N;

  cin >> X >> N;

  int *p;
  p = new int[N];

  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  bool found = true;
  int output = 0;

  for (int i = 0; i < N; i++) {
    if (p[i] == X) {
      found = true;
      i = N;
    } else {
      found = false;
      output = X;
    }
  }
  int j = 1;
  while (found) {
    for (int i = 0; i < N; i++) {
      if (p[i] == X - j) {
        found = true;
        i = N;
      } else {
        found = false;
        output = X - j;
      }
    }

    if (found) {
      for (int i = 0; i < N; i++) {
        if (p[i] == X + j) {
          found = true;
          i = N;
        } else {
          found = false;
          output = X + j;
        }
      }
    }
    j++;
  }
  cout << output;

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define DESC std::greater<int>() // sort 3rd arg

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> v;

  REP(i, n) {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }

  if (n == 1) {
    if (x == v[0]) {
      cout << x - 1 << endl;
      return 0;
    }
  }

  const int INIT = -10;

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

  auto itr = std::find(v.begin(), v.end(), x);

  if (itr == v.end()) {
    cout << x << endl;
  } else {
    int before = INIT;
    int next = INIT;

    auto be_itr = itr;
    auto ne_itr = itr;

    while (be_itr != v.begin() + 1) {
      if (*(be_itr - 1) + 1 == *(be_itr)) {
        be_itr--;
      } else {
        before = *(be_itr)-1;
        break;
      }
    }

    if (before == INIT) {
      before = v[0] - 1;
    }

    while (ne_itr != v.end() - 1) {
      if (*(ne_itr + 1) - 1 == *(ne_itr)) {
        ne_itr++;
      } else {
        next = *(ne_itr) + 1;
        break;
      }
    }

    if (next == INIT) {
      next = v[n - 1] + 1;
    }

    if (x - before > next - x) {
      cout << next << endl;
    } else {
      cout << before << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define DESC std::greater<int>() // sort 3rd arg

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> v;

  REP(i, n) {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }

  const int INIT = -10;

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

  auto itr = std::find(v.begin(), v.end(), x);

  if (itr == v.end() && x != *(itr)) {
    cout << x << endl;
  } else {
    int before = INIT;
    int next = INIT;

    auto be_itr = itr;
    auto ne_itr = itr;

    while (be_itr != v.begin() + 1) {
      if (*(be_itr - 1) + 1 == *(be_itr)) {
        be_itr--;
      } else {
        before = *(be_itr)-1;
        break;
      }
    }

    if (before == INIT) {
      before = v[0] - 1;
    }

    while (ne_itr != v.end() - 1) {
      if (*(ne_itr + 1) - 1 == *(ne_itr)) {
        ne_itr++;
      } else {
        next = *(ne_itr) + 1;
        break;
      }
    }

    if (next == INIT) {
      next = v[n - 1] + 1;
    }

    if (x - before > next - x) {
      cout << next << endl;
    } else {
      cout << before << endl;
    }
  }

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

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

int main() {
  vector<int> num(102, 0);
  for (int i = 0; i <= 101; i++)
    num[i] = i;

  int x, n, t;
  cin >> n >> x;

  if (x != 0) {
    for (int i = 0; i < x; i++) {
      cin >> t;
      num[t] = 1000;
    }
    bool judge = true;
    int dn = n - 1;
    int da = n + 1;
    while (judge) {
      if (num[n] != 1000) {
        dn = n;
        da = 1000;
        judge = false;
      } else if (num[dn] != 1000 || num[da] != 1000) {
        dn = num[dn];
        da = num[da];
        judge = false;
      } else {
        dn--;
        da++;
      }
    }
    cout << min(dn, da);
  } else
    cout << n;
}


Error: WA

Fixed submission:

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

int main() {
  vector<int> num(101, 0);
  for (int i = 1; i <= 100; i++)
    num[i] = i;

  int x, n, t;
  cin >> n >> x;

  if (x != 0) {
    for (int i = 0; i < x; i++) {
      cin >> t;
      num[t] = 1000;
    }
    bool judge = true;
    int dn = n - 1;
    int da = n + 1;
    while (judge) {
      if (num[n] != 1000) {
        dn = n;
        da = 1000;
        judge = false;
      } else if (num[dn] == 1000 || num[da] == 1000) {
        dn = num[dn];
        da = num[da];
        judge = false;
      } else {
        dn--;
        da++;
      }
    }
    cout << min(dn, da);
  } else
    cout << n;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int X, N, atai, M = 0, M2 = 0;
  cin >> X >> N;
  vector<int> p(N + 1);
  bool dekita = false;
  p.at(0) = 0;
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  if (p.at(0) == 0) {
    dekita = true;
    atai = X;
  }
  sort(p.rbegin(), p.rend());

  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j < N; j++) {
      if (X - i == p.at(j)) {
        M = j;
      }
      if (X + i == p.at(j)) {
        M2 = j;
      }
    }
    if (dekita == true) {
      cout << atai << endl;
      break;
    } else if (X - i != p.at(M) && X - i != p.at(M2)) {
      atai = X - i;
      cout << atai << endl;
      break;
    } else if (X + i != p.at(M) && X + i != p.at(M2)) {
      atai = X + i;
      cout << atai << endl;
      break;
    }
  }
}


Error: 0

Fixed submission:

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

int main() {
  int X, N, atai, M, M2;
  cin >> X >> N;
  vector<int> p(N + 2), sa(100, 0), sa2(100, 999);
  bool dekita = false;
  p.at(0) = 0;
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  if (p.at(0) == 0) {
    dekita = true;
    atai = X;
  }
  sort(p.rbegin(), p.rend());

  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < N; j++) {
      if (X - i == p.at(j)) {
        M = j;
      }
      if (X + i == p.at(j)) {
        M2 = j;
      }
    }
    if (dekita == true) {
      cout << atai << endl;
      break;
    } else if (X - i != p.at(M) && X - i != p.at(M2)) {
      atai = X - i;
      cout << atai << endl;
      break;
    } else if (X + i != p.at(M) && X + i != p.at(M2)) {
      atai = X + i;
      cout << atai << endl;
      break;
    }
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  typedef long long ll;
  ll x, n;
  cin >> x >> n;
  vector<ll> v;
  for (ll i = 0; i < n; i++) {
    ll t;
    cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());

  if (n == 0) {
    cout << x;
  } else {
    vector<ll> nv;

    for (ll i = 0; i < 102; i++) {
      bool np = true;
      for (ll j = 0; j < n; j++) {
        if (v[j] == i) {
          np = false;
          break;
        }
      }
      if (np != false)
        nv.push_back(i);
    }

    ll ans = 0;
    ll mini = 100;

    for (ll i = 0; i < (nv.size()); i++) {
      if (abs(x - nv[i]) < mini) {
        mini = abs(x - nv[i]);
        ans = nv[i];
      }
    }
    cout << ans;
  }
}

Error: WA

Fixed submission:

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

int main() {
  typedef long long ll;
  ll x, n;
  cin >> x >> n;
  vector<ll> v;
  for (ll i = 0; i < n; i++) {
    ll t;
    cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());

  vector<ll> nv;

  for (ll i = v[0]; i < x * 100; i++) {
    bool np = true;
    for (ll j = 0; j < n; j++) {
      if (v[j] == i) {
        np = false;
        break;
      }
    }
    if (np != false)
      nv.push_back(i);
  }

  ll ans = 0;
  ll mini = 100;

  for (ll i = 0; i < (nv.size()); i++) {
    if (abs(x - nv[i]) < mini) {
      mini = abs(x - nv[i]);
      ans = nv[i];
    }
  }
  if (n != 0)
    cout << ans;
  else
    cout << x;
}