Problem:
Score : 500 points

Problem Statement

We have N integers. The i-th number is A_i.

\{A_i\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N.

\{A_i\} is said to be setwise coprime when \{A_i\} is not pairwise coprime but GCD(A_1,\ldots,A_N)=1.

Determine if \{A_i\} is pairwise coprime, setwise coprime, or neither.

Here, GCD(\ldots) denotes greatest common divisor.

Constraints

2 \leq N \leq 10^6

1 \leq A_i\leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 \ldots A_N

Output

If \{A_i\} is pairwise coprime, print pairwise coprime; if \{A_i\} is setwise coprime, print setwise coprime; if neither, print not coprime.

Sample Input 1

3
3 4 5

Sample Output 1

pairwise coprime

GCD(3,4)=GCD(3,5)=GCD(4,5)=1, so they are pairwise coprime.

Sample Input 2

3
6 10 15

Sample Output 2

setwise coprime

Since GCD(6,10)=2, they are not pairwise coprime. However, since GCD(6,10,15)=1, they are setwise coprime.

Sample Input 3

3
6 10 16

Sample Output 3

not coprime

GCD(6,10,16)=2, so they are neither pairwise coprime nor setwise coprime.

Solution in C++ (GCC 9.2.1) (judge verdict: Time Limit Exceeded)

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);


ll gcd(ll n, ll m){
    while(true){
        if(n<m) swap(n, m);
        if(!m) break;
        n %= m;
    }
    return n;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

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

    vector<bool> prime(1000001, true);
    prime[0] = prime[1] = false;
    rep(i, 1000001){
        if(prime[i]){
            for(ll j=i+i; j<1000001; j+=i){
                prime[j] = false;
            }
        }
    }

    bool pc = true;
    vector<bool> appeared(1000001, false);
    rep(i, N){
        if(A[i]>=2 && appeared[A[i]]){
            pc = false;
            break;
        }
        appeared[A[i]] = true;
    }
    vll B;
    rep(i, N){
        if(!prime[i]) B.push_back(A[i]);
    }
    ll M = B.size();
    REP(i, 2, 500001){
        if(!prime[i]) continue;
        bool flag = false;
        bool valid = true;
        rep(j, M){
            if(B[j]%i==0){
                if(flag){
                    valid = false;
                    break;
                }
                else flag = true;
            }
        }
        if(!valid){
            pc = false;
            break;
        }
    }

    if(pc) cout << "pairwise coprime" << endl;
    else{
        ll g = A[0];
        REP(i, 1, N) g = gcd(g, A[i]);
        if(g==1) cout << "setwise coprime" << endl;
        else cout << "not coprime" << endl;
    }
}