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

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

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

int main() {
  int N, K, mi = 1e9, ma = 1;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mi = min(mi, A[i]);
    ma = max(ma, A[i]);
  }
  if (N == 1) {
    cout << (A[0] == K ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
  }
  int g = abs(A[1] - A[0]);
  for (int i = 2; i < N; i++) {
    g = gcd(g, abs(A[i] - A[0]));
  }
  if (K <= ma && abs(K - A[0]) % g == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


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

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

int main() {
  int N, K, mi = 1e9, ma = 1;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mi = min(mi, A[i]);
    ma = max(ma, A[i]);
  }
  if (N == 1) {
    cout << (A[0] == K ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
  }
  int g = abs(A[1] - A[0]);
  for (int i = 2; i < N; i++) {
    g = gcd(g, abs(A[i] - A[0]));
  }
  if (K <= ma && ((mi == K && ma == K) || abs(K - A[0]) % 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;

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
typedef unsigned long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> A;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    A.push_back(temp);
  }
  sort(A.begin(), A.end());
  int max = A.back();
  int gg = 0;
  for (int i = 1; i < n; i++) {
    gg = gcd(gg, A[i]);
  }
  if (k <= max && k % gg == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
typedef unsigned long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> A;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    A.push_back(temp);
  }
  sort(A.begin(), A.end());
  int max = A.back();
  int gg = A[0];
  for (int i = 1; i < n; i++) {
    gg = gcd(gg, A[i]);
  }
  if (k <= max && k % gg == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  set<ll> st;
  for (auto e : a)
    st.insert(e);

  priority_queue<ll, vector<ll>, greater<ll>> que;
  ll minn = 1e10;
  ll maxx = 0;
  for (auto e : st) {
    que.push(e);
    minn = min(minn, e);
    maxx = max(maxx, e);
  }

  if (maxx < k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  ll x = 1e10;
  bool b = true;
  while (b) {
    for (auto e : st) {
      if (0 < e && k <= e && e % minn == k % minn) {
        x = k;
        break;
      }
      ll v = e - minn;
      while (0 < v) {
        st.insert(v);
        v -= minn;
      }
    }
    if (0 < st.count(k)) {
      x = k;
      break;
    }

    b = false;
    for (auto e : st) {
      if (e < minn) {
        minn = e;
        b = true;
        break;
      }
    }
  }

  if (x == k)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  set<ll> st;
  for (auto e : a)
    st.insert(e);

  priority_queue<ll, vector<ll>, greater<ll>> que;
  ll minn = 1e10;
  ll maxx = 0;
  for (auto e : st) {
    que.push(e);
    minn = min(minn, e);
    maxx = max(maxx, e);
  }

  if (maxx < k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  ll x = 1e10;
  bool b = true;
  while (b) {
    for (auto e : st) {
      if (0 < e && k <= e && e % minn == k % minn) {
        x = k;
        break;
      }
      if (0 < e && 0 < e % minn)
        st.insert(e % minn);
    }
    if (0 < st.count(k)) {
      x = k;
      break;
    }

    b = false;
    for (auto e : st) {
      if (e < minn) {
        minn = e;
        b = true;
        break;
      }
    }
  }

  if (x == k)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int a[100000 + 5];
int gcd(int x, int y) {
  if (x < y)
    return gcd(y, x);
  if (y == 0)
    return x;
  else
    return gcd(x - y, y);
}

int main() {
  int N, K, flag = 0, max1 = 0;
  scanf("%d%d", &N, &K);
  int temp;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
    max1 = max(max1, a[i]);
    if (i > 0)
      a[i] = gcd(a[i], a[i - 1]);
  }
  if (K > max1 || K % a[N - 1] != 0)
    printf("IMPOSSIBLE");
  else
    printf("POSSIBLE");
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int a[100000 + 5];
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  int N, K, flag = 0, max1 = 0;
  scanf("%d%d", &N, &K);
  int temp;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
    max1 = max(max1, a[i]);
    if (i > 0)
      a[i] = gcd(a[i], a[i - 1]);
  }
  if (K > max1 || K % a[N - 1] != 0)
    printf("IMPOSSIBLE");
  else
    printf("POSSIBLE");
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
int main() {
  int n, k;
  cin >> n >> k;
  int a[100005] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    // sort(a,a+n);
  }
  sort(a, a + n);
  int diff = 1e9;
  if (n == 1)
    diff = a[0];
  for (int i = 0; i < n - 1; i++)
    diff = min(diff, a[i + 1] - a[i]);
  for (int i = n - 1; a[i] >= k && i >= 0; i--) {
    if ((a[i] - k) % diff == 0) {
      cout << "POSSIBLE\n";
      return 0;
    }
  }
  cout << "IMPOSSIBLE\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
int main() {
  int n, k;
  cin >> n >> k;
  int a[100005] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    // sort(a,a+n);
  }
  sort(a, a + n);
  int diff = 1e9;
  if (n == 1)
    diff = a[0];
  for (int i = 0; i < n - 1; i++) {
    if (a[i + 1] != a[i])
      diff = min(diff, a[i + 1] - a[i]);
  }
  for (int i = n - 1; a[i] >= k && i >= 0; i--) {
    if ((a[i] - k) % diff == 0) {
      cout << "POSSIBLE\n";
      return 0;
    }
  }
  cout << "IMPOSSIBLE\n";
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include "iostream"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

int main(int argc, char const *argv[]) {
  int n;
  ll a[100010], k, b[100010];
  bool f = false;
  std::cin >> n >> k;

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    if (a[i] == k)
      f = true;
  }

  sort(a, a + n, greater<ll>());
  if (a[0] < k) {
    std::cout << "IMPOSSIBLE" << '\n';
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    b[i] = a[i] - a[i + 1];
    if (k % b[i] == 0)
      f = true;
  }
  if (f)
    std::cout << "POSSIBLE" << '\n';
  else
    std::cout << "IMPOSSIBLE" << '\n';
  return 0;
}


Fixed submission:
#include "iostream"
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

int main(int argc, char const *argv[]) {
  int n;
  ll a[100010], k, b[100010];
  bool f = false;
  std::cin >> n >> k;

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    if (a[i] == k)
      f = true;
  }

  sort(a, a + n, greater<ll>());
  if (a[0] < k) {
    std::cout << "IMPOSSIBLE" << '\n';
    return 0;
  }
  for (int i = 0; i < n - 1; i++) {
    b[i] = a[i] - a[i + 1];
    if (b[i] == 0)
      continue;
    if (k % b[i] == 0)
      f = true;
  }
  if (f)
    std::cout << "POSSIBLE" << '\n';
  else
    std::cout << "IMPOSSIBLE" << '\n';
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int get_gcd(int a, int b) {
  if (a < b)
    std::swap(a, b);
  int r;
  while (1) {
    r = a % b;
    if (r == 0) {
      return b;
    } else {
      a = b;
      b = r;
    }
  }
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  std::vector<int> ball;
  int m1;
  bool is_ok = false;
  for (int i = 0; i < n; i++) {
    cin >> m1;
    ball.push_back(m1);
  }
  std::sort(ball.begin(), ball.end());
  int max = *(ball.end() - 1);
  if (max < k) {
    is_ok = false;
  } else if (max == k) {
    is_ok = true;
  } else {
    int min = *(ball.begin());
    int gcd;
    for (int i = 0; i < n; i++) {
      gcd = get_gcd(gcd, ball[i]);
    }
    if (k % gcd == 0) {
      is_ok = true;
    } else {
      is_ok = false;
    }
  }

  if (is_ok) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int get_gcd(int a, int b) {
  if (a < b)
    std::swap(a, b);
  int r;
  while (1) {
    r = a % b;
    if (r == 0) {
      return b;
    } else {
      a = b;
      b = r;
    }
  }
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  std::vector<int> ball;
  int m1;
  bool is_ok = false;
  for (int i = 0; i < n; i++) {
    cin >> m1;
    ball.push_back(m1);
  }
  std::sort(ball.begin(), ball.end());
  int max = *(ball.end() - 1);
  if (max < k) {
    is_ok = false;
  } else if (max == k) {
    is_ok = true;
  } else {
    int min = *(ball.begin());
    int gcd = ball[0];
    for (int i = 1; i < n; i++) {
      gcd = get_gcd(gcd, ball[i]);
    }
    if (k % gcd == 0) {
      is_ok = true;
    } else {
      is_ok = false;
    }
  }

  if (is_ok) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}
Problem p03651 (C++)

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

int gcd(int x, int y) {
  if (x == 1 || y == 1)
    return 1;
  if (x == y)
    return x;
  if (x > y)
    return gcd(x - y, y);
  return gcd(x, y - x);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int g = a[0], mx = a[0];
  for (int i = 1; i < n; i++) {
    g = gcd(g, a[i]);
    mx = max(mx, a[i]);
  }
  if (n == 1) {
    if (a[0] == k)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
    return 0;
  } else {
    if (k % g == 0 && k <= mx)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


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

int gcd(int x, int y) {
  while (x != 0) {
    y %= x;
    if (y == 0)
      return x;
    x %= y;
  }
  return y;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int g = a[0], mx = a[0];
  for (int i = 1; i < n; i++) {
    g = gcd(g, a[i]);
    mx = max(mx, a[i]);
  }
  if (n == 1) {
    if (a[0] == k)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
    return 0;
  } else {
    if (k % g == 0 && k <= mx)
      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 pii = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N, K;
  cin >> N >> K;
  map<ll, ll> mp;
  vector<ll> A(N);
  rep(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end());
  ll sa = 1e18, sa_prev = 1e18;
  rep(i, N - 1) { chmin(sa, A[i + 1] - A[i]); }
  while (1) {
    rep(i, N) {
      ll a = A[i] % sa;
      if (a != 0)
        chmin(sa, a);
    }
    if (sa == sa_prev) {
      break;
    }
    sa_prev = sa;
  }
  rep(i, N) {
    if (A[i] < K)
      continue;
    if ((A[i] - K) % sa == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N, K;
  cin >> N >> K;
  map<ll, ll> mp;
  vector<ll> A(N);
  rep(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end());
  ll sa = 1e18, sa_prev = 1e18;
  rep(i, N - 1) {
    if (A[i + 1] - A[i] > 0)
      chmin(sa, A[i + 1] - A[i]);
  }
  while (1) {
    rep(i, N) {
      ll a = A[i] % sa;
      if (a != 0)
        chmin(sa, a);
    }
    if (sa == sa_prev) {
      break;
    }
    sa_prev = sa;
  }
  rep(i, N) {
    if (A[i] < K)
      continue;
    if ((A[i] - K) % sa == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  int g = 0, i, n, a, K, M = 0;
  scanf("%d%d", n, K);
  for (i = 0; i < n; i++) {
    scanf("%d", &a);
    if (M < a)
      M = a;
    g = gcd(g, a);
  }
  printf((K % g || M < K) ? "IMPOSSIBLE\n" : "POSSIBLE\n");
}

Fixed submission:
#include <cstdio>
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  int g = 0, i, n, a, K, M = 0;
  scanf("%d%d", &n, &K);
  for (i = 0; i < n; i++) {
    scanf("%d", &a);
    if (M < a)
      M = a;
    g = gcd(g, a);
  }
  printf((K % g || M < K) ? "IMPOSSIBLE\n" : "POSSIBLE\n");
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main() {
  int K;
  cin >> N >> K;
  cnt = N;
  int A[300000] = {0};
  int maxv = 0;
  rep(i, N) {
    cin >> A[i];
    maxv = max(maxv, A[i]);
  }
  rep(i, N) {
    if (A[i] == K) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  if (K > maxv)
    cout << "IMPOSSIBLE" << endl;
  else {
    sort(A, A + N);
    rep(i, N - 1) {
      tmp = abs(A[i] - A[i + 1]);
      if (tmp == 1 || K % tmp == 0) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main() {
  int K;
  cin >> N >> K;
  cnt = N;
  int A[300000] = {0};
  int maxv = 0;
  rep(i, N) {
    cin >> A[i];
    maxv = max(maxv, A[i]);
  }
  rep(i, N) {
    if (A[i] == K) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  if (K > maxv)
    cout << "IMPOSSIBLE" << endl;
  else {
    sort(A, A + N);
    rep(i, N - 1) {
      tmp = abs(A[i] - A[i + 1]);
      if (tmp != 0) {
        if (tmp == 1 || K % tmp == 0) {
          cout << "POSSIBLE" << endl;
          return 0;
        }
      }
    }
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}
Problem p03651 (C++)

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

using namespace std;

int gcd(int n, int m) {
  if (n < m)
    swap(n, m);
  while (m != 0) {
    int tmp = m;
    m = n % m;
    n = tmp;
  }
  return n;
}

int main() {
  int N, K;
  int A_max = 0;
  int A[100000];
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A_max = max(A_max, A[i]);
  }
  int m = A[0];
  for (int i = 1; i < K; i++) {
    m = gcd(m, A[i]);
  }
  if (K % m == 0 && K <= A_max)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <iostream>

using namespace std;

int gcd(int n, int m) {
  if (n < m)
    swap(n, m);
  while (m != 0) {
    int tmp = m;
    m = n % m;
    n = tmp;
  }
  return n;
}

int main() {
  int N, K;
  int A_max = 0;
  int A[100000];
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A_max = max(A_max, A[i]);
  }
  int m = A[0];
  for (int i = 1; i < N; i++) {
    m = gcd(m, A[i]);
  }
  if (K % m == 0 && K <= A_max)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  bool ans = false;
  rep(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());
  int g = gcd(a.at(0), a.at(1));
  rep(i, n - 2) { g = gcd(g, a.at(i + 2)); }
  if (k % g == 0 && k <= a.at(n - 1))
    ans = true;
  if (ans)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  bool ans = false;
  rep(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());
  if (n == 1) {
    if (a.at(0) == k)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  int g = gcd(a.at(1), a.at(0));
  rep(i, n - 2) { g = gcd(a.at(i + 2), g); }
  if (k % g == 0 && k <= a.at(n - 1))
    ans = true;
  if (ans)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
#define rep_r(i, s, n) for (ll i = n - 1; i >= s; i--)
#define repe_r(i, s, n) for (ll i = s; i <= n; i++)

ll a[100001] = {};
ll s[100001] = {};
int main() {
  ll n, k;
  cin >> n >> k;
  ll maxV = 0;
  repe(i, 1, n) {
    cin >> a[i];
    if (a[i] == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    maxV = max(maxV, a[i]);
  }
  if (maxV < k || n == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(a + 1, a + 1 + n);
  repe(i, 1, n) {
    s[i] = a[i] - a[i - 1];
    if (s[i] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    } else if (k % s[i] == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
#define rep_r(i, s, n) for (ll i = n - 1; i >= s; i--)
#define repe_r(i, s, n) for (ll i = s; i <= n; i++)

ll a[100001] = {};
ll s[100001] = {};
int main() {
  ll n, k;
  cin >> n >> k;
  ll maxV = 0;
  repe(i, 1, n) {
    cin >> a[i];
    if (a[i] == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    maxV = max(maxV, a[i]);
  }
  if (maxV < k || n == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  sort(a + 1, a + 1 + n);
  repe(i, 1, n) {
    s[i] = a[i] - a[i - 1];
    if (s[i] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    } else if (s[i] != 0 && k % s[i] == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll gcdd = gcd(a[0], a[1]);
  for (int i = 2; i < n; i++) {
    gcdd = gcd(gcdd, a[i]);
  }
  sort(rall(a));
  if (k <= a[0] && k % gcdd == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll gcdd = a[0];
  for (int i = 1; i < n; i++) {
    gcdd = gcd(gcdd, a[i]);
  }
  sort(rall(a));
  if (k <= a[0] && k % gcdd == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

/*================================================
        GCD function
================================================*/
int gcd(int a, int b) {
  if (a < b)
    return gcd(b, a);
  int r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int A[100000];

int main() {
  int N, K, g;
  bool ans = false;

  cin >> N >> K;
  rep(i, N) cin >> A[i];

  sort(A, A + N);

  if (A[N - 1] < K)
    ans = false;
  else {
    rep(i, N - 1) {
      if (i == 0)
        g = gcd(A[i], A[i + 1]);
      else
        g = gcd(g, A[i + 1]);
    }

    if ((A[N - 1] - K) % g == 0)
      ans = true;
    else
      ans = false;
  }

  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

/*================================================
        GCD function
================================================*/
int gcd(int a, int b) {
  if (a < b)
    return gcd(b, a);
  int r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int A[100000];

int main() {
  int N, K, g;
  bool ans = false;

  cin >> N >> K;
  rep(i, N) cin >> A[i];

  sort(A, A + N);

  if (N == 1) {
    if (A[0] == K)
      ans = true;
    else
      ans = false;
  } else if (A[N - 1] < K)
    ans = false;
  else {
    rep(i, N - 1) {
      if (i == 0)
        g = gcd(A[i], A[i + 1]);
      else
        g = gcd(g, A[i + 1]);
    }

    if ((A[N - 1] - K) % g == 0)
      ans = true;
    else
      ans = false;
  }

  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define pb push_back
#define DEBUG false

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e9 + 7, INF = 1 << 30;
const double EPS = 1e-12, PI = 3.1415926535897932384626;
const ll LINF = 1LL << 60;
const int MAX_N = 100005;

ll a[MAX_N];

int main() {
  ll N, K, mindif = LINF;
  cin >> N >> K;
  rep(i, N) scanf("%lld", &a[i]);
  sort(a, a + N);
  if (N == 1) {
    if (a[0] == K)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  rep(i, N - 1) mindif = min(mindif, a[i + 1] - a[i]);
  rep(i, N) {
    if (a[i] >= K && (a[i] - K) % mindif == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define pb push_back
#define DEBUG false

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e9 + 7, INF = 1 << 30;
const double EPS = 1e-12, PI = 3.1415926535897932384626;
const ll LINF = 1LL << 60;
const int MAX_N = 100005;

ll a[MAX_N];

int main() {
  ll N, K, mindif = LINF;
  cin >> N >> K;
  rep(i, N) scanf("%lld", &a[i]);
  sort(a, a + N);
  if (N == 1) {
    if (a[0] == K)
      cout << "POSSIBLE" << endl;
    else
      cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  rep(i, N - 1) if (a[i + 1] - a[i] != 0) mindif = min(mindif, a[i + 1] - a[i]);
  rep(i, N) {
    if (a[i] >= K && (a[i] - K) % mindif == 0) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int gcd(int m, int n) {
  if ((0 == m) || (0 == n))
    return 1;
  while (m != n) {
    if (m > n)
      m = m - n;
    else
      n = n - m;
  }
  return m;
}

int main() {
  int n, k, in, saidaikouyakusu;
  cin >> n >> k;
  bool s = false;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> in;
    v.push_back(in);
    if (in >= k)
      s = true;
  }
  saidaikouyakusu = v[0];
  for (int i = 1; i < n; i++) {
    saidaikouyakusu = gcd(saidaikouyakusu, v[i]);
  }
  if (!s || k % saidaikouyakusu)
    cout << "IM";
  cout << "POSSIBLE";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  int n, k, in, saidaikouyakusu;
  cin >> n >> k;
  bool s = false;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> in;
    v.push_back(in);
    if (in >= k)
      s = true;
  }
  saidaikouyakusu = v[0];
  for (int i = 1; i < n; i++) {
    saidaikouyakusu = gcd(saidaikouyakusu, v[i]);
  }
  if (!s || k % saidaikouyakusu)
    cout << "IM";
  cout << "POSSIBLE";
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

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


Fixed submission:
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  if (a[n - 1] < k) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  ll gcd_num = a[0];
  for (int i = 1; i < n; ++i) {
    gcd_num = gcd(a[i], gcd_num);
  }
  if (k % gcd_num == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, x) for (ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max() / 4;
const ll MOD = 1e9 + 7;
const int n_max = 1e5 + 10;

template <class T, class U> ll euclid_gcd(T a, U b) {
  if (a < b)
    return euclid_gcd(b, a);
  if (a == 0 || b == 0)
    return 1;
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a;
  ll ma = 0;
  rep(i, n) {
    cin >> a[i];
    chmax(ma, a[i]);
  }

  ll g = euclid_gcd(a[0], a[1]);
  for (int i = 2; i < n; i++) {
    g = euclid_gcd(g, a[i]);
    if (g == 1)
      break;
  }

  cout << ((k % g == 0) && (k <= ma) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, x) for (ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max() / 4;
const ll MOD = 1e9 + 7;
const int n_max = 1e5 + 10;

template <class T, class U> ll euclid_gcd(T a, U b) {
  if (a < b)
    return euclid_gcd(b, a);
  if (a == 0 || b == 0)
    return 1;
  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  ll ma = 0;
  rep(i, n) {
    cin >> a[i];
    chmax(ma, a[i]);
  }

  ll g = euclid_gcd(a[0], a[1]);
  for (int i = 2; i < n; i++) {
    g = euclid_gcd(g, a[i]);
    if (g == 1)
      break;
  }

  cout << ((k % g == 0) && (k <= ma) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
const int MaxN = 1e5;
using namespace std;
int a[MaxN + 5];
int n, k;
int main() {
  while (~scanf("%d%d", &n, &k)) {
    int Min = 1 << 30;
    bool ok = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a + 1, a + n + 1);
    for (int i = 2; i <= n; i++) {
      Min = min(Min, abs(a[i] - a[i - 1]));
    }
    for (int i = 1; i <= n; i++) {
      if (abs(a[i] - k) % Min == 0)
        ok = 1;
    }
    if (k > a[n])
      ok = 0;
    if (ok)
      printf("POSSIBLE\n");
    else
      printf("IMPOSSIBLE\n");
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
const int MaxN = 1e5;
using namespace std;
int a[MaxN + 5];
int n, k;
int main() {
  while (~scanf("%d%d", &n, &k)) {
    int Min = 1 << 30;
    bool ok = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    sort(a + 1, a + n + 1);
    for (int i = 2; i <= n; i++) {
      if (a[i] - a[i - 1] != 0)
        Min = min(Min, abs(a[i] - a[i - 1]));
    }
    for (int i = 1; i <= n; i++) {
      if (abs(a[i] - k) % Min == 0)
        ok = 1;
    }
    if (k > a[n])
      ok = 0;
    if (ok)
      printf("POSSIBLE\n");
    else
      printf("IMPOSSIBLE\n");
  }
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define max0(a, b, c) max(max(a, b), c)
#define min0(a, b, c) min(min(a, b), c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int, int>> pvec;
typedef vector<pair<ll, ll>> plvec;
typedef vector<tuple<ll, ll, ll>> tvec;
typedef vector<string> svec;

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

int main() {
  ll n, k;
  cin >> n >> k;
  lvec a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  bool ok = false;
  if (a[0] == 1)
    ok = true;
  for (int i = 0; i < k; i++) {
    if (a[i] == k)
      ok = true;
  }
  if (!ok && k <= a[n - 1]) {
    ll s = gcd(a[0], a[1]);
    if (n > 3) {
      for (int i = 2; i < n; i++) {
        s = gcd(s, a[i]);
      }
    }
    if (k % s == 0)
      ok = true;
  }
  if (ok)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define max0(a, b, c) max(max(a, b), c)
#define min0(a, b, c) min(min(a, b), c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int, int>> pvec;
typedef vector<pair<ll, ll>> plvec;
typedef vector<tuple<ll, ll, ll>> tvec;
typedef vector<string> svec;

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

int main() {
  ll n, k;
  cin >> n >> k;
  lvec a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  bool ok = false;
  if (a[0] == 1)
    ok = true;
  for (int i = 0; i < n; i++) {
    if (a[i] == k)
      ok = true;
  }
  if (!ok && k <= a[n - 1]) {
    ll s = gcd(a[0], a[1]);
    if (n > 3) {
      for (int i = 2; i < n; i++) {
        s = gcd(s, a[i]);
      }
    }
    if (k % s == 0)
      ok = true;
  }
  if (ok)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <sstream>
#include <stdio.h>
// #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctype.h>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

typedef long long int lli;
#define rep(i, s, N) for (int i = s; i < N; i++)
#define MOD 1000000007
#define more(a, b) (((a) > (b)) ? (a) : (b))
#define less(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
lli GCD(lli a, lli b) {
  lli x = more(a, b);
  lli y = less(a, b);
  lli r = x % y;
  while (r > 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}

int main(void) {
  lli N, K;
  cin >> N >> K;
  vector<lli> A(N);
  lli max = 0;
  rep(i, 0, N) {
    lli tmp;
    cin >> tmp;
    max = more(max, tmp);
    A[i] = tmp;
  }
  lli gcd = GCD(A[0], A[1]);
  rep(i, 2, N) gcd = GCD(gcd, A[i]);

  if (K <= max && K % gcd == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <sstream>
#include <stdio.h>
// #define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctype.h>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

typedef long long int lli;
#define rep(i, s, N) for (int i = s; i < N; i++)
#define MOD 1000000007
#define more(a, b) (((a) > (b)) ? (a) : (b))
#define less(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
lli GCD(lli a, lli b) {
  lli x = more(a, b);
  lli y = less(a, b);
  lli r = x % y;
  while (r > 0) {
    x = y;
    y = r;
    r = x % y;
  }

  return y;
}

int main(void) {
  lli N, K;
  cin >> N >> K;
  vector<lli> A(N);
  lli max = 0;
  rep(i, 0, N) {
    lli tmp;
    cin >> tmp;
    max = more(max, tmp);
    A[i] = tmp;
  }
  lli gcd = A[0];
  if (N >= 2)
    rep(i, 1, N) gcd = GCD(gcd, A[i]);

  if (K <= max && K % gcd == 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;

#define MAXN 110
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps (1e-6)
typedef long long LL;

int n, k, a[MAXN];

int GCD(int a, int b) {
  for (int t; b; t = a % b, a = b, b = t)
    ;
  return a;
}

int main() {
  int i, j;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  for (i = 2, j = a[1]; i <= n; ++i) {
    j = GCD(j, a[i]);
  }
  for (i = 1; i <= n; ++i) {
    if (k > a[i])
      continue;
    if ((a[i] - k) % j == 0) {
      printf("POSSIBLE\n");
      return 0;
    }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}


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

using namespace std;

#define MAXN 100010
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps (1e-6)
typedef long long LL;

int n, k, a[MAXN];

int GCD(int a, int b) {
  for (int t; b; t = a % b, a = b, b = t)
    ;
  return a;
}

int main() {
  int i, j;
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  for (i = 2, j = a[1]; i <= n; ++i) {
    j = GCD(j, a[i]);
  }
  for (i = 1; i <= n; ++i) {
    if (k > a[i])
      continue;
    if ((a[i] - k) % j == 0) {
      printf("POSSIBLE\n");
      return 0;
    }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}
Problem p03651 (C++)

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

#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
template <typename T> bool chmax(T &a, const T &b) {
  return a < b ? (a = b, true) : false;
}
template <typename T> bool chmin(T &a, const T &b) {
  return b < a ? (a = b, true) : false;
}
typedef long long ll;

int N, K;
vector<int> A;

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

int main() {
  scanf("%d%d", &N, &K);
  A.assign(N, 0);
  FOR(i, 0, N) { scanf("%d", &A[i]); }
  sort(A.begin(), A.end());

  if (N == 1) {
    puts(A[0] == K ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
  }

  int g = A[1] - A[0];
  FOR(i, 2, N) { g = gcd(A[i] - A[i - 1], g); }

  bool ans = A.front() <= K && K <= A.back() && (K - A.front()) % g == 0;
  puts(ans ? "POSSIBLE" : "IMPOSSIBLE");

  return 0;
}


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

#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
template <typename T> bool chmax(T &a, const T &b) {
  return a < b ? (a = b, true) : false;
}
template <typename T> bool chmin(T &a, const T &b) {
  return b < a ? (a = b, true) : false;
}
typedef long long ll;

int N, K;
vector<int> A;

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

int main() {
  scanf("%d%d", &N, &K);
  A.assign(N, 0);
  FOR(i, 0, N) { scanf("%d", &A[i]); }
  sort(A.begin(), A.end());

  if (N == 1 || A.front() == A.back()) {
    puts(A[0] == K ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
  }

  int g = A[1] - A[0];
  FOR(i, 2, N) { g = gcd(A[i] - A[i - 1], g); }

  bool ans = A.front() <= K && K <= A.back() && (K - A.front()) % g == 0;
  puts(ans ? "POSSIBLE" : "IMPOSSIBLE");

  return 0;
}
Problem p03651 (C++)

Buggy submission (status: Runtime Error):
// Getting Difference

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i, x, y) for (ll i = x; i < y; i++)
#define irep(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n, a)                                                           \
  ll n;                                                                        \
  cin >> n;                                                                    \
  vector<ll> a(n);                                                             \
  rep(i, 0, n) cin >> a[i]
#define vecrep(n, a, type)                                                     \
  vector<type> a(n);                                                           \
  rep(i, 0, n) cin >> a[i]
#define lcm(a, b) (a / __gcd(a, b) * b)
#define range(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;         // 2*10^9
const ll INF = 9223372036854775807; // 9*10^18

signed main() {
  int n, k;
  cin >> n >> k;
  vecrep(n, a, int);
  if (*max_element(range(a)) < k) {
    cout << "IMPOSSIBLE" << nnn;
    return 0;
  }
  int c = inf;
  sort(range(a), greater<int>());
  rep(i, 0, n - 1) { c = min(c, a[i] - a[i + 1]); }
  rep(i, 0, n) {
    if (abs(k - a[i]) % c == 0 || k == a[i]) {
      cout << "POSSIBLE" << nnn;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << nnn;
  return 0;
}

Fixed submission:
// Getting Difference

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i, x, y) for (ll i = x; i < y; i++)
#define irep(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n, a)                                                           \
  ll n;                                                                        \
  cin >> n;                                                                    \
  vector<ll> a(n);                                                             \
  rep(i, 0, n) cin >> a[i]
#define vecrep(n, a, type)                                                     \
  vector<type> a(n);                                                           \
  rep(i, 0, n) cin >> a[i]
#define lcm(a, b) (a / __gcd(a, b) * b)
#define range(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;         // 2*10^9
const ll INF = 9223372036854775807; // 9*10^18

signed main() {
  int n, k;
  cin >> n >> k;
  vecrep(n, a, int);
  if (*max_element(range(a)) < k) {
    cout << "IMPOSSIBLE" << nnn;
    return 0;
  }
  int c = inf;
  sort(range(a), greater<int>());
  rep(i, 0, n - 1) {
    if (a[i] == a[i + 1])
      continue;
    c = min(c, a[i] - a[i + 1]);
  }
  rep(i, 0, n) {
    if (abs(k - a[i]) % c == 0 || k == a[i]) {
      cout << "POSSIBLE" << nnn;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << nnn;
  return 0;
}