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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
using namespace std;
const int maxn = 100005;
int n, k;
int a[maxn];

int main() {
  while (scanf("%d%d", &n, &k)) {
    int ans = 0, g = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      g = __gcd(g, a[i]);
    }
    sort(a, a + n);
    if (k <= a[n - 1] && k % g == 0)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
using namespace std;
const int maxn = 100005;
int n, k;
int a[maxn];

int main() {
  while (~scanf("%d%d", &n, &k)) {
    int ans = 0, g = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      g = __gcd(g, a[i]);
    }
    sort(a, a + n);
    if (k <= a[n - 1] && k % g == 0)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}
Problem p03651 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
import copy

N, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))

a_list = sorted(a_list)


def judge(w_list, k):
    w_list = sorted(w_list)

    for i in range(len(w_list) - 1):
        w_list += [abs(w_list[i] - w_list[i + 1])]

    w_list = sorted(list(set(w_list)))

    if k in w_list:
        return True, w_list
    elif 1 in w_list:
        return True, w_list
    elif abs(w_list[0] - w_list[-1]) < K:
        return False, w_list
    elif k % 2 == 0 and 2 in w_list:
        return True, w_list
    else:
        for w in w_list:
            if w + K in w_list:
                return True, w_list

        return False, w_list


w_list = a_list

while True:
    org_w_list = copy.copy(w_list)
    is_ok, w_list = judge(w_list, K)
    if is_ok:
        break
    else:
        if abs(w_list[0] - w_list[-1]) < K:
            break
        if w_list == org_w_list:
            break

ans = "POSSIBLE" if is_ok else "IMPOSSIBLE"

print(ans)


Fixed submission:
#!/usr/bin/env python3
import copy

N, K = list(map(int, input().split()))
a_list = list(map(int, input().split()))

a_list = sorted(a_list)


def judge(w_list, k):
    w_list = sorted(w_list)

    for i in range(len(w_list) - 1):
        w_list += [abs(w_list[i] - w_list[i + 1])]

    w_list = sorted(list(set(w_list)))

    if k in w_list:
        return True, w_list
    elif 1 in w_list:
        return True, w_list
    elif abs(w_list[0] - w_list[-1]) < K:
        return False, w_list
    elif k % 2 == 0 and 2 in w_list:
        return True, w_list
    else:
        ww_list = set([w + K for w in w_list])
        if ww_list & set(w_list):
            return True, w_list
        else:
            return False, w_list


w_list = a_list

while True:
    org_w_list = copy.copy(w_list)
    is_ok, w_list = judge(w_list, K)
    if is_ok:
        break
    else:
        if abs(w_list[0] - w_list[-1]) < K:
            break
        if w_list == org_w_list:
            break

ans = "POSSIBLE" if is_ok else "IMPOSSIBLE"

print(ans)
Problem p03651 (Python)

Buggy submission (status: Runtime Error):
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]


def gcd(x, y):
    if x < y:
        return gcd(y, x)
    elif y == 0:
        return x
    else:
        return gcd(y, x % y)


g = A.pop()
for a in A:
    g = gcd(g, a)
if K <= max(A) and K % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Fixed submission:
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]


def gcd(x, y):
    if x < y:
        return gcd(y, x)
    elif y == 0:
        return x
    else:
        return gcd(y, x % y)


g = A[0]
for a in A:
    g = gcd(g, a)
if K <= max(A) and K % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03651 (Python)

Buggy submission (status: Runtime Error):
from math import gcd

n, k = map(int, input().split())
a = list(map(int, input().split()))

x = a[0]
for i in range(1, n):
    x = gcd(x, a[i])

print("POSSIBLE" if k % x == 0 and max(a) >= k else "IMPOSSIBLE")


Fixed submission:
from fractions import gcd

n, k = map(int, input().split())
a = list(map(int, input().split()))

x = a[0]
for i in range(1, n):
    x = gcd(x, a[i])

print("POSSIBLE" if k % x == 0 and max(a) >= k else "IMPOSSIBLE")
Problem p03651 (Python)

Buggy submission (status: Runtime Error):
from math import gcd
from functools import reduce

N, K = map(int, input().split())
A = list(map(int, input().split()))

d = reduce(gcd, A)
print("POSSIBLE" if K <= max(A) and K % d == 0 else "IMPOSSIBLE")


Fixed submission:
from fractions import gcd
from functools import reduce

N, K = map(int, input().split())
A = list(map(int, input().split()))

d = reduce(gcd, A)
print("POSSIBLE" if K <= max(A) and K % d == 0 else "IMPOSSIBLE")
Problem p03651 (C++)

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

int n, k, r, a, maxa;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main(void) {
  scanf("%d%d%d", &n, &k, &r);
  maxa = r;
  for (int i = 1; i < n; i++) {
    scanf("%d", a);
    r = gcd(r, a);
    maxa = max(maxa, a);
  }
  if (!(k % r) && k <= maxa)
    printf("POSSIBLE");
  else
    printf("IMPOSSIBLE");
}

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

int n, k, r, a, maxa;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main(void) {
  scanf("%d%d%d", &n, &k, &r);
  maxa = r;
  for (int i = 1; i < n; i++) {
    scanf("%d", &a);
    r = gcd(r, a);
    maxa = max(maxa, a);
  }
  if (!(k % r) && k <= maxa)
    printf("POSSIBLE");
  else
    printf("IMPOSSIBLE");
}
Problem p03651 (C++)

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  if (k > v.back()) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    int g = __gcd(v.at(0), v.at(1));
    for (int i = 2; i < n; i++) {
      g = __gcd(g, v.at(i));
    }
    if (k % g == 0) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
  }

  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  if (k > v.back()) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    int g = v.at(0);
    for (int i = 1; i < n; i++) {
      g = __gcd(g, v.at(i));
    }
    if (k % g == 0) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
  }

  return 0;
}
Problem p03651 (C++)

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

typedef long long ll;

ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  unique(a.begin(), a.end());
  n = a.size();
  if (n == 1) {
    if (a[0] != k)
      cout << "IMPOSSIBLE" << endl;
    else
      cout << "POSSIBLE" << endl;
    return 0;
  }
  if (k > a[n - 1]) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  ll g = a[1] - a[0];
  for (int i = 2; i < n; i++) {
    if (a[i] - a[i - 1] == 0)
      continue;
    g = gcd(g, a[i] - a[i - 1]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] < k)
      continue;
    if ((a[i] - k) % g == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


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

typedef long long ll;

ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  auto result = unique(a.begin(), a.end());
  a.erase(result, a.end());
  n = a.size();
  if (n == 1) {
    if (a[0] != k)
      cout << "IMPOSSIBLE" << endl;
    else
      cout << "POSSIBLE" << endl;
    return 0;
  }
  if (k > a[n - 1]) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  ll g = a[1] - a[0];
  for (int i = 2; i < n; i++) {
    if (a[i] - a[i - 1] == 0)
      continue;
    g = gcd(g, a[i] - a[i - 1]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] < k)
      continue;
    if ((a[i] - k) % g == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(void) {
  int n, k, a[100010], b[100010];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0)
      b[i - 1] = a[i] - a[i - 1];
  }

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

  int gd;
  if (n == 2)
    gd = b[0];
  else
    gd = gcd(b[0], b[1]);

  for (int i = 2; i < n - 1; i++) {
    gd = gcd(gd, b[i]);
  }

  for (int i = 0; i < n; i++) {
    if (a[i] - k >= 0 && (a[i] - k) % gd == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(void) {
  int n, k, a[100010], b[100010];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0)
      b[i - 1] = a[i] - a[i - 1];
  }

  bool zeroes = true;
  for (int i = 0; i < n - 1; i++) {
    if (b[i] != 0)
      zeroes = false;
  }

  if (zeroes) {
    if (a[0] == k)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
    return 0;
  }

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

  int gd;
  if (n == 2)
    gd = b[0];
  else
    gd = gcd(b[0], b[1]);

  for (int i = 2; i < n - 1; i++) {
    gd = gcd(gd, b[i]);
  }

  for (int i = 0; i < n; i++) {
    if (a[i] - k >= 0 && (a[i] - k) % gd == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(v) v.begin(), v.end()
#define fio()                                                                  \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
#define forn(i, a, n) for (ll i = a; i < n; i++)
#define fornn(i, a, n) for (ll i = a; i <= n; i++)
#define pb push_back
#define MAXN 100005LL
#define INF 1000000005LL
inline void solve() {
  ll n, k, maxi = 0LL, ans = 0LL;
  cin >> n >> k;
  while (n--) {
    ll temp;
    cin >> temp;
    ans = __gcd(temp, ans);
    maxi = max(maxi, temp);
  }
  if (k <= maxi && k % ans == 0) {
    cout << "POSSIBLE";
  } else
    cout << "IMPOSSIBLE";
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
#endif
  fio();
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(v) v.begin(), v.end()
#define fio()                                                                  \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
#define forn(i, a, n) for (ll i = a; i < n; i++)
#define fornn(i, a, n) for (ll i = a; i <= n; i++)
#define pb push_back
#define MAXN 100005LL
#define INF 1000000005LL
inline void solve() {
  ll n, k, maxi = 0LL, ans = 0LL;
  cin >> n >> k;
  while (n--) {
    ll temp;
    cin >> temp;
    ans = __gcd(temp, ans);
    maxi = max(maxi, temp);
  }
  if (k <= maxi && k % ans == 0) {
    cout << "POSSIBLE";
  } else
    cout << "IMPOSSIBLE";
}
int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("output.txt","w",stdout);
  // freopen("input.txt","r",stdin);
  // #endif
  fio();
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

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

long lcm(long a, long b) { return (a * b) / gcd(a, b); }

template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

ll a[102345];

int main() {
  ll n;
  ll k;

  cin >> n >> k;

  ll ma = 0;

  ll ans = 0;

  REP(i, n) {
    cin >> a[i];

    ma = max(ma, a[i]);
  }

  if (n != 1)
    ans = gcd(a[0], a[1]);

  REP(i, n - 2) { ans = gcd(ans, a[i + 2]); }

  if (k > ma)
    cout << "IMPOSSIBLE" << endl;
  else {
    if (k % ans == 0)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

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

long lcm(long a, long b) { return (a * b) / gcd(a, b); }

template <typename A, typename B> inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

ll a[102345];

int main() {
  ll n;
  ll k;

  cin >> n >> k;

  ll ma = 0;

  ll ans = 1;

  REP(i, n) {
    cin >> a[i];

    ma = max(ma, a[i]);
  }

  if (n != 1)
    ans = gcd(a[0], a[1]);

  REP(i, n - 2) { ans = gcd(ans, a[i + 2]); }

  if (k > ma)
    cout << "IMPOSSIBLE" << endl;
  else {
    if (k % ans == 0)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
#define fr(i, n) for (ll i = 0; i < n; i++)

ll gcd(ll a, ll b) {
  if (a * b == 0)
    return a + b;
  else if (a >= b)
    return gcd(b, a % b);
  else
    return gcd(a, b % a);
}

int main() {
  ll n, k, a[10000], gd = 0;
  cin >> n >> k;
  fr(i, n) cin >> a[i];
  sort(a, a + n);
  fr(i, n) gd = gcd(gd, a[i]);
  if (a[n - 1] < k)
    cout << "IMPOSSIBLE";
  else {
    if ((a[n - 1] - k) % gd == 0)
      cout << "POSSIBLE";
    else
      cout << "IMPOSSIBLE";
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
#define fr(i, n) for (ll i = 0; i < n; i++)

ll gcd(ll a, ll b) {
  if (a * b == 0)
    return a + b;
  else if (a >= b)
    return gcd(b, a % b);
  else
    return gcd(a, b % a);
}

int main() {
  ll n, k, a[100000], gd = 0;
  cin >> n >> k;
  fr(i, n) cin >> a[i];
  sort(a, a + n);
  fr(i, n) gd = gcd(gd, a[i]);
  if (a[n - 1] < k)
    cout << "IMPOSSIBLE";
  else {
    if ((a[n - 1] - k) % gd == 0)
      cout << "POSSIBLE";
    else
      cout << "IMPOSSIBLE";
  }
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  int n, k;
  int a[100010];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = gcd(a[0], a[1]);
  for (int j = 2; j < n; j++) {
    ans = gcd(a[j], ans);
  }
  if (k % ans == 0) {
    if (a[n - 1] < k) {
      cout << "IMPOSSIBLE" << endl;
    } else {
      cout << "POSSIBLE" << endl;
    }
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  int n, k;
  int a[100010];
  cin >> n >> k;
  if (n == 1) {
    cin >> a[0];
    if (a[0] == k) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = gcd(a[0], a[1]);
  for (int j = 2; j < n; j++) {
    ans = gcd(a[j], ans);
  }
  if (k % ans == 0) {
    if (a[n - 1] < k) {
      cout << "IMPOSSIBLE" << endl;
    } else {
      cout << "POSSIBLE" << endl;
    }
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}
Problem p03651 (C++)

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

using namespace std;
using ll = long long;

int const N = 100 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;

int n, k;
int a[N];

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

  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  sort(a, a + n);

  vector<int> d;
  for (int i = 1; i < n; ++i)
    d.emplace_back(a[i] - a[i - 1]);

  sort(d.begin(), d.end());
  bool all = true;
  for (int x : d)
    all &= (x % d[0] == 0);

  bool cant = true;
  for (int i = 0; cant && i < n; ++i)
    if (a[i] == k || a[i] > k && (not all || ((a[i] - k) % d[0] == 0)))
      cant = false;

  cout << (cant ? "IMPOSSIBLE" : "POSSIBLE") << endl;
}

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

using namespace std;
using ll = long long;

int const N = 100 * 1000 + 16;
int const M = 1000 * 1000 * 1000 + 7;

int n, k;
int a[N];

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

  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  sort(a, a + n);

  vector<int> d;
  for (int i = 1; i < n; ++i)
    d.emplace_back(a[i] - a[i - 1]);

  sort(d.begin(), d.end(), greater<int>());
  while (d.size() && d.back() == 0)
    d.pop_back();

  reverse(d.begin(), d.end());
  bool all = true;
  for (int x : d)
    all &= (x % d[0] == 0);

  bool cant = true;
  for (int i = 0; cant && i < n; ++i)
    if (a[i] == k || a[i] > k && (not all || ((a[i] - k) % d[0] == 0)))
      cant = false;

  cout << (cant ? "IMPOSSIBLE" : "POSSIBLE") << endl;
}
Problem p03651 (C++)

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

// http://agc018.contest.atcoder.jp/tasks/agc018_a

using namespace std;

typedef long long LL;
typedef pair<LL, LL> pp;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  unordered_set<int> s(v.begin(), v.end());

  if (s.count(K) != 0) {
    cout << "POSSIBLE" << endl;
    exit(0);
  }
  if (K > v[N - 1]) {
    cout << "IMPOSSIBLE" << endl;
    exit(0);
  }
  for (int i = 1; i < N; i++) {
    if (K % (v[i] - v[i - 1]) == 0) {
      cout << "POSSIBLE" << endl;
      exit(0);
    }
  }
  cout << "IMPOSSIBLE" << endl;
  exit(0);
}


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

// http://agc018.contest.atcoder.jp/tasks/agc018_a

using namespace std;

typedef long long LL;
typedef pair<LL, LL> pp;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  unordered_set<int> s(v.begin(), v.end());

  if (s.count(K) != 0) {
    cout << "POSSIBLE" << endl;
    exit(0);
  }
  if (K > v[N - 1]) {
    cout << "IMPOSSIBLE" << endl;
    exit(0);
  }
  for (int i = 1; i < N; i++) {
    if (v[i] == v[i - 1])
      continue;
    if (K % (v[i] - v[i - 1]) == 0) {
      cout << "POSSIBLE" << endl;
      exit(0);
    }
  }
  cout << "IMPOSSIBLE" << endl;
  exit(0);
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, m, i, a[101010], b[101010], ma;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == m) {
      cout << "POSSIBLE\n";
      return 0;
    }
    b[a[i]] = 1;
    ma = max(ma, a[i]);
  }
  if (ma > m) {
    for (i = 1; i <= n; i++) {
      if (b[m - a[i]] == 1) {
        cout << "POSSIBLE\n";
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE\n";
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, m, i, a[101010], ma;
map<ll, bool> b;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == m) {
      cout << "POSSIBLE\n";
      return 0;
    }
    b[a[i]] = 1;
    ma = max(ma, a[i]);
  }
  if (ma > m) {
    for (i = 1; i <= n; i++) {
      if (b[m - a[i]] == 1) {
        cout << "POSSIBLE\n";
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE\n";
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>

using namespace std;
typedef long long ll;

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

int main() {

  ll N, K;
  cin >> N >> K;

  vector<ll> V(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> V[i];
  }

  sort(V.rbegin(), V.rend());

  // 入力の最大値が求めるK未満のとき成り立たない
  if (V[0] < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  ll n_gcd = 0;
  for (ll i = 1; i < N; i++) {
    if (i == 1) {
      n_gcd = gcd(V[i - 1], V[i]);
    } else {
      n_gcd = gcd(n_gcd, V[i]);
    }
  }

  if (K % n_gcd == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>

using namespace std;
typedef long long ll;

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

int main() {

  ll N, K;
  cin >> N >> K;

  vector<ll> V(N, 0);
  for (ll i = 0; i < N; i++) {
    cin >> V[i];
  }

  sort(V.rbegin(), V.rend());

  // 入力の最大値が求めるK未満のとき成り立たない
  if (V[0] < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  ll n_gcd = V[0];
  for (ll i = 1; i < N; i++) {
    if (i == 1) {
      n_gcd = gcd(V[i - 1], V[i]);
    } else {
      n_gcd = gcd(n_gcd, V[i]);
    }
  }

  if (K % n_gcd == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mii map<int, int>
#define pii pair<int, int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007        // 10^9+7
#define inf 10000000000000000 // 10^16
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec)                                                           \
  vsort(vec);                                                                  \
  vrever(vec);
#define bisea binary_search
#define cend cout << endl;
#define F first
#define S second
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
using namespace std;
signed main() {
  int n, k, gcm;
  cin >> n >> k;
  int a[n];
  int ma = 0;
  rep(i, n) {
    cin >> a[i];
    ma = max(ma, a[i]);
  }
  rep(i, n - 1) {
    if (i == 0)
      gcm = gcd(a[i], a[i + 1]);
    else
      gcm = gcd(gcm, a[i + 1]);
  }
  if (k <= ma && k % gcm == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mii map<int, int>
#define pii pair<int, int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007        // 10^9+7
#define inf 10000000000000000 // 10^16
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec)                                                           \
  vsort(vec);                                                                  \
  vrever(vec);
#define bisea binary_search
#define cend cout << endl;
#define F first
#define S second
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
using namespace std;
signed main() {
  int n, k, gcm;
  cin >> n >> k;
  int a[n];
  int ma = 0;
  rep(i, n) {
    cin >> a[i];
    ma = max(ma, a[i]);
  }
  if (n == 1) {
    if (k == a[0]) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
    return 0;
  }
  rep(i, n - 1) {
    if (i == 0)
      gcm = gcd(a[i], a[i + 1]);
    else
      gcm = gcd(gcm, a[i + 1]);
  }
  if (k <= ma && k % gcm == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

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

using namespace std;
typedef long long ll;

ll INF = 10000000000;

ll gcd(ll a, ll b) {
  ll na = 0, nb = 0;
  if (a < b) {
    na = b;
    nb = a;
  } else {
    na = a;
    nb = b;
  }
  ll c = na % nb;
  ll ans = 0;
  if (c != 0)
    ans = gcd(nb, c);
  else
    ans = nb;
  return ans;
}

void show(vector<ll> vec) {
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << endl;
}

ll getMaxGcd(vector<ll> vec) {
  ll maxGcd = gcd(vec[0], vec[1]);
  for (int i = 2; i < vec.size(); i++) {
    maxGcd = gcd(vec[i], maxGcd);
  }

  return maxGcd;
}

ll getMax(vector<ll> vec) {
  ll max = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (max < vec[i])
      max = vec[i];
  }
  return max;
}

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> vec;

  for (int i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    vec.push_back(tmp);
  }

  ll max = getMax(vec);
  ll maxGcd = getMaxGcd(vec);
  if (K <= max && K % maxGcd == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;

ll INF = 10000000000;

ll gcd(ll a, ll b) {
  ll na = 0, nb = 0;
  if (a < b) {
    na = b;
    nb = a;
  } else {
    na = a;
    nb = b;
  }
  ll c = na % nb;
  ll ans = 0;
  if (c != 0)
    ans = gcd(nb, c);
  else
    ans = nb;
  return ans;
}

void show(vector<ll> vec) {
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << endl;
}

ll getMaxGcd(vector<ll> vec) {
  ll maxGcd = 0;
  if (vec.size() == 1)
    maxGcd = vec[0];
  else
    maxGcd = gcd(vec[0], vec[1]);
  for (int i = 2; i < vec.size(); i++) {
    maxGcd = gcd(vec[i], maxGcd);
  }

  return maxGcd;
}

ll getMax(vector<ll> vec) {
  ll max = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (max < vec[i])
      max = vec[i];
  }
  return max;
}

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> vec;

  for (int i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    vec.push_back(tmp);
  }

  ll max = getMax(vec);
  ll maxGcd = getMaxGcd(vec);
  if (K <= max && K % maxGcd == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100010;
int a[N], s[N];
inline int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    ch = getchar(), o = -1;
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
  int n, k;
  cin >> n >> k;
  if (n == 1)
    return puts(gi() == k ? "POSSIBLE" : "IMPOSSIBLE");
  for (int i = 1; i <= n; i++)
    a[i] = gi(), s[i] = gcd(s[i - 1], a[i]);
  for (int i = n, g = 0; i; i--) {
    int c = gcd(s[i - 1], g);
    if (a[i] >= k && a[i] % c == k % c)
      return puts("POSSIBLE"), 0;
    g = gcd(a[i], g);
  }
  puts("IMPOSSIBLE");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int N = 100010;
int a[N], s[N];
inline int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    ch = getchar(), o = -1;
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
  int n, k;
  cin >> n >> k;
  if (n == 1)
    return puts(gi() == k ? "POSSIBLE" : "IMPOSSIBLE"), 0;
  for (int i = 1; i <= n; i++)
    a[i] = gi(), s[i] = gcd(s[i - 1], a[i]);
  for (int i = n, g = 0; i; i--) {
    int c = gcd(s[i - 1], g);
    if (a[i] >= k && a[i] % c == k % c)
      return puts("POSSIBLE"), 0;
    g = gcd(a[i], g);
  }
  puts("IMPOSSIBLE");
  return 0;
}
Problem p03651 (C++)

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

using namespace std;

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

  int n, k;
  int a[10000];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mx = a[0];
  int gc = a[0];

  for (int i = 0; i < n; i++) {
    gc = __gcd(gc, a[i]);
    mx = max(mx, a[i]);
  }
  if (mx >= k && k % gc == 0)
    cout << "POSSIBLE\n";
  else {
    cout << "IMPOSSIBLE\n";
  }
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

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

  int n, k;
  int a[100000];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mx = a[0];
  int gc = a[0];

  for (int i = 0; i < n; i++) {
    gc = __gcd(gc, a[i]);
    mx = max(mx, a[i]);
  }
  if (mx >= k && k % gc == 0)
    cout << "POSSIBLE\n";
  else {
    cout << "IMPOSSIBLE\n";
  }
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
// cout << fixed << std::setprecision(9)
// memset(a, 0, sizeof(a));
//--------------------------

vector<int> a;
int n, k;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.push_back(t);
  }

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

  if (a[n - 1] < k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (a[i] == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  for (int i = 0; i < n - 1; i++) {
    if (a[i + 1] - a[i] == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }

    if (a[i + 1] - a[i] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      if (gcd(a[i], a[j]) == 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }

  cout << "IMPOSSIBLE" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
// cout << fixed << std::setprecision(9)
// memset(a, 0, sizeof(a));
//--------------------------

vector<int> a;
int n, k;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.push_back(t);
  }

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

  if (a[n - 1] < k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (a[i] == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  for (int i = 0; i < n - 1; i++) {
    if (a[i + 1] - a[i] == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }

    if (a[i + 1] - a[i] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  int d = a[0];
  for (int i = 1; i < n; i++) {
    d = gcd(d, a[i]);
  }

  if (d == 1) {
    cout << "POSSIBLE" << endl;
    return 0;
  }

  if (k % d == 0) {
    cout << "POSSIBLE" << endl;
    return 0;
  }

  cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int eu(int a, int b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  eu(a - b, b);
}

int main() {
  int n, k;
  cin >> n >> k;
  int maxl = 0, gcd = 1;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (i == 0)
      gcd = a;
    maxl = max(maxl, a);
    gcd = eu(gcd, a);
  }
  if (k <= maxl && k % gcd == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int eu(int a, int b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  eu(a % b, b);
}

int main() {
  int n, k;
  cin >> n >> k;
  int maxl = 0, gcd = 1;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (i == 0)
      gcd = a;
    maxl = max(maxl, a);
    gcd = eu(gcd, a);
  }
  if (k <= maxl && k % gcd == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

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

using namespace std;

int n, k, x, cx, i, Max, A;

int cmmdc(int a, int b) {
  int r = 0;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
#endif // ONLINE_JUDGE

  scanf("%d %d\n", &n, &k);
  Max = 0;
  for (i = 1; i <= n; ++i) {
    scanf("%d ", &x);
    Max = max(Max, x);
    if (i == 1) {
      A = x;
      continue;
    }
    A = cmmdc(A, x);
  }

  if (k <= Max && k % A == 0 && k >= A)
    printf("POSSIBLE\n");
  else
    printf("IMPOSSIBLE\n");

  return 0;
}


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

using namespace std;

int n, k, x, cx, i, Max, A;

int cmmdc(int a, int b) {
  int r = 0;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  // freopen("in", "r", stdin);
  // freopen("out", "w", stdout);

  scanf("%d %d\n", &n, &k);
  Max = 0;
  for (i = 1; i <= n; ++i) {
    scanf("%d ", &x);
    Max = max(Max, x);
    if (i == 1) {
      A = x;
      continue;
    }
    A = cmmdc(A, x);
  }

  if (k <= Max && k % A == 0 && k >= A)
    printf("POSSIBLE\n");
  else
    printf("IMPOSSIBLE\n");

  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++)
using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  bool odd, even;
  odd = even = true;
  REP(i, n) {
    if (a[i] % 2)
      even = false;
    else
      odd = false;
  }
  bool allSame = true;
  bool diffFlag = true;
  int diff = INT_MAX;
  REP(i, n - 1) diff = min(diff, abs(a[i] - a[i + 1]));
  REP(i, n - 1) {
    if (a[i] != a[i + 1])
      allSame = false;
    if (abs(a[i] - a[i + 1]) % diff)
      diffFlag = false;
  }

  if (k > *max_element(a.begin(), a.end())) {
    cout << "IMPOSSIBLE" << '\n';
  } else if (find(a.begin(), a.end(), k) != a.end()) {
    cout << "POSSIBLE" << '\n';
  } else if (allSame) {
    cout << ((k == a[0]) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
  } else if (diffFlag) {
    cout << ((k % diff == 0) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
  } else {
    if (k % 2) {
      bool ok = true;
      if (even)
        ok = false;
      if (k == 1 && (even || odd))
        ok = false;
      cout << ((ok) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
    } else {
      cout << "POSSIBLE" << '\n';
    }
  }
  return 0;
}


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

int main() {
  cin.tie(0)->sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  bool odd, even;
  odd = even = true;
  REP(i, n) {
    if (a[i] % 2)
      even = false;
    else
      odd = false;
  }
  bool allSame = true;
  bool diffFlag = true;
  int diff = INT_MAX;
  REP(i, n - 1) {
    if (abs(a[i] - a[i + 1]))
      diff = min(diff, abs(a[i] - a[i + 1]));
  }
  REP(i, n - 1) {
    if (a[i] != a[i + 1])
      allSame = false;
    if (abs(a[i] - a[i + 1]) % diff)
      diffFlag = false;
  }

  if (k > *max_element(a.begin(), a.end())) {
    cout << "IMPOSSIBLE" << '\n';
  } else if (find(a.begin(), a.end(), k) != a.end()) {
    cout << "POSSIBLE" << '\n';
  } else if (allSame) {
    cout << ((k == a[0]) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
  } else if (diffFlag) {
    cout << ((k % diff == 0) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
  } else {
    if (k % 2) {
      bool ok = true;
      if (even)
        ok = false;
      if (k == 1 && (even || odd))
        ok = false;
      cout << ((ok) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
    } else {
      cout << "POSSIBLE" << '\n';
    }
  }
  return 0;
}
Problem p03651 (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 repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                                             \
  ifstream in("atcoder-problems/agc018_a.txt");                                \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                                                           \
  rep(l, v.size()) { cout << v[l] << " "; }                                    \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE                                                           \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K;
  cin >> N >> K;

  vector<ll> c(N);
  set<ll> s;
  ll m = 0;
  rep(i, N) {
    ll x;
    cin >> x;
    c[i] = x;
    s.insert(x);
    m = max(m, x);
  }
  if (m < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(c.begin(), c.end());
  rep(i, N - 1) { s.insert(abs(c[i] - c[i + 1])); }

  bool ret = false;
  for (auto a : s) {
    if (K % a == 0) {
      ret = true;
      break;
    }
  }

  cout << (ret ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                                                             \
  ifstream in("atcoder-problems/agc018_a.txt");                                \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                                                           \
  rep(l, v.size()) { cout << v[l] << " "; }                                    \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE                                                           \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K;
  cin >> N >> K;

  vector<ll> c(N);
  set<ll> s;
  ll m = 0;
  rep(i, N) {
    ll x;
    cin >> x;
    c[i] = x;
    s.insert(x);
    m = max(m, x);
  }
  if (m < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(c.begin(), c.end());
  rep(i, N - 1) { s.insert(abs(c[i] - c[i + 1])); }

  bool ret = false;
  for (auto a : s) {
    if (a != 0 && K % a == 0) {
      ret = true;
      break;
    }
  }

  cout << (ret ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1001001001;
const long long INFL = (1LL << 60);
const double eps = (1e-9);

ll mod = 1000000007;

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    if (tmp == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    a[i] = tmp;
  }

  sort(ALL(a));

  if (k > a[n - 1]) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  vector<ll> b(n);
  b[0] = a[0];
  for (int i = 0; i < n - 1; i++) {
    b[i + 1] = a[i + 1] - a[i];
  }

  sort(ALL(b));

  for (auto &v : b) {
    k %= v;
  }

  if (k == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1001001001;
const long long INFL = (1LL << 60);
const double eps = (1e-9);

ll mod = 1000000007;

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    if (tmp == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    a[i] = tmp;
  }

  sort(ALL(a));

  if (k > a[n - 1]) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  vector<ll> b(n);
  b[0] = a[0];
  for (int i = 0; i < n - 1; i++) {
    b[i + 1] = a[i + 1] - a[i];
  }

  sort(ALL(b));

  for (auto &v : b) {
    if (v == 0)
      continue;
    k %= v;
  }

  if (k == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}
Problem p03651 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
#define PINT pair<int, int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

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() {
  cin.tie(0), ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  if (k > a[n - 1]) {
    cout << "IMPOSSIBLE\n";
    return 0;
  }

  if (*lower_bound(a.begin(), a.end(), k) == k) {
    cout << "POSSIBLE\n";
    return 0;
  }
  int adiv = a[0];
  REP(i, n) adiv = gcd(adiv, a[i]);
  if (k % adiv)
    cout << "IMPOSSIBLE\n";
  else
    cout << "POSSIBLE\n";
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
#define PINT pair<int, int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

int gcd(int m, int n) {
  // 引数に０がある場合は０を返す
  if ((0 == m) || (0 == n))
    return 0;
  else if (m % n == 0)
    return n;
  else if (n % m == 0)
    return m;

  // ユークリッドの方法
  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  sort(a.begin(), a.end());
  if (k > a[n - 1]) {
    cout << "IMPOSSIBLE\n";
    return 0;
  }

  if (*lower_bound(a.begin(), a.end(), k) == k) {
    cout << "POSSIBLE\n";
    return 0;
  }
  int adiv = a[0];
  REP(i, n) adiv = gcd(adiv, a[i]);
  if (k % adiv)
    cout << "IMPOSSIBLE\n";
  else
    cout << "POSSIBLE\n";
  return 0;
}