Buggy python submission (verdict: Time Limit Exceeded):
# ρ法でとおるかためす。

# 参考1: https://qiita.com/Kiri8128/items/eca965fe86ea5f4cbb98
# 参考2: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
# 参考3: https://ja.wikipedia.org/wiki/%E3%83%9D%E3%83%A9%E3%83%BC%E3%83%89%E3%83%BB%E3%83%AD%E3%83%BC%E7%B4%A0%E5%9B%A0%E6%95%B0%E5%88%86%E8%A7%A3%E6%B3%95


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def is_prime(n):
    "Miller Rabin primality test. 2 <= n <= 2 ** 64 is required"
    if n % 2 == 0:
        return n == 2
    d = n - 1
    r = (d & -d).bit_length() - 1
    d >>= r

    # witnesses をいい感じに決める。
    if n < 2152302898747:
        if n < 9080191:
            if n < 2047:
                witnesses = [2]
            else:
                witnesses = [31, 73]
        else:
            if n < 4759123141:
                witnesses = [2, 7, 61]
            else:
                witnesses = [2, 3, 5, 7, 11]
    else:
        if n < 341550071728321:
            if n < 3474749660383:
                witnesses = [2, 3, 5, 7, 11, 13]
            else:
                witnesses = [2, 3, 5, 7, 11, 13, 17]
        else:
            if n < 3825123056546413051:
                witnesses = [2, 3, 5, 7, 11, 13, 17, 19]
            else:
                witnesses = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
    # witnesses の決定終了

    for a in witnesses:
        x = pow(a, d, n)
        if x == 1 or x == n - 1:
            continue
        for _ in range(r - 1):
            x *= x
            x %= n
            if x == n - 1:
                break
        else:
            return False
    return True


def find_factor(n):
    "Find a non-trivial factor of n by using Pollard's rho algorithm."
    m = int(n ** 0.125) + 1
    c = 1
    while True:
        y = 1
        r = 1
        q = 1
        g = 1
        while g == 1:
            x = y
            for _ in range(r):
                y = (y * y + c) % n
            for k in range(0, r, m):
                ys = y
                for _ in range(m):
                    y = (y * y + c) % n
                    q = q * (x - y) % n
                g = gcd(q, n)
                if g != 1:
                    break
            else:  # 残りの k から r までをやる
                ys = y
                for _ in range(r-k):
                    y = (y * y + c) % n
                    q = q * (x - y) % n
                g = gcd(q, n)
            r *= 2

        if g == n:
            g = 1
            while g == 1:
                ys = (ys * ys + c) % n
                g = gcd(x - ys, n)

        if g == n:
            c += 1  # c を変えて続行。
        else:  # g は n の非自明な素因数。
            return g


def fac(n):
    "計算量は O(n ^ 1/4) 程度。"
    if n == 1:
        return []
    if is_prime(n):
        return [n]

    ret = []
    for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]:
        while n % p == 0:
            ret.append(p)
            n //= p
        if n == 1:
            return ret

    while n != 1 and not is_prime(n):
        f = find_factor(n)
        if is_prime(f):
            while n % f == 0:
                ret.append(f)
                n //= f
        elif is_prime(n // f):
            ret.append(n // f)
            n = f
        else:
            return sorted(ret + fac(f) + fac(n // f))

    if n == 1:
        return sorted(ret)
    else:
        ret.append(n)
        return sorted(ret)




N = int(input())
As = list(map(int, input().split()))

divisible_by_prime = dict()
divisible_by_prime[1] = 1
for A in As:
    for p in set(fac(A)):
        if p not in divisible_by_prime:
            divisible_by_prime[p] = 1
        else:
            divisible_by_prime[p] += 1

ispair = True
isset = True
ans = max(v for v in divisible_by_prime.values())
if ans <= 1:
    print("pairwise coprime")
elif ans < N:
    print("setwise coprime")
else:
    print("not coprime")
    

Fixed submission:
# 与えられた N 以下の素数を列挙して、その N 以下の素数の素因数分解を高速に与えるアルゴリズム。
# 
# 計算量:
#     構築: O(N)　
#     素因数分解: n <= N なる n に対し O(log n)、N < n <= N**2 なる n に対し、O(N / log N)
#
# 
# 参考: https://cp-algorithms.com/algebra/prime-sieve-linear.html (n <= N に対して O(log n) の部分)

N = 10 ** 6 # 10 ** 7 以下だとよさそう。10 ** 7 でPyPy3で構築に500ms程度。
lp = [0] * (N+1)
pr = [] # N 以下の素数のリスト
for i in range(2, N+1):
    if lp[i] == 0:
        lp[i] = i
        pr.append(i)
    for j, p in enumerate(pr):
        if p > lp[i] or i * p > N:
            break
        lp[i * p] = p

def fac_small(n):
    """
    引数 n の素因数分解をして、素因数を昇順に格納したリストを返す。
    ex. fac_small(60) == [2, 2, 3, 5]
    与えられた n について 1 <= n <= N を仮定する。n == 1 では空リストを返す。
    計算量は O(log n) 
    """
    # assert 1 <= n <= N
    ret = []
    while n > 1:
        ret.append(lp[n])
        n //= lp[n]
    return ret

def fac(n):
    """
    引数 n の素因数分解をして、素因数を昇順に格納したリストを返す。
    ex. fac_small(60) == [2, 2, 3, 5]
    与えられた n について 1 <= n <= N**2 を仮定する。n == 1 では空リストを返す。
    計算量は、1 <= n <= N で O(log n)、N < n <= N ** 2 で O(N / log N) 程度。
    """
    # assert 1 <= n <= N**2
    if 1 <= n <= N:
        return fac_small(n)
    else:
        sqr = int(N ** 0.5) + 10
        ret = []
        for p in pr:
            while n % p == 0:
                n //= p
                ret.append(p)
            if n == 1:
                return ret
            elif n <= N:
                return ret + fac_small(n)
            if p > sqr:
                break
        ret.append(n)
        return ret


from collections import defaultdict

N = int(input())
As = list(map(int, input().split()))

divisible_by_prime = defaultdict(list)
divisible_by_prime[1] = []
for A in As:
    for p in set(fac_small(A)):
        divisible_by_prime[p].append(A)

ispair = True
isset = True
ans = max(v for v in map(len, divisible_by_prime.values()))
if ans <= 1:
    print("pairwise coprime")
elif ans < N:
    print("setwise coprime")
else:
    print("not coprime")

Buggy python submission (verdict: Time Limit Exceeded):
# ρ法でとおるかためす。

# 参考1: https://qiita.com/Kiri8128/items/eca965fe86ea5f4cbb98
# 参考2: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
# 参考3: https://ja.wikipedia.org/wiki/%E3%83%9D%E3%83%A9%E3%83%BC%E3%83%89%E3%83%BB%E3%83%AD%E3%83%BC%E7%B4%A0%E5%9B%A0%E6%95%B0%E5%88%86%E8%A7%A3%E6%B3%95


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def is_prime(n):
    "Miller Rabin primality test. 2 <= n <= 2 ** 64 is required"
    if n % 2 == 0:
        return n == 2
    d = n - 1
    r = (d & -d).bit_length() - 1
    d >>= r

    # witnesses をいい感じに決める。
    if n < 2152302898747:
        if n < 9080191:
            if n < 2047:
                witnesses = [2]
            else:
                witnesses = [31, 73]
        else:
            if n < 4759123141:
                witnesses = [2, 7, 61]
            else:
                witnesses = [2, 3, 5, 7, 11]
    else:
        if n < 341550071728321:
            if n < 3474749660383:
                witnesses = [2, 3, 5, 7, 11, 13]
            else:
                witnesses = [2, 3, 5, 7, 11, 13, 17]
        else:
            if n < 3825123056546413051:
                witnesses = [2, 3, 5, 7, 11, 13, 17, 19]
            else:
                witnesses = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
    # witnesses の決定終了

    for a in witnesses:
        x = pow(a, d, n)
        if x == 1 or x == n - 1:
            continue
        for _ in range(r - 1):
            x *= x
            x %= n
            if x == n - 1:
                break
        else:
            return False
    return True


def find_factor(n):
    "Find a non-trivial factor of n by using Pollard's rho algorithm."
    m = int(n ** 0.125) + 1
    c = 1
    while True:
        y = 1
        r = 1
        q = 1
        g = 1
        while g == 1:
            x = y
            for _ in range(r):
                y = (y * y + c) % n
            for k in range(0, r, m):
                ys = y
                for _ in range(m):
                    y = (y * y + c) % n
                    q = q * (x - y) % n
                g = gcd(q, n)
                if g != 1:
                    break
            else:  # 残りの k から r までをやる
                ys = y
                for _ in range(r-k):
                    y = (y * y + c) % n
                    q = q * (x - y) % n
                g = gcd(q, n)
            r *= 2

        if g == n:
            g = 1
            while g == 1:
                ys = (ys * ys + c) % n
                g = gcd(x - ys, n)

        if g == n:
            c += 1  # c を変えて続行。
        else:  # g は n の非自明な素因数。
            return g


def fac(n):
    "計算量は O(n ^ 1/4) 程度。"
    if n == 1:
        return []
    if is_prime(n):
        return [n]

    ret = []
    for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]:
        while n % p == 0:
            ret.append(p)
            n //= p
        if n == 1:
            return ret

    while n != 1 and not is_prime(n):
        f = find_factor(n)
        if is_prime(f):
            while n % f == 0:
                ret.append(f)
                n //= f
        elif is_prime(n // f):
            ret.append(n // f)
            n = f
        else:
            return sorted(ret + fac(f) + fac(n // f))

    if n == 1:
        return sorted(ret)
    else:
        ret.append(n)
        return sorted(ret)


from collections import defaultdict

N = int(input())
As = list(map(int, input().split()))

divisible_by_prime = defaultdict(int)
divisible_by_prime[1] = 1
for A in As:
    for p in set(fac(A)):
        divisible_by_prime[p] += 1

ispair = True
isset = True
ans = max(v for v in divisible_by_prime.values())
if ans <= 1:
    print("pairwise coprime")
elif ans < N:
    print("setwise coprime")
else:
    print("not coprime")

Fixed submission:
# 与えられた N 以下の素数を列挙して、その N 以下の素数の素因数分解を高速に与えるアルゴリズム。
# 
# 計算量:
#     構築: O(N)　
#     素因数分解: n <= N なる n に対し O(log n)、N < n <= N**2 なる n に対し、O(N / log N)
#
# 
# 参考: https://cp-algorithms.com/algebra/prime-sieve-linear.html (n <= N に対して O(log n) の部分)

N = 10 ** 6 # 10 ** 7 以下だとよさそう。10 ** 7 でPyPy3で構築に500ms程度。
lp = [0] * (N+1)
pr = [] # N 以下の素数のリスト
for i in range(2, N+1):
    if lp[i] == 0:
        lp[i] = i
        pr.append(i)
    for j, p in enumerate(pr):
        if p > lp[i] or i * p > N:
            break
        lp[i * p] = p

def fac_small(n):
    """
    引数 n の素因数分解をして、素因数を昇順に格納したリストを返す。
    ex. fac_small(60) == [2, 2, 3, 5]
    与えられた n について 1 <= n <= N を仮定する。n == 1 では空リストを返す。
    計算量は O(log n) 
    """
    # assert 1 <= n <= N
    ret = []
    while n > 1:
        ret.append(lp[n])
        n //= lp[n]
    return ret

def fac(n):
    """
    引数 n の素因数分解をして、素因数を昇順に格納したリストを返す。
    ex. fac_small(60) == [2, 2, 3, 5]
    与えられた n について 1 <= n <= N**2 を仮定する。n == 1 では空リストを返す。
    計算量は、1 <= n <= N で O(log n)、N < n <= N ** 2 で O(N / log N) 程度。
    """
    # assert 1 <= n <= N**2
    if 1 <= n <= N:
        return fac_small(n)
    else:
        sqr = int(N ** 0.5) + 10
        ret = []
        for p in pr:
            while n % p == 0:
                n //= p
                ret.append(p)
            if n == 1:
                return ret
            elif n <= N:
                return ret + fac_small(n)
            if p > sqr:
                break
        ret.append(n)
        return ret


from collections import defaultdict

N = int(input())
As = list(map(int, input().split()))

divisible_by_prime = defaultdict(list)
divisible_by_prime[1] = []
for A in As:
    for p in set(fac_small(A)):
        divisible_by_prime[p].append(A)

ispair = True
isset = True
ans = max(v for v in map(len, divisible_by_prime.values()))
if ans <= 1:
    print("pairwise coprime")
elif ans < N:
    print("setwise coprime")
else:
    print("not coprime")