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;
  int a, f[200], q = 0, w = 0;
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++) {
    cin >> a;
    f[a] = 1;
  }
  for (int i = x; i <= 105; i++) { // cout<<f[i]<<endl;
    if (f[i] == 0) {

      q = i; // da
      break;
    }
  }
  for (int i = x; i >= 0; i--) {
    if (f[i] == 0) {
      w = i; // xiao
      break;
    }
  }

  // cout<<q<<w;

  if (q - x >= x - w) {
    cout << w;
  } else {
    cout << q;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n;
  cin >> x >> n;
  int a, f[n + 5], q = 0, w = 0;
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++) {
    cin >> a;
    f[a] = 1;
  }
  for (int i = x; i <= 105; i++) {
    if (f[i] == 0) {
      // cout<<i<<endl;
      q = i; // da
      break;
    }
  }
  for (int i = x; i >= 0; i--) {
    if (f[i] == 0) {
      w = i; // xiao
      break;
    }
  }

  // cout<<q<<w;

  if (q - x >= x - w) {
    cout << w;
  } else {
    cout << q;
  }
}
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 << endl;
    return 0;
  }
  vector<int> vec(n);
  vector<int> a(300);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < 301; i++) {
    a[i] = i - 100;
  }
  for (int i = 0; i < n; i++) {
    int m = vec[i];
    a.erase(a.begin() + m + 100 - i);
  }
  int ans = 200;
  int q = a.size();
  for (int i = 0; i < q; i++) {
    ans = min(ans, abs(a[i] - x));
  }
  for (int i = 0; i < n; i++) {
    if (x - ans == vec[i]) {
      cout << x + ans << endl;
      return 0;
    }
  }
  cout << x - ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<int> vec(n);
  vector<int> a(200);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < 201; i++) {
    a[i] = i - 100;
  }
  for (int i = 0; i < n; i++) {
    int m = vec[i];
    a.erase(a.begin() + m + 100 - i);
  }
  int ans = 200;
  int q = a.size();
  for (int i = 0; i < q; i++) {
    ans = min(ans, abs(a[i] - x));
  }
  for (int i = 0; i < n; i++) {
    if (x - ans == vec[i]) {
      cout << x + ans << endl;
      return 0;
    }
  }
  cout << x - ans << endl;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

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

  if (N == 0) {
    cout << X << endl;
    exit(0);
  }

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  int count = 0;

  while (1) {
    for (int i = 0; i < N; i++) {
      if (vec[i] == X - count) {
        break;
      }
      if (i == N - 1) {
        cout << X - count << endl;
        exit(0);
      }
    }

    for (int i = 0; i < N; i++) {
      if (vec[i] == X + count) {
        break;
      }
      if (i == N - 1) {
        cout << X + count << endl;
        exit(0);
      }
    }
    count++;
  }
}

Error: 1

Fixed submission:

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

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

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  if (N == 0) {
    cout << X << endl;
    exit(0);
  }

  int count = 0;

  while (1) {
    for (int i = 0; i < N; i++) {
      if (vec[i] == X - count) {
        break;
      }
      if (i == N - 1) {
        cout << X - count << endl;
        exit(1);
      }
    }

    for (int i = 0; i < N; i++) {
      if (vec[i] == X + count) {
        break;
      }
      if (i == N - 1) {
        cout << X + count << endl;
        exit(1);
      }
    }
    count++;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int x;
  int n;
  cin >> x >> n;
  vector<int> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i];
  }
  if (find(in.begin(), in.end(), x) == in.end()) {
    cout << x << endl;
    return 0;
  }
  int len = 1;
  while (1) {
    if (find(in.begin(), in.end(), x - len) == in.end()) {
      cout << x - len << endl;
      return 0;
    }
    if (find(in.begin(), in.end(), x + len) == in.end()) {
      cout << x + len << endl;
      return 0;
    }
    len++;
  }
}


Error: 10

Fixed submission:

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

int main() {
  int x;
  int n;
  cin >> x >> n;
  vector<int> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i];
  }
  if (find(in.begin(), in.end(), x) == in.end()) {
    cout << x << endl;
    return 0;
  }
  int len = 1;
  while (1) {
    if (find(in.begin(), in.end(), x - len) == in.end()) {
      cout << x - len << endl;
      return 5;
    }
    if (find(in.begin(), in.end(), x + len) == in.end()) {
      cout << x + len << endl;
      return 10;
    }
    len++;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

// include all standard library.
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(int argc, char const *argv[]) {
  int x, n;
  vector<int> p;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    p.push_back(k);
  }

  // 数列pに含まれない整数でxに最も近いものをプリント
  // 複数ある時は小さいものを答える．
  sort(p.begin(), p.end());
  for (int i = 0; i < p[n - 1] + 1; i++) {
    int zantei_1 = x + i;
    int zantei_2 = x - i;
    // cout << zantei_1 << ", " << zantei_2 << endl;

    if (!binary_search(p.begin(), p.end(), zantei_2)) {
      cout << zantei_2 << endl;
      return 0;
    }
    if (!binary_search(p.begin(), p.end(), zantei_1)) {
      cout << zantei_1 << endl;
      return 0;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

// include all standard library.
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(int argc, char const *argv[]) {
  int x, n;
  vector<int> p;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    p.push_back(k);
  }

  // 数列pに含まれない整数でxに最も近いものをプリント
  // 複数ある時は小さいものを答える．
  int d = 0;
  while (true) {
    bool flag = true;
    int curr = d + x;
    for (int i = 0; i < n; i++) {
      if (p[i] == curr) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << curr << endl;
      return 0;
    }
  }

  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> list(110, 0);
  for (int i = 0; i < N; i++)
    cin >> list.at(i);
  if (N == 0) {
    cout << X << endl;
    return 0;
  }
  bool checkm = 1;
  bool checkp = 1;
  int ans = 0;

  for (int i = 0; i < 110; i++) {
    checkm = 1;
    checkp = 1;
    for (int j = 0; j < N; j++) {
      if (X - i == list.at(j)) {
        checkm = 0;
      }
      if (X + i == list.at(j)) {
        checkp = 0;
      }
    }

    if (checkm) {
      ans = X - i;
      break;
    } else if (checkp) {
      ans = X + i;
      break;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> list(N, 0);
  vector<int> list3(N, 0);
  for (int i = 0; i < N; i++)
    cin >> list3.at(i);
  // int ans = 1000;
  int list2;
  // int temp = 100000;
  bool check = 1;
  if (N == 0) {
    cout << X << endl;
    return 0;
  }
  // int tempp = 0;

  for (int i = 0; i < N; i++) {
    list.at(i) = abs(X - list3.at(i));
  }
  sort(list.begin(), list.end());

  int now = 0;
  int ans;

  for (int i = 0; i < N; i++) {
    if (list.at(i) == (i + 1) / 2) {
      continue;
    } else {
      if (i % 2) {
        ans = 1 + list.at(i - 1);
        break;
      } else {
        ans = list.at(i - 1);
        break;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    if (list3.at(i) == X - ans) {
      check = 0;
      cout << X + ans << endl;
      break;
    }
  }
  if (check) {
    cout << X - ans << endl;
  }

  // cout << X - list.at(0) << endl;
  /*
      for(int i = 0; i < N;i++){
          for(int j = 0; j < N;j++){
              check = 1;
              if(X-i < 0){
                  check = 0;
                  break;
              }
              list2 = i;

              if(list.at(j) == X-i){
                  check = 0;
  //                cout << '(' << i << ','<< j << ')' <<endl;
                  break;

              }
          }
          if(check){
              cout << X-list2;
              break;
          }


          for(int j = 0; j < N;j++){
              check = 1;
  //            if(X+i > N){
  //                check = 0;
  //                break;
  //            }
              list2 = i;
              if(list.at(j) == X+i){
                  check = 0;
  //                cout << '(' << i << ','<< j << ')' <<endl;
                  break;
              }
          }
          if(check){
              cout << X+list2;
              break;
          }
      }


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

#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <random>
#include <stack>
#include <string>

#include <algorithm>
#include <fstream>
#include <vector>

#define ll long long int

using namespace std;

int main(void) {

  int x, n, tmp;
  int res, res_u;
  vector<int> p;

  cin >> x >> n;
  res = x;
  res_u = x;

  for (int i = 0; i < n; i++) {
    cin >> tmp;
    p.push_back(tmp);
  }

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

  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n; i++) {
      if (p[i] == res) {
        res--;
      }
      if (p[n - i] == res_u) {
        res_u++;
      }
    }
  }

  if (n) {
    if (p[0] == res_u) {
      res_u++;
    }
  }

  if (abs(res - x) <= abs(res_u - x)) {
    cout << res;
  } else {
    cout << res_u;
  }
}

Error: WA

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <random>
#include <stack>
#include <string>

#include <algorithm>
#include <fstream>
#include <vector>

#define ll long long int

using namespace std;

int main(void) {

  int x, n, tmp;
  int res, res_u;
  vector<int> p;

  cin >> x >> n;
  res = x;
  res_u = x;

  for (int i = 0; i < n; i++) {
    cin >> tmp;
    p.push_back(tmp);
  }

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

  for (int j = 0; j < n; j++) {
    for (int i = 0; i < n; i++) {
      if (p[i] == res) {
        res--;
      }
      if (p[n - i] == res_u) {
        res_u++;
      }
    }
  }

  if (p[0] == res_u) {
    res_u++;
  }

  if (abs(res - x) <= abs(res_u - x)) {
    cout << res;
  } else {
    cout << res_u;
  }
}
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++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  int x, n;
  cin >> x >> n;
  vector<bool> h(102);
  rep(i, n) {
    int p;
    cin >> p;
    h[p] = true;
  }
  pair<int, int> ans(100000, -1);
  for (int i = 0; i <= 101; i++) {
    if (h[i])
      continue;
    int dif = abs(x - i);
    ans = min(ans, pair<int, int>(dif, i));
  }
  cout << ans.second << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int x, n;
  cin >> x >> n;
  vector<bool> h(102);
  rep(i, 102) {
    int p;
    cin >> p;
    h[p] = true;
  }
  pair<int, int> ans(100000, -1);
  for (int i = 0; i <= 101; i++) {
    if (h[i])
      continue;
    int dif = abs(x - i);
    ans = min(ans, pair<int, int>(dif, i));
  }
  cout << ans.second << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repto(i, n) for (int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

  set<int> s;
  int X, N;
  int p;
  cin >> X >> N;
  for (int i = -1000; i <= 1000; i++)
    s.insert(i);
  rep(i, N) {
    cin >> p;
    s.erase(p);
  }
  // if (s.lower_bound(X) == s.begin())
  //   cout << *s.lower_bound(X) << endl;
  // else {
  int s1 = *s.lower_bound(X);
  int s2 = *(--s.lower_bound(X));
  if (s1 - X >= X - s2)
    cout << s2 << endl;
  else
    cout << s1 << endl;
  // }
}


Error: 0

Fixed submission:

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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repto(i, n) for (int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

  set<int> s;
  int X, N;
  int p;
  cin >> X >> N;
  for (int i = 1; i <= 100; i++)
    s.insert(i);
  rep(i, N) {
    cin >> p;
    s.erase(p);
  }
  int s1 = *s.lower_bound(X);
  int s2 = *(--s.lower_bound(X));
  if (s1 - X >= X - s2)
    cout << s2 << endl;
  else
    cout << s1 << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

/******************************************
 * AUTHOR : AMAN SAXENA *
 * "There's some good in this world, and it's worth fighting for." *
 * INSTITUTION : KIET Group of Institutions *
 ******************************************/
#include <bits/stdc++.h>

const long long MODULO = 1000000007;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define FOR1(i, a, n) for (int i = a; i <= n; i++)
#define FOR2(i, a, n) for (int i = a; i >= n; i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pi 3.14159265359

using namespace std;

template <typename TYPE> void in(TYPE &x) { cin >> x; }

void solve() {
  int x, n;
  cin >> x >> n;
  set<int> p;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    p.insert(a);
  }
  int m = 0;
  for (int i = 0; i <= 101; i++)
    m = (abs(x - i) < abs(x - m) && !p.count(i) ? i : m);
  cout << m << endl;
}

void test() {
  int t;
  cin >> t;
  while (t--) // for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
  {
    solve();
  }
}

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

  // test();
  solve();

  return 0;
}


Error: 0

Fixed submission:

/******************************************
 * AUTHOR : AMAN SAXENA *
 * "There's some good in this world, and it's worth fighting for." *
 * INSTITUTION : KIET Group of Institutions *
 ******************************************/
#include <bits/stdc++.h>

const long long MODULO = 1000000007;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define FOR1(i, a, n) for (int i = a; i <= n; i++)
#define FOR2(i, a, n) for (int i = a; i >= n; i--)
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define rep(i, begin, end)                                                     \\
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \\
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pi 3.14159265359

using namespace std;

template <typename TYPE> void in(TYPE &x) { cin >> x; }

void solve() {
  int x, n, y, c = 0;
  cin >> x >> n;
  int b[101] = {0}, d = x;
  vector<int> s;
  FOR(i, 0, n) {
    cin >> y;
    s.pb(y);
  }
  sort(s.begin(), s.end());
  FOR(i, 0, 101) {
    vector<int>::iterator it, it1;
    it = find(s.begin(), s.end(), x - i);
    it1 = find(s.begin(), s.end(), x + i);
    if (it == s.end() && x - i >= s[0] && x - i <= s[n - 1]) {
      c = x - i;
      break;
    } else if (it1 == s.end() && x + i >= s[0] && x + i <= s[n - 1]) {
      c = x + i;
      break;
    }
  }
  cout << c << '\\n';
}

void test() {
  int t;
  cin >> t;
  while (t--) // for(int j=1;j<=t;j++) cout << "Case #" << j << ": ";
  {
    solve();
  }
}

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

  // test();
  solve();

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

#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int main() {
  int x, n;
  int p;
  bool q[101];
  int i;

  cin >> x >> n;
  if (n == 0) {
    printf("%d\\n", x);
    return 0;
  }
  for (i = 1; i <= 100; i++)
    q[i] = true;
  for (i = 0; i < n; i++) {
    cin >> p;
    q[p] = false;
  }
  // for (i=1; i<=100; i++) printf("%d ", q[i]);
  // printf("\\n");
  for (i = x; i >= 1; i--) {
    if (q[i]) {
      break;
    }
    // printf("x*2-i = %d q[]=%d\\n", x*2-i, q[x*2-i]);
    int i2 = x * 2 - i;
    if (i2 <= 100) {
      if (q[i2]) {
        i = i2;
        break;
      }
    } else {
      i = i2;
      break;
    }
  }

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


Error: TLE

Fixed submission:

#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int main() {
  int x, n;
  int p;
  bool q[101];
  int i;

  cin >> x >> n;
  if (n == 0) {
    printf("%d\\n", x);
    return 0;
  }
  for (i = 1; i <= 100; i++)
    q[i] = true;
  for (i = 0; i < n; i++) {
    cin >> p;
    q[p] = false;
  }
  // for (i=1; i<=100; i++) printf("%d ", q[i]);
  // printf("\\n");
  for (i = x; i >= 1; i--) {
    if (q[i]) {
      break;
    }
    // printf("x*2-i = %d q[]=%d\\n", x*2-i, q[x*2-i]);
    int i2 = x * 2 - i;
    if (i2 <= 100) {
      if (q[i2]) {
        i = i2;
        break;
      }
    } else {
      i = i2;
    }
  }

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define endl "\\n"
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
void solve() {
  int x, n;
  cin >> x >> n;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]] = 1;
  }
  int g = x;
  while (mp[x] == 1) {
    x++;
  }
  int ans = x;
  x = g;

  while (mp[x] == 1) {
    x--;
  }
  if (abs(x - g) <= abs(ans - g)) {
    ans = x;
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  tc = 1;
  // cin >> tc;
  while (tc--) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define endl "\\n"
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
void solve() {
  int x, n;
  cin >> x >> n;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]] = 1;
  }
  queue<int> q;
  q.push(x);
  while (!q.empty()) {
    int u = q.front();
    if (mp[u] == 0) {
      cout << u << endl;
      return;
    }
    q.pop();
    q.push(u - 1);
    q.push(u + 1);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  tc = 1;
  // cin >> tc;
  while (tc--) {
    solve();
  }

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

#include <bits/stdc++.h>
using namespace std;
// using std::cin;
// using std::cout;
// using std::endl;
// using std::string;

int main() {
  int X, N;
  int m = 0, ANS = 0;

  cin >> X >> N;

  if (N != 0) {
    vector<int> vec(N);
    for (int k = 0; k < N; k++) {
      cin >> vec.at(k);
    }

    vector<int> subt(N);
    for (int k = 0; k < N; k++) {
      subt.at(k) = vec.at(k) - X;
    }

    // 小さい順に並び変え
    sort(subt.begin(), subt.end());
    /*
    for(int k=0; k<N; k++){
        cout << subt.at(k) << endl;
    }
    */
    if (subt.at(0) > 0) {
      ANS = 0;
    } else if (subt.at(N - 1) < 0) {
      ANS = 0;
    } else if (subt.at(0) <= 0) {
      ANS = subt.at(0) - 1;
    }

    m = subt.at(0); // k番目と比較する初期値
    for (int k = 1; k < N; k++) {
      if (subt.at(k) > 0) {
        if (m >= 0) {
          if (subt.at(k) - m != 1 && abs(subt.at(k - 1) + 1) < abs(ANS)) {
            ANS = subt.at(k - 1) + 1;
          }
        } else {
          ANS = 0;
        }
      }
      if (subt.at(k) <= 0) {
        if (subt.at(k) - m != 1 && abs(subt.at(k) - 1) < abs(ANS)) {
          ANS = subt.at(k) - 1;
        }
      }

      m = subt.at(k);
    }

    if (ANS == subt.at(0) - 1) {
      if (abs(subt.at(N - 1) + 1) < abs(subt.at(0) - 1)) {
        ANS = subt.at(N - 1) + 1;
      }
    }
    // cout << ANS << endl;
    cout << X + ANS << endl;
  } else {
    cout << X << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// using std::cin;
// using std::cout;
// using std::endl;
// using std::string;

int main() {
  int X, N;
  int m = 0, ANS = 0;

  cin >> X >> N;

  if (N != 0) {
    vector<int> vec(N);
    for (int k = 0; k < N; k++) {
      cin >> vec.at(k);
    }

    vector<int> subt(N);

    for (int k = 0; k < N; k++) {
      subt.at(k) = vec.at(k) - X;
    }

    // 小さい順に並び変え
    sort(subt.begin(), subt.end());
    /*
    for(int k=0; k<N; k++){
        cout << subt.at(k) << endl;
    }
    */
    if (subt.at(0) > 0) {
      ANS = 0;
    } else if (subt.at(0) <= 0) {
      ANS = subt.at(0) - 1;
    }

    m = subt.at(0); // k番目と比較する初期値
    for (int k = 1; k < N; k++) {
      if (subt.at(k) > 0) {
        if (m >= 0) {
          if (subt.at(k) - m != 1 && abs(subt.at(k - 1) + 1) < abs(ANS)) {
            ANS = subt.at(k - 1) + 1;
          }
        } else {
          ANS = 0;
        }
      }
      if (subt.at(k) <= 0) {
        if (subt.at(k) - m != 1 && abs(subt.at(k) - 1) < abs(ANS)) {
          ANS = subt.at(k) - 1;
        }
      }

      m = subt.at(k);
    }

    if (ANS == subt.at(0) - 1) {
      if (abs(subt.at(N) + 1) < abs(subt.at(0) - 1)) {
        ANS = X + subt.at(N) + 1;
      }
    }
    // cout << ANS << endl;
    cout << X + ANS << endl;
  } else {
    cout << X << endl;
  }

  return 0;
}