Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
N = int(input())
*A, = map(int, input().split())

def lcm(a, b):
    return a*b//gcd(a,b)

g = 1
for a in A:
    if lcm(g, a) == g * a:
        g *= a
    else:
        if reduce(gcd, A) == 1:
            print("setwise coprime")
        else:
            print('not coprime')
        break
else:
    print('pairwise coprime')
    exit()

Fixed submission:
from math import gcd
from functools import reduce
N = int(input())
*A, = map(int, input().split())

MAX_N = max(A)+5
primes = list(range(MAX_N+1))
for i in range(2, int(MAX_N**0.5)+1):
    if primes[i] < i:
        continue
    for j in range(2*i, MAX_N+1, i):
        primes[j] = i


def check():
    S = set()
    for a in A:
        T = set()
        while True:
            p = primes[a]
            if p != 1 and p in S:
                return False
            T.add(p)
            if p == a:
                break
            a //= p
        S |= T
    return True


if check() or all(a == 1 for a in A):
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from operator import mul
from functools import reduce
N = int(input())
*A, = map(int, input().split())

def lcm(a, b):
    return a*b//gcd(a,b)

if reduce(lcm, A) == reduce(mul, A):
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print("setwise coprime")
else:
    print('not coprime')

Fixed submission:
from math import gcd
from functools import reduce
N = int(input())
*A, = map(int, input().split())

MAX_N = max(A)+5
primes = list(range(MAX_N+1))
for i in range(2, int(MAX_N**0.5)+1):
    if primes[i] < i:
        continue
    for j in range(2*i, MAX_N+1, i):
        primes[j] = i


def check():
    S = set()
    for a in A:
        T = set()
        while True:
            p = primes[a]
            if p != 1 and p in S:
                return False
            T.add(p)
            if p == a:
                break
            a //= p
        S |= T
    return True


if check() or all(a == 1 for a in A):
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
N = int(input())
*A, = map(int, input().split())

n = max(A)

is_prime = [True]*(n+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(n**0.5)+1):
    if not is_prime[i]:
        continue
    for j in range(i*2, n+1, i):
        is_prime[j] = False
primes = [i for i in range(n+1) if is_prime[i]]

for p in primes:
    flag = 0
    for i in range(N):
        if A[i] % p == 0:
            if flag:
                break
            flag = 1
    else:
        continue

    # not pairwise coprime
    gcd_set = reduce(gcd, A)
    if gcd_set == 1:
        print("setwise coprime")
    else:
        print('not coprime')
    exit()
print('pairwise coprime')

    


Fixed submission:
from math import gcd
from functools import reduce
N = int(input())
*A, = map(int, input().split())

MAX_N = max(A)+5
primes = list(range(MAX_N+1))
for i in range(2, int(MAX_N**0.5)+1):
    if primes[i] < i:
        continue
    for j in range(2*i, MAX_N+1, i):
        primes[j] = i


def check():
    S = set()
    for a in A:
        T = set()
        while True:
            p = primes[a]
            if p != 1 and p in S:
                return False
            T.add(p)
            if p == a:
                break
            a //= p
        S |= T
    return True


if check() or all(a == 1 for a in A):
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
N = int(input())
*A, = map(int, input().split())

n = 1000_000

is_prime = [True]*(n+1)
is_prime[0] = is_prime[1] = False
for i in range(2, int(n**0.5)+1):
    if not is_prime[i]:
        continue
    for j in range(i*2, n+1, i):
        is_prime[j] = False
primes = [i for i in range(n+1) if is_prime[i]]

for p in primes:
    flag = 0
    for i in range(N):
        if A[i] % p == 0:
            if flag:
                break
            flag = 1
    else:
        continue

    # not pairwise coprime
    gcd_set = reduce(gcd, A)
    if gcd_set == 1:
        print("setwise coprime")
    else:
        print('not coprime')
    exit()
print('pairwise coprime')

    


Fixed submission:
from math import gcd
from functools import reduce
N = int(input())
*A, = map(int, input().split())

MAX_N = max(A)+5
primes = list(range(MAX_N+1))
for i in range(2, int(MAX_N**0.5)+1):
    if primes[i] < i:
        continue
    for j in range(2*i, MAX_N+1, i):
        primes[j] = i


def check():
    S = set()
    for a in A:
        T = set()
        while True:
            p = primes[a]
            if p != 1 and p in S:
                return False
            T.add(p)
            if p == a:
                break
            a //= p
        S |= T
    return True


if check() or all(a == 1 for a in A):
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
N = int(input())
*A, = map(int, input().split())


MAX_N = 1000_000

primes = [1]*(MAX_N+1)
primes[1] = 1
for i in range(2, int(MAX_N**0.5)+1):
    if primes[i] > 1:
        continue
    for j in range(i, MAX_N+1, i):
        primes[j] = i

gcd_set = reduce(gcd, A)


b = {}

def prime_fact(n):
    ret = {}
    while n > 1:
        p = primes[n]
        if p in ret:
            ret[p] += 1
        else:
            ret[p] = 1
        n //= p


    for p in ret.keys():
        if p in b:
            return False
        else:
            b[p] = 1
    return True

for a in A:
    if not prime_fact(a):
        if gcd_set == 1:
            print('setwise coprime')
        else:
            print('not coprime')
        exit()

print('pairwise coprime')   




Fixed submission:
from math import gcd
from functools import reduce
N = int(input())
*A, = map(int, input().split())

MAX_N = max(A)+5
primes = list(range(MAX_N+1))
for i in range(2, int(MAX_N**0.5)+1):
    if primes[i] < i:
        continue
    for j in range(2*i, MAX_N+1, i):
        primes[j] = i


def check():
    S = set()
    for a in A:
        T = set()
        while True:
            p = primes[a]
            if p != 1 and p in S:
                return False
            T.add(p)
            if p == a:
                break
            a //= p
        S |= T
    return True


if check() or all(a == 1 for a in A):
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')