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 Rust (1.42.0) (judge verdict: Wrong Answer)

#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
           n:usize,
    mut       a:[usize;n],
       }
    let mut st = BTreeSet::new();
    for &x in a.iter() {
        st.insert(x);
    }
    let mut allgcd = gcd_list(&a);
    if st.len() != n {
        if allgcd == 1 {
            println!("{}", "setwise coprime");
        } else {
            println!("{}", "not coprime");
        }
        return;
    }
    a.sort();
    let mut st = BTreeSet::new();
    let mut all = true;
    for &x in a.iter() {
        let mut pf = prime_factor(x as i64);
        for (k, v) in pf {
            let kk = k;
            if st.contains(&k) {
                all = false;
                break;
            } else {
                st.insert(kk);
            }
        }
    }
    // let mut all = true;
    // let mut ps = prime_sieve(1010101).1;
    // for &x in a.iter() {
    //     if !ps[x] {
    //         all = false;
    //         break;
    //     }
    // }

    if all {
        println!("{}", "pairwise coprime");
    } else {
        if allgcd == 1 {
            println!("{}", "setwise coprime");
        } else {
            println!("{}", "not coprime");
        }
    }
}
fn prime_factor(mut n: i64) -> std::collections::HashMap<i64, i64> {
    let mut res: std::collections::HashMap<i64, i64> = std::collections::HashMap::new();
    let mut i = 2;
    while i * i <= n {
        while n % i == 0 {
            let v = match res.get(&i) {
                Some(v) => *v + 1,
                None => 1,
            };
            res.insert(i, v);
            n /= i;
        }
        i += 1;
    }
    if n != 1 {
        res.insert(n, 1);
    }
    res
}
pub fn prime_sieve(n: usize) -> (Vec<usize>, Vec<bool>) {
    let mut prime = Vec::new();
    let mut is_prime = Vec::with_capacity(n + 1);
    is_prime.resize(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for i in 2..n + 1 {
        if is_prime[i] {
            prime.push(i);
            {
                let mut j = 2 * i;
                while j <= n {
                    is_prime[j] = false;
                    j += i;
                }
            }
        }
    }
    (prime, is_prime)
}
pub fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
pub fn gcd_list(list: &[usize]) -> usize {
    list.iter().fold(list[0], |a, &b| gcd(a, b))
}