prithivMLmods/Coder-Stat huggingface dataset:
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<int> x(4);
  for (int i = 0; i < 5; i++) {
    cin >> x.at(i);
  }

  int ans = 0;
  for (int i = 0; i < 5; i++) {
    if (x.at(i) == 0) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << endl;
}

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

int main() {
  vector<int> x(5);
  for (int i = 0; i < 5; i++) {
    cin >> x.at(i);
  }

  int ans = 0;
  for (int i = 0; i < 5; i++) {
    if (x.at(i) == 0) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int i, var[5];
  for (i = 1; i <= 5; ++i) {
    cin >> var[i];
    if (var[i] == 0)
      cout << i << "\n";
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;

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

  long long var;
  for (int i = 1; i <= 5; ++i) {
    cin >> var;
    if (var == 0)
      cout << i << "\n";
  }
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n = 0;
  vector<int> vec(n);
  for (int i = 0; i < 6; i++) {
    cin >> vec.at(i);
    if (vec.at(i) == 0) {
      cout << i + 1 << endl;
    }
  }
  return 0;
}


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

int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if (a == 0)
    cout << 1 << endl;
  if (b == 0)
    cout << 2 << endl;
  if (c == 0)
    cout << 3 << endl;
  if (d == 0)
    cout << 4 << endl;
  if (e == 0)
    cout << 5 << endl;
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int num;
  while (1) {
    for (int i = 1; i <= 5; i++) {
      cin >> num;
      if (num == 0) {
        cout << i << endl;
        break;
      }
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int num;
  while (1) {
    for (int i = 1; i <= 5; i++) {
      cin >> num;
      if (num == 0) {
        cout << i << endl;
        break;
      }
    }
    break;
  }
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int in;
  vector<int> v;
  int s(0), save;
  int i = 0;
  while (i < 5) {
    cin >> in;
    s++;
    v.push_back(in);
    if (in == 0) {
      save = s;
    }
  }
  cout << save << "\n";
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int in;
  vector<int> v;
  int s(0), save;
  int i = 0;
  while (i < 5) {
    cin >> in;
    s++;
    v.push_back(in);
    if (in == 0) {
      save = s;
    }
    i++;
  }
  cout << save << "\n";
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int)1e5;
const int INF = (int)1e9 + 7;

int main(int argc, char *argv[]) {
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);

  int a[5];
  int ans = 1;
  for (int i = 1; i <= 5; ++i) {
    sf("%d", &a[i]);
    if (a[i] == 0)
      ans = i;
  }
  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int)1e5;
const int INF = (int)1e9 + 7;

int main(int argc, char *argv[]) {
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);

  int a[6];
  int ans = 1;
  for (int i = 1; i <= 5; ++i) {
    sf("%d", &a[i]);
    if (a[i] == 0)
      ans = i;
  }
  printf("%d\n", ans);

  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>

#define ll long long

using namespace std;

int main() {
  int arr[5];
  arr[0] = -1333;
  int ans = -1;
  for (int i = 1; i < 6; i++) {
    cin >> arr[i];
    if (arr[i] == 0) {
      ans = i;
    }
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>

#define ll long long

using namespace std;

int main() {
  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  if (x1 == 0)
    cout << "1";
  else if (x2 == 0)
    cout << "2";
  else if (x3 == 0)
    cout << "3";
  else if (x4 == 0)
    cout << "4";
  else
    cout << "5";
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int arr[5];
  for (int i = 1; i <= 5; i++) {
    cin >> arr[i];
    if (arr[i] == 0) {
      cout << i;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if (a == 0) {
    cout << 1;
    return 0;
  } else if (b == 0) {
    cout << 2;
    return 0;
  } else if (c == 0) {
    cout << 3;
    return 0;
  } else if (d == 0) {
    cout << 4;
    return 0;
  } else if (e == 0) {
    cout << 5;
    return 0;
  }
}
Problem p02639 (Python)

Buggy submission (status: Runtime Error):
nums = [int(x) for x in input()]

for i in range(5):
    if nums[i] == 0:
        print(i + 1)
        exit(0)


Fixed submission:
nums = [int(x) for x in input().split(" ")]

for i in range(5):
    if nums[i] == 0:
        print(i + 1)
        exit(0)
Problem p02639 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-
a, b, c, d, e = map(int, input().split())

suuji_list = ["", a, b, c, d, e]

print(list.index(0))


Fixed submission:
# -*- coding: utf-8 -*-
a, b, c, d, e = map(int, input().split())

suuji_list = ["", a, b, c, d, e]

print(suuji_list.index(0))
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define dbg(x) cout << (#x) << " is " << (x) << '\n'
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define getc getchar_unlocked
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve() {
  int x[5], ans = 0;
  fp(i, 1, 5) {
    cin >> x[i];
    if (x[i] == 0)
      ans = i;
  }
  cout << ans << '\n';
  return;
}

signed main() {
  FAST int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define dbg(x) cout << (#x) << " is " << (x) << '\n'
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define getc getchar_unlocked
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve() {
  int x[6], ans = 0;
  fp(i, 1, 5) {
    cin >> x[i];
    if (x[i] == 0)
      ans = i;
  }
  cout << ans << '\n';
  return;
}

signed main() {
  FAST int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {

  vector<int> x(4);
  for (int i = 0; i < 5; i++) {
    cin >> x.at(i);
  }
  for (int i = 0; i < 5; i++) {
    if (x.at(i) == 0) {
      cout << i + 1;
      break;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {

  vector<int> x(5);
  for (int i = 0; i < 5; i++) {
    cin >> x.at(i);
  }
  for (int i = 0; i < 5; i++) {
    if (x.at(i) == 0) {
      cout << i + 1;
      break;
    }
  }
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {

  int arr[1000000000];

  for (int i = 1; i <= 5; i++) {

    cin >> arr[i];
  }
  for (int i = 1; i <= 5; i++) {

    if (arr[i] == 0) {
      cout << i;
    }
  }

  return 0;
}

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

int main() {

  int arr[20];

  for (int i = 1; i <= 5; i++) {

    cin >> arr[i];
  }
  for (int i = 1; i <= 5; i++) {

    if (arr[i] == 0) {
      cout << i;
    }
  }

  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x[5], ans;
  for (int i = 1; i <= 5; i++) {
    cin >> x[i];
    if (x[i] == 0)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x[6];
  int ans;
  for (int i = 1; i <= 5; i++) {
    cin >> x[i];
    if (x[i] == 0)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
// Remeber Choose Compiler: GCC9
#include <bits/stdc++.h>

using namespace std;

// Debug Output Utility
#ifdef LOCAL
#define dbg(args...)                                                           \
  do {                                                                         \
    cout << #args << " -> ";                                                   \
    err(args);                                                                 \
  } while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args> void err(T a, Args... args) {
  std::cout << a << ' ';
  err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
  for (auto &v : arg)
    std::cout << v << ' ';
  err(args...);
}
#else
#define dbg(...)
#endif

// Macro Definitions:
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

// Type Alias:
using int64 = long long;
using PII = pair<int, int>;

// Global Const Variable
const int64 INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int MAXN = 200005;
const int MAXL = 1000;

int v[MAXN], w[MAXN], dp[MAXN][MAXL];

void run() {
  int a[5], ans = -1;
  for (int i = 1; i <= 5; i++) {
    cin >> a[i];
    if (a[i] == 0)
      ans = i;
  }
  cout << ans << endl;
}

// Debug Input Redirection
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  run();
}

Fixed submission:
// Remeber Choose Compiler: GCC9
#include <bits/stdc++.h>

using namespace std;

// Debug Output Utility
#ifdef LOCAL
#define dbg(args...)                                                           \
  do {                                                                         \
    cout << #args << " -> ";                                                   \
    err(args);                                                                 \
  } while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args> void err(T a, Args... args) {
  std::cout << a << ' ';
  err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
  for (auto &v : arg)
    std::cout << v << ' ';
  err(args...);
}
#else
#define dbg(...)
#endif

// Macro Definitions:
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

// Type Alias:
using int64 = long long;
using PII = pair<int, int>;

// Global Const Variable
const int64 INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1000000007;
const int MAXN = 200005;
const int MAXL = 1000;

int v[MAXN], w[MAXN], dp[MAXN][MAXL];

void run() {
  int a[6], ans = -1;
  for (int i = 1; i <= 5; i++) {
    cin >> a[i];
    if (a[i] == 0)
      ans = i;
  }
  cout << ans << endl;
}

// Debug Input Redirection
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  run();
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define fastio                                                                 \
  ios_base ::sync_with_stdio(false);                                           \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;

int main() {
  fastio ll a[5];
  ll ans = 0;
  for (ll i = 1; i <= 5; ++i) {
    cin >> a[i];
    if (a[i] == 0)
      ans = i;
  }
  cout << ans;
}


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

int main() {
  fastio ll a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  if (a == 0)
    cout << 1 << "\n";
  if (b == 0)
    cout << 2 << "\n";
  if (c == 0)
    cout << 3 << "\n";
  if (d == 0)
    cout << 4 << "\n";
  if (e == 0)
    cout << 5 << "\n";
}
Problem p02640 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int X, Y;

bool dfs(int i, int sum) {
  if (i == X)
    return sum == Y;
  if (dfs(i + 1, sum + 2))
    return true;
  if (dfs(i + 1, sum + 4))
    return true;

  return false;
}

int main() {
  cin >> X >> Y;
  if (Y / 4 > X) {
    cout << "No";
    return 0;
  }
  if (dfs(0, 0))
    cout << "Yes";
  else
    cout << "No";
}


Fixed submission:
#include <iostream>
using namespace std;
int X, Y;

bool dfs(int i, int sum) {
  if (i == X)
    return sum == Y;
  if (dfs(i + 1, sum + 2))
    return true;
  if (dfs(i + 1, sum + 4))
    return true;

  return false;
}

int main() {
  cin >> X >> Y;
  if (Y >= X * 2 && Y <= X * 4 && Y % 2 == 0) {
    if (dfs(0, 0))
      cout << "Yes";
  } else
    cout << "No";
}
Problem p02640 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
int main() {

  int x, y;
  cin >> x >> y;
  rep(i, x) {
    if (2 * i + 4 * (x - i) == y) {
      cout << "Yes  ";
      exit(1);
    }
  }
  cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
int main() {

  int x, y;
  cin >> x >> y;
  rep(i, x) {
    if (2 * i + 4 * (x - i) == y) {
      cout << "Yes  ";
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p02640 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll)(1e15)
#define mod (ll)(1e9 + 7)
#define endl "\n"
#define tt                                                                     \
  ll testcase;                                                                 \
  cin >> testcase;                                                             \
  while (testcase--)

const int mxn = 1 * (1e5) + 5;
ll n;

int solve() {
  ll x, y;
  cin >> x >> y;
  if ((4 * x - y >= 0) && ((4 * x - y) % 2 == 0)) {
    if (y % 2 == 0) {
      if ((y - 2 * x >= 0) && ((y - 2 * x) % 2 == 0)) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
}

int main() {
  fast;
  // tt
  solve();
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll)(1e15)
#define mod (ll)(1e9 + 7)
#define endl "\n"
#define tt                                                                     \
  ll testcase;                                                                 \
  cin >> testcase;                                                             \
  while (testcase--)

const int mxn = 1 * (1e5) + 5;
ll n;

int solve() {
  ll x, y;
  cin >> x >> y;
  if ((4 * x - y >= 0) && ((4 * x - y) % 2 == 0)) {
    if (y % 2 == 0) {
      if ((y - 2 * x >= 0) && ((y - 2 * x) % 2 == 0)) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}

int main() {
  fast;
  // tt
  solve();
}
Problem p02640 (Python)

Buggy submission (status: Time Limit Exceeded):
from numba import jit


@jit
def solve(X, Y, Z):
    while X >= 0:
        if 2 * X + 4 * Z == Y:
            return True
        elif 2 * X + 4 * Z < Y:
            X -= 1
            Z += 1
    return False


def main():
    X, Y = map(int, input().split())
    Z = 0

    if solve(X, Y, Z):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Fixed submission:
from numba import jit


@jit
def solve(X, Y, Z):
    while X >= 0:
        if 2 * X + 4 * Z == Y:
            return True
        elif 2 * X + 4 * Z < Y:
            X -= 1
            Z += 1
        else:
            return False
    return False


def main():
    X, Y = map(int, input().split())
    Z = 0

    if solve(X, Y, Z):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
Problem p02640 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define U(i, a, b) for (int i = (a); i <= (b); ++i)
#define D(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int gi() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
typedef long long LL;
typedef pair<int, int> pi;

int main() {
  int x, y;
  cin >> x >> y;
  for (int many = 0; many <= x; ++many) {
    int left = (y - many * 2);
    if (left >= 0 && (x - many) * 4 == left)
      return puts("Yes");
  }
  puts("No");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define U(i, a, b) for (int i = (a); i <= (b); ++i)
#define D(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int gi() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
typedef long long LL;
typedef pair<int, int> pi;

int main() {
  int x, y;
  cin >> x >> y;
  for (int many = 0; many <= x; ++many) {
    int left = (y - many * 2);
    if (left >= 0 && (x - many) * 4 == left)
      return puts("Yes"), 0;
  }
  puts("No");
  return 0;
}
Problem p02640 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  bool flag = false;
  for (int l = 0; l <= n; l++) {
    if (((l * 2) + ((n - l) * 4)) == k) {
      flag = true;
      break;
    }
  }
  flag ? cout << "Yes\n" : cout << "No\n";
  main();
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  bool flag = false;
  for (int l = 0; l <= n; l++) {
    if (((l * 2) + ((n - l) * 4)) == k) {
      flag = true;
      break;
    }
  }
  flag ? cout << "Yes\n" : cout << "No\n";
  // main();
  return 0;
}
Problem p02640 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double pi = 3.14159265358979323846;
#define x first
#define y second

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  ll t = 1;
  // cin>>t;
  while (t--) {
    ll x, y;
    cin >> x >> y;
    if (y % x == 0 && y / x == 4)
      cout << "Yes";
    else if (y % x == 0 && y / x == 2)
      cout << "Yes";
    else if (y > x * 4 || y < x * 2)
      cout << "No";
    else {
      while (x && y) {
        y -= 4;
        x--;
        if (y % x == 0 && y / x == 2) {
          cout << "Yes";
          return 0;
        }
      }
      cout << "No";
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double pi = 3.14159265358979323846;
#define x first
#define y second

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  ll t = 1;
  // cin>>t;
  while (t--) {
    ll x, y;
    cin >> x >> y;
    if (y % x == 0 && y / x == 4)
      cout << "Yes";
    else if (y % x == 0 && y / x == 2)
      cout << "Yes";
    else if (y > x * 4 || y < x * 2)
      cout << "No";
    else {
      while (x && y) {
        y -= 4;
        x--;
        if (!x)
          break;
        if (!y)
          break;
        if (y % x == 0 && y / x == 2) {
          cout << "Yes";
          return 0;
        }
      }
      cout << "No";
    }
  }
  return 0;
}
Problem p02641 (C++)

Buggy submission (status: 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> vec(102);
  rep(i, n) {
    int a = 0;
    cin >> a;
    vec.at(a)++;
  }
  int ans = 200;

  for (int i = x; i >= 0; i--) {
    if (vec.at(i) == 0) {
      ans = i;
      break;
    }
  }
  for (int i = x; i < 210; i++) {
    if (vec.at(i) == 0 && ans == 200) {
      ans = i;
      break;
    } else if (vec.at(i) == 0 && ans != 200 && x - ans > i - x) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
}


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;

  vector<int> vec(300);
  rep(i, n) {
    int a = 0;
    cin >> a;
    vec.at(a)++;
  }
  int ans = 200;

  for (int i = x; i >= 0; i--) {
    if (vec.at(i) == 0) {
      ans = i;
      break;
    }
  }
  for (int i = x; i < 210; i++) {
    if (vec.at(i) == 0 && ans == 200) {
      ans = i;
      break;
    } else if (vec.at(i) == 0 && ans != 200 && x - ans > i - x) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n;
  int p[105];
  int mi, minv, maxv = 0, ans = 0;
  int flg[105] = {};
  cin >> x >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    flg[p[i]] = 1;
    maxv = max(p[i], maxv);
    minv = min(p[i], minv);
  }
  mi = (x - (minv - 1));
  ans = minv - 1;
  if (n == 0) {
    cout << x << '\n';
  } else {
    for (int i = minv; i <= maxv + 1; i++) {
      if (mi > abs(x - i)) {
        if (flg[i] != 1) {
          mi = abs(x - i);
          ans = i;
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, n;
  int p[105];
  int mi, minv, maxv = 0, ans = 0;
  int flg[105] = {};
  cin >> x >> n;
  minv = 105;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    flg[p[i]] = 1;
    maxv = max(p[i], maxv);
    minv = min(p[i], minv);
  }
  mi = (x - (minv - 1));
  ans = minv - 1;
  if (n == 0) {
    cout << x << '\n';
  } else {
    for (int i = minv; i <= maxv + 1; i++) {
      if (mi > abs(x - i)) {
        if (flg[i] != 1) {
          mi = abs(x - i);
          ans = i;
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

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

  int Min = 1000;
  int ans = 1000;
  sort(p, p + N);
  for (int i = -1000; i <= 1000; i++) {
    if (p[i] == i)
      continue;

    int num = abs(X - i);
    if (Min > num) {
      ans = i;
      Min = num;
    }
  }

  cout << ans << endl;

  return 0;
}

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

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

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

  int Min = 1000;
  int ans = 1000;
  sort(p, p + N);
  for (int i = 0; i <= 101; i++) {
    bool flag = true;
    for (int j = 0; j < N; j++) {
      if (p[j] == i)
        flag = false;
    }
    if (!flag)
      continue;

    int num = abs(X - i);
    if (Min > num) {
      ans = i;
      Min = num;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k, i, n) for (ll i = k; i < n; ++i)
#define push_back pb
int main(void) {
  // Your code here!
  ll x, n;
  cin >> x >> n;
  vector<ll> a(n);
  rep(0, i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  ll m = 1e9, ans, c = 0;
  rep(0, i, 110) {
    if (a[c] == i && c < n) {
      ++c;
      continue;
    }
    ll d = abs(i - x);
    if (d < m) {
      m = d;
      ans = i;
    }
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k, i, n) for (ll i = k; i < n; ++i)
#define push_back pb
int main(void) {
  // Your code here!
  ll x, n;
  cin >> x >> n;
  vector<ll> a(n);
  rep(0, i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());
  ll m = 1e9, ans, c = 0;
  rep(0, i, 110) {
    if (c < n && a[c] == i) {
      ++c;
      continue;
    }
    ll d = abs(i - x);
    if (d < m) {
      m = d;
      ans = i;
    }
  }
  cout << ans;
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int X, N, ans;
  cin >> X >> N;
  vector<bool> all(100, false);
  vector<int> p(N);

  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
    all.at(p.at(i) - 1) = true;
  }
  // sort(p.begin(),p.end(),greater<int>());
  for (int i = 0; i < 101; i++) {
    if ((X - i - 1 >= 0) && (all.at(X - i - 1) == false)) {
      ans = X - i;
      break;
    } else if ((X + i - 1 < 101) && (all.at(X + i - 1) == false)) {
      ans = X + i;
      break;
    }
  }

  cout << ans << endl;
}

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

int main() {
  int X, N, ans;
  cin >> X >> N;
  vector<bool> all(100, false);
  vector<int> p(N);

  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
    all.at(p.at(i) - 1) = true;
  }
  // sort(p.begin(),p.end(),greater<int>());
  for (int i = 0; i < 101; i++) {
    if ((X - i - 1 >= 0) && (all.at(X - i - 1) == false)) {
      ans = X - i;
      break;
    } else if (X - i - 1 < 0) {
      ans = X - i;
      break;
    } else if ((X + i - 1 < 100) && (all.at(X + i - 1) == false)) {
      ans = X + i;
      break;
    } else if (X + i - 1 >= 100) {
      ans = X + i;
      break;
    }
  }

  cout << ans << endl;
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> d(n);
  rep(i, n) {
    int p;
    cin >> p;
    d[p] = 1;
  }
  P ans(999999, -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;
}


Fixed submission:
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回

int main() {
  int x, n;
  cin >> x >> n;
  vector<int> d(102);
  rep(i, n) {
    int p;
    cin >> p;
    d[p] = 1;
  }
  P ans(999999, -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;
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>

int main() {
  int X, N, *p, dif = 1, num = -1;
  std::cin >> X >> N;
  p = new int[N + 2];
  for (int i = 0; i < N; i++) {
    std::cin >> p[i];
  }
  p[N + 1] = -1000;
  p[N + 2] = 1000;
  std::sort(p, p + N);
  for (int i = 0; i < N; i++) {
    if (p[i] == X)
      num = i;
  }
  if (num == -1) {
    std::cout << X;
    exit(0);
  }
  while (true) {
    if (p[num - dif] != X - dif) {
      std::cout << X - dif;
      break;
    }
    if (p[num + dif] != X + dif) {
      std::cout << X + dif;
      break;
    }
    dif += 1;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>

int main() {
  int X, N, *p, dif = 1, num = -1;
  std::cin >> X >> N;
  p = new int[N + 2];
  for (int i = 0; i < N; i++) {
    std::cin >> p[i];
  }
  p[N] = -1000;
  p[N + 1] = 1000;
  std::sort(p, p + N + 2);
  for (int i = 1; i < N + 1; i++) {
    if (p[i] == X)
      num = i;
  }
  if (num == -1) {
    std::cout << X;
    exit(0);
  }
  while (true) {
    if (p[num - dif] != X - dif) {
      std::cout << X - dif;
      break;
    }
    if (p[num + dif] != X + dif) {
      std::cout << X + dif;
      break;
    }
    dif += 1;
  }
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

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

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

  vector<int> a(n), b(0);
  rep(i, n) cin >> a[i];
  sort(all(a));

  int j = 0;

  rep(i, 100) {
    if (i + 1 != a[j]) {
      b.push_back(i + 1);
      // cout << i+1 << endl;
    } else
      j++;
  }
  int l = b.size();
  vector<int> c(l);

  rep(i, l) c[i] = abs(b[i] - x);

  sort(all(c));

  int d = c[0];

  // cout << d << endl;

  rep(i, n) {
    if (b[i] == x - d) {
      cout << x - d << endl;
      return 0;
    } else if (x - d <= 0) {
      cout << 0 << endl;
      return 0;
    } else if (b[i] == x + d) {
      cout << x + d << endl;
      return 0;
    } else if (x + d >= 101) {
      cout << 101 << endl;
      return 0;
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

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

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

  vector<int> a(n), b(0);
  rep(i, n) cin >> a[i];
  sort(all(a));

  int j = 0;

  rep(i, 100) {
    if (i + 1 != a[j]) {
      b.push_back(i + 1);
      // cout << i+1 << endl;
    } else
      j++;
  }
  int l = b.size();

  if (l == 0) {
    if (x <= 50) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << 101 << endl;
      return 0;
    }
  }
  vector<int> c(l);

  rep(i, l) c[i] = abs(b[i] - x);

  sort(all(c));

  int d = c[0];

  // cout << d << endl;

  rep(i, n) {
    if (b[i] == x - d) {
      cout << x - d << endl;
      return 0;
    } else if (x - d <= 0) {
      cout << 0 << endl;
      return 0;
    } else if (b[i] == x + d) {
      cout << x + d << endl;
      return 0;
    } else if (x + d >= 101) {
      cout << 101 << endl;
      return 0;
    }
  }

  return 0;
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define mset(s, _) memset(s, _, sizeof s)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
// head
int a[110];
void run() {
  int n, x;
  cin >> x >> n;
  for (int i = 1; i <= n; i++) {
    int tp;
    cin >> tp;
    a[tp] = 1;
  }
  if (n == 0) {
    cout << x << '\n';
    return;
  }
  int ans = 0;
  int pre = 1000, pos = 0;
  for (int i = -1000; i <= 1000; i++) {
    if (!a[i] && abs(i - x) < pre)
      pos = i, pre = abs(i - x);
  }
  cout << pos << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
  // int T; cin >> T; while (T--)
  run();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define mset(s, _) memset(s, _, sizeof s)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
// head
map<int, int> a;
void run() {
  int n, x;
  cin >> x >> n;
  for (int i = 1; i <= n; i++) {
    int tp;
    cin >> tp;
    a[tp] = 1;
  }
  if (n == 0) {
    cout << x << '\n';
    return;
  }
  int ans = 0;
  int pre = 1000, pos = 0;
  for (int i = -1000; i <= 1000; i++) {
    if (!a[i] && abs(i - x) < pre)
      pos = i, pre = abs(i - x);
  }
  cout << pos << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(20);
  // int T; cin >> T; while (T--)
  run();
  return 0;
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, x;
  cin >> x >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  int ans = -1, diff = 1001;
  for (int i = 1; i <= v[n - 1] + 1; i++) {
    if (binary_search(v.begin(), v.end(), i))
      continue;
    if (abs(x - i) < diff) {
      diff = abs(x - i);
      ans = i;
    }
  }
  if (ans == -1)
    cout << x;
  else
    cout << ans;
  return 0;
}


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

int main() {
  int n, x;
  cin >> x >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  int ans = -1, diff = 1001;
  if (n > 0) {
    for (int i = 0; i <= v[n - 1] + 1; i++) {
      if (binary_search(v.begin(), v.end(), i))
        continue;
      if (abs(x - i) < diff) {
        diff = abs(x - i);
        ans = i;
      }
    }
  }
  if (ans == -1)
    cout << x;
  else
    cout << ans;
  return 0;
}
Problem p02641 (C++)

Buggy submission (status: 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;
}


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 (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.second < b.second);
}
int main() {

  ll t, i, j, k, n, l, x, y;
  cin >> x >> n;
  map<ll, ll> m;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<pair<ll, ll>> v;
  for (i = 0; i < n; i++) {
    ll p;
    cin >> p;
    m[p]++;
  }
  for (i = 1; i <= 100; i++) {
    if (m[i] == 0) {
      v.push_back({i, abs(i - x)});
    }
  }
  sort(v.begin(), v.end(), sortbysec);
  cout << v[0].first << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.second < b.second);
}
int main() {

  ll t, i, j, k, n, l, x, y;
  cin >> x >> n;
  map<ll, ll> m;
  if (n == 0) {
    cout << x << endl;
    return 0;
  }
  vector<pair<ll, ll>> v;
  for (i = 0; i < n; i++) {
    ll p;
    cin >> p;
    m[p]++;
  }
  for (i = -1000; i <= 1000; i++) {
    if (m[i] == 0) {
      v.push_back({i, abs(i - x)});
    }
  }
  sort(v.begin(), v.end(), sortbysec);
  cout << v[0].first << endl;

  return 0;
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define M 200005
#define MOD 1000000007
#define PI 3.14159265358979323846
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int, int> PII;
typedef pair<lli, lli> PLL;

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

  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

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

  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    mp[temp]++;
  }

  vector<PII> res;
  for (int i = 1; i <= 100; i++) {
    if (mp[i] == 0) {
      res.ep(mk(abs(i - x), i));
    }
  }

  sort(all(res));

  int ans = res[0].second;
  cout << ans << "\n";
}

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

#define M 200005
#define MOD 1000000007
#define PI 3.14159265358979323846
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int, int> PII;
typedef pair<lli, lli> PLL;

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

  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

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

  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    mp[temp]++;
  }

  vector<PII> res;
  for (int i = 0; i <= 1000; i++) {
    if (mp[i] == 0) {
      res.ep(mk(abs(i - x), i));
    }
  }

  sort(all(res));

  int ans = res[0].second;
  cout << ans << "\n";
}
Problem p02641 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }

int main() {
  ll x, n;
  cin >> x >> n;
  if (!n) {
    cout << x << endl;
    return 0;
  }
  bitset<101> bs;
  rep(i, n) {
    int a;
    cin >> a;
    bs.set(a, true);
  }
  for (int i = 0;; i++) {
    if (!bs.test(x - i)) {
      cout << x - i << endl;
      break;
    }
    if (!bs.test(x + i)) {
      cout << x + i << endl;
      break;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T, class C> void chmax(T &a, C b) { a > b ?: a = b; }
template <class T, class C> void chmin(T &a, C b) { a < b ?: a = b; }

int main() {
  ll x, n;
  cin >> x >> n;
  if (!n) {
    cout << x << endl;
    return 0;
  }
  bitset<102> bs;
  rep(i, n) {
    int a;
    cin >> a;
    bs.set(a, true);
  }
  for (int i = 0;; i++) {
    if (!bs.test(x - i)) {
      cout << x - i << endl;
      break;
    }
    if (!bs.test(x + i)) {
      cout << x + i << endl;
      break;
    }
  }
}
Problem p02641 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  // your code goes here
  int x, n; // a+b=x;2*a + 4*b=y;
  cin >> x >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  set<int> st;
  for (int i = 0; i < n; i++)
    st.insert(a[i]);
  int dif = 0;
  while (1) {
    if (st.find(x - dif) == st.end()) {
      cout << x - dif << endl;
      break;
    }
    if (st.find(x + dif) == st.end()) {
      cout << x + dif << endl;
      break;
    }
  }
  return 0;
}

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

int main() {
  // your code goes here
  int x, n; // a+b=x;2*a + 4*b=y;
  cin >> x >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  set<int> st;
  for (int i = 0; i < n; i++)
    st.insert(a[i]);
  int dif = 0;
  while (1) {
    if (st.find(x - dif) == st.end()) {
      cout << x - dif << endl;
      break;
    }
    if (st.find(x + dif) == st.end()) {
      cout << x + dif << endl;
      break;
    }
    dif++;
  }
  return 0;
}
Problem p02641 (Python)

Buggy submission (status: Runtime Error):
x, n = map(int, input().split())
p = list(map(int, input().split()))
min = float("inf")

for i in range(1, 101)[::-1]:
    if abs(x - i) <= min:
        if i not in p:
            min = abs(x - i)
            ans = i

print(ans)


Fixed submission:
x, n = map(int, input().split())
p = list(map(int, input().split()))
min = float("inf")

for i in range(0, 102)[::-1]:
    if abs(x - i) <= min:
        if i not in p:
            min = abs(x - i)
            ans = i

print(ans)
Problem p02641 (Python)

Buggy submission (status: Runtime Error):
x, n = map(int, input().split())

if n != 0:
    p = list(map(int, input().split()))
else:
    print(x)
    exit(1)

dif = 100
ans = 0

for i in range(min(p) - 1, max(p) + 2):
    if not (i in p):
        if dif > abs(x - i):
            dif = abs(x - i)
            ans = i

print(ans)


Fixed submission:
x, n = map(int, input().split())

if n != 0:
    p = list(map(int, input().split()))
else:
    print(x)
    exit()

dif = 100
ans = 0

for i in range(min(p) - 1, max(p) + 2):
    if not (i in p):
        if dif > abs(x - i):
            dif = abs(x - i)
            ans = i

print(ans)
Problem p02641 (Python)

Buggy submission (status: Runtime Error):
import numpy as np

X, N = map(int, input().split())
P = list(map(int, input().split()))
candidate = list(range(1, 101))
P = sorted(set(candidate).difference(set(P)))
i = np.argmin([abs(p - X) for p in P])
print(P[i])


Fixed submission:
import numpy as np

X, N = map(int, input().split())
P = list(map(int, input().split()))
candidate = list([x - 500 for x in range(1, 1000)])
P = sorted(set(candidate).difference(set(P)))
i = np.argmin([abs(p - X) for p in P])
print(P[i])