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

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

int main() {
  int n, x, t;
  set<int> s;
  cin >> x >> n;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    s.insert(t);
  }

  vector<pair<int, int>> diff;
  for (int i = -200; i <= 200; ++i) {
    if (s.count(i))
      continue;
    diff.emplace_back(abs(x - i), i);
  }
  sort(diff.begin(), diff.end());
  int mn = 2e9;
  for (int i = 0; i < diff.size(); ++i) {
    if (diff[i].first != diff[0].first)
      break;
    mn = min(diff[i].second, mn);
  }
  cout << mn;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n, x, t;
  set<int> s;
  cin >> x >> n;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    s.insert(t);
  }

  vector<pair<int, int>> diff;
  for (int i = 1; i <= 100; ++i) {
    if (s.count(i))
      continue;
    diff.emplace_back(abs(x - i), i);
  }
  sort(diff.begin(), diff.end());
  cout << diff[0].second;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int x, n;
  cin >> x >> n;
  map<int, int> mp;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  rep(i, n) {
    int p;
    cin >> p;
    mp[p] = 1;
  }
  bool flag = 0;
  int ans = x;
  if (mp[x] != 1) {
    cout << x << endl;
    return 0;
  }
  for (int i = 1; i <= 130; i++) {
    if (mp[x + i] != 1) {
      ans = x + i;
      flag = 1;
    }
    if (mp[x - i] != 1) {
      ans = x - i;
      flag = 1;
    }
    if (flag) {
      break;
    }
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

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

int main() {
  ll x, n, ans = 200;
  cin >> x >> n;
  vector<ll> a(n);
  vector<ll> b(200); // 0~200
  vector<ll> c(200); // abs
  rep(i, n) { cin >> a[i]; }
  rep(i, 200) {
    b[i] = i;
    c[i] = abs(a[i] - x);
  }
  bool ahaha = true;
  rep(i, 200) {
    rep(j, n) {
      if (i == a[j]) {
        ahaha = false;
      }
    }
    if (ahaha) {
      ans = min(c[i], ans);
    } else {
      ahaha = true;
    }
  }
  rep(i, n) {
    if (x - ans == a[i]) {
      cout << ans + x;
      return 0;
    }
  }
  cout << x - ans << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;

int main() {
  int i, x, n, ans = 0, dist = 999, j = 0;
  cin >> x >> n;
  if (n == 0) {
    cout << x;
    return 0;
  }
  vector<int> p(n);
  for (i = 0; i < n; i++)
    cin >> p[i];
  sort(p.begin(), p.end());
  for (i = 1; i < x; i++) {
    if (i != p[j]) {
      ans = i;
    } else {
      j++;
    }
  }
  for (i = x; i < x + (x - ans); i++) {
    if (i != p[j]) {
      ans = i;
      break;
    } else {
      j++;
    }
  }

  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;

int main() {
  int i, x, n, ans = 0, dist = 999, j = 0;
  cin >> x >> n;
  vector<int> p(n);
  for (i = 0; i < n; i++)
    cin >> p[i];
  sort(p.begin(), p.end());
  for (i = 1; i < x; i++) {
    if (i != p[j]) {
      ans = i;
    } else {
      j++;
    }
  }
  for (i = x; i < x + (x - ans); i++) {
    if (i != p[j]) {
      ans = i;
      break;
    } else {
      j++;
    }
  }

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

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

int main() {
  int X, Y, min, ans, j;
  cin >> X >> Y;
  vector<int> box(1000, 10000);
  rep(i, Y) { cin >> box.at(i); }
  sort(box.begin(), box.begin() + Y);
  min = 10000;
  j = 0;
  for (int i = -1 * X; i <= 2 * X; i++) {
    if (box.at(j) == i) {
      j++;
      continue;
    }

    if (min > abs(X - i)) {
      min = abs(X - i);
      ans = i;
    }
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int X, Y, min, ans, j;
  cin >> X >> Y;
  vector<int> box(100, 10000);
  rep(i, Y) { cin >> box.at(i); }
  sort(box.begin(), box.begin() + Y);
  min = 10000;
  j = 0;
  for (int i = -1 * X; i <= 2 * X; i++) {
    if (box.at(j) == i) {
      j++;
      continue;
    }

    if (min > abs(X - i)) {
      min = abs(X - i);
      ans = i;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

int n, x;
int f[1000];
int main() {
  cin >> x >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    a += 105;
    f[a]++;
  }
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  int A = -1, B = -1;
  x += 105;
  for (int i = 0; i <= 210; ++i) {
    if (!f[i]) {
      if (i <= x)
        A = i;
      else {
        B = i;
        break;
      }
    }
  }
  if (A == -1)
    cout << B - 105 << endl;
  else if (B == -1)
    cout << A - 105 << endl;
  else {
    if (x - A <= B - x)
      cout << A - 105 << endl;
    else
      cout << B - 105;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int n, x;
int f[1000];
set<int> s;
int main() {
  cin >> x >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    f[a]++;
  }
  for (int i = 1; i <= 100; ++i) {
    if (!f[i])
      s.insert(i);
  }
  auto it = s.lower_bound(x);
  auto it1 = it;
  it--;
  if (x - *it <= *it1 - x)
    cout << *it << endl;
  else
    cout << *it1;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define IO                                                                     \\
  std::ios_base::sync_with_stdio(false);                                       \\
  std::cin.tie(NULL);                                                          \\
  std::cout.tie(NULL);
#define FIN freopen("entrada.in", "r", stdin);
#define FOUT freopen("saida.sol", "w", stdout);

#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define MAX int(1e6 + 4)

const int INF = 0x3f3f3f3f;
using namespace std;

int main() {

  IO int x, n, dif = INT_MAX;
  cin >> x >> n;
  int ind = x;
  if (n == 0) {
    cout << x << "\\n";
    return 0;
  }
  vector<int> vet(n);
  for (int &i : vet)
    cin >> i;
  sort(vet.begin(), vet.end());
  for (int i = 0; i <= vet.back() + 1; i++)
    if (!binary_search(vet.begin(), vet.end(), i) && abs(i - x) < dif)
      dif = abs(x - i), ind = i;

  cout << ind << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define IO                                                                     \\
  std::ios_base::sync_with_stdio(false);                                       \\
  std::cin.tie(NULL);                                                          \\
  std::cout.tie(NULL);
#define FIN freopen("entrada.in", "r", stdin);
#define FOUT freopen("saida.sol", "w", stdout);

#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define MAX int(1e6 + 4)

const int INF = 0x3f3f3f3f;
using namespace std;

int main() {

  IO int x, n, dif = INT_MAX, ind;
  cin >> x >> n;
  vector<int> vet(n);
  for (int &i : vet)
    cin >> i;
  sort(vet.begin(), vet.end());
  for (int i = 0; i <= vet.back() + 1; i++)
    if (!binary_search(vet.begin(), vet.end(), i) && abs(i - x) < dif)
      dif = abs(x - i), ind = i;

  cout << ind << "\\n";

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

#include <stdio.h>
signed main(void) {
  int X, N, a, left, right, P[102] = {};
  if (scanf("%d %d", &X, &N) > 0) {
    if (N == 0)
      return printf("%d\\n", X), 0;
    for (int i = 0; i < 102; i++) {
      P[i] = i;
    }
    while (N--) {
      if (scanf("%d", &a) == 1) {
        P[a] = 102;
      }
    }
    for (int i = X; i >= 0; i--) {
      if (P[i] == 102)
        continue;
      left = i;
      break;
    }
    for (int i = X; i < 102; i++) {
      if (P[i] == 102)
        continue;
      right = i;
      break;
    }
    return printf("%d\\n", (X - left <= right - X) ? left : right), 0;
  }
}

Error: WA

Fixed submission:

#include <stdio.h>
signed main(void) {
  int X, N, a, dis = 101, P[102] = {}, min = 101, save = 101, temp;
  if (scanf("%d %d", &X, &N) > 0) {
    if (N == 0)
      return printf("%d\\n", X);
    while (N--) {
      if (scanf("%d", &a) == 1) {
        P[a - 1] = 103;
      }
    }
    for (int i = -1; i < 102; i++) {
      if (P[i] == 103)
        continue;
      dis = i + 1 < X ? X - i - 1 : i + 1 - X;
      temp = i + 1 < X ? X - dis : X + dis;
      save = save < temp ? save : temp;
    }
    return printf("%d\\n", save), 0;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\\n'

const int N = 200;
set<int> marked;

class node {
public:
  int num, distance;
  bool operator<(const node &other) const {
    if (distance == other.distance)
      return num < other.num;
    return distance < other.distance;
  }
};

int32_t main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(nullptr), cout.tie(nullptr);

  int x, n;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    marked.insert(x);
  }
  vector<node> ans;
  for (int i = 0; i <= N; i++) {
    if (!marked.count(i))
      ans.push_back({i, abs(i - x)});
  }
  sort(ans.begin(), ans.end());
  cout << ans[0].num << endl;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\\n'

const int N = 120;
bool marked[N];

class node {
public:
  int num, distance;
  bool operator<(const node &other) const {
    if (distance == other.distance)
      return num < other.num;
    return distance < other.distance;
  }
};

int32_t main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(nullptr), cout.tie(nullptr);

  memset(marked, false, sizeof marked);
  int x, n;
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    marked[x] = true;
  }
  vector<node> ans;
  for (int i = 1; i <= N; i++) {
    if (!marked[i])
      ans.push_back({i, abs(i - x)});
  }
  sort(ans.begin(), ans.end());
  cout << ans[0].num << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int X, N;
  int p[100];

  cin >> X >> N;
  bool samef = false;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    if (X == p[i])
      samef = true;
  }
  if (samef == false) {
    cout << X;
  } else {
    sort(p, p + N);

    int xIndex;
    for (int i = 0; i < N; i++) {
      if (X == p[i]) {
        xIndex = i;
        break;
      }
    }
    int ans;
    for (int d = X--, di = xIndex--; 1; di--, d--) {
      if (di < 0 || d != p[di]) {
        ans = d;
        break;
      }
    }
    for (int u = X++, ui = xIndex++; 1; ui++, u++) {
      if (ui >= N || u != p[ui]) {
        if (u - X < X - ans) {
          ans = u;
        }
        break;
      }
    }
    cout << ans;
  }
  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int X, N;
  int p[10];

  cin >> X >> N;
  bool samef = false;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    if (X == p[i])
      samef = true;
  }
  if (samef == false)
    cout << X;
  else {
    sort(p, p + N);

    int xIndex;
    for (int i = 0; i < N; i++) {
      if (X == p[i]) {
        xIndex = i;
        break;
      }
    }
    int ans;
    for (int d = X--, di = xIndex--; 1; di--, d--) {
      if (di < 0 || d != p[di]) {
        ans = d;
        break;
      }
    }
    for (int u = X++, ui = xIndex++; 1; ui++, u++) {
      if (ui >= N || u != p[ui]) {
        if (u - X < X - ans) {
          ans = u;
        }
        break;
      }
    }
    cout << ans;
  }
  cout << 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 = long long;
using P = pair<int, int>;

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

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

  vector<int> p(101, 1);
  rep(i, N) {
    int ibuff;
    cin >> ibuff;
    p.at(ibuff) = 0;
  }

  int i1 = 0;
  for (int i = x; i > 0; --i) {
    if (p.at(i) == 1) {
      i1 = i;
      break;
    }
  }

  int i2 = 101;
  for (int i = x; i <= 100; ++i) {
    if (p.at(i) == 1) {
      i2 = i;
      break;
    }
  }

  if (x - i1 <= i2 - x) {
    cout << i1 << endl;
  } else {
    cout << i2 << 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;
using P = pair<int, int>;

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

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

  vector<int> p(100, 1);
  rep(i, N) {
    int ibuff;
    cin >> ibuff;
    p.at(ibuff - 1) = 0;
  }

  int i1 = -1, i2 = 100;
  for (int i = x; i >= 0; --i) {
    if (p.at(i) == 1) {
      i1 = i;
      break;
    }
  }

  for (int i = x; i < 100; ++i) {
    if (p.at(i) == 1) {
      i2 = i;
      break;
    }
  }

  if (x - i1 <= i2 - x) {
    cout << i1 - 1 << endl;
  } else {
    cout << i2 + 1 << endl;
  }
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define I_O ios::sync_with_stdio(false), cin.tie(0)
#define ll long long
#define ff first
#define ss second
#define mod 1000000007
#define rep(i, n) for (ll i = 1; i <= n; i++)
#define repv(i, a, n) for (ll i = a; i <= n; i++)
#define pb push_back
#define newl '\\n'
#define deb(x) cout << x << " "
int main() {
  I_O;
  int x, n, val, diff, mn = 200;
  cin >> x >> n;
  set<int> s;
  rep(i, n) cin >> val, s.insert(val);
  repv(i, 0, 101) {
    bool isin = s.find(i) != s.end();
    if (!isin) {
      diff = abs(x - i);
      mn = min(mn, diff);
    }
  }
  repv(i, 0, 101) {
    bool isin = s.find(i) != s.end();
    if (!isin) {
      diff = abs(x - i);
      if (diff == mn)
        return cout << i, 0;
    }
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define I_O ios::sync_with_stdio(false), cin.tie(0)
#define ll long long
#define ff first
#define ss second
#define mod 1000000007
#define rep(i, n) for (ll i = 1; i <= n; i++)
#define repv(i, a, n) for (ll i = a; i <= n; i++)
#define pb push_back
#define newl '\\n'
#define deb(x) cout << x << " "
int main() {
  I_O;
  int x, n, num, mx = 0, diff, mn = 200;
  cin >> x >> n;
  set<int> s;
  rep(i, n) cin >> num, mx = max(mx, num), s.insert(num);
  if (n == 0)
    return cout << x, 0;
  vector<int> v;
  for (int i = 0; i <= mx + 1; i++) {
    bool isin = s.find(i) != s.end();
    if (!isin) {
      diff = abs(x - i);
      mn = min(mn, diff);
    }
  }
  for (int i = 0; i <= mx + 1; i++) {
    if (i != x) {
      bool isin = s.find(i) != s.end();
      if (!isin) {
        diff = abs(x - i);
        if (diff == mn)
          v.pb(i);
      }
    }
  }
  sort(v.begin(), v.end());
  cout << v[0];
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

// Driver program
int main() {
  int x, n;
  cin >> x >> n;
  vector<int> v(n);
  int f = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (v[i] == x)
      f = 1;
  }
  if (!n) {
    cout << x;
    return 0;
  }
  if (!f) {
    cout << x;
    return 0;
  }
  sort(v.begin(), v.end());
  auto it = lower_bound(v.begin(), v.end(), x);
  if (*it != x)
    cout << x;
  else if (*it == x) {
    int j = it - v.begin();
    int i = 1;
    while (true) {
      if (j - i >= 0 && v[j - i] != v[j] - i) {
        cout << v[j] - i;
        return 0;
      } else if (j + i < n && v[j + i] != v[j] + i) {
        cout << v[j] + i;
        return 0;
      } else if (j + i < n && j - i >= 0) {
        i++;
      } else {
        break;
      }
    }
    if (j + i == n && j - i >= 0) {
      if (v[j - i] != v[j] - i) {
        cout << v[j] - i;
      } else
        cout << v[j] + i;
    } else if (j - i < 0 && j + i < n) {
      if (v[j + i] != v[j] + i) {
        cout << v[j] + i;
      } else
        cout << v[j] - i;
    } else {
      cout << v[j] - i;
    }
  }
}

Error: WA

Fixed submission:

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

// Driver program
int main() {
  int x, n;
  cin >> x >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  if (!n) {
    cout << x;
    return 0;
  }
  sort(v.begin(), v.end());
  auto it = lower_bound(v.begin(), v.end(), x);
  if (*it != x)
    cout << x;
  else if (*it == x) {
    int j = it - v.begin();
    int i = 1;
    while (true) {
      if (j - i >= 0 && v[j - i] != v[j] - i) {
        cout << v[j] - i;
        break;
      } else if (j + i < n && v[j + i] != v[j] + i) {
        cout << v[j] + i;
        break;
      } else {
        i++;
      }
    }
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  int X, N;
  cin >> X >> N;
  vector<bool> fg(120);
  for (int i = 0; i < N; i++) {
    int P;
    cin >> P;
    fg[P] = 1;
  }
  int sa = 10000;
  int ans = -1;
  for (int i = 110; i >= 0; i--) {
    if (abs(i - X) <= sa && fg[i] == false) {
      sa = abs(i - X);
      ans = i;
    }
  }
  cout << ans << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  priority_queue<pair<int, int>> pq;
  int a, b;
  cin >> a >> b;
  set<int> se;
  for (int i = 0; i < b; ++i) {
    int k;
    cin >> k;
    se.insert(k);
  }
  for (int i = 1; i <= 100; ++i) {
    if (!se.count(i)) {
      pair<int, int> p(-abs(i - a), -i);
      pq.push(p);
    }
  }
  cout << -pq.top().second;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define con continue;
#define MOAE                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
void coutv(vector<ll> v) {
  for (auto it : v)
    cout << it << " ";
  cout << endl;
}
void couts(set<int> v) {
  for (auto it : v)
    cout << it << " ";
}

int main() {
  MOAE;
  ll x, n, mn = LLONG_MAX, a = 0, b = 0;
  cin >> x >> n;
  vector<ll> v(n);
  multiset<ll> s;
  for (auto &i : v)
    cin >> i, s.insert(i);
  if (!s.count(x)) {
    cout << x << endl;
    ok;
  }
  for (int i = x - 1, j = x + 1;; i--, j++) {
    if (!s.count(i)) {
      cout << i << endl;
      ok;
    }
    if (!s.count(j)) {
      cout << j << endl;
      ok;
    }
  }
}


Error: 0

Fixed submission:

/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define con continue;
#define MOAE                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
void coutv(vector<ll> v) {
  for (auto it : v)
    cout << it << " ";
  cout << endl;
}
void couts(set<int> v) {
  for (auto it : v)
    cout << it << " ";
  cout << endl;
}

int main() {
  MOAE;
  ll x, n, mn = LLONG_MAX, a = 0, b = 0;
  cin >> x >> n;
  vector<ll> v(n), ansi, ans;
  multiset<ll> s;
  for (auto &i : v)
    cin >> i, s.insert(i);
  ll start = 100;
  while (start != 0) {
    if (!s.count(start)) {
      ansi.push_back(start);
    }
    start--;
  }
  sort(all(ansi));
  ll j = 0;
  for (int i = 0; i < ansi.size(); i++) {
    ll ab = abs(x - ansi[i]);
    if (ab < mn) {
      mn = ab;
      j = i;
    }
  }
  // cout << j << endl;
  cout << ansi[j] << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int comp(const void *a, const void *b) { return *(int *)a - *(int *)b; }

int main() {
  int X, N, p[102], num;
  bool flag = 1;

  cin >> X >> N;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  qsort(p, N, sizeof(int), comp);

  for (int j = 0; j < N; j++) {
    if (X == p[j]) {
      flag = 0;
      num = j;
    }
  }
  if (flag) {
    cout << X << endl;
    return 0;
  }
  for (int k = 1; k <= N; k++) {
    if (p[max(num - k, 0)] != (p[num] - k)) {
      cout << p[num] - k << endl;
      break;
    }
    if (p[min(num + k, N - 1)] != (p[num] + k)) {
      cout << p[num] + k << endl;
      break;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; ++i) {
    flag = 0;
    for (int j = N - 1; j >= i + 1; --j) {
      if (A[j - 1] > A[j]) {
        int box;

        box = A[j - 1];
        A[j - 1] = A[j];
        A[j] = box;

        sw++;
        flag = 1;
      }
    }
  }
}

int main() {
  int X, N, p[102], num;
  bool flag = 1;

  cin >> X >> N;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  bubbleSort(p, N);

  for (int j = 0; j < N; j++) {
    if (X == p[j]) {
      flag = 0;
      num = j;
    }
  }
  if (flag) {
    cout << X << endl;
    return 0;
  }
  for (int k = 1; k < (N + 1) / 2; k++) {
    if (p[max(num - k, 0)] != (p[num] - k)) {
      cout << p[num] - k << endl;
      break;
    }
    if (p[min(num + k, N - 1)] != (p[num] + k)) {
      cout << p[num] + k << endl;
      break;
    }
  }

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

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

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


Error: 0

Fixed submission:

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

int main() {
  int x, n, p;
  vector<int> b(201);
  cin >> x >> n;
  for (int i = 51; i < 151; i++) {
    b.at(i) = 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> p;
    b.at(p + 50) = 0;
  }
  for (int i = 0; i < 101; i++) {
    if (b.at(x - i + 50) == 1) {
      cout << x - i << endl;
      break;
    } else if (b.at(x + i + 50) == 1) {
      cout << x + i << endl;
      break;
    }
  }
}