Problem p03651 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef pair<string, int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, n) for (int i = 2; i < (int)(n); i++)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
// #define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> void remove(T &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

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

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

  if (maxel(A) < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  } else {
    ll gcd;
    rep(i, N - 1) {
      gcd = __gcd(A[i], A[i + 1]);
      if (gcd == 1LL)
        break;
    }

    if (gcd == 1LL) {
      cout << "POSSIBLE" << endl;
      return 0;
    } else {
      if (K % gcd == 0) {
        cout << "POSSIBLE" << endl;
        return 0;
      } else {
        cout << "IMPOSSIBLE" << endl;
        return 0;
      }
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef pair<string, int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, n) for (int i = 2; i < (int)(n); i++)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
// #define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> void remove(T &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

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

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

  if (maxel(A) < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  } else if (maxel(A) == K) {
    cout << "POSSIBLE" << endl;
    return 0;
  } else {
    ll gcd;
    rep(i, N - 1) {
      gcd = __gcd(A[i], A[i + 1]);
      if (gcd == 1LL)
        break;
    }

    if (gcd == 1LL) {
      cout << "POSSIBLE" << endl;
      return 0;
    } else {
      if (K % gcd == 0) {
        cout << "POSSIBLE" << endl;
        return 0;
      } else {
        cout << "IMPOSSIBLE" << endl;
        return 0;
      }
    }
  }
  return 0;
}