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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

inline int at(ll x, int k) { return (x >> k) & 1; }
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)

int main() {
  int x, n;
  cin >> x >> n;
  int flag = 3;
  int x1 = x;
  int x2 = x;

  if (n != 0) {
    int p[n];

    rep(i, 0, n) {
      cin >> p[i];
      if (p[i] == x) {
        flag = 0;
      }
    }

    while (flag == 0) {
      x1 -= 1;
      x2 += 1;

      int c1 = 0;
      int c2 = 0;
      rep(i, 0, n) {
        if (p[i] == x1) {
          c1 = 1;
        } else if (p[i] == x2) {
          c2 = 1;
        }
      }
      if (c1 == 0 && c2 == 0) {
        flag = 1;
      } else if (c1 == 1 && c2 == 0) {
        flag = 2;
      } else if (c1 == 0 && c2 == 1) {
        flag = 1;
      }
    }
  }
  if (flag == 1) {
    cout << x1 << endl;
  } else if (flag == 2) {
    cout << x2 << endl;
  } else if (flag == 3) {
    cout << x << endl;
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

inline int at(ll x, int k) { return (x >> k) & 1; }
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)

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

  int flag = 3;
  rep(i, 0, n) {
    cin >> p[i];
    if (p[i] == x) {
      flag = 0;
    }
  }
  int x1 = x;
  int x2 = x;

  while (flag == 0) {
    x1 -= 1;
    x2 += 1;

    int c1 = 0;
    int c2 = 0;
    rep(i, 0, n) {
      if (p[i] == x1) {
        c1 = 1;
      } else if (p[i] == x2) {
        c2 = 1;
      }
    }
    if (c1 == 0 && c2 == 0) {
      flag = 1;
    } else if (c1 == 1 && c2 == 0) {
      flag = 2;
    } else if (c1 == 0 && c2 == 1) {
      flag = 1;
    }
  }
  if (flag == 1) {
    cout << x1 << endl;
  } else if (flag == 2) {
    cout << x2 << endl;
  } else if (flag == 3) {
    cout << x << endl;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main() {
  int X, N;
  scanf("%d %d", &X, &N);
  int candidate[101];
  candidate[0] = X;
  for (size_t i = 1; i <= 50; i++) {
    candidate[i * 2 - 1] = X - i;
    candidate[i * 2] = X + i;
  }

  int answer = 200;
  for (size_t i = 0; i < N; i++) {
    int tmp;
    scanf("%d", &tmp);
    if (tmp == X)
      candidate[0] = 300;
    else if (tmp < X) {
      if (2 * (X - tmp) - 1 <= 100)
        candidate[2 * (X - tmp) - 1] = 300;
    } else if (2 * (tmp - X) <= 100)
      candidate[2 * (tmp - X)] = 300;
  }
  for (size_t i = 0; i < 101; i++) {
    if (candidate[i] != 300) {
      printf("%d\\n", candidate[i]);
      return 0;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1000000007;

int main() {
  int X, N;
  scanf("%d %d", &X, &N);
  int candidate[101];
  candidate[0] = X;
  for (size_t i = 1; i <= 50; i++) {
    candidate[i * 2 - 1] = X - i;
    candidate[i * 2] = X + i;
  }

  int answer = 200;
  for (size_t i = 0; i < N; i++) {
    int tmp;
    scanf("%d", &tmp);
    if (tmp == X)
      candidate[0] = 300;
    else if (tmp < X)
      candidate[2 * (X - tmp) - 1] = 300;
    else
      candidate[2 * (tmp - X)] = 300;
  }
  for (size_t i = 0; i < 101; i++) {
    if (candidate[i] != 300) {
      printf("%d\\n", candidate[i]);
      return 0;
    }
  }
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
  int X, N;
  cin >> X >> N;
  if (N == 0) {
    cout << X << endl;
    return 0;
  }
  vector<pair<int, int>> ans;
  vector<bool> num(100, false);
  rep(i, N) {
    int p;
    cin >> p;
    num[p - 1] = true;
  }
  rep2(i, -100, 101) {
    if (i < 0) {
      ans.push_back(make_pair(abs(i + 1 - X), i + 1));
      continue;
    }
    if (!num[i]) {
      ans.push_back(make_pair(abs(i + 1 - X), i + 1));
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans[0].second << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
  int X, N;
  cin >> X >> N;
  if (N == 0) {
    cout << X << endl;
    return 0;
  }
  vector<pair<int, int>> ans;
  int def = 100;
  vector<bool> num(100, false);
  rep(i, N) {
    int p;
    cin >> p;
    num[p - 1] = true;
  }
  rep(i, 100) {
    if (!num[i]) {
      ans.push_back(make_pair(abs(i + 1 - X), i + 1));
    }
  }
  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;

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

  if (N == 0)
    cout << X << endl;

  else if (N != 0) {
    vector<int> vec(102);
    vector<int> vecD(102);
    vector<int> vecAns(102, 1000);

    for (int i = 0; i < 102; i++)
      vec.at(i) = i; // 0-101までの列

    for (int i = 0; i < N; i++) {
      int p;
      cin >> p;
      vec.at(p) = 1000; // 入力した配列を1000で除外
    }

    for (int i = 0; i < 102; i++)
      vecD.at(i) = abs(vec.at(i) - X); // Xとの差の絶対値の配列

    int counter = 0;
    for (int j = 0; j < 101; j++) {
      for (int i = 0; i < 102; i++) {
        if (vecD.at(i) == j) { // 差がjとなるかチェック
          vecAns.at(i) = vec.at(i);
          counter += 1;
        }
      }
      if (counter == 0)
        continue;
      else if (counter != 0)
        break;
    }
    int min = vecAns.at(0);
    for (int i = 0; i < 102; i++) {
      if (vecAns.at(i) <= min)
        min = vecAns.at(i);
    }
    cout << min << endl;
  }
}

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


Fixed submission:

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

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

  if (N == 0)
    cout << X << endl;

  else if (N != 0) {
    vector<int> vec(102);
    vector<int> vecD(102);
    vector<int> vecAns(102, 1000);

    for (int i = 0; i < 103; i++)
      vec.at(i) = i;

    for (int i = 0; i < N; i++) {
      int p;
      cin >> p;
      vec.at(p - 1) = 1000; // 入力配列の除外
    }

    for (int i = 0; i < 102; i++)
      vecD.at(i) = abs(vec.at(i) - X); // Xとの差の配列

    int counter = 0;
    for (int j = 0; j < 101; j++) {
      for (int i = 0; i < 102; i++) {
        if (vecD.at(i) == j) {
          vecAns.at(i) = vec.at(i);
          counter++;
        }
        if (counter == 0)
          continue;
        else if (counter != 0)
          break;
      }
    }
    sort(vecAns.begin(), vecAns.end());
    cout << vecAns.at(0) << endl;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int A, B, C, D, E;
  cin >> A >> B;

  vector<int> JNY(B);
  vector<int> OOT(102);

  for (int YUNI = 0; YUNI < 102; YUNI++) {
    OOT.at(YUNI) = YUNI;
  }

  for (int YUNI = 0; YUNI < B; YUNI++) {
    cin >> JNY.at(YUNI);
  }

  for (int YUNI = 0; YUNI < 102; YUNI++) {
    OOT.at(YUNI) -= A;
  }

  for (int YUNI = 0; YUNI < B; YUNI++) {
    OOT.at(JNY.at(YUNI)) = 200;
  }

  for (int YUNI = 0; YUNI < 102; YUNI++) {
    if (OOT.at(YUNI) < 0) {
      OOT.at(YUNI) = -OOT.at(YUNI);
    }
  }

  int KYR = 200;

  for (int YUNI = 0; YUNI < 102; YUNI++) {
    D = OOT.at(YUNI);
    if (D < KYR) {
      KYR = D;
      C = YUNI;
    }
  }

  cout << C << endl;
  // cout << OOT.at(2) << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int A, C, D = 0, E;
  cin >> A >> C;

  vector<int> JNY(C);
  vector<int> PKRN(100);

  for (int YUNI = 1; YUNI < 100; YUNI++) {
    PKRN.at(YUNI) = YUNI;
  }

  for (int YUNI = 0; YUNI < C; YUNI++) {
    cin >> JNY.at(YUNI);
  }

  for (int YUNI = 0; YUNI < C; YUNI++) {
    PKRN.at(JNY.at(YUNI)) = 200;
  }

  for (int YUNI = 1; YUNI < 100; YUNI++) {
    PKRN.at(YUNI) -= A;
  }

  // cout << PKRN.at(9) <<endl;

  for (int YUNI = 1; YUNI < 100; YUNI++) {

    if (PKRN.at(YUNI) == -1) {
      continue;
    }

    if (PKRN.at(YUNI) < 0) {
      PKRN.at(YUNI) = (PKRN.at(YUNI) * (PKRN.at(YUNI) * 2));
    }
  }

  // cout << PKRN.at(9) <<endl;
  int min = 101;

  for (int YUNI = 1; YUNI < 100; YUNI++) {

    if (PKRN.at(YUNI) == 200 - A) {
      continue;
    }

    if (PKRN.at(YUNI) < min) {
      min = PKRN.at(YUNI);
      E = YUNI;
    }
  }

  if (C == 0) {
    cout << A << endl;
  }

  else {
    cout << E << endl;
    // cout << PKRN.at(11) << endl;
    // cout << D << endl;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ios_base::sync_with_stdio(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, x;
    cin >> x >> n;
    set<int> s;
    for (int i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      s.insert(temp);
    }
    int ans = 1000;
    for (int i = 0;; ++i) {
      if (!s.count(x - i)) {
        ans = x - i;
        break;
      } else if (!s.count(x + i)) {
        ans = x + i;
        break;
      }
    }
    cout << ans;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, x;
    cin >> x >> n;
    set<int> s;
    for (int i = 1; i <= 100; i++)
      s.insert(i);
    for (int i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      s.erase(temp);
    }
    set<int>::iterator it = lower_bound(s.begin(), s.end(), x);
    int ans1 = *it;
    it--;
    int ans2 = *it;
    if (abs(ans2 - x) <= (ans1 - x))
      cout << ans2;
    else
      cout << ans1;
  }
  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 = long long;
using P = pair<int, int>;

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


Error: WA

Fixed submission:

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

int main() {
  int X, N;
  cin >> X >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  bool re = true;

  for (int i = 0; i < N; i++) {
    if (vec.at(i) == X) {

      int j = 0;
      while (re) {
        if (vec.at(i - j) != X - j) {
          cout << X - j;
          re = false;
          break;
        } else if (vec.at(i + j) != X + j) {
          cout << X + j;
          re = false;
          break;
        }
        j++;
      }
    }
  }
  if (re) {
    cout << X;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint &arg1, const pint &arg2) {
  return arg1.first > arg2.first;
}
template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

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

  vector<int> p(100);
  int ptmp;
  for (int in = 0; in < n; in++) {
    cin >> ptmp;
    ptmp--;
    p.at(ptmp) = 1;
  }

  int ans = x;
  bool flg;
  for (int in = 0; in < 100; in++) {
    ans = x - in;
    flg = true;
    for (int in = 0; in < n; in++) {
      if (1 <= ans && ans <= 100) {
        if (p.at(ans - 1) == 1) {
          flg = false;
        }
      }
    }
    if (flg) {
      cout << ans << endl;
      return 0;
    }

    ans = x + in;
    flg = true;
    for (int in = 0; in < n; in++) {
      if (1 <= ans && ans <= 100) {
        if (p.at(ans - 1) == 1) {
          flg = false;
        }
      }
    }
    if (flg) {
      cout << ans << endl;
      return 0;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint &arg1, const pint &arg2) {
  return arg1.first > arg2.first;
}
template <class T> void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

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

  vector<int> p(100);
  int ptmp;
  for (int in = 0; in < n; in++) {
    cin >> ptmp;
    ptmp--;
    p.at(ptmp) = 1;
  }

  int ans = x;
  for (int in = 0; in < 100; in++) {
    if (1 <= ans - in && ans - in <= 100) {
      if (p.at(ans - in - 1) == 0) {
        cout << ans - in << endl;
        return 0;
      }
      if (p.at(ans + in - 1) == 0) {
        cout << ans + in << endl;
        return 0;
      }
    } else {
      cout << ans - in - 1 << endl;
      return 0;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> x >> n;
  int a[n], b[110] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]] = 1;
  }
  for (int i = 0; i < 110; i++) {
    if (b[x - i] == 0) {
      cout << x - i << endl;
      break;
    }
    if (b[x + i] == 0) {
      cout << x + i << endl;
      break;
    }
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n;
  cin >> x >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int k;
  int NUM;
  k = lower_bound(a, a + n, x) - a;
  for (int i = 0; i < n; i++) {
    if (a[i] == k) {
      NUM = i;
      break;
    }
  }
  int m;
  for (int i = 1; i < 9; i++) {
    int o;
    o = k - i;
    if (a[NUM] != o) {
      m = o;
      break;
    }
  }
  if (m > k) {
    m = k - 2 * (k - x);
  }
  cout << m << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
#define lli long long int
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
lli arr[100];
unordered_map<lli, bool> maps;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  lli x, n;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    maps[arr[i]] = true;
  }
  sort(arr, arr + n);
  if (binary_search(arr, arr + n, x)) {
    lli index = binary_search(arr, arr + n, x);
    if (n == 0)
      cout << x << endl;
    else if (index == n - 1) {
      if (!maps[x - 1])
        cout << x - 1 << endl;
      else
        cout << x + 1 << endl;
    }

    else if (index == 0)
      cout << x - 1 << endl;
    else {
      lli j = x - 1;
      lli last = x + 1;
      lli ans1, ans2;
      while (true) {
        if (!maps[j]) {
          ans1 = j;
          break;
        }
        j--;
      }
      while (true) {
        if (!maps[last]) {
          ans2 = last;
          break;
        }
        last++;
      }
      if (abs(x - ans1) > (abs(x - ans2)))
        cout << ans2 << endl;
      else
        cout << ans1 << endl;
    }

  } else {
    cout << x << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  int n, x;
  cin >> x >> n;
  if (n == 0) {
    cout << x;
    return 0;
  }
  set<int> s;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s.insert(a);
  }
  vector<pair<int, int>> v;
  for (int i = 1; i <= 100; i++) {
    if (s.find(i) != s.end()) {
      continue;
    } else {
      int diff = abs(x - i);
      v.push_back(make_pair(diff, i));
    }
  }
  sort(v.begin(), v.end());
  cout << v[0].second;
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
  author:@bhaskar_8998
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef vector<i64> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef map<int, int> mi;
#define all(A) (A).begin(), (A).end()
#define pb push_back
#define MOD 1000000007
#define ff first
#define ss second
#define deb(x) cerr << #x << " " << x << "\\n";
#define fastio()                                                               \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  fastio();
  clock_t beg = clock();
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> k >> n;
    mi m;
    m.clear();
    for (int i = 0, a; i < n; i++) {
      cin >> a;
      m[a] += 1;
    }
    int xm = 0;
    for (int i = 0;; i++) {
      int x = INT_MAX, y = INT_MAX;
      if (m[k - i] == 0)
        x = k - i;
      if (m[k + i] == 0)
        y = k + i;
      xm = min(x, y);
      if (xm >= 0 && xm != INT_MAX)
        break;
    }
    cout << xm;
  }
  clock_t end = clock();
  fprintf(stderr, "\\n%lf sec\\n", (double)(end - beg) / (CLOCKS_PER_SEC));
  return 0;
}


Error: TLE

Fixed submission:

/*
  author:@bhaskar_8998
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef vector<i64> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef map<int, int> mi;
#define all(A) (A).begin(), (A).end()
#define pb push_back
#define MOD 1000000007
#define ff first
#define ss second
#define deb(x) cerr << #x << " " << x << "\\n";
#define fastio()                                                               \\
  {                                                                            \\
    ios_base::sync_with_stdio(false);                                          \\
    cin.tie(NULL);                                                             \\
  }

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  fastio();
  clock_t beg = clock();
  int t = 1;
  // cin>>t;
  while (t--) {
    int n, k;
    cin >> k >> n;
    mi m;
    m.clear();
    for (int i = 0, a; i < n; i++) {
      cin >> a;
      m[a] += 1;
    }
    int xm = 0;
    for (int i = 0;; i++) {
      int x = INT_MAX, y = INT_MAX;
      if (m[k - i] == 0)
        x = k - i;
      if (m[k + i] == 0)
        y = k + i;
      xm = min(x, y);
      if (xm > 0 && xm != INT_MAX)
        break;
    }
    cout << xm;
  }
  clock_t end = clock();
  fprintf(stderr, "\\n%lf sec\\n", (double)(end - beg) / (CLOCKS_PER_SEC));
  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) {
    cin.ignore();
    cin.ignore();
    cout << x;
    return 0;
  }
  vector<int> p(n);
  vector<int> ans;
  vector<pair<int, int>> tmp;
  for (int i = 0; i < n; i++)
    cin >> p.at(i);
  for (int i = -200; i <= 200; i++) {
    int flag = 0;
    for (int j = 0; j < n; j++) {
      if (i == p.at(j))
        flag = 1;
    }
    if (flag == 0) {
      ans.push_back(i);
    }
  }
  int mi = 1000;
  for (int i = 0; i < ans.size(); i++) {
    if (mi > abs(x - ans.at(i))) {
      tmp.push_back(make_pair(abs(x - ans.at(i)), ans.at(i)));
    }
  }
  sort(tmp.begin(), tmp.end());
  cout << tmp.at(0).second;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0) {
    string s;
    cin.ignore();
    getline(cin, s);
    cout << x;
    return 0;
  }
  vector<int> p(n);
  vector<int> ans;
  vector<pair<int, int>> tmp;
  for (int i = 0; i < n; i++)
    cin >> p.at(i);
  for (int i = 1; i <= 100; i++) {
    int flag = 0;
    for (int j = 0; j < n; j++) {
      if (i == p.at(j))
        flag = 1;
    }
    if (flag == 0) {
      ans.push_back(i);
    }
  }
  int mi = 1000;
  for (int i = 0; i < ans.size(); i++) {
    if (mi > abs(x - ans.at(i))) {
      tmp.push_back(make_pair(abs(x - ans.at(i)), ans.at(i)));
    }
  }
  sort(tmp.begin(), tmp.end());
  cout << tmp.at(0).second;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define all(x) x.begin(), x.end()
#define MOD 998244353

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve() {
  // Your code goes here.
  int n, r;
  cin >> r >> n;
  vector<int> v(n);
  set<int> s;

  for (int i = 0; i < n; i++) {
    cin >> v[i];
    s.insert(v[i]);
  }
  if (n == 0 || s.find(r) == s.end()) {
    cout << r << endl;
    return;
  }
  int i = 1, check, nextt, g;
  check = r;
  while (i <= 1000) {
    nextt = (pow((-1), i));
    g = nextt * i;
    check = (check + g);

    if (s.find(check) == s.end()) {
      cout << check << endl;
      return;
    } else {
      // cout<<i<<endl;
      // cout<<check<<endl;
      i++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int T = 1;
  // cin >> T; // If only one test case then you can comment this line out.

  while (T--) {
    solve();
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define all(x) x.begin(), x.end()
#define MOD 998244353

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve() {
  // Your code goes here.
  int n, r;
  cin >> r >> n;
  vector<int> v(n);
  set<int> s;

  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    s.insert(v[i]);
  }
  if (n == 0) {
    cout << r << endl;
    return;
  }
  int i = 1, check, nextt, g;
  check = r;
  while (i <= 100) {
    nextt = (pow((-1), i));
    g = nextt * i;
    check = (check + g);

    if (s.find(check) == s.end()) {
      cout << check << endl;
      return;
    } else {
      // cout<<i<<endl;
      // cout<<check<<endl;
      i++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int T = 1;
  // cin >> T; // If only one test case then you can comment this line out.

  while (T--) {
    solve();
  }

  return 0;
}