Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import deque
import copy
def solve(maze, start):
  memo = [[False]*len(maze[0]) for _ in range(len(maze))]
  q = deque()
  q.append([start,0])
  ans = 0
  while q:
    cur, cnt = q.popleft()
    ans = max(ans, cnt)
    memo[cur[0]][cur[1]] = True
    for y, x in zip((0,0,1,-1),(1,-1,0,0)):
      if maze[cur[0]+y][cur[1]+x] == "." and not memo[cur[0]+y][cur[1]+x]:
        q.append([[cur[0]+y,cur[1]+x],cnt+1])
  return ans


H, W = map(int, input().split())
Maze = [["#"]*(W+2)]+[["#"]+list(input())+["#"] for _ in range(H)] + [["#"]*(W+2)]
Ans = 0
for sy in range(1, H+1):
  for sx in range(1, W+1):
    if Maze[sy][sx] == "#":
      continue
    else:
      Ans = max(Ans, solve(Maze, [sy, sx]))
print(Ans)

### FIXED CODE ###

H, W = map(int, input().split())
S = [input() for _ in range(H)]


def f(i, j):
    t = [[-1] * W for _ in range(H)]
    t[i][j] = 0
    q = [(i, j)]
    while q:
        y, x = q.pop(0)
        if y - 1 >= 0 and S[y - 1][x] != '#' and t[y - 1][x] == -1:
            t[y - 1][x] = t[y][x] + 1
            q.append((y - 1, x))
        if y + 1 < H and S[y + 1][x] != '#' and t[y + 1][x] == -1:
            t[y + 1][x] = t[y][x] + 1
            q.append((y + 1, x))
        if x - 1 >= 0 and S[y][x - 1] != '#' and t[y][x - 1] == -1:
            t[y][x - 1] = t[y][x] + 1
            q.append((y, x - 1))
        if x + 1 < W and S[y][x + 1] != '#' and t[y][x + 1] == -1:
            t[y][x + 1] = t[y][x] + 1
            q.append((y, x + 1))
    return max(max(tt) for tt in t)


result = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            result = max(result, f(i, j))
print(result)
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
  x,y = map(int,input().split())
  a.append([x,y])
ans = 0
ima = 0
for j in range(n):
  ban = -1
  to = 0
  for i in range(len(a)):
    if a[i][0] <= ima and a[i][1]>= ima:
      continue
    toa = min(abs(ima-a[i][0]),abs(ima-a[i][1]))
    if to < toa:
      ban = i
      to = toa
  if ban ==-1:
    print(ans+abs(ima))
    break
  ans += to
  if abs(ima-a[ban][0])>abs(ima-a[ban][1]):
    ima = a[ban][1]
  else:
    ima = a[ban][0]
  a.pop(ban)
else:
  print(ans+abs(ima))
  

### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
  x,y = map(int,input().split())
  a.append([x,y])
l = sorted(a,key=lambda x: -x[0])
r = sorted(a,key=lambda x: x[1])
left = 0
hi = 0
mi = 0
for i in range(n):
  hi += l[i][0]
  left = max(left,(hi-mi)*2)
  mi += r[i][1]
  left = max(left,(hi-mi)*2)
right = 0
hi = 0
mi = 0
for i in range(n):
  mi += r[i][1]
  right = max(right,(hi-mi)*2)
  hi += l[i][0]
  right = max(right,(hi-mi)*2)
print(max(right,left))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
for i in range(1, N+1):
  print(A.count(i))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = [0 for i in range(N)]
for a in A:
  ans[a-1] += 1
for i in range(N):
  print(ans[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    Query.append([c,b])
Query.sort(reverse=True)
for i in range(m):
    b,c = Query[i][1],Query[i][0]
    if min(A) >= c:
        break
    else:
        A.sort()
        index = bisect.bisect_left(A,c)
        if b <= index:
            for i in range(b):
                A[i] = c
        else:
            for i in range(index):
                A[i] = c
print(sum(A))

### FIXED CODE ###

import sys
input = sys.stdin.readline
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

minA = A[0]
Query = []
for _ in range(m):
    b,c = map(int,input().split())
    if c > minA:
        Query.append([b,c])
Query = sorted(Query, key=lambda x:(x[1], x[0]), reverse=True)

ans = 0
index = 0
for b,c in Query:
    if index >= n:
        break
    #print("----")
    cnt = 0
    Flag = True
    while Flag:
        #print(A,b,c,index)
        if A[index] < c:
            A[index] = c
            cnt += 1
            index += 1
            if (cnt >= b) or (index >= n):
                Flag = False
        else:
            Flag = False
    '''
    #A.sort()
    if A[0] >= c:
        break
    else:
        index = min(bisect.bisect_left(A,c),b)
        if index > len(A):
            ans += c * len(A)
            break
        else:
            ans += c * index
            A = A[index:]
    print(A)
    '''
print(sum(A))
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = []
for i in range(N):
    s = list(input().strip())
    s_list = [int(k) for k in s]
    S.append(s_list)

count_max = 0
for i in range(N):
    flag = [-1]*N
    q = deque([i])
    flag[i] = 0
    count = 0
    while(q):
        count += 1
        for k in range(len(q)):
            v = q.popleft()
            for j in range(len(S[v])):
                if S[v][j] == 1 and flag[j] == -1:
                    flag[j] = count
                    q.append(j)
                elif S[v][j] == 1:
                    if flag[j]%2 != count%2:
                        print(-1)
                        sys.exit()
    count_max = max(count, count_max)
print(count_max)
        


### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
S = []
for i in range(N):
    s = list(input().strip())
    s_list = [int(k) for k in s]
    S.append(s_list)

count_max = 0
for i in range(N):
    flag = [-1]*N
    q = deque([i])
    flag[i] = 0
    count = 0
    while(q):
        count += 1
        for k in range(len(q)):
            v = q.popleft()
            for j in range(len(S[v])):
                if S[v][j] == 1 and flag[j] == -1:
                    flag[j] = count
                    q.append(j)
                elif S[v][j] == 1:
                    if flag[j]%2 != count%2:
                        print(-1)
                        sys.exit()
    count_max = max(count, count_max)
print(count_max)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10**9+7

N = int(input())
S = list(input())

if S[0] == "W" or S[-2] == "W":
    print(0)
    sys.exit()

LR = [0]
for i in range(1, 2*N):
    if LR[i-1] == 0:
        if S[i] == S[i-1]:
            LR.append(1)
        else:
            LR.append(0)
    else:
        if S[i] == S[i-1]:
            LR.append(0)
        else:
            LR.append(1)

if LR.count(0) != N:
    print(0)
    sys.exit()

count0 = 0
ans = 1
for i in range(2*N):
    if LR[i] == 0:
        count0 += 1
    else:
        ans *= count0
        count0 -= 1

def factorial(N, mod):
    if N == 0 or N == 1:
        return 1
    else:
        return N * factorial(N, mod) % mod

print(ans*factorial(N,MOD)%MOD)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 10**9+7

N = int(input())
S = list(input().rstrip())

if S[0] == "W" or S[-1] == "W":
    print(0)
    sys.exit()

LR = [0 for i in range(2*N)]
count0 = 1
count0_raw = 1
ans = 1
for i in range(1, 2*N):
    if LR[i-1] == 0:
        if S[i] == S[i-1]:
            LR[i] = 1
        else:
            LR[i] = 0
    else:
        if S[i] == S[i-1]:
            LR[i] = 0
        else:
            LR[i] = 1

    if LR[i] == 0:
        count0 += 1
        count0_raw += 1
    else:
        ans *= count0
        ans %= MOD
        count0 -= 1

if count0_raw != N:
    print(0)
    sys.exit()

N_k = 1
for i in range(N):
    N_k *= i+1
    N_k %= MOD

print(ans*N_k%MOD)
### BUGGY CODE ###

n=int(input())
 
list=[]
 
for i in range(1,n+1):
    if len(list) == 1 and i>int(n/i):
        ans=(list[-1][0]-1)+(list[-1][1]-1)
        break
    a=n%i
    if a == 0:
        if(i<n/i):
            list.append([i,int(n/i)])
        else:
            list.append([int(n/i),i])
            if len(list) == 1:
                ans=(list[-1][0]-1)+(list[-1][1]-1)
                break
            if list[-1]==list[-2]:
                ans=(list[-1][0]-1)+(list[-1][1]-1)
print(ans)

### FIXED CODE ###

import math

n = int(input())

for i in range(int(math.sqrt(n)), 0, -1):
  if n % i == 0:
    print(int(i + n / i - 2))
    break
### BUGGY CODE ###

def resolve():
    def lcm(X, Y):
        x = X
        y = Y
        if y > x:
            x, y = y, x
        while x % y != 0:
            x, y = y, x % y
        return X * Y // y
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    lsd = a[0]
    for i in range(1, n):
        lsd = lcm(lsd, a[i])

    ans = 0
    for i in range(n):
        ans += (lsd//a[i]) % mod

    print(int(ans % mod))
resolve()

### FIXED CODE ###

def resolve():
    def lcm(X, Y):
        x = X
        y = Y
        if y > x:
            x, y = y, x
        while x % y != 0:
            x, y = y, x % y
        return X * Y // y
    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    lsd = a[0]
    for i in range(1, n):
        lsd = lcm(lsd, a[i])
    lsd = lsd % mod

    ans = 0
    for i in range(n):
        ans += (lsd * pow(a[i], mod-2, mod)) % mod

    print(int(ans % mod))

resolve()
### BUGGY CODE ###

n = int(input())
arr = list(map(int, input().split()))

c = 0
prev = 0
for i in range(n):
    flag = False
    s = sum(arr[:i+1])
    if i > 0:
        if prev > 0 and s >= 0:
            diff = s + 1
            c += diff
            arr[i] -= diff 
        elif prev < 0 and s <= 0:
            diff = -1 * s + 1
            c += diff
            arr[i] += diff
        else:
            flag = True
    prev = s if flag else sum(arr[:i+1])
print(c)

### FIXED CODE ###

n = int(input())
_arr = list(map(int, input().split()))

ans = []
for first in (_arr[0], -1 * _arr[1] + 1, -1 * _arr[1] - 1, 1, -1):
    arr = _arr[:]
    c = 0
    prev = 0
    for i in range(n):
        t = prev + arr[i]
        if i == 0:
            c += abs(arr[i] - first)
            arr[i] = first
        elif prev > 0 and t >= 0:
            diff = t + 1
            c += diff
            arr[i] -= diff
        elif prev < 0 and t <= 0:
            diff = -1 * t + 1
            c += diff
            arr[i] += diff
        prev += arr[i]
    ans.append(c)
print(min(ans))
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())

    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    AA = sorted(A)
    m = AA[-1]
    m2 = AA[-2]
    maxIndex = [i for i, x in enumerate(A) if x == max(A)]
    
    for i in range(N):
        if i not in maxIndex or len(maxIndex) > 1:
            print(m)
        else:
            print(m2)


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())

    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    ii = A.index(max(A))
    m = max(A)
    A.pop(ii)
    m2 = max(A)
    
    for i in range(N):
        if i == ii:
            print(m2)
        else:
            print(m)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import queue
from collections import Counter

def main():
    N,X,Y=map(int,input().split())
    q=queue.Queue()
    c=Counter()

    for i in range(1,N+1):
        dist=[-1]*(N+1)#indexと頂点の番号を合わせる
        q=queue.Queue()
        q.put([i,0])
        dist[i]=0
        while not q.empty():
            j,kyori=q.get()

            if j-1>=1:
                if dist[j-1]==-1:
                    q.put([j-1,kyori+1])
                    dist[j-1]=kyori+1

            if j+1<=N:
                if dist[j+1]==-1:
                    q.put([j+1,kyori+1])
                    dist[j+1]=kyori+1
            
            if j == X and dist[Y]==-1:
                q.put([Y,kyori+1])
                dist[Y]=kyori+1

            if j == Y and dist[X]==-1:
                q.put([X,kyori+1])
                dist[X]=kyori+1

        c.update(Counter(dist[1:]))

    ans=list(c.items())
    ans.sort()
    lenans=len(ans)
    for i in range(1,N):
        if i<=lenans-1:
            print(ans[i][1]//2)
        else:
            print(0)
main()

### FIXED CODE ###

from collections import deque
N,X,Y=map(int,input().split())

count=[0]*N

def bfs(start):
    dist=[-1]*(N+1)#indexと頂点の番号を合わせる
    q=deque()
    q.append([start,0])
    dist[start]=0
    while q:
        j,kyori=q.popleft()

        if j-1>=1:
            if dist[j-1]==-1:
                q.append([j-1,kyori+1])
                dist[j-1]=kyori+1

        if j+1<=N:
            if dist[j+1]==-1:
                q.append([j+1,kyori+1])
                dist[j+1]=kyori+1
        
        if j == X and dist[Y]==-1:
            q.append([Y,kyori+1])
            dist[Y]=kyori+1

        if j == Y and dist[X]==-1:
            q.append([X,kyori+1])
            dist[X]=kyori+1

    return dist[1:]

def main():
    for start in range(1,N+1):
        dist=bfs(start)
        for d in dist:
            count[d]+=1

    for i in count[1:]:
        print(i//2)

main()
### BUGGY CODE ###

s = input()
n = int(input())
qs = [input().split(' ') for i in range(n)]

div = True
for q in qs:
    if q[0] == '1':
        div = not div
    else:
        if (q[1] == '1' and div) or (q[1] == '2' and not div):
            s = q[2] + s
        else:
            s = s + q[2]


if div:
    print(s)
else:
    s = ''.join(list(reversed(s)))
    print(s)


### FIXED CODE ###

from collections import deque

s = input()
n = int(input())
ans = deque(s)

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        ans.appendleft(q[2])
    else:
        ans.append(q[2])

if div:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]


#%%
# n, a = 4, [2, 10, 8, 40]


#%%

a.sort()

#%%

#%%
while len(a) >= 2:
    if a[0] > a[1]:
        a[0], a[1] = a[1], a[0]

    for i in range(len(a) -1, 0, -1):
        a[i] = a[i] % a[0]
        if a[i] == 0:
            a.remove(a[i])
    


#%%
print(a[0])

#%%


### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]


def euclid_lcf(a, b):
    if b < a:
        a, b = b, a

    if b % a == 0:
        return a
    else:
        r = b % a
        return euclid_lcf(a, r)


com_factor = euclid_lcf(a[0], a[1])

if len(a) == 2:
    print(com_factor)
else:
    for i in range(2, len(a)):
        com_factor = euclid_lcf(com_factor, a[i])

    print(com_factor)
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
for j in range(N):
    if (A[j] != max(A)):
        print(max(A))
    elif(A.count(A[j]) != 1):
        print(A[j])
    else:
        print(sorted(A)[-2])

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
maxA = max(A)
secondA = sorted(A)[-2]
for j in range(N):
    if (A[j] != maxA):
        print(maxA)
    else:
        print(secondA)
### BUGGY CODE ###

k, s = map(int, input().split())
ans = 0

for i in range(k+1):
    for j in range(k+1):
        for m in range(k+1):

            if i + j + m == s:
                ans += 1

print(ans)


### FIXED CODE ###

k, s = map(int, input().split())
ans = 0

for i in range(k+1):
    for j in range(k+1):
        if (i + j <= s) and (s - i - j <= k):
            ans += 1

print(ans)
### BUGGY CODE ###

import collections
from scipy.special import comb

n = int(input())
aa = list(map(int, input().split()))
xx = [0]*n
for i in range(n):
  a = 0
  if i == 0:
    bb = aa[1:]
  elif i == n-1:
    bb = aa[:-1]
  else:
    bb = aa[:i] + aa[i+1:]
  cc = collections.Counter(bb)
  d = [c[1] for c in cc.items()]
  for j in range(len(d)):
    a += comb(d[j], 2, exact=True)
  print(a)

### FIXED CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
cnt = 0

c = collections.Counter(a)
for i in c:
  cnt += c[i]*(c[i]-1)//2



for i in range(n):
	print(cnt-c[a[i]]+1)
### BUGGY CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**7)

N=int(input())
M=N*(N-1)//2
D=[[]for i in range(M)]
F=[[]for i in range(M)]
for i in range(N):
  x=list(map(int,input().split()))
  for j in range(N-2):
    a,b,c=i+1,x[j],x[j+1]
    x1,x2=min(i+1,x[j]),max(i+1,x[j])
    y1,y2=min(i+1,x[j+1]),max(i+1,x[j+1])
    e=M-(N-x1)*(N-x1+1)//2
    f=e+(x2-x1-1)
    g=M-(N-y1)*(N-y1+1)//2
    h=g+(y2-y1-1)
    D[f].append(h)
    F[h].append(f)
P=[-1]*M
def bfs(u):
  P[u]=0
  queue=deque([u])
  while queue:
    v=queue.popleft()    
    for i in D[v]:
      if P[v]+1>P[i]:
        P[v]+1>P[i]
        P[i]=P[v]+1
        queue.append(i)
for i in range(M):
  if len(F[i])==0:
    bfs(i)
if min(P)==-1:
  print(-1)
else:
  print(max(P)+1)

### FIXED CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**7)

N=int(input())
M=N*(N-1)//2
D=[[]for i in range(M)]
F=[[]for i in range(M)]
for i in range(N):
  x=list(map(int,input().split()))
  for j in range(N-2):
    a,b,c=i+1,x[j],x[j+1]
    x1,x2=min(i+1,x[j]),max(i+1,x[j])
    y1,y2=min(i+1,x[j+1]),max(i+1,x[j+1])
    e=M-(N-x1)*(N-x1+1)//2
    f=e+(x2-x1-1)
    g=M-(N-y1)*(N-y1+1)//2
    h=g+(y2-y1-1)
    D[f].append(h)
    F[h].append(f)
    
q=deque()
P=[0]*M
for i in range(M):
  if len(F[i])==0:
    q.append((i,0))

r=[]
while q:
  v1,cnt=q.popleft()
  r.append((v1,cnt))
  for v2 in D[v1]:
    P[v2]+=1
    if P[v2]==len(F[v2]):
      q.append((v2,cnt+1))

if len(r)!=M:
  print(-1)
else:
  print(r[-1][-1]+1)
### BUGGY CODE ###

K, S = map(int, input().split())
ans = 0
for x in range(K + 1):
	for y in range(K + 1):
		for z in range(K + 1):
			if x + y + z == S:
				ans += 1
print(ans)


### FIXED CODE ###

K, S = map(int, input().split())
ans = 0
for x in range(K + 1):
	for y in range(K + 1):
			if 0 <= S - x - y <= K:
				ans += 1
print(ans)
### BUGGY CODE ###

S = input()
ans = 0
for i in range(len(S)):
    for j in range(100):
        if i+j+1 > len(S): break
        if int(S[i:i+j+1]) % 2019 == 0:
            ans += 1
print(ans)

### FIXED CODE ###

S = input()
r = 1
arr = [0]
for c in S[::-1]:
    arr.append((arr[-1] + int(c) * r) % 2019)
    r *= 10
    r %= 2019
from collections import Counter
ctr = Counter(arr)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)
### BUGGY CODE ###

from collections import defaultdict
s=input().strip()
t=input().strip()
def gg(cc, c, l, d):
    if d[c][-1] <= cc:
        return d[c][1], l+1
    ll = d[c]
    mx, mn = len(ll)-2, 0
    x = (mx - mn)//2
    while True:
        if ll[x] <= cc and cc < ll[x+1]:
            return ll[x+1], l
        if cc < ll[x]:
            mx = x
            x = (mx-mn)//2
        else:
            mn = x
            x = (mx-mn)//2

def main():
    ss=set(s)
    tt=set(t)
    if len(tt - ss) != 0: 
        return -1
    d = dict()
    for i, c in enumerate(s):
        if c not in d:
            d[c] = [0]
        d[c].append(i+1)
    cc, l = 0, 0
    for c in t:
        cc, l = gg(cc, c, l, d)
    return l*len(s) + cc

if __name__ == '__main__':
    print(main())



### FIXED CODE ###

from collections import defaultdict
s=input().strip()
t=input().strip()
def gg(cc, c, l, d):
    if d[c][-1] <= cc:
        return d[c][1], l+1
    ll = d[c]
    mx, mn = len(ll)-1, 0
    x = (mx + mn)//2
    while True:
#        print(x,cc,mx,mn,ll)
        if ll[x] <= cc and cc < ll[x+1]:
            return ll[x+1], l
        if cc < ll[x]:
            mx = x
            x = (mx+mn)//2
        else:
            mn = x
            x = (mx+mn)//2

def main():
    ss=set(s)
    tt=set(t)
    if len(tt - ss) != 0: 
        return -1
    d = dict()
    for i, c in enumerate(s):
        if c not in d:
            d[c] = [0]
        d[c].append(i+1)
    cc, l = 0, 0
    for c in t:
#        print(c)
        cc, l = gg(cc, c, l, d)
    return l*len(s) + cc

if __name__ == '__main__':
    print(main())
### BUGGY CODE ###

k,s=map(int,input().split())
a=0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z==s:
                a+=1
print(a)

### FIXED CODE ###

k,s=map(int,input().split())
a=0
b=0
c=0
l=0
while l*2<=s and l<=k:
    if s-l*2<=k:
        b+=1
    l+=1
if s%3==0:
    a+=1
    b-=1
for x in range(k+1):
    for y in range(x+1,k+1):
        if k>=s-x-y>y:
            c+=1
print(a+3*b+6*c)
### BUGGY CODE ###

import copy

n = int(input())
a = []

for _ in range(n):
  a.append(int(input()))

tmp = []

for i in range(len(a)):
  tmp = copy.deepcopy(a)
  del tmp[i]
  print(max(tmp))
  tmp.clear


### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
#print(a)
a_sort = sorted(a)
#print(a_sort)

max_number = a_sort[-1]
sub_max_number = a_sort[-2]

for i in range(n):
  if a[i] == max_number:
    print(sub_max_number)
  else:
    print(max_number)
### BUGGY CODE ###

#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections

N = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param

from math import gcd
import math
acc = a[0]
LIMIT=10**6
minPrime = [0]*(LIMIT+1)
minPrime[1] = 1
count = 0
for i in range(2,LIMIT):
    if minPrime[i] == 0:
        count += 1
        j = i
        while j <= LIMIT:
            if minPrime[j] == 0:
                minPrime[j] = i
            j += i
#print(minPrime)
def factrial(N):
    ret = []
    while minPrime[N] != N:
        ret.append(minPrime[N])
        N = N//minPrime[N]
    if N != 1:
        ret.append(N)
    return ret

for i in range(N):
    acc = gcd(acc,a[i])
if acc != 1:
    print("not coprime")
    exit()

pairwise = True
# facts = [set(factrial(e)) for e in a]
p = set() #all prime
#s = set(factrial(a[0])) # pair prime
for e in a:
    if not pairwise:
        break
    f = set(factrial(e))
    # s = s & f
    if p & f != set():
        pairwise = False
    p = p | f
#print(p,s,pairwise)

if pairwise:
    print("pairwise coprime")
else:
    print("setwise coprime")
# for s:
#     acc = math.gcd(acc,a[i])
# if acc != 1:
#     print("not coprime")
#     exit()
# print("pairwise coprime")
# for i in range(N):
#     for j in range(i+1,N):
#         b = gcd(a[i],a[j])
#         if b != 1:
#             print("setwise coprime")
#             exit()
# if pairwise == True:
#     print("pairwise coprime")
# else:
#     print("not coprime")


### FIXED CODE ###

import math
from collections import defaultdict
pc = True
n = int(input())
a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
    g = math.gcd(g,a[i])
M = max(a)
class Sieve_of_Eratosthenes:
    def __init__(self, N):
        self.sieve = [-1] * (N+1)
 
        for i in range(2,N+1):
            if self.sieve[i] == -1:
                for j in range(1,1+N//i):
                    self.sieve[i*j] = i
 
    def isprime(self, num):
        if num <= 1:
            return False
        else:
            return self.sieve[num] == num
 
    def factorization(self, num):
        ret = set([])
        while num != 1:
            div = self.sieve[num]
            ret.add(div)
            num //= div
        return ret
 
sofe = Sieve_of_Eratosthenes(M)
ddic = defaultdict()
judge = set([])
 
for i in a:
    if not pc:
        break
    asf = sofe.factorization(i)
    
    if judge & asf != set():
        pc = False
    judge |= asf
if pc:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")