Problem p02574 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

// bit op
int popcnt(unsigned int x) { return __builtin_popcount(x); }
int popcnt(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned int x) { return 31 - __builtin_clz(x); }
int bsr(unsigned long long x) { return 63 - __builtin_clzll(x); }
int bsf(unsigned int x) { return __builtin_ctz(x); }
int bsf(unsigned long long x) { return __builtin_ctzll(x); }

// binary gcd
long long gcd(long long _a, long long _b) {
  unsigned long long a = abs(_a), b = abs(_b);
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  int shift = bsf(a | b);
  a >>= bsf(a);
  do {
    b >>= bsf(b);
    if (a > b)
      swap(a, b);
    b -= a;
  } while (b);
  return (a << shift);
}

template <class T, class U> T pow_mod(T x, U n, T md) {
  T r = 1 % md;
  x %= md;
  while (n) {
    if (n & 1)
      r = (r * x) % md;
    x = (x * x) % md;
    n >>= 1;
  }
  return r;
}

bool is_prime(long long n) {
  if (n <= 1)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  long long d = n - 1;
  while (d % 2 == 0)
    d /= 2;
  for (long long a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) {
    if (n <= a)
      break;
    long long t = d;
    long long y = pow_mod<__int128_t>(a, t, n); // over
    while (t != n - 1 && y != 1 && y != n - 1) {
      y = __int128_t(y) * y % n; // flow
      t <<= 1;
    }
    if (y != n - 1 && t % 2 == 0) {
      return false;
    }
  }
  return true;
}

long long pollard_single(long long n) {
  auto f = [&](long long x) { return (__int128_t(x) * x + 1) % n; };
  if (is_prime(n))
    return n;
  if (n % 2 == 0)
    return 2;
  long long st = 0;
  while (true) {
    st++;
    long long x = st, y = f(x);
    while (true) {
      long long p = gcd((y - x + n), n);
      if (p == 0 || p == n)
        break;
      if (p != 1)
        return p;
      x = f(x);
      y = f(f(y));
    }
  }
}

vector<long long> pollard(long long n) {
  if (n == 1)
    return {};
  long long x = pollard_single(n);
  if (x == n)
    return {x};
  vector<long long> le = pollard(x);
  vector<long long> ri = pollard(n / x);
  le.insert(le.end(), ri.begin(), ri.end());
  return le;
}

/*	author:  Kite_kuma
        created: 2020.09.06 12:15:47 */

#pragma region aliases

#define rep(i, n) for (long long i = 0; i < (n); i++)
#define rrep(i, n) for (long long i = (n)-1; i > -1; i--)
#define Rep(i, m, n) for (long long i = (m); i < (n); i++)
#define rRep(i, m, n) for (long long i = (n)-1; i >= (m); i--)
#define REP(i, m, n, p) for (long long i = m; i < n; i += p)
#define foa(s, v) for (auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bcnt(n) __builtin_popcountll(n)
#define endk endl
#define ednl endl
#define enld endl

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using qll = queue<long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
template <class T = ll> using VVV = V<V<V<T>>>;
// 昇順pq(小さい方から取り出す)
template <class T = ll> using pqup = priority_queue<T, vector<T>, greater<T>>;
// 降順pq(大きい方から取り出す)
template <class T = ll> using pqdn = priority_queue<T>;

#pragma endregion

#pragma region constants

long long const limLL = 9223372036854775807; // POW(2,63)-1 ~ 9.22e18
long long const dekai = 3e16;
const long double pi = acos(-1);
const char el = '\\n';
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

const int mod = 1000000007;
// const int mod = 998244353;

#pragma endregion

#pragma region basic_procedure

template <class T> inline bool isin(T x, T lef, T rig) {
  return ((lef <= x) && (x < rig));
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void Yes(bool f = 1) { cout << (f ? "Yes" : "No") << "\\n"; }
void No() { cout << "No\\n"; }
void YES(bool f = 1) { cout << (f ? "YES" : "NO") << "\\n"; }
void NO() { cout << "NO\\n"; }
template <class T> void drop(T answer) {
  cout << answer << "\\n";
  exit(0);
}
void err() {
  cout << -1 << "\\n";
  exit(0);
}

vector<long long>
vin(long long n) { // 整数n個の入力を受け取ってベクトルに突っ込んで返す
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  return v;
}

// ベクトルの出力(検証済)
//  vectorの中身を出力する 答えの出力に利用可能
template <class T> void vout(vector<T> &v, bool tate = 0) {
  if (v.size() > 0) {
    for (auto it = v.begin(); it < v.end(); it++) {
      cout << *it;
      if (it != v.end() - 1) {
        if (tate)
          cout << endl;
        else
          cout << " ";
      }
    }
  }
  cout << endl;
}

template <class T> void add(vector<T> &v, T val) { // ベクトルの各要素に加算
  for (auto &a : v)
    a += val;
  return;
}

// vectorの中身を数える map<要素,個数>を返す
template <class T> map<T, long long> cntv(vector<T> v) {
  map<T, long long> m;
  for (auto &g : v) {
    if (m.count(g))
      m[g]++;
    else
      m[g] = 1;
  }
  return m;
}

// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1,  0}にする
template <class T> vector<long long> press(vector<T> &v) {
  long long n = v.size();
  vector<long long> w(n);
  map<T, long long> m;
  for (T &p : v)
    m[p] = 0;
  long long i = 0;
  for (auto &p : m) {
    p.second = i;
    i++;
  }
  for (long long i = 0; i < n; i++)
    w.at(i) = m[v.at(i)];
  return w;
}

template <class T> T divup(T a, T b) {
  // 端数繰りあがり割り算
  assert(b != 0);
  T x = abs(a);
  T y = abs(b);
  T z = (x + y - 1) / y;
  if ((a < 0 && b > 0) || (a > 0 && b < 0))
    return -z;
  else if (a == 0)
    return 0;
  else
    return z;
}

long long POW(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a;
    a = a * a;
    n >>= 1;
  }
  return res;
}

template <class T> int sgn(T x) { // 符号関数
  if (x < 0)
    return -1;
  if (x == 0)
    return 0;
  return 1;
}

long long modpow(long long a, long long n, long long mod) { // a^n mod
  if (mod == 1)
    return 0LL;
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a * x % mod == __gcd(a,mod)なるxを返す
// a が modの倍数でないことが条件
long long modinv(long long a, long long mod) {
  long long b = mod, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

vvll comb(100, vll(100, -1));
long long com(long long n, long long k) { // 普通の二項計数(overflowに注意)
  assert(n < 100 && k < 100);
  if (n < k || k < 0 || n < 0)
    return 0;
  if (comb[n][k] != -1)
    return comb[n][k];
  ll res;
  if (n - k < k)
    res = com(n, n - k);
  else if (k == 0)
    res = 1;
  else
    res = com(n - 1, k - 1) + com(n - 1, k);
  comb[n][k] = res;
  return res;
}

// nCk modを求める
const ll MAX = 5100000;
// この値は求める二項計数の値に応じて変える
// MAX=3*10^7のとき1900msほど、ほぼ比例
// MAX=5*10^6程度ならそれほど気にしなくてよい(300ms程)
long long fac[MAX], finv[MAX], inv[MAX];

void cominit() {
  // テーブルを作る前処理
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
long long commod(ll n, ll k) { // 二項係数計算
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
long long pmod(ll n, ll k) { // 順列計算
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * finv[n - k] % mod;
}
long long hmod(ll n, ll k) { // nHk計算
  // n個の区別しないoを区別するk個の箱に入れる方法の総数
  //(n+k-1)C(k-1)と等しい
  return commod(n + k - 1, n);
}
#pragma endregion

#pragma region input
#define VEC(type, name, size)                                                  \\
  vector<type> name(size);                                                     \\
  IN(name)
#define VVEC(type, name, h, w)                                                 \\
  vector<vector<type>> name(h, vector<type>(w));                               \\
  IN(name)
#define INT(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  IN(__VA_ARGS__)
#define LL(...)                                                                \\
  long long __VA_ARGS__;                                                       \\
  IN(__VA_ARGS__)
#define STR(...)                                                               \\
  string __VA_ARGS__;                                                          \\
  IN(__VA_ARGS__)
#define CHAR(...)                                                              \\
  char __VA_ARGS__;                                                            \\
  IN(__VA_ARGS__)
#define DOUBLE(...)                                                            \\
  double __VA_ARGS__;                                                          \\
  IN(__VA_ARGS__)
#define LD(...)                                                                \\
  long double __VA_ARGS__;                                                     \\
  IN(__VA_ARGS__)

template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) {
  for (auto &i : a)
    scan(i);
}
template <class T, class L> void scan(pair<T, L> &p) {
  scan(p.first);
  scan(p.second);
}
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {
  scan(head);
  IN(tail...);
}
template <class T> inline void print(T x) { cout << x << '\\n'; }

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
#pragma endregion

#pragma region debug

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  rep(i, v.size()) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}

template <typename T> void view(const std::vector<T> &v) {
  std::cerr << "{ ";
  for (const auto &e : v) {
    std::cerr << e << ", ";
  }
  std::cerr << "\\b\\b }";
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
  std::cerr << "{\\n";
  for (const auto &v : vv) {
    std::cerr << "\\t";
    view(v);
    cerr << "\\n";
  }
  std::cerr << "}";
}
template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
  std::cerr << "{\\n";
  for (const auto &c : v) {
    std::cerr << "\\t(" << c.first << ", " << c.second << ")\\n";
  }
  std::cerr << "}";
}
template <typename T, typename U> void view(const std::map<T, U> &m) {
  std::cerr << "{\\n";
  for (auto &t : m) {
    std::cerr << "\\t[" << t.first << "] : " << t.second << "\\n";
  }
  std::cerr << "}";
}
template <typename T, typename U> void view(const std::pair<T, U> &p) {
  std::cerr << "(" << p.first << ", " << p.second << ")";
}
template <typename T> void view(const std::set<T> &s) {
  std::cerr << "{ ";
  for (auto &t : s) {
    view(t);
    std::cerr << ", ";
  }
  std::cerr << "\\b\\b }";
}
template <typename T> void view(T e) { std::cerr << e; }

// when debugging : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  view(H);
  cerr << ", ";
  debug_out(T...);
}
#define debug(...)                                                             \\
  do {                                                                         \\
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : [";                       \\
    debug_out(__VA_ARGS__);                                                    \\
    cerr << "\\b\\b]\\n";                                                         \\
  } while (0)
#define dump(x)                                                                \\
  do {                                                                         \\
    cerr << __LINE__ << " " << #x << " : ";                                    \\
    view(x);                                                                   \\
    cerr << "\\n";                                                              \\
  } while (0)
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

#pragma endregion

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  // int h = 1000001;

  // Fast_Factorization ff(h);

  // rep(i, h) {
  // 	if(i == 0) continue;
  // 	auto m = ff.facmap(i);
  // 	auto mm = soinsuu(i);
  // 	if(i % 163807 == 238) {
  // 		auto v = ff.factor(i);
  // 		debug(i);
  // 		debug(v);
  // 	}
  // 	if(m != mm) {
  // 		cout << "error" << endl;
  // 		exit(0);
  // 	}
  // }
  INT(n);
  VEC(int, a, n);
  int h = POW(10, 6) + 1;

  int f = 1;
  int g = 0;
  rep(i, n) { g = __gcd(g, a[i]); }
  if (g > 1) {
    cout << "not coprime" << endl;
    exit(0);
  }

  set<int> se;

  rep(i, n) {
    vll m;
    if (a[i] < 1000) {
      ll k = a[i];
      Rep(i, 2, k) {
        if (k % i == 0) {
          m.push_back(i);
          while (k % i == 0) {
            k /= i;
          }
        }
      }
      if (k > 1) {
        m.push_back(k);
      }
      // m = pollard(a[i]);
    } else {
      m = pollard(a[i]);
    }
    // debug(m);
    // debug(m);
    sort(all(m));
    m.erase(unique(all(m)), m.end());
    foa(t, m) {
      // debug(t);
      if (se.count(t)) {
        cout << "setwise coprime" << endl;
        return 0;
      }
      se.insert(t);
    }
  }
  cout << "pairwise coprime" << endl;

  // debug(s);
  // debug(s);
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

// bit op
int popcnt(unsigned int x) { return __builtin_popcount(x); }
int popcnt(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned int x) { return 31 - __builtin_clz(x); }
int bsr(unsigned long long x) { return 63 - __builtin_clzll(x); }
int bsf(unsigned int x) { return __builtin_ctz(x); }
int bsf(unsigned long long x) { return __builtin_ctzll(x); }

// binary gcd
long long gcd(long long _a, long long _b) {
  unsigned long long a = abs(_a), b = abs(_b);
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  int shift = bsf(a | b);
  a >>= bsf(a);
  do {
    b >>= bsf(b);
    if (a > b)
      swap(a, b);
    b -= a;
  } while (b);
  return (a << shift);
}

template <class T, class U> T pow_mod(T x, U n, T md) {
  T r = 1 % md;
  x %= md;
  while (n) {
    if (n & 1)
      r = (r * x) % md;
    x = (x * x) % md;
    n >>= 1;
  }
  return r;
}

bool is_prime(long long n) {
  if (n <= 1)
    return false;
  if (n == 2)
    return true;
  if (n % 2 == 0)
    return false;
  long long d = n - 1;
  while (d % 2 == 0)
    d /= 2;
  for (long long a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) {
    if (n <= a)
      break;
    long long t = d;
    long long y = pow_mod<__int128_t>(a, t, n); // over
    while (t != n - 1 && y != 1 && y != n - 1) {
      y = __int128_t(y) * y % n; // flow
      t <<= 1;
    }
    if (y != n - 1 && t % 2 == 0) {
      return false;
    }
  }
  return true;
}

long long pollard_single(long long n) {
  auto f = [&](long long x) { return (__int128_t(x) * x + 1) % n; };
  if (is_prime(n))
    return n;
  if (n % 2 == 0)
    return 2;
  long long st = 0;
  while (true) {
    st++;
    long long x = st, y = f(x);
    while (true) {
      long long p = gcd((y - x + n), n);
      if (p == 0 || p == n)
        break;
      if (p != 1)
        return p;
      x = f(x);
      y = f(f(y));
    }
  }
}

vector<long long> pollard(long long n) {
  if (n == 1)
    return {};
  long long x = pollard_single(n);
  if (x == n)
    return {x};
  vector<long long> le = pollard(x);
  vector<long long> ri = pollard(n / x);
  le.insert(le.end(), ri.begin(), ri.end());
  return le;
}

/*	author:  Kite_kuma
        created: 2020.09.06 12:15:47 */

#pragma region aliases

#define rep(i, n) for (long long i = 0; i < (n); i++)
#define rrep(i, n) for (long long i = (n)-1; i > -1; i--)
#define Rep(i, m, n) for (long long i = (m); i < (n); i++)
#define rRep(i, m, n) for (long long i = (n)-1; i >= (m); i--)
#define REP(i, m, n, p) for (long long i = m; i < n; i += p)
#define foa(s, v) for (auto &s : v)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define bcnt(n) __builtin_popcountll(n)
#define endk endl
#define ednl endl
#define enld endl

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using qll = queue<long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
template <class T = ll> using VVV = V<V<V<T>>>;
// 昇順pq(小さい方から取り出す)
template <class T = ll> using pqup = priority_queue<T, vector<T>, greater<T>>;
// 降順pq(大きい方から取り出す)
template <class T = ll> using pqdn = priority_queue<T>;

#pragma endregion

#pragma region constants

long long const limLL = 9223372036854775807; // POW(2,63)-1 ~ 9.22e18
long long const dekai = 3e16;
const long double pi = acos(-1);
const char el = '\\n';
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

const int mod = 1000000007;
// const int mod = 998244353;

#pragma endregion

#pragma region basic_procedure

template <class T> inline bool isin(T x, T lef, T rig) {
  return ((lef <= x) && (x < rig));
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void Yes(bool f = 1) { cout << (f ? "Yes" : "No") << "\\n"; }
void No() { cout << "No\\n"; }
void YES(bool f = 1) { cout << (f ? "YES" : "NO") << "\\n"; }
void NO() { cout << "NO\\n"; }
template <class T> void drop(T answer) {
  cout << answer << "\\n";
  exit(0);
}
void err() {
  cout << -1 << "\\n";
  exit(0);
}

vector<long long>
vin(long long n) { // 整数n個の入力を受け取ってベクトルに突っ込んで返す
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  return v;
}

// ベクトルの出力(検証済)
//  vectorの中身を出力する 答えの出力に利用可能
template <class T> void vout(vector<T> &v, bool tate = 0) {
  if (v.size() > 0) {
    for (auto it = v.begin(); it < v.end(); it++) {
      cout << *it;
      if (it != v.end() - 1) {
        if (tate)
          cout << endl;
        else
          cout << " ";
      }
    }
  }
  cout << endl;
}

template <class T> void add(vector<T> &v, T val) { // ベクトルの各要素に加算
  for (auto &a : v)
    a += val;
  return;
}

// vectorの中身を数える map<要素,個数>を返す
template <class T> map<T, long long> cntv(vector<T> v) {
  map<T, long long> m;
  for (auto &g : v) {
    if (m.count(g))
      m[g]++;
    else
      m[g] = 1;
  }
  return m;
}

// 配列圧縮(検証済)
//{1,36,1,3,8,-2,-92}を
//{2, 5,2,3,4, 1,  0}にする
template <class T> vector<long long> press(vector<T> &v) {
  long long n = v.size();
  vector<long long> w(n);
  map<T, long long> m;
  for (T &p : v)
    m[p] = 0;
  long long i = 0;
  for (auto &p : m) {
    p.second = i;
    i++;
  }
  for (long long i = 0; i < n; i++)
    w.at(i) = m[v.at(i)];
  return w;
}

template <class T> T divup(T a, T b) {
  // 端数繰りあがり割り算
  assert(b != 0);
  T x = abs(a);
  T y = abs(b);
  T z = (x + y - 1) / y;
  if ((a < 0 && b > 0) || (a > 0 && b < 0))
    return -z;
  else if (a == 0)
    return 0;
  else
    return z;
}

long long POW(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a;
    a = a * a;
    n >>= 1;
  }
  return res;
}

template <class T> int sgn(T x) { // 符号関数
  if (x < 0)
    return -1;
  if (x == 0)
    return 0;
  return 1;
}

long long modpow(long long a, long long n, long long mod) { // a^n mod
  if (mod == 1)
    return 0LL;
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a * x % mod == __gcd(a,mod)なるxを返す
// a が modの倍数でないことが条件
long long modinv(long long a, long long mod) {
  long long b = mod, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

vvll comb(100, vll(100, -1));
long long com(long long n, long long k) { // 普通の二項計数(overflowに注意)
  assert(n < 100 && k < 100);
  if (n < k || k < 0 || n < 0)
    return 0;
  if (comb[n][k] != -1)
    return comb[n][k];
  ll res;
  if (n - k < k)
    res = com(n, n - k);
  else if (k == 0)
    res = 1;
  else
    res = com(n - 1, k - 1) + com(n - 1, k);
  comb[n][k] = res;
  return res;
}

// nCk modを求める
const ll MAX = 5100000;
// この値は求める二項計数の値に応じて変える
// MAX=3*10^7のとき1900msほど、ほぼ比例
// MAX=5*10^6程度ならそれほど気にしなくてよい(300ms程)
long long fac[MAX], finv[MAX], inv[MAX];

void cominit() {
  // テーブルを作る前処理
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
long long commod(ll n, ll k) { // 二項係数計算
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
long long pmod(ll n, ll k) { // 順列計算
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * finv[n - k] % mod;
}
long long hmod(ll n, ll k) { // nHk計算
  // n個の区別しないoを区別するk個の箱に入れる方法の総数
  //(n+k-1)C(k-1)と等しい
  return commod(n + k - 1, n);
}
#pragma endregion

#pragma region input
#define VEC(type, name, size)                                                  \\
  vector<type> name(size);                                                     \\
  IN(name)
#define VVEC(type, name, h, w)                                                 \\
  vector<vector<type>> name(h, vector<type>(w));                               \\
  IN(name)
#define INT(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  IN(__VA_ARGS__)
#define LL(...)                                                                \\
  long long __VA_ARGS__;                                                       \\
  IN(__VA_ARGS__)
#define STR(...)                                                               \\
  string __VA_ARGS__;                                                          \\
  IN(__VA_ARGS__)
#define CHAR(...)                                                              \\
  char __VA_ARGS__;                                                            \\
  IN(__VA_ARGS__)
#define DOUBLE(...)                                                            \\
  double __VA_ARGS__;                                                          \\
  IN(__VA_ARGS__)
#define LD(...)                                                                \\
  long double __VA_ARGS__;                                                     \\
  IN(__VA_ARGS__)

template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) {
  for (auto &i : a)
    scan(i);
}
template <class T, class L> void scan(pair<T, L> &p) {
  scan(p.first);
  scan(p.second);
}
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {
  scan(head);
  IN(tail...);
}
template <class T> inline void print(T x) { cout << x << '\\n'; }

template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
#pragma endregion

#pragma region debug

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  rep(i, v.size()) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}

template <typename T> void view(const std::vector<T> &v) {
  std::cerr << "{ ";
  for (const auto &e : v) {
    std::cerr << e << ", ";
  }
  std::cerr << "\\b\\b }";
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
  std::cerr << "{\\n";
  for (const auto &v : vv) {
    std::cerr << "\\t";
    view(v);
    cerr << "\\n";
  }
  std::cerr << "}";
}
template <typename T, typename U>
void view(const std::vector<std::pair<T, U>> &v) {
  std::cerr << "{\\n";
  for (const auto &c : v) {
    std::cerr << "\\t(" << c.first << ", " << c.second << ")\\n";
  }
  std::cerr << "}";
}
template <typename T, typename U> void view(const std::map<T, U> &m) {
  std::cerr << "{\\n";
  for (auto &t : m) {
    std::cerr << "\\t[" << t.first << "] : " << t.second << "\\n";
  }
  std::cerr << "}";
}
template <typename T, typename U> void view(const std::pair<T, U> &p) {
  std::cerr << "(" << p.first << ", " << p.second << ")";
}
template <typename T> void view(const std::set<T> &s) {
  std::cerr << "{ ";
  for (auto &t : s) {
    view(t);
    std::cerr << ", ";
  }
  std::cerr << "\\b\\b }";
}
template <typename T> void view(T e) { std::cerr << e; }

// when debugging : g++ foo.cpp -DLOCAL
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  view(H);
  cerr << ", ";
  debug_out(T...);
}
#define debug(...)                                                             \\
  do {                                                                         \\
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : [";                       \\
    debug_out(__VA_ARGS__);                                                    \\
    cerr << "\\b\\b]\\n";                                                         \\
  } while (0)
#define dump(x)                                                                \\
  do {                                                                         \\
    cerr << __LINE__ << " " << #x << " : ";                                    \\
    view(x);                                                                   \\
    cerr << "\\n";                                                              \\
  } while (0)
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

#pragma endregion

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

  INT(n);
  VEC(int, a, n);
  int h = POW(10, 6) + 1;

  int f = 1;
  int g = 0;
  rep(i, n) { g = __gcd(g, a[i]); }
  if (g > 1) {
    cout << "not coprime" << endl;
    exit(0);
  }

  set<int> se;

  rep(i, n) {
    vll m;
    if (a[i] < 1000) {
      ll k = a[i];
      Rep(i, 2, k) {
        if (k % i == 0) {
          m.push_back(i);
          while (k % i == 0) {
            k /= i;
          }
        }
      }
      if (k > 1) {
        m.push_back(k);
      }
    } else {
      m = pollard(a[i]);
    }
    // debug(m);
    // debug(m);
    sort(all(m));
    m.erase(unique(all(m)));
    foa(t, m) {
      // debug(t);
      if (se.count(t)) {
        cout << "setwise coprime" << endl;
        return 0;
      }
      se.insert(t);
    }
  }
  cout << "pairwise coprime" << endl;

  // debug(s);
  // debug(s);
}