Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = [int(input()) for i in range(n)]
asc = 0
desc = 0
for t in range(1, n+1):
    target = t
    tmp = 0
    for i in p:
        if i == target:
            tmp += 1
            target += 1
    asc = max(asc, tmp)
for t in range(n, 0, -1):
    target = t
    tmp = 0
    for i in reversed(p):
        if i == target:
            tmp += 1
            target -= 1
    desc = max(desc, tmp)

ans = n - max(asc, desc)
print(ans)

Fixed submission:
n = int(input())
p = [int(input()) for i in range(n)]
tl = 1
n2i = [-1 for i in range(n)]
for i in range(n):
    n2i[p[i]-1] = i
tmp = 1
for i in range(n-1):
    if n2i[i] < n2i[i+1]:
        tmp += 1
    else:
        tmp = 1
    tl = max(tl, tmp)

ans = n - tl
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import re

s = input()
k = int(input())
ans = [min(s)]
i = 1
while True:
    if len(ans) == k:
        print(ans[-1])
        break
    else:
        base = ans[-1]
        sub = sorted(re.findall(base + '.', s))
        if len(sub) == 0:
            while True:
                if chr(ord(min(s))+1) in s:
                    ans.append(chr(ord(min(s))+1))
                    break
                elif i >= 100:
                    print('error')
                    break
                else:
                    i += 1

        else:
            ans.append(sub[0])


Fixed submission:
import re

s = input()
k = int(input())
ans = [min(s)]
i = 1
while True:
    if len(ans) == k:
        print(ans[-1])
        break
    else:
        base = ans[-1]
        sub = sorted(re.findall(base + '.', s))
        if len(sub) == 0:
            while True:
                if chr(ord(min(s))+i) in s:
                    ans.append(chr(ord(min(s))+i))
                    break
                else:
                    i += 1

        else:
            ans.append(sub[0])

Buggy python submission (verdict: Time Limit Exceeded):
import re

s = input()
k = int(input())
ans = [min(s)]
i = 1
while True:
    if len(ans) == k:
        print(ans[-1])
        break
    else:
        base = ans[-1]
        sub = sorted(re.findall(base + '.', s))
        if len(sub) == 0:
            while True:
                if chr(ord(min(s))+1) in s:
                    ans.append(chr(ord(min(s))+1))
                    break
                else:
                    i += 1
        else:
            ans.append(sub[0])


Fixed submission:
import re

s = input()
k = int(input())
ans = [min(s)]
i = 1
while True:
    if len(ans) == k:
        print(ans[-1])
        break
    else:
        base = ans[-1]
        sub = sorted(re.findall(base + '.', s))
        if len(sub) == 0:
            while True:
                if chr(ord(min(s))+i) in s:
                    ans.append(chr(ord(min(s))+i))
                    break
                else:
                    i += 1

        else:
            ans.append(sub[0])
Buggy python submission (verdict: Runtime Error):
from itertools import combinations
n = int(input())

isprime = [True for i in range(55556)]
isprime[0] = False
isprime[1] = False
for i in range(4, 55556, 2):
    isprime[i] = False
for i in range(3, 237):
    if isprime[i]:
        for j in range(i*3, 55556, i*2):
            isprime[j] = False
ans = []
for i in range(55556):
    flag = False
    if isprime[i]:
        if len(ans) >= 4:
            for c in combinations(ans, 4):
                if isprime[sum(c) + i]:
                    flag = True
                    break
            if flag:
                continue
        ans.append(i)
    if len(ans) == n:
        break
for i in ans:
    print(i, end=' ')

Fixed submission:
n = int(input())

isprime = [True for i in range(55556)]
isprime[0] = False
isprime[1] = False
for i in range(4, 55556, 2):
    isprime[i] = False
for i in range(3, 237):
    if isprime[i]:
        for j in range(i*3, 55556, i*2):
            isprime[j] = False
ans = []
for i in range(55556):
    flag = False
    if isprime[i] and i % 5 == 1:
        ans.append(i)
    if len(ans) == n:
        break
for i in ans:
    print(i, end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
    ans = 0
    now = 0
    for j, a in enumerate(A):
        if i == j:
            continue
        ans += abs(a-now)
        now = a
    print(ans + abs(now))

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
ans = 0
now = 0
for a in A:
    ans += abs(a - now)
    now = a
for i in range(1, n+1):
    removei = abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])
    concati = abs(A[i-1] - A[i+1])
    print(ans - removei + concati)
Buggy python submission (verdict: Time Limit Exceeded):
h, w, d = map(int, input().split())
index = [(0,0) for x in range(h*w+1)]
for i in range(1,h+1):
    col = list(map(int, input().split()))
    for j in range(1,w+1):
        index[col[j-1]] = (i, j)

q = int(input())
memo = [0 for x in range(h*w+1)]
for i in range(q):
    ans = 0
    l, r = map(int, input().split())
    while l != r:
        if memo[l+d] == 0:
            memo[l+d] = abs(index[l+d][0] - index[l][0]) + abs(index[l+d][1]-index[l][1])
        ans += memo[l+d]
        l += d
    print(ans)



Fixed submission:
h, w, d = map(int, input().split())
index = [(0,0) for x in range(h*w+1)]
for i in range(1,h+1):
    col = list(map(int, input().split()))
    for j in range(1,w+1):
        index[col[j-1]] = (i, j)

memo = [0 for x in range(h*w+1)]
l = 0
for l in range(1, h*w+1-d):
    memo[l+d] = memo[l] + abs(index[l+d][0] - index[l][0]) + abs(index[l+d][1]-index[l][1])

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(memo[r]-memo[l])

Buggy python submission (verdict: Time Limit Exceeded):
h, w, d = map(int, input().split())
index = [(0,0) for x in range(h*w+1)]
for i in range(1,h+1):
    col = list(map(int, input().split()))
    for j in range(1,w+1):
        index[col[j-1]] = (i, j)

q = int(input())
memo = [0 for x in range(h*w+1)]
for i in range(q):
    ans = 0
    l, r = map(int, input().split())
    while l != r:
        if memo[l+d] == 0:
            memo[l+d] = abs(index[l+d][0] - index[l][0]) + abs(index[l+d][1]-index[l][1])
        ans += memo[l+d]
        l += d
    print(ans)



Fixed submission:
h, w, d = map(int, input().split())
index = [(0,0) for x in range(h*w+1)]
for i in range(1,h+1):
    col = list(map(int, input().split()))
    for j in range(1,w+1):
        index[col[j-1]] = (i, j)

memo = [0 for x in range(h*w+1)]
l = 0
for l in range(1, h*w+1-d):
    memo[l+d] = memo[l] + abs(index[l+d][0] - index[l][0]) + abs(index[l+d][1]-index[l][1])

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(memo[r]-memo[l])

Buggy python submission (verdict: Time Limit Exceeded):
h, w, d = map(int, input().split())
index = [(0,0) for x in range(h*w+1)]
for i in range(1,h+1):
    col = list(map(int, input().split()))
    for j in range(1,w+1):
        index[col[j-1]] = (i, j)

q = int(input())
for i in range(q):
    ans = 0
    l, r = map(int, input().split())
    while l != r:
        ans += abs(index[l+d][0] - index[l][0]) + abs(index[l+d][1]-index[l][1])
        l += d
    print(ans)



Fixed submission:
h, w, d = map(int, input().split())
index = [(0,0) for x in range(h*w+1)]
for i in range(1,h+1):
    col = list(map(int, input().split()))
    for j in range(1,w+1):
        index[col[j-1]] = (i, j)

memo = [0 for x in range(h*w+1)]
l = 0
for l in range(1, h*w+1-d):
    memo[l+d] = memo[l] + abs(index[l+d][0] - index[l][0]) + abs(index[l+d][1]-index[l][1])

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(memo[r]-memo[l])
Buggy python submission (verdict: Runtime Error):
n = input()
tail = int(n[1:])
m = str(int(n) - tail - 1)
ans = 0
for i in m:
    ans += int(i)
print(ans)

Fixed submission:
n = input()
head = n[0]
tail = '0' * (len(n) - 1)
m = str(int(head + tail) - 1)
sumn = 0
summ = 0
for i in n:
    sumn += int(i)
for i in m:
    summ += int(i)
print(max(sumn, summ))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list()
for i in range(N):
	A = int(input())
	if A in L:
		L.remove(A)
	else:
		L.append(A)
print(len(L))

Fixed submission:
N = int(input())
ans = {}
for i in range(N):
  ai = int(input())
  if ans.get(ai):
    ans.pop(ai)
  else:
    ans[ai] = 1
print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Ex = [False for i in range(1000000001)]
for i in range(N):
	A = int(input())
	Ex[A] = not Ex[A]
count = 0
for tf in range(1000000001):
	if Ex[tf]:
		count += 1
print(count)

Fixed submission:
N = int(input())
ans = {}
for i in range(N):
  ai = int(input())
  if ans.get(ai):
    ans.pop(ai)
  else:
    ans[ai] = 1
print(len(ans))

Buggy python submission (verdict: Runtime Error):
N = int(input())
Ex = [False for i in range(100001)]
for i in range(N):
	A = int(input())
	Ex[A] = not Ex[A]
count = 0
for tf in range(100001):
	if Ex[tf]:
		count += 1
print(count)

Fixed submission:
N = int(input())
ans = {}
for i in range(N):
  ai = int(input())
  if ans.get(ai):
    ans.pop(ai)
  else:
    ans[ai] = 1
print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
A = list(map(int, input().split()))
new_A = set([abs(ai-aj) for aj in A for ai in A]) - {0}
max_a = max(A)
set_A = set(A)
if k in A:
    print("POSSIBLE")
elif max_a >= k:
    if new_A - set_A == set():
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")
elif max_a < k:
    print("IMPOSSIBLE")


Fixed submission:
from fractions import gcd
N, K = map(int, input().split())
A = list(map(int, input().split()))
if K in A:
  print('POSSIBLE')
elif K > max(A):
  print('IMPOSSIBLE')
else:
  A_gcd = A[0]
  for i in range(1, N):
    A_gcd = gcd(A_gcd, A[i])

  if K % A_gcd == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N, k = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
isPossible = False

K = [k]

for a in A:
	if a > k:
		break
	if k - a in A:
		isPossible = True
		break
	elif a in K:
		isPossible = True
		break
	else:
		K.append(k-a)


if k > max(A):
	isPossible = False

if isPossible:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Fixed submission:
from fractions import gcd
N, K = map(int, input().split())
A = list(map(int, input().split()))
if K in A:
  print('POSSIBLE')
elif K > max(A):
  print('IMPOSSIBLE')
else:
  A_gcd = A[0]
  for i in range(1, N):
    A_gcd = gcd(A_gcd, A[i])

  if K % A_gcd == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N, k = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
isPossible = False

K = [k]

for a in A:
	if a in K:
		isPossible = True
		break
	else:
		K.append(abs(k-a))
for a in A:
	if a in K:
		isPossible = True
		break



if k in A:
	isPossible = True

if k > max(A):
	isPossible = False

# print(K)
if isPossible:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Fixed submission:
from fractions import gcd
N, K = map(int, input().split())
A = list(map(int, input().split()))
if K in A:
  print('POSSIBLE')
elif K > max(A):
  print('IMPOSSIBLE')
else:
  A_gcd = A[0]
  for i in range(1, N):
    A_gcd = gcd(A_gcd, A[i])

  if K % A_gcd == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N, k = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
isPossible = False

K = [k]

for a in A:
	if abs(k - a) in A:
		isPossible = True
		break
	elif a in K:
		isPossible = True
		break
	else:
		K.append(abs(k-a))

if k in A:
	isPossible = True

if k > max(A):
	isPossible = False

if isPossible:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Fixed submission:
from fractions import gcd
N, K = map(int, input().split())
A = list(map(int, input().split()))
if K in A:
  print('POSSIBLE')
elif K > max(A):
  print('IMPOSSIBLE')
else:
  A_gcd = A[0]
  for i in range(1, N):
    A_gcd = gcd(A_gcd, A[i])

  if K % A_gcd == 0:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().split()
b = list()
for i in range(n):
	if i % 2 == n % 2:
		b.append(a[i])
	else:
		b.insert(0, a[i])

print(' '.join(b))

Fixed submission:
from collections import deque
d = deque()
n = int(input())
a = input().split()

for i in range(n):
	if i % 2 == n % 2:
		d.append(a[i])
	else:
		d.appendleft(a[i])

print(' '.join(d))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = list()
for i in range(n):
	if i % 2 == n % 2:
		b.append(a[i])
	else:
		b.insert(0, a[i])

for x in b:
	print(x, end=' ')
print()

Fixed submission:
from collections import deque
d = deque()
n = int(input())
a = input().split()

for i in range(n):
	if i % 2 == n % 2:
		d.append(a[i])
	else:
		d.appendleft(a[i])

print(' '.join(d))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if i % 2 == n % 2:
		b.insert(0, a[i])
	else:
		b.append(a[i])

for x in b:
	print(x, end=' ')
print()

Fixed submission:
from collections import deque
d = deque()
n = int(input())
a = input().split()

for i in range(n):
	if i % 2 == n % 2:
		d.append(a[i])
	else:
		d.appendleft(a[i])

print(' '.join(d))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if i % 2 == n & 2:
		b.insert(0, a[i])
	else:
		b.append(a[i])

for x in b:
	print(x, end=' ')
print()

Fixed submission:
from collections import deque
d = deque()
n = int(input())
a = input().split()

for i in range(n):
	if i % 2 == n % 2:
		d.append(a[i])
	else:
		d.appendleft(a[i])

print(' '.join(d))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = list()
for i in range(n):
	if i % 2 == 0:
		b.append(a[i])
	else:
		b.insert(0, a[i])
if n % 2 == 1:
	b = b[::-1]

for x in b:
	print(x, end=' ')
print()

Fixed submission:
from collections import deque
d = deque()
n = int(input())
a = input().split()

for i in range(n):
	if i % 2 == n % 2:
		d.append(a[i])
	else:
		d.appendleft(a[i])

print(' '.join(d))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = list()
for i in range(n):
	b.append(a[i])
	b = b[::-1]
for x in b:
	print(x, end=' ')
print()

Fixed submission:
from collections import deque
d = deque()
n = int(input())
a = input().split()

for i in range(n):
	if i % 2 == n % 2:
		d.append(a[i])
	else:
		d.appendleft(a[i])

print(' '.join(d))
Buggy python submission (verdict: Runtime Error):
import copy
def explore(key, flags):
    flags = copy.copy(flags)
    if flags[key-1]:
        return 0
    flags[key-1] = True
    if False not in flags:
        return 1
    elif key in graph:
        value = graph[key]
        ans = 0
        for i in value:
            ans += explore(i, flags)
        return ans
    else:
        return 0

n, m = map(int, input().split())
graph = {}
for i in range(m):
    a, b = map(int, input().split())
    if a in graph:
        graph[a].append(b)
    else:
        graph[a] = [b]
    if b in graph:
        graph[b].append(a)
    else:
        graph[b] = [a]

flags = [False for i in range(m)]
ans = explore(1, flags)
print(ans)


Fixed submission:
import copy
def explore(key, flags):
    flags = copy.copy(flags)
    if flags[key-1]:
        return 0
    flags[key-1] = True
    if False not in flags:
        return 1
    elif key in graph:
        value = graph[key]
        ans = 0
        for i in value:
            ans += explore(i, flags)
        return ans
    else:
        return 0

n, m = map(int, input().split())
graph = {}
for i in range(m):
    a, b = map(int, input().split())
    if a in graph:
        graph[a].append(b)
    else:
        graph[a] = [b]
    if b in graph:
        graph[b].append(a)
    else:
        graph[b] = [a]

flags = [False for i in range(n)]
ans = explore(1, flags)
print(ans)
Buggy python submission (verdict: Runtime Error):
nums = input().split()
N = int(nums[0])
A = int(nums[1])
B = int(nums[2])
S = input()
count = 0
bcount = 0
for x in S:
	if x == 'a' and A+B > count:
		count += 1
		print("Yes")
	elif x == 'b' and A+B > count and bcount < B :
		count += 1
		bcount += 1
		print("Yes")
	else :
		print("No")


Fixed submission:
s = input()
count = 0;
anser = "CODEFESTIVAL2016"
for i in range(0,16):
	if not s[i] == anser[i]:
		count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
while "ST" in s:
	s = s.replace("ST", "", 100000)
print(len(s))

Fixed submission:
S = input()
cs = 0
ans = 0
for i in range(len(S)):
  si = S[i]
  if si == 'T' and cs > 0:
    cs -= 1
    ans += 2
  elif si == 'S':
    cs += 1
    
print(len(S)-ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
while "ST" in s:
	s = s.replace("ST", "")
print(len(s))

Fixed submission:
S = input()
cs = 0
ans = 0
for i in range(len(S)):
  si = S[i]
  if si == 'T' and cs > 0:
    cs -= 1
    ans += 2
  elif si == 'S':
    cs += 1
    
print(len(S)-ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
N = len(S)
chl = [0] * N

peo = 0
for i in range(0, N, 1):
  if(S[i] == "R"):
    peo += 1
  else:
    chl[i-1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0

peo = 0
for i in reversed(range(0, N, 1)):
  if(S[i] == "L"):
    peo += 1
  else:
    chl[i+1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0
    
print(" ".join(map(str, chl)))

Fixed submission:
S = input()
N = len(S)
chl = [0] * N

peo = 0
for i in range(0, N, 1):
  if(S[i] == "R"):
    peo += 1
  else:
    chl[i-1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0

peo = 0
for i in reversed(range(0, N, 1)):
  if(S[i] == "L"):
    peo += 1
  else:
    chl[i+1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0
    
print(" ".join(map(str, chl)))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
N = len(S)
chl = [0] * N

peo = 0
for i in range(0, N, 1):
  if(S[i] == "R"):
    peo += 1
  else:
    chl[i-1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0

peo = 0
for i in reversed(range(0, N, 1)):
  if(S[i] == "L"):
    peo += 1
  else:
    chl[i+1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0
    
print(" ".join(map(str, chl)))

Fixed submission:
S = input()
N = len(S)
chl = [0] * N

peo = 0
for i in range(0, N, 1):
  if(S[i] == "R"):
    peo += 1
  else:
    chl[i-1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0

peo = 0
for i in reversed(range(0, N, 1)):
  if(S[i] == "L"):
    peo += 1
  else:
    chl[i+1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0
    
print(" ".join(map(str, chl)))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(A[-1] - A[1])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(A[-1] - A[0])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
col = [0] * 9
for i in A:
  r = i//400
  if r > 9:
    r = 8
  col[r] += 1

ans = 0
for i in col[:8]:
  if i > 0:
    ans += 1

print(ans, ans + col[-1])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
col = [0] * 9
for i in A:
  r = i//400
  if r > 8:
    r = 8
  col[r] += 1

ans = 0
for i in col[:8]:
  if i > 0:
    ans += 1

if ans == 0:
  print(1, col[-1])
else:
  print(ans, ans + col[-1])

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
col = [0] * 9
for i in A:
  col[i // 400] += 1

ans = 0
for i in col[:8]:
  if i > 0:
    ans += 1

print(ans, ans + col[-1])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
col = [0] * 9
for i in A:
  r = i//400
  if r > 8:
    r = 8
  col[r] += 1

ans = 0
for i in col[:8]:
  if i > 0:
    ans += 1

if ans == 0:
  print(1, col[-1])
else:
  print(ans, ans + col[-1])
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    N = int(input())
    A = list(map(int, input().split()))
    maxA = max(A)
    # エラトステネスの篩
    sieve = [0] * (maxA + 1)
    sieve[0] = sieve[1] = -1
    for i in range(maxA+1):
        if sieve[i] != 0:
            continue
        for j in range(i, maxA+1, i):
            if sieve[j] == 0:
                sieve[j] = i

    # 素因数分解
    primelist = []
    lenprimelist = 0
    for i in range(N):
        tmpset = set()
        j = A[i]
        for _ in range(N):
            tmp = sieve[j]
            if tmp <= 0:
                break
            tmpset.add(tmp)
            j = j//tmp
        lenprimelist += len(tmpset)
        primelist.append(tmpset)
    
    # 素因数の和集合を取ったときに, 元の素因数の配列の長さから小さくなっている 
    #   => ある i, j で共通する素因数を持つAi, Ajが存在する
    #   => pairwise coprime ではない
    # 全ての素因数の配列に対して共通部分を取ったときに, 空集合となる
    #   => A全体での公約数は 1 
    #   => setwise coprime である

    primeset = set()
    primeintersection = set(range(2, maxA+1))
    for s in primelist:
        primeset.update(s)
        primeintersection.intersection_update(s)
    if len(primeset) == lenprimelist:
        print('pairwise coprime')
        return
    if len(primeintersection) == 0:
        print('setwise coprime')
        return
    print('not coprime')
    return

if __name__ == "__main__":
    main()



Fixed submission:

def main():
    N = int(input())
    A = list(map(int, input().split()))
    maxA = max(A)
    # エラトステネスの篩
    sieve = [0] * (maxA + 1)
    sieve[0] = sieve[1] = -1
    for i in range(maxA+1):
        if sieve[i] != 0:
            continue
        for j in range(i, maxA+1, i):
            if sieve[j] == 0:
                sieve[j] = i

    # 素因数分解
    primelist = []
    lenprimelist = 0
    for i in range(N):
        tmpset = set()
        j = A[i]
        for _ in range(N):
            tmp = sieve[j]
            if tmp <= 0:
                break
            tmpset.add(tmp)
            j = j//tmp
        lenprimelist += len(tmpset)
        primelist.append(tmpset)
    
    # 素因数の和集合を取ったときに, 元の素因数の配列の長さから小さくなっている 
    #   => ある i, j で共通する素因数を持つAi, Ajが存在する
    #   => pairwise coprime ではない
    # 全ての素因数の配列に対して共通部分を取ったときに, 空集合となる
    #   => A全体での公約数は 1 
    #   => setwise coprime である

    primeset = set()
    primeintersection = set(range(2, maxA+1))
    for s in primelist:
        primeset.update(s)
        primeintersection.intersection_update(s)
    if len(primeset) == lenprimelist:
        print('pairwise coprime')
        return
    if len(primeintersection) == 0:
        print('setwise coprime')
        return
    print('not coprime')
    return

if __name__ == "__main__":
    main()