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


#include <algorithm>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int main() {
  ll x, N, p[210] = {0}, cnt[210] = {0}, min = 100000;
  cin >> x >> N;
  for (int i = 1; i <= N; i++)
    cin >> p[i];
  for (int i = 1; i <= N; i++) {
    cnt[p[i]]++;
  }
  for (int j = 0; j <= 200; j++) {
    if (cnt[j] == 0) {
      if (abs(j - x) < min)
        min = abs(j - x);
    }
  }

  if (cnt[x - min] == 0)
    p(x - min);
  else if (cnt[x + min] == 0)
    p(x + min);
}

Error: -7

Fixed submission:


#include <algorithm>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
int main() {
  ll x, N, p[110], cnt[110] = {0}, min = 100000;
  cin >> x >> N;
  for (int i = 1; i <= 100; i++)
    cin >> p[i];
  for (int i = 1; i <= 100; i++) {
    cnt[p[i]]++;
  }
  for (int j = 1; j <= 100; j++) {
    if (cnt[p[j] == 0]) {
      if (abs(j - x) < min)
        min = abs(j - x);
    }
  }
  p(x - min);
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

// Created by Kira

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

#define IOS                                                                    \\
  cin.sync_with_stdio(0);                                                      \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);

int main() {
  IOS

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

  set<int> st;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    st.insert(v);
  }

  int i = x;

  for (int d = 0; d <= 100; d++) {
    if (!st.count(x - d)) {
      cout << x - d << "\\n";
      return 0;
    } else if (!st.count(x + d)) {
      cout << x + d << "\\n";
      return 0;
    }
  }
}

ll pwr(ll a, ll b) {
  a %= mod; // Remove mod if not required
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }

  return res;
}


Error: TLE

Fixed submission:

// Created by Kira

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

#define IOS                                                                    \\
  cin.sync_with_stdio(0);                                                      \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);

int main() {
  IOS

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

  set<int> st;
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    st.insert(v);
  }

  queue<int> q;
  q.push(x);

  while (!q.empty()) {
    int p = q.front();
    q.pop();

    if (!st.count(p)) {
      cout << p << "\\n";
      return 0;
    }

    q.push(p - 1);
    q.push(p + 1);
  }
}

ll pwr(ll a, ll b) {
  a %= mod; // Remove mod if not required
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }

  return res;
}
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;
  }

  set<int> s;
  for (int i = 0; i < 102; i++) {
    s.insert(i);
  }
  vector<int> p(n);
  bool flag = false;
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
    s.erase(p.at(i));
    if (p.at(i) == x) {
      flag = true;
    }
  }
  s.insert(x);

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

  vector<int> ss(s.size());
  for (int i = 0; i < 102; i++) {
    if (s.count(i) == 1) {
      ss.push_back(i);
    }
  }
  int k = ss.size();
  int num;
  for (int i = 0; i < k; i++) {
    if (ss.at(i) == x) {
      num = i;
      break;
    }
  }
  if (abs(ss.at(num - 1) - ss.at(num)) <= abs(ss.at(num + 1) - ss.at(num))) {
    cout << ss.at(num - 1) << endl;
    return 0;
  } else {
    cout << ss.at(num + 1) << 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;
  }

  set<int> s;
  for (int i = 0; i < 102; i++) {
    s.insert(i);
  }
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
    s.erase(p.at(i));
  }
  s.insert(x);

  vector<int> ss(s.size());
  int k = s.size();
  for (int i = 0; i < k; i++) {
    if (s.count(i) == 1) {
      ss.push_back(i);
    }
  }
  k = ss.size();
  int num;
  for (int i = 0; i < k; i++) {
    if (ss.at(i) == x) {
      num = i;
    }
  }
  if (abs(ss.at(num - 1) - ss.at(num)) <= abs(ss.at(num + 1) - ss.at(num))) {
    cout << ss.at(num - 1) << endl;
    return 0;
  } else {
    cout << ss.at(num + 1) << endl;
    return 0;
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
int main() {
  int x, n, p, i, q, ans;
  cin >> x >> n;
  int vis[105] = {0};
  for (i = 0; i < n; i++) {
    cin >> p;
    vis[p] = 1;
  }
  for (i = x; i >= 0; i--) {
    if (vis[i] == 0) {
      p = i;
      break;
    }
  }
  for (i = x; i <= 101; i++) {
    if (vis[i] == 0) {
      q = i;
      break;
    }
  }
  if (abs(x - p) <= abs(x - q))
    ans = p;
  else
    ans = q;
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
int main() {
  int x, n, p, i;
  cin >> x >> n;
  int vis[101] = {0};
  for (i = 0; i < n; i++) {
    cin >> p;
    vis[p] = 1;
  }
  i = 0;
  while (1) {
    if (x - i >= 1) {
      if (vis[x - i] == 0) {
        p = x - i;
        goto a;
      }
    }
    if (x + i <= 100) {
      if (vis[x + i] == 0) {
        p = x + i;
        goto a;
      }
    }
    i++;
  }
a : {}
  cout << p;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

int main() {
  fastio;

  int n, x;
  cin >> x >> n;
  int a[n];
  int mini = INT_MAX;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  sort(a, a + n);
  int index = x;

  for (int i = -101; i <= 101; ++i) {
    int flag = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == i) {
        flag = 1;
        break;
      }
    }

    if (flag == 0) {
      if (abs(i - x) < mini) {
        mini = abs(i - x);
        index = i;
      }
    }
  }

  cout << index;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

int main() {
  fastio;

  int n, x;
  cin >> x >> n;
  if (n == 0) {
    cout << x;
    return 0;
  }
  int a[n];
  int mini = INT_MAX;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  sort(a, a + n);
  int index = 0;
  vector<int> v;
  for (int i = 1; i <= 100; ++i) {
    if (abs(x - i) < mini && (binary_search(a, a + n, i) == false)) {
      mini = abs(x - i);
      v.push_back(i);
    }
  }

  sort(v.begin(), v.end(), greater<int>());

  cout << v[0];

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

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

int main() {
  int x, n, ans = 100, tmp = 100;
  cin >> x >> n;
  vector<int> p(n), test(102);
  for (int i = 0; i <= 101; i++)
    test.at(i) = i;
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
    test.erase(remove(test.begin(), test.end(), p.at(i)), test.end());
  }
  for (int i : test) {
    if (abs(x - i) < tmp) {
      ans = i;
      tmp = abs(x - i);
    }
  }
  cout << ans << endl;
  return 0;
}

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


Fixed submission:

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

int main() {
  int x, n, ans = 100, tmp = 100;
  cin >> x >> n;
  vector<int> p(n), test(100);
  for (int i = 0; i <= 100; i++)
    test.at(i) = i;
  for (int i = 0; i < n; i++) {
    cin >> p.at(i);
    test.erase(remove(test.begin(), test.end(), p.at(i)), test.end());
  }
  for (int i : test) {
    if (abs(x - i) < tmp) {
      ans = i;
      tmp = abs(x - i);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02641 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  std::vector<int> p(n);
  for (int i = 0; i < n; ++i)
    std::cin >> p[i];

  int minD = 1000;
  int result = 0;
  for (int j = 200; j > -100; --j) {
    if (std::any_of(p.begin(), p.end(), [j](int v) { return j == v; }))
      continue;

    if (minD >= std::abs(j - x)) {
      minD = std::abs(j - x);
      result = j;
    }
  }

  std::cout << result << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

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

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

  std::vector<int> p(n);
  for (int i = 0; i < n; ++i)
    std::cin >> p[i];

  int minD = 1000;
  int result = 0;
  for (int j = 200; j > -100; ++j) {
    if (std::any_of(p.begin(), p.end(), [j](int v) { return j == v; }))
      continue;

    if (minD >= std::abs(j - x)) {
      minD = std::abs(j - x);
      result = j;
    }
  }

  std::cout << result << std::endl;

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

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

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

  int j = 0;
  int result = 0;
  int diff = 100;
  for (int i = 0; i <= 101; i++) {
    auto tmp = find(p.begin(), p.end(), i);
    if (tmp == p.end()) {
      if (abs(x - i) < diff) {
        result = i;
        diff = abs(x - i);
      }
    } else {
      continue;
    }
  }

  cout << result << endl;
}


Error: WA

Fixed submission:

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

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

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

  int j = 0;
  int result = 0;
  int diff = 100;
  for (int i = 0; i <= 101; i++) {
    rep(j, n) {
      if (i == p.at(j))
        break;
    }
    if (i == p.at(j))
      continue;
    if (abs(x - i) < diff) {
      result = i;
      diff = abs(x - i);
    }
  }
  cout << result << endl;
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int x, n, a;
  cin >> x >> n;
  vector<int> p(n);
  vector<int> arr(101, 1);
  for (int i = 0; i < n; i++) {
    cin >> a;
    arr.at(a) = 0;
  }
  int j = 1, check = 1;
  if (arr.at(x) == 1) {
    cout << x << endl;
    return 0;
  }
  while (check == 1) {
    if (x + j > 100) {
      int ans = x + j;
      if (arr.at(x - j) == 1) {
        ans = x - j;
      }
      cout << ans << endl;
      return 0;
    }
    if (x - j < 1) {
      int ans = x - j;
      if (arr.at(x + j) == 1) {
        ans = min(x - j, x + j);
      }
      cout << ans << endl;
      return 0;
    }
    if (x - j < 1) {
      int ans = min(abs(x + j), abs(x - j));
      cout << ans << endl;
      return 0;
    }
    if (arr.at(x - j) == 1) {
      cout << x - j << endl;
      return 0;
    } else if (arr.at(x + j) == 1) {
      cout << x + j << endl;
      return 0;
    }
    j++;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int x, n, a;
  cin >> x >> n;
  vector<int> p(n);
  vector<int> arr(101, 1);
  for (int i = 0; i < n; i++) {
    cin >> a;
    arr.at(a) = 0;
  }
  int j = 1, check = 1;
  if (arr.at(x) == 1) {
    cout << x << endl;
    return 0;
  }
  while (check == 1) {
    if (arr.at(x - j) == 1) {
      cout << x - j << endl;
      return 0;
    } else if (arr.at(x + j) == 1) {
      cout << x + j << endl;
      return 0;
    }
    j++;
    if (x + j > 100 or x - j < 1) {
      int ans = min(abs(x + j), abs(x - j));
      cout << ans << endl;
      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++)
#define repa(i, a, n) for (int i = (a); i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rrepa(i, a, n) for (int i = n - 1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define MOD 1000000007
#define cmax(a, b) a = max(a, b)
#define cmin(a, b) a = min(a, b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

int main() {

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

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

  vi p(n);
  rep(i, n) cin >> p[i];

  sort(all(p));

  int ans = x, abso = 105, idx = 0;
  rep(i, 102) {
    if (p[idx] == i) {
      idx++;
      continue;
    }
    if (abs(x - i) < abso) {
      abso = abs(x - i);
      ans = i;
    }
  }

  cout << ans << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repa(i, a, n) for (int i = (a); i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rrepa(i, a, n) for (int i = n - 1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define MOD 1000000007
#define cmax(a, b) a = max(a, b)
#define cmin(a, b) a = min(a, b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

int main() {

  int x, n;
  cin >> x >> n;
  vi p(n);
  rep(i, n) cin >> p[i];

  sort(all(p));

  int ans = 0, abso = 105, idx = 0;
  repa(i, -1, 101) {
    if (p[idx] == i) {
      while (p[idx] == i)
        idx++;
      continue;
    }
    if (abs(x - i) < abso) {
      abso = abs(x - i);
      ans = i;
    }
  }

  cout << ans << "\\n";

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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

  for (int i = 0; i < 102; i++)
    q[i] = i;

  int z;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> z;
    for (int j = 0; j < 102; j++) {
      if (z == q[j]) {
        q.erase(q.begin() + j);
        count++;
      }
    }
  }

  int ans = 1000000;
  int y = 0;
  for (int i = 0; i < 102 - count; i++) {
    if (ans > abs(x - q[i]))
      y = i;
    ans = min(abs(x - q[i]), ans);
  }

  if (ans == 0)
    cout << x << endl;
  else
    cout << q[y] << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

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

  for (int i = 0; i < 101; i++)
    q[i] = i;

  int z;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> z;
    for (int j = 0; j < 101; j++) {
      if (z == q[j]) {
        q.erase(q.begin() + j);
        count++;
      }
    }
  }

  int ans = 1000000;
  int y = 0;
  for (int i = 0; i < 101 - count; i++) {
    if (ans >= abs(x - q[i]))
      y = i;
    ans = min(abs(x - q[i]), ans);
  }

  if (ans == 0)
    cout << x << endl;
  else
    cout << q[y] << endl;

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

typedef pair<ll, ll> Pair;

int main() {

  ll X, N;
  ll ansabs = 101;
  ll ans = 101;

  cin >> X >> N;

  vector<ll> p(N);

  for (ll i = 0; i < N; ++i)
    cin >> p[i];

  /*
  for(ll i = 100;i >= -100;--i){

      bool exists = std::find(std::begin(p), std::end(p), i) != std::end(p);

      if(exists) continue;
      else{

          ll temp;
          temp = abs(X + (i*(-1)));

          if(ansabs >= temp){
              ansabs = temp;
              ans = i;
          }
      }
  }
  */

  bool flg = false;
  ll j = 0;

  while (!flg) {

    ll pre = X - j;
    ll post = X + j;

    bool existsPre = std::find(std::begin(p), std::end(p), pre) != std::end(p);
    bool existsPost =
        std::find(std::begin(p), std::end(p), post) != std::end(p);

    if (!existsPre) {

      cout << pre << endl;
      flg = true;

    } else if (!existsPost) {

      cout << post << endl;
      flg = true;
    }

    ++j;
  }

  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

typedef pair<ll, ll> Pair;

int main() {

  double B;

  ll X, N;
  vector<ll> p(N);
  ll ansabs = 101;
  ll ans = 101;

  cin >> X >> N;

  for (ll i = 0; i < N; ++i)
    cin >> p[i];

  for (ll i = 100; i > 0; --i) {

    bool exists = std::find(std::begin(p), std::end(p), i) != std::end(p);

    if (exists)
      continue;
    else {

      ll temp;
      temp = abs(X - i);

      if (ansabs >= temp) {
        ansabs = temp;
        ans = i;
      }
    }
  }

  cout << ans << endl;

  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> map(102);
  for (int i = 0; i < n; i++) {
    int key;
    cin >> key;
    map.at(key) = key;
  }

  for (int sa = 0; sa < 100; sa++) {
    if (map.at(x - sa) == 0) {
      cout << x - sa;
      return 0;
    }
    if (map.at(x + sa) == 0) {
      cout << x + sa;
      return 0;
    }
  }
}


Error: WA

Fixed submission:

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

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

  vector<int> map(101);
  for (int i = 0; i < n; i++) {
    int key;
    cin >> key;
    map.at(key) = key;
  }

  for (int sa = 0; sa < 100; sa++) {
    if (map.at(x - sa) == 0) {
      cout << x - sa;
      return 0;
    } else if (map.at(x + sa) == 0) {
      cout << x + sa;
      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++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int X, N;
  int tmp;
  cin >> X >> N;

  vector<int> check(101);

  REP(i, N) {
    cin >> tmp;
    check.at(tmp)++;
  }

  int j, ans;
  REP(i, 202) {
    if (i % 2 == 0)
      j = i / 2;
    else
      j = -i / 2 - 1;
    if (X + j > 100) {
      ans = 101;
      break;
    }

    if (check.at(X + j) == 0) {
      ans = X + j;
      break;
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int X, N;
  int tmp;
  cin >> X >> N;

  vector<int> check(101);

  REP(i, N) {
    cin >> tmp;
    check.at(tmp)++;
  }

  int j, ans;
  REP(i, 101) {
    if (i % 2 == 0)
      j = i / 2;
    else
      j = -i / 2 - 1;
    if (X + j < 0)
      continue;
    else if (X + j > 101)
      continue;

    if (check.at(X + j) == 0) {
      ans = X + j;
      cout << ans << endl;
      break;
    }
  }
}
Problem p02641 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  int x, n;
  cin >> x >> n;
  vector<bool> p(102, false);

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

  pair<int, int> ans = make_pair(INF, INF);
  for (int i = 0; i <= 101; i++) {
    if (p[i] == false) {
      ans = min(ans, pair<int, int>(abs(x - i), i));
    }
  }
  cout << ans.second << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e9;

int main() {
  int x, n;
  cin >> x >> n;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<int> p(101, INF);
  for (int i = 0; i < n; i++) {
    int inp;
    cin >> inp;
    p[inp] = abs(inp - x);
  }
  int ans = INF;
  int ians = INF;
  for (int i = 1; i <= 100; i++) {
    if (ans > p[i]) {
      ans = p[i];
      ians = i;
    }
  }
  int d = 0;
  while (true) {
    if (p[ians - d] == INF && ians - d >= 1) {
      cout << ians - d << endl;
      break;
    }
    if (p[ians + d] == INF && ians + d <= 100) {
      cout << ians + d << endl;
      break;
    }
    d++;
  }
}