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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int ne[N], tot, fi[N], zz[N], Stack[N], cnt, vis[N], a[N], mex[N], x, n,
    flag[N];
void jb(int x, int y) {
  ne[++tot] = fi[x];
  fi[x] = tot;
  zz[tot] = y;
}
void dfs1(int x) {
  flag[x] = 1;
  Stack[++cnt] = x;
  for (int i = fi[x]; i; i = ne[i])
    if (!flag[zz[i]])
      dfs1(zz[i]);
    else if (flag[zz[i]] == 1) {
      tot = cnt;
      for (int i = 1; i <= cnt; i++)
        a[i] = Stack[i], vis[a[i]] = 1;
    }
  flag[x] = 2;
  cnt--;
}
void dfs2(int x) {
  for (int i = fi[x]; i; i = ne[i])
    if (!vis[zz[i]])
      dfs2(zz[i]);
  for (int i = fi[x]; i; i = ne[i])
    if (!vis[zz[i]])
      flag[mex[zz[i]]] = x;
  while (flag[mex[x]] == x)
    mex[x]++;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    jb(x, i);
  }
  tot = 0;
  for (int i = 1; i <= n; i++)
    if (!flag[i])
      dfs1(i);
  if (tot % 2 == 0) {
    puts("POSSIBLE");
    return 0;
  }
  memset(flag, 0, sizeof flag);
  for (int i = 1; i <= tot; i++)
    dfs2(a[i]);
  for (int i = 2; i <= tot; i++)
    if (mex[a[i]] != mex[a[1]]) {
      puts("POSSIBLE");
      return 0;
    }
  puts("IMPOSSIBLE");
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int ne[N], tot, fi[N], zz[N], Stack[N], cnt, vis[N], a[N], mex[N], x, n,
    flag[N];
void jb(int x, int y) {
  ne[++tot] = fi[x];
  fi[x] = tot;
  zz[tot] = y;
}
void dfs1(int x) {
  flag[x] = 1;
  Stack[++cnt] = x;
  for (int i = fi[x]; i; i = ne[i])
    if (!flag[zz[i]])
      dfs1(zz[i]);
    else if (flag[zz[i]] == 1) {
      tot = cnt;
      for (int i = 1; i <= cnt; i++)
        a[i] = Stack[i], vis[a[i]] = 1;
    }
  flag[x] = 2;
  cnt--;
}
void dfs2(int x) {
  for (int i = fi[x]; i; i = ne[i])
    if (!vis[zz[i]])
      dfs2(zz[i]);
  for (int i = fi[x]; i; i = ne[i])
    if (!vis[zz[i]])
      flag[mex[zz[i]]] = x;
  while (flag[mex[x]] == x)
    mex[x]++;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    jb(x, i);
  }
  tot = 0;
  for (int i = 1; i <= n; i++)
    if (!flag[i])
      dfs1(i);
  if (tot % 2 == 0) {
    puts("POSSIBLE");
    return 0;
  }
  memset(flag, 0, sizeof flag);
  for (int i = 1; i <= tot; i++)
    dfs2(a[i]);
  for (int i = 2; i <= tot; i++)
    if (mex[a[i]] != mex[a[1]]) {
      puts("POSSIBLE");
      return 0;
    }
  puts("IMPOSSIBLE");
}
Problem p03650 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define N 200005
vector<int> v[N];
int fa[N], du[N], sg[N];
int n;
void calc(int u) {
  sort(v[u].begin(), v[u].end());
  sg[u] = 0;
  for (int i : v[u])
    i == sg[u] ? sg[u]++ : 0;
}
void tp(int u) {
  calc(u);
  du[fa[u]]--;
  du[u] = -1;
  v[fa[u]].push_back(sg[u]);
  if (du[fa[u]] == 0)
    tp(fa[u]);
}
vector<int> temp;
void DFS(int u, int top) {
  temp.push_back(sg[u]);
  if (fa[u] != top)
    DFS(fa[u], top);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &fa[i]), du[fa[i]]++;
  for (int i = 1; i <= n; i++)
    if (du[i] == 0)
      tp(i);
  for (int i = 1; i <= n; i++)
    if (du[i] == 1)
      calc(i);
  for (int i = 1; i <= n; i++)
    if (du[i] == 1) {
      DFS(i, i);
      sort(temp.begin(), temp.end());
      if (temp[0] == temp[temp.size() - 1] && temp.size() % 2 == 1)
        return puts("IMPOSSIBLE"), 0;
      temp.clear();
    }
  return puts("POSSIBLE"), 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define N 200005
vector<int> v[N];
int fa[N], du[N], sg[N];
int n;
void calc(int u) {
  sort(v[u].begin(), v[u].end());
  sg[u] = 0;
  for (int i : v[u])
    i == sg[u] ? sg[u]++ : 0;
}
void tp(int u) {
  calc(u);
  du[fa[u]]--;
  du[u] = -1;
  v[fa[u]].push_back(sg[u]);
  if (du[fa[u]] == 0)
    tp(fa[u]);
}
vector<int> temp;
void DFS(int u, int top) {
  temp.push_back(sg[u]);
  du[u] = -1;
  if (fa[u] != top)
    DFS(fa[u], top);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &fa[i]), du[fa[i]]++;
  for (int i = 1; i <= n; i++)
    if (du[i] == 0)
      tp(i);
  for (int i = 1; i <= n; i++)
    if (du[i] == 1)
      calc(i);
  for (int i = 1; i <= n; i++)
    if (du[i] == 1) {
      DFS(i, i);
      sort(temp.begin(), temp.end());
      if (temp[0] == temp[temp.size() - 1] && temp.size() % 2 == 1)
        return puts("IMPOSSIBLE"), 0;
      temp.clear();
    }
  return puts("POSSIBLE"), 0;
}
Problem p03650 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

const int Maxn = 200005;
const int Maxm = 200;

bool has[Maxn][Maxm];
int res[Maxn];
bool tk[Maxn];
int root, rootval;
int n;
vector<int> neigh[Maxn];
int P[Maxn];

void Solve(int v) {
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    if (u == root)
      has[v][rootval] = true;
    else {
      Solve(u);
      has[v][res[u]] = true;
    }
  }
  res[v] = 0;
  while (has[v][res[v]])
    res[v]++;
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    if (u == root)
      has[v][rootval] = false;
    else
      has[v][res[u]] = false;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &P[i]);
    neigh[P[i]].push_back(i);
  }
  root = 1;
  while (!tk[root]) {
    tk[root] = true;
    root = P[root];
  }
  for (rootval = 0; rootval < Maxm; rootval++) {
    res[root] = rootval;
    for (int j = 0; j < neigh[root].size(); j++) {
      int u = neigh[root][j];
      Solve(u);
      has[root][res[u]] = true;
    }
    int my = 0;
    while (has[root][my])
      my++;
    if (res[root] == my) {
      printf("POSSIBLE\n");
      return 0;
    }
    for (int j = 0; j < neigh[root].size(); j++) {
      int u = neigh[root][j];
      has[root][res[u]] = false;
    }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

const int Maxn = 200005;
const int Maxm = 100;

bool has[Maxn][Maxm];
int res[Maxn];
bool tk[Maxn];
int root, rootval;
int n;
vector<int> neigh[Maxn];
int P[Maxn];

void Solve(int v) {
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    if (u == root)
      has[v][rootval] = true;
    else {
      Solve(u);
      has[v][res[u]] = true;
    }
  }
  res[v] = 0;
  while (has[v][res[v]])
    res[v]++;
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    if (u == root)
      has[v][rootval] = false;
    else
      has[v][res[u]] = false;
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &P[i]);
    neigh[P[i]].push_back(i);
  }
  root = 1;
  while (!tk[root]) {
    tk[root] = true;
    root = P[root];
  }
  for (rootval = 0; rootval < Maxm; rootval++) {
    res[root] = rootval;
    for (int j = 0; j < neigh[root].size(); j++) {
      int u = neigh[root][j];
      Solve(u);
      has[root][res[u]] = true;
    }
    int my = 0;
    while (has[root][my])
      my++;
    if (res[root] == my) {
      printf("POSSIBLE\n");
      return 0;
    }
    for (int j = 0; j < neigh[root].size(); j++) {
      int u = neigh[root][j];
      has[root][res[u]] = false;
    }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  int high = 0;
  rep(i, N) {
    cin >> v[i];
    if (high < v[i])
      high = v[i];
  }
  ll GCD = gcd(v[0], v[1]);
  for (int i = 2; i < N; i++) {
    GCD = gcd(GCD, v[i]);
  }
  if (high >= K && (high - K) % GCD == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  int high = 0;
  rep(i, N) {
    cin >> v[i];
    if (high < v[i])
      high = v[i];
  }
  ll GCD = v[0];
  for (int i = 0; i < N; i++) {
    GCD = gcd(GCD, v[i]);
  }
  if (high >= K && (high - K) % GCD == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int, int>
using namespace std;
int a[100000], b[100000];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
signed main() {
  int n, k, ma = 0;
  cin >> n >> k;
  f(i, n) {
    cin >> a[i];
    if (i)
      b[i - 1] = abs(a[i] - a[i - 1]);
    ma = max(ma, a[i]);
  }
  int z = mod;
  f(i, n - 2) {
    if (i)
      z = gcd(z, b[i + 1]);
    else
      z = gcd(b[0], b[1]);
  }
  if (ma < k || a[0] % z != k % z)
    puts("IMPOSSIBLE");
  else
    puts("POSSIBLE");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int, int>
using namespace std;
int a[100000], b[100000];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
signed main() {
  int n, k, ma = 0;
  cin >> n >> k;
  f(i, n) {
    cin >> a[i];
    if (i)
      b[i - 1] = abs(a[i] - a[i - 1]);
    ma = max(ma, a[i]);
  }
  int z = mod;
  f(i, n - 2) {
    if (i)
      z = gcd(z, b[i + 1]);
    else
      z = gcd(b[0], b[1]);
  }
  if (z == 0 && a[0] == k)
    puts("POSSIBLE");
  else if ((z == 0 && a[0] != k) || ma < k || a[0] % z != k % z)
    puts("IMPOSSIBLE");
  else
    puts("POSSIBLE");
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return x % y == 0 ? y : gcd(y, x % y); }
int main() {
  int N, K;
  cin >> N >> K;
  int M = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    M = max(A[i], M);
    if (A[i] == K) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  int g = gcd(A[0], A[1]);
  for (int i = 2; i < N; i++)
    g = gcd(g, A[i]);
  cout << (K % g == 0 && K <= M ? "POSSIBLE" : "IMPOSSIBLE");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return x % y == 0 ? y : gcd(y, x % y); }
int main() {
  int N, K;
  cin >> N >> K;
  int M = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    M = max(A[i], M);
    if (A[i] == K) {
      cout << "POSSIBLE";
      return 0;
    }
  }
  if (N == 1) {
    cout << (K == A[0] ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
  }
  int g = gcd(A[0], A[1]);
  for (int i = 2; i < N; i++)
    g = gcd(g, A[i]);
  cout << (K % g == 0 && K <= M ? "POSSIBLE" : "IMPOSSIBLE");
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

// PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~

#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 0;
  lli k = 0ll, g = 0ll;
  cin >> n >> k;
  vector<lli> a(n);
  cin >> a[0];
  for (int i = 1; i < n; ++i) {
    cin >> a[i];
    g = __gcd(g, a[i]);
  }
  if (k % g == 0 && k <= *max_element(a.begin(), a.end()))
    cout << "POSSIBLE";
  else
    cout << "IMPOSSIBLE";
  cout << endl;
}

Fixed submission:
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

// PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~

#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 0;
  lli k = 0ll, g = 0ll;
  cin >> n >> k;
  vector<lli> a(n);
  cin >> a[0];
  g = a[0];
  for (int i = 1; i < n; ++i) {
    cin >> a[i];
    g = __gcd(g, a[i]);
  }
  if (k % g == 0 && k <= *max_element(a.begin(), a.end()))
    cout << "POSSIBLE";
  else
    cout << "IMPOSSIBLE";
  cout << endl;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
// Copyright 2017 wu_qing
#include <algorithm>
#include <cstdio>

const int N = 1e5 + 10;
int n, k, a[N], cur, ma;

template <typename T> inline T gcd(T a, T b) { return b == 0 ? a : (b, a % b); }

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  ma = cur = a[1];
  for (int i = 2; i <= n; i++) {
    cur = gcd(cur, a[i]);
    ma = std::max(ma, a[i]);
  }
  if (k % cur == 0 && k <= ma)
    puts("POSSIBLE");
  else
    puts("IMPOSSIBLE");
  return 0;
}


Fixed submission:
// Copyright 2017 wu_qing
#include <algorithm>
#include <cstdio>

const int N = 1e5 + 10;
int n, k, a[N], cur, ma;

template <typename T> inline T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  ma = cur = a[1];
  for (int i = 2; i <= n; i++) {
    cur = gcd(cur, a[i]);
    ma = std::max(ma, a[i]);
  }
  if (k % cur == 0 && k <= ma)
    puts("POSSIBLE");
  else
    puts("IMPOSSIBLE");
  return 0;
}
Problem p03651 (C++)

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

long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

int n, k, a[100100], dif[100100], g;

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  if (n == 1) {
    if (k == a[1])
      puts("POSSIBLE");
    else
      puts("IMPOSSIBLE");
    return 0;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i < n; ++i)
    dif[i] = a[i + 1] - a[i];
  sort(dif + 1, dif + n, greater<int>());
  if (dif[1] == 0) {
    if (k == a[1])
      puts("POSSIBLE");
    else
      puts("IMPOSSIBLE");
    return 0;
  }
  g = dif[1];
  for (int i = 2; i < n; ++i)
    if (dif[i])
      g = gcd(g, dif[i]);
  for (int i = 1; i <= n; ++i)
    if (a[i] >= k && (a[i] - k) % g == 0)
      return puts("POSSIBLE");
  puts("IMPOSSIBLE");

  return 0;
}

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

long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

int n, k, a[100100], dif[100100], g;

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  if (n == 1) {
    if (k == a[1])
      puts("POSSIBLE");
    else
      puts("IMPOSSIBLE");
    return 0;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i < n; ++i)
    dif[i] = a[i + 1] - a[i];
  sort(dif + 1, dif + n, greater<int>());
  if (dif[1] == 0) {
    if (k == a[1])
      puts("POSSIBLE");
    else
      puts("IMPOSSIBLE");
    return 0;
  }
  g = dif[1];
  for (int i = 2; i < n; ++i)
    if (dif[i])
      g = gcd(g, dif[i]);
  for (int i = 1; i <= n; ++i)
    if (a[i] >= k && (a[i] - k) % g == 0) {
      puts("POSSIBLE");
      return 0;
    }
  puts("IMPOSSIBLE");

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
// https://atcoder.jp/contests/agc018/tasks/agc018_a
// A - Getting Difference
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define FOR(i, a, b) for (int64_t i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
ll lcm(ll num1, ll num2) { return num1 / __gcd(num1, num2) * num2; }
int main() {
#if LOCAL & 01
  std::ifstream in("./test/sample-4.in"); // input.txt
  std::cin.rdbuf(in.rdbuf());
#endif
  ll N, K;
  cin >> N >> K;
  vector<ll> an(N);
  bool ans = false;
  for (auto &&a : an) {
    cin >> a;
    if (K <= a)
      ans = true;
  }
  assert(an.size() >= 2);
  ll gcdv = __gcd(an[0], an[1]);
  FOR(i, 2, N) { gcdv = __gcd(gcdv, an[i]); }
  ans &= (K % gcdv == 0);
#if 0
    sort(an.begin(),an.end());

    vector<ll> candidate;
    for(const auto& a:an){
        auto df=a-K;
        if(df>=0) candidate.push_back(df);
    }

    bool ans=false;
    for(ll i=0;i<an.size();++i){
        for(ll j=i+1;j<an.size();++j){
            auto val = abs(an[i]-an[j]);
            if (val==0) continue;
            for(auto& cv:candidate){
                if(cv%val==0){
                    ans=true;
                    break;
                }
            }
        }
    }
#endif
  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}

Fixed submission:
// https://atcoder.jp/contests/agc018/tasks/agc018_a
// A - Getting Difference
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define FOR(i, a, b) for (int64_t i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
ll lcm(ll num1, ll num2) { return num1 / __gcd(num1, num2) * num2; }
int main() {
#if LOCAL & 01
  std::ifstream in("./test/sample-4.in"); // input.txt
  std::cin.rdbuf(in.rdbuf());
#endif
  ll N, K;
  cin >> N >> K;
  vector<ll> an(N);
  bool ans = false;
  for (auto &&a : an) {
    cin >> a;
    if (K <= a)
      ans = true;
  }
  assert(an.size() >= 1);
  ll gcdv = an[0];
  FOR(i, 1, N) { gcdv = __gcd(gcdv, an[i]); }
  ans &= (K % gcdv == 0);
#if 0
    sort(an.begin(),an.end());

    vector<ll> candidate;
    for(const auto& a:an){
        auto df=a-K;
        if(df>=0) candidate.push_back(df);
    }

    bool ans=false;
    for(ll i=0;i<an.size();++i){
        for(ll j=i+1;j<an.size();++j){
            auto val = abs(an[i]-an[j]);
            if (val==0) continue;
            for(auto& cv:candidate){
                if(cv%val==0){
                    ans=true;
                    break;
                }
            }
        }
    }
#endif
  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;

int box[100001];

int get_gcd(int a, int b) {
  if (a == 0 || b == 0)
    return 0;

  if (b == a)
    return a;

  if (a > b)
    return get_gcd(a - b, b);
  return get_gcd(a, b - a);
}

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

  int n, k, a, gcd, max = 0;

  cin >> n >> k;

  for (int i = 0; i < n; ++i) {
    cin >> a;
    box[i] = a;
    if (a > max)
      max = a;
    if (a == k) {
      cout << "POSSIBLE\n";
      return 0;
    }
  }

  sort(box, box + n);

  gcd = box[0];

  for (int i = 1; i < n; ++i)
    gcd = get_gcd(gcd, box[i]);

  if (k % gcd != 0 || k > max)
    cout << "IMPOSSIBLE\n";
  else
    cout << "POSSIBLE\n";
}

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

int box[100001];

int get_gcd(int a, int b) {
  while (b != 0) {
    int t = b;
    b = a % b;
    a = t;
  }
  return a;
}

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

  int n, k, a, gcd, max = 0;

  cin >> n >> k;

  for (int i = 0; i < n; ++i) {
    cin >> a;
    box[i] = a;
    if (a > max)
      max = a;
    if (a == k) {
      cout << "POSSIBLE\n";
      return 0;
    }
  }

  sort(box, box + n);

  gcd = box[0];

  for (int i = 1; i < n; ++i)
    gcd = get_gcd(gcd, box[i]);

  if (k % gcd != 0 || k > max)
    cout << "IMPOSSIBLE\n";
  else
    cout << "POSSIBLE\n";
}
Problem p03651 (C++)

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

using namespace std;

long long getgcd(long long n, long long m) {
  int r;
  if (n > m) {
    int t = m;
    m = n;
    n = t;
  }
  while ((r = m % n) != 0) {
    m = n;
    n = r;
  }
  return n;
}

int main() {

  long long N, K;
  cin >> N >> K;
  long long a;
  vector<long long> b;
  for (int i = 0; i < N; i++) {
    cin >> a;
    b.push_back(a);
  }

  sort(b.begin(), b.end());
  long long gcd = 0, k = 2;
  gcd = getgcd(b[0], b[1]);
  while (gcd != 1) {
    if (k >= b.size())
      break;
    gcd = getgcd(gcd, b[k]);
    k++;
  }

  if (gcd == 1 || (b.size() == 1 && b[0] == K))
    cout << "POSSIBLE" << endl;
  else if (K % gcd == 0 && b[b.size() - 1] >= K) {
    cout << "POSSIBLE" << endl;
  } else
    cout << "IMPOSSIBLE" << endl;
}


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

using namespace std;

long long getgcd(long long n, long long m) {
  int r;

  while ((r = m % n) != 0) {
    m = n;
    n = r;
  }
  return n;
}

int main() {

  long long N, K;
  cin >> N >> K;
  long long a;
  vector<long long> b;
  for (int i = 0; i < N; i++) {
    cin >> a;
    b.push_back(a);
  }

  sort(b.begin(), b.end());
  long long gcd = 0, k = 2;
  gcd = getgcd(b[0], b[1]);
  while (gcd != 1) {
    if (k >= b.size())
      break;
    gcd = getgcd(gcd, b[k]);
    k++;
  }

  if (gcd == 1 || (b.size() == 1 && b[0] == K))
    cout << "POSSIBLE" << endl;
  else if (K % gcd == 0 && b[b.size() - 1] >= K) {
    cout << "POSSIBLE" << endl;
  } else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

ll n, k;
ll a[101010];
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);

  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  cin >> n >> k;
  REP(i, 0, n) cin >> a[i];

  sort(a, a + n);
  ll gg = a[n];
  RREP(i, 0, n - 1) { gg = gcd(gg, a[i]); }

  if (k % gg == 0 && k <= a[n - 1])
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

ll n, k;
ll a[101010];
ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);

  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  cin >> n >> k;
  REP(i, 0, n) cin >> a[i];

  sort(a, a + n);
  ll gg = a[n - 1];
  RREP(i, 0, n) { gg = gcd(gg, a[i]); }

  if (k % gg == 0 && k <= a[n - 1])
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03651 (C++)

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

using namespace std;

int N, K;
int A[10005];
int maxA;

int gcd(int m, int n) {
  int r = 0;
  while (r = m % n)
    m = n, n = r;
  return n;
}

int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i != N; ++i) {
    scanf("%d", &A[i]);
    maxA = max(maxA, A[i]);
  }
  if (maxA < K) {
    puts("IMPOSSIBLE");
    return 0;
  }
  int g = A[0];
  for (int i = 1; i != N; ++i)
    g = gcd(g, A[i]);
  if (K % g != 0) {
    puts("IMPOSSIBLE");
    return 0;
  }
  puts("POSSIBLE");
  return 0;
}

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

using namespace std;

int N, K;
int A[100005];
int maxA;

int gcd(int m, int n) {
  int r = 0;
  while (r = m % n)
    m = n, n = r;
  return n;
}

int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i != N; ++i) {
    scanf("%d", &A[i]);
    maxA = max(maxA, A[i]);
  }
  if (maxA < K) {
    puts("IMPOSSIBLE");
    return 0;
  }
  int g = A[0];
  for (int i = 1; i != N; ++i)
    g = gcd(g, A[i]);
  if (K % g != 0) {
    puts("IMPOSSIBLE");
    return 0;
  }
  puts("POSSIBLE");
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#define MAX 1000000000000000000LL
long long inf = 1000000007;
using namespace std;
int gcd(int m, int n) {
  // 引数に０がある場合は０を返す
  if ((0 == m) || (0 == n))
    return 0;

  // ユークリッドの方法
  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}
int main() {
  int n, k;
  cin >> n >> k;
  int a[100005];
  int mini = 1000000000;
  int maxi = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mini = min(mini, a[i]);
    maxi = max(maxi, a[i]);
    if (a[i] == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  if (maxi < k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  int key = a[0];
  if (n > 1) {
    for (int i = 1; i < n; i++) {
      key = gcd(key, a[i]);
    }
  }
  if (k % key != 0)
    cout << "IMPOSSIBLE" << endl;
  else
    cout << "POSSIBLE" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#define MAX 1000000000000000000LL
long long inf = 1000000007;
using namespace std;
int gcd(int m, int n) {
  // 引数に０がある場合は０を返す
  if ((0 == m) || (0 == n))
    return 0;

  // ユークリッドの方法
  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}
int main() {
  int n, k;
  cin >> n >> k;
  int a[100005];
  int mini = 1000000000;
  int maxi = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mini = min(mini, a[i]);
    maxi = max(maxi, a[i]);
    if (a[i] == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  if (maxi < k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  int key = a[0];
  if (n > 1) {
    key = gcd(a[0], a[1]);
    for (int i = 2; i < n; i++) {
      if (a[i] % key != 0) {
        key = gcd(key, a[i]);
      }
    }
  }
  if (k % key != 0)
    cout << "IMPOSSIBLE" << endl;
  else
    cout << "POSSIBLE" << endl;
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, N) for (int i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

ll n, k;
ll a[100100];

int main() {
  cin >> n >> k;
  ll MAX = 0, MIN = INF;
  rep(i, n) {
    cin >> a[i];
    MAX = max(a[i], MAX);
    MIN = min(a[i], MIN);
  }
  if (k > MAX || MIN > k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(a, a + n);
  ll mod = a[0];
  rep(i, n - 1) { mod = min(mod, a[i + 1] - a[i]); }
  bool f = 0;
  rep(i, n) {
    a[i] %= mod;
    if (k % mod == a[i])
      f = 1;
  }
  if (f)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, N) for (int i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

ll n, k;
ll a[100100];

int main() {
  cin >> n >> k;
  ll MAX = 0, MIN = INF;
  rep(i, n) {
    cin >> a[i];
    MAX = max(a[i], MAX);
    MIN = min(a[i], MIN);
  }
  if (k > MAX || MIN > k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(a, a + n);
  ll mod = a[0];
  rep(i, n - 1) {
    if (a[i + 1] - a[i] != 0)
      mod = min(mod, a[i + 1] - a[i]);
  }
  bool f = 0;
  rep(i, n) {
    a[i] %= mod;
    if (k % mod == a[i])
      f = 1;
  }
  if (f)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; // Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int>>
    IntReversePrioQueue; // A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const int MOD = 1000000007;

vector<int> v;

int gcd(int a, int b) {
  int m = max(a, b), n = min(a, b);
  if (m % n) {
    return gcd(n, m - n);
  } else
    return n;
}

void solve(void) {
  int N, K;
  cin >> N >> K;
  rep(N, i) {
    int A;
    cin >> A;
    v.pb(A);
  }
  sort(all(v));
  if (find(all(v), K) != v.end())
    cout << "POSSIBLE" << '\n';
  else if (v[N - 1] < K)
    cout << "IMPOSSIBLE" << '\n';
  else {
    int dif = INF;
    rep(N - 1, i) { dif = min(dif, gcd(v[i + 1], v[0])); }
    if ((v[N - 1] - K) % dif == 0)
      cout << "POSSIBLE" << '\n';
    else
      cout << "IMPOSSIBLE" << '\n';
  }
}

int main(void) {
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; // Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int>>
    IntReversePrioQueue; // A->Z

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1 << 29;
const int MOD = 1000000007;

vector<int> v;

int gcd(int a, int b) {
  int m = max(a, b), n = min(a, b);
  if (m % n) {
    return gcd(n, m % n);
  } else
    return n;
}

void solve(void) {
  int N, K;
  cin >> N >> K;
  rep(N, i) {
    int A;
    cin >> A;
    v.pb(A);
  }
  sort(all(v));
  if (find(all(v), K) != v.end())
    cout << "POSSIBLE" << '\n';
  else if (v[N - 1] < K)
    cout << "IMPOSSIBLE" << '\n';
  else {
    int dif = INF;
    rep(N - 1, i) { dif = min(dif, gcd(v[i + 1], v[0])); }
    if ((v[N - 1] - K) % dif == 0)
      cout << "POSSIBLE" << '\n';
    else
      cout << "IMPOSSIBLE" << '\n';
  }
}

int main(void) {
  solve();
  return 0;
}
Problem p03651 (C++)

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

using namespace std;
int n, k;
int a[400000], fp[400000], fs[400000];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  int g = a[1];
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    g = __gcd(g, a[i]);
    fp[i] = g;
  }
  g = a[n];
  for (int i = n; i >= 1; i--) {
    g = __gcd(g, a[i]);
    fs[i] = g;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] < k)
      continue;
    int g = __gcd(fp[i - 1], fs[i + 1]);
    if (a[i] % g == k % g) {
      cout << "POSSIBLE\n";
      return 0;
    }
  }
  cout << "IMPOSSIBLE\n";
  return 0;
}


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

using namespace std;
int n, k;
int a[400000], fp[400000], fs[400000];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  int g = a[1];
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    g = __gcd(g, a[i]);
    fp[i] = g;
  }
  if (n == 1 && a[1] == k) {
    cout << "POSSIBLE\n";
    return 0;
  } else if (n == 1) {
    cout << "IMPOSSIBLE\n";
    return 0;
  }
  g = a[n];
  for (int i = n; i >= 1; i--) {
    g = __gcd(g, a[i]);
    fs[i] = g;
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] < k)
      continue;
    int g = __gcd(fp[i - 1], fs[i + 1]);
    if (a[i] % g == k % g) {
      cout << "POSSIBLE\n";
      return 0;
    }
  }
  cout << "IMPOSSIBLE\n";
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int n, k;
int a[100010];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (a[i] == k) {
      printf("POSSIBLE");
      return 0;
    }
  }
  sort(a + 1, a + n + 1);
  if (k > a[n]) {
    printf("IMPOSSIBLE");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int md = a[i + 1] - a[i];
    if (a[n] % md == k % md) {
      printf("POSSIBLE");
      return 0;
    }
  }
  printf("IMPOSSIBLE");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int n, k;
int a[100010];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (a[i] == k) {
      printf("POSSIBLE");
      return 0;
    }
  }
  sort(a + 1, a + n + 1);
  if (k > a[n]) {
    printf("IMPOSSIBLE");
    return 0;
  }
  for (int i = 1; i < n; i++) {
    int md = a[i + 1] - a[i];
    if (md == 0)
      continue;
    if (a[n] % md == k % md) {
      printf("POSSIBLE");
      return 0;
    }
  }
  printf("IMPOSSIBLE");
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  int N, K;
  vector<int> A;

  int gcd_vec(vector<int> a, int l, int r) {
    if (l + 1 == r)
      return a[l];
    int m = (l + r) / 2;
    return gcd(gcd_vec(a, l, m), gcd_vec(a, m, r));
  }

  int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }

  void ans() {
    cin >> N >> K;
    A.resize(N);
    int mx = 0;
    REP(i, N) {
      cin >> A[i];
      mx = max(mx, A[i]);
    }
    int g = gcd_vec(A, 0, N);
    string res = "IMPOSSIBLE\n";
    if (K <= mx && K % g == 0)
      res = "POSSIBLE\n";
    cout << res;
  }
};

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

  question q;
  q.ans();

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  int N, K;
  vector<int> A;

  int gcd_vec(vector<int> a, int l, int r) {
    if (l + 1 == r)
      return a[l];
    int m = (l + r) / 2;
    return gcd(gcd_vec(a, l, m), gcd_vec(a, m, r));
  }

  int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }

  void ans() {
    cin >> N >> K;
    A.resize(N);
    int mx = 0;
    REP(i, N) {
      cin >> A[i];
      mx = max(mx, A[i]);
    }
    int g = A[0];
    FOR(i, 1, N) g = gcd(g, A[i]);
    string res = "IMPOSSIBLE\n";
    if (K <= mx && K % g == 0)
      res = "POSSIBLE\n";
    cout << res;
  }
};

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

  question q;
  q.ans();

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
  if (a < b) {
    int tem = a;
    a = b;
    b = tem;
  }
  while (b != 0) {
    int c = a % b;
    a = b;
    b = c;
    if (b == 0)
      return a;
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> num(n);
  for (int i = 0; i < n; i++)
    cin >> num[i];
  int gcd = GCD(num[0], num[1]);
  sort(num.begin(), num.end(), greater<int>());
  if (num[0] < k)
    cout << "IMPOSSIBLE" << endl;
  else {
    for (int i = 0; i < n; i++) {
      gcd = GCD(gcd, num[i]);
    }
    if (k % gcd == 0)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
  if (a < b) {
    int tem = a;
    a = b;
    b = tem;
  }
  while (b != 0) {
    int c = a % b;
    a = b;
    b = c;
    if (b == 0)
      return a;
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> num(n);
  for (int i = 0; i < n; i++)
    cin >> num[i];
  int gcd = GCD(num[0], num[0]);
  sort(num.begin(), num.end(), greater<int>());
  if (num[0] < k)
    cout << "IMPOSSIBLE" << endl;
  else {
    for (int i = 0; i < n; i++) {
      gcd = GCD(gcd, num[i]);
    }
    if (k % gcd == 0)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03651 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define N 100010
using namespace std;
int Max(int &a, int b) { return a = max(a, b); }
int Min(int &a, int b) { return a = min(a, b); }
int n, K;
int A[N];
set<int> S;
unordered_set<int> used;
clock_t start = clock();

bool solve(int target) {
  clock_t end = clock();
  if ((double)(end - start) / CLOCKS_PER_SEC > 1.8)
    return 0;

  if (used.count(target))
    return 0;
  used.insert(target);
  auto it = S.lower_bound(target);
  if (it == S.end() || *it == -1)
    return 0;
  if (*it == target)
    return 1;

  while (it != S.end())
    if (solve(*it++ - target))
      return 1;
  return 0;
}

signed main() {

  cin >> n >> K;
  S.insert(-1);
  for (int i = 0; i < n; i++)
    scanf("%d", &A[i]), S.insert(A[i]);
  sort(A, A + n);
  int ans = solve(K);
  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define N 100010
using namespace std;
int Max(int &a, int b) { return a = max(a, b); }
int Min(int &a, int b) { return a = min(a, b); }
int n, K;
int A[N];
set<int> S;
unordered_set<int> used;
clock_t start = clock();

bool solve(int target) {
  clock_t end = clock();
  if ((double)(end - start) / CLOCKS_PER_SEC > 1.8) {
    cout << (0 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    exit(0);
  }

  if (used.count(target))
    return 0;
  used.insert(target);
  auto it = S.lower_bound(target);
  if (it == S.end() || *it == -1)
    return 0;
  if (*it == target)
    return 1;

  while (it != S.end())
    if (solve(*it++ - target))
      return 1;
  return 0;
}

signed main() {

  cin >> n >> K;
  S.insert(-1);
  for (int i = 0; i < n; i++)
    scanf("%d", &A[i]), S.insert(A[i]);
  sort(A, A + n);
  int ans = solve(K);
  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: 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 MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int, int>;

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  ll N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  ll GCD = gcd(A[0], A[1]);
  FOR(i, 2, N) { GCD = gcd(GCD, A[i]); }

  if (K % GCD == 0 && A[N - 1] >= K) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

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 MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int, int>;

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  ll N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  ll GCD;
  if (N >= 2) {
    GCD = gcd(A[0], A[1]);
    FOR(i, 2, N) { GCD = gcd(GCD, A[i]); }
  } else {
    GCD = A[0];
  }

  if (K % GCD == 0 && A[N - 1] >= K) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &arr[i]);
  sort(arr.begin(), arr.end());
  int g = 0;
  for (int i = 1; i < n; ++i)
    g = gcd(g, arr[i] - arr[i - 1]);
  if (abs(k - arr[0]) % g == 0 && arr[n - 1] >= k)
    puts("POSSIBLE");
  else
    puts("IMPOSSIBLE");
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &arr[i]);
  sort(arr.begin(), arr.end());
  int g = 0;
  for (int i = 1; i < n; ++i)
    g = gcd(g, arr[i] - arr[i - 1]);
  if (g == 0) {
    if (arr[0] == k)
      puts("POSSIBLE");
    else
      puts("IMPOSSIBLE");
    return 0;
  }
  if (abs(k - arr[0]) % g == 0 && arr[n - 1] >= k)
    puts("POSSIBLE");
  else
    puts("IMPOSSIBLE");
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
#define dump(x) cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  gcd(b, a % b);
}

int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  if (a[a.size() - 1] < k) {
    cout << "IMPOSSIBLE" << std::endl;
    return 0;
  }
  ll G = gcd(a[0], a[1]);
  if (n >= 2) {
    for (int i = 2; i < n; ++i)
      G = gcd(G, a[i]);
  }
  if (k % G == 0)
    cout << "POSSIBLE" << std::endl;
  else
    cout << "IMPOSSIBLE" << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
#define dump(x) cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  gcd(b, a % b);
}

int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  if (a[a.size() - 1] < k) {
    cout << "IMPOSSIBLE" << std::endl;
    return 0;
  }
  ll G = 0;
  if (n <= 1)
    G = a[0];
  else
    G = gcd(a[0], a[1]);
  for (int i = 2; i < n; ++i)
    G = gcd(G, a[i]);
  if (k % G == 0)
    cout << "POSSIBLE" << std::endl;
  else
    cout << "IMPOSSIBLE" << std::endl;
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
//
//  main.cpp
//  Getting Difference
//
//  Created by wenhan on 2017/7/23.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int a[100005];
int main() {
  int n, m;
  cin >> n >> m;
  bool f = false;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == m) {
      f = true;
      break;
    }
  }
  if (f)
    printf("POSSIBLE\n");
  else if (n == 1)
    printf("IMPOSSIBLE\n");
  else {
    sort(a, a + n);
    int s = a[1] - a[0];
    for (int i = 1; i < n - 1; i++)
      s = min(s, a[i + 1] - a[i]);
    s = min(s, a[0] - 0);
    if (m % s == 0 && a[n - 1] > m)
      printf("POSSIBLE\n");
    else
      printf("IMPOSSIBLE\n");
  }
  // insert code here...
  // std::cout << "Hello, World!\n";
  return 0;
}


Fixed submission:
//
//  main.cpp
//  Getting Difference
//
//  Created by wenhan on 2017/7/23.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int a[100005];
int main() {
  int n, m;
  cin >> n >> m;
  bool f = false;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == m) {
      f = true;
      break;
    }
  }
  if (f)
    printf("POSSIBLE\n");
  else if (n == 1)
    printf("IMPOSSIBLE\n");
  else {
    sort(a, a + n);
    int s = a[0] - 0;
    for (int i = 0; i < n - 1; i++)
      if (a[i + 1] - a[i] != 0)
        s = min(s, a[i + 1] - a[i]);
    if (m % s == 0 && a[n - 1] > m)
      printf("POSSIBLE\n");
    else
      printf("IMPOSSIBLE\n");
  }
  // insert code here...
  // std::cout << "Hello, World!\n";
  return 0;
}