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

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

def make_divisors(n):
    res = []
    x = n
    y = 2
    while y*y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1:
        res.append(x)
    return res

n = ni()
a = na()

wa = set(make_divisors(a[0]))
s = len(wa)
seki = wa

for i in range(1,n):
    ii = set(make_divisors(a[i]))
    s += len(ii)
    wa = wa | ii
    seki = seki & ii
    if s != len(wa) and len(seki) == 0:
        print('setwise coprime')
        exit()

if len(wa) == s:
    print('pairwise coprime')
elif len(seki) == 0:
    print('setwise coprime')
else:
    print('not coprime')

### FIXED CODE ###

from operator import truediv
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

def make_divisors(n):
    res = []
    x = n
    y = 2
    while y*y <= x:
        while x % y == 0:
            res.append(y)
            x //= y
        y += 1
    if x > 1:
        res.append(x)
    return res

n = ni()
a = na()
g = [0]*1000000

for i in range(n):
    ii = list(set(make_divisors(a[i])))
    b = True
    for p in ii:
        if g[p] == 0:
            g[p] += 1
        else:
            b = False
            break
    if not b:
        break
else:
    print('pairwise coprime')
    exit()

import math

k = a[0]
for i in a:
    k = math.gcd(k,i)
    if k == 1:
        print('setwise coprime')
        exit()

print('not coprime')
### BUGGY CODE ###

import numpy as np
N, M = [int(i) for i in input().split()]

INF = int(1e18)
G = np.full((N, N), INF)
for i in range(N):
    G[i][i] = 0

edge = []
for i in range(M):
    a, b, c = [int(i) for i in input().split()]
    a, b = a - 1, b - 1
    G[a][b] = G[b][a] = c
    edge.append((a, b, c))


rng = range(N)
for k in rng:
    for i in rng:
        for j in range(i + 1, N):
            x = G[i][k] + G[k][j]
            if G[i][j] > x:
                G[i][j] = G[j][i] = x;
                
ans = 0
for (a, b, c) in edge:
    flag = False
    for s in rng:
        if flag:
            break;
        for t in rng:
            flag = flag | (G[s][t] == G[s][a] + c + G[b][t])

    ans = ans + (flag == False)
print(ans)
    
        
    



### FIXED CODE ###

import numpy as np
N, M = [int(i) for i in input().split()]

INF = int(1e18)
G = np.full((N, N), INF)
for i in range(N):
    G[i][i] = 0

edge = []
for i in range(M):
    a, b, c = [int(i) for i in input().split()]
    a, b = a - 1, b - 1
    G[a][b] = G[b][a] = c
    edge.append((a, b, c))


rng = range(N)
for k in rng:
    for i in rng:
        for j in range(i + 1, N):
            x = G[i][k] + G[k][j]
            if G[i][j] > x:
                G[i][j] = G[j][i] = x;
                
ans = 0
for (a, b, c) in edge:
    ans = ans + (G[a][b] != c)
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

S = input()
Q = int(input())

preffix = ""
suffix = ""
revcnt = 0
for i in range(Q):
    query = input()
    if query[0] == "1":
        wk = preffix
        preffix = suffix
        suffix = wk
        suffix = suffix[::-1]
        preffix = preffix[::-1]
        revcnt += 1
    elif query[2] == "1":
        preffix = (query[4]+preffix)
    else:
        suffix += query[4]

if revcnt%2 == 1:
    S = S[::-1]

print(preffix+S+suffix)



### FIXED CODE ###

# -*- coding: utf-8 -*-

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

S = input()
Q = int(input())

preffix = ""
suffix = ""
revcnt = 0
for i in range(Q):
    query = input()
    if query[0] == "1":
        wk = preffix
        preffix = suffix
        suffix = wk
        revcnt += 1
    elif query[2] == "1":
        if revcnt %2 ==0:
            preffix = (query[4]+preffix)
        else:
            preffix += query[4]
    else:
        if revcnt %2 ==1:
            suffix = (query[4]+suffix)
        else:
            suffix += query[4]

if revcnt%2 == 1:
    S = S[::-1]
    suffix = suffix[::-1]
    preffix = preffix[::-1]


print(preffix+S+suffix)
### BUGGY CODE ###

import math
N=int(input().strip())
a=list(map(int, input().strip().split(' ')))
for i in range(N):
    a[i]=a[i]-(i+1)
b=sum(a)/N
ans1=0
ans2=0
for i in range(N):
    ans1+=abs(a[i]-math.floor(sum(a)/N))
for i in range(N):
    ans2+=abs(a[i]-math.ceil(sum(a)/N))


print(min(ans1,ans2))

### FIXED CODE ###

N=int(input().strip())
a=list(map(int, input().strip().split(' ')))
for i in range(N):
    a[i]=a[i]-i
a.sort()
m=a[(N-1)//2]
ans=0
for i in range(N):
    ans+=abs(a[i]-m)
print(ans)
### BUGGY CODE ###

N = int(input())
lis = [int(input()) for _ in range(N)]
l_copy = lis.copy()

for i in lis:
    lis = l_copy.copy()
    lis.remove(i)
    print(max(lis))



### FIXED CODE ###

N = int(input())
lis = [int(input()) for _ in range(N)]
lis_c = lis.copy()

mx1 = max(lis_c)
lis_c.remove(mx1)
mx2 = max(lis_c)

for i in lis:
    if i == mx1:
        print(mx2)
    else:
        print(mx1)
### BUGGY CODE ###

S = list(input())
Q = int(input())
for i in range(Q):
    a = list(input().split())
    if len(a) == 1:##T_i=1
        S.reverse()
    else:#T_i == 2
        if a[1] == "1":
            S.insert(0,a[2])
        else:
            S.append(a[2])

for i in range(len(S)):
    print(S[i],end="")


### FIXED CODE ###

S = input()
Q = int(input())
Atama = []
Osiri = []
rev = [0]*Q
for i in range(Q):
    a = list(input().split())
    if len(a) == 1:##T_i=1
        rev[i] = 1
    else:#T_i == 2
        if a[1] == "1":
            Atama.append([i,a[2],1])
        else:
            Osiri.append([i,a[2],-1])

##revの累積和
Rev = []
tmp = 0
r = sum(rev)
for i in range(len(rev)):
    r -= rev[i]
    Rev.append(r)
##print(Rev)
for i in range(len(Atama)):
    Atama[i][2] *= (-1)**Rev[Atama[i][0]]
for i in range(len(Osiri)):
    Osiri[i][2] *= (-1)**Rev[Osiri[i][0]]

Ans = Atama+Osiri
Ans.sort()
##print(Ans)
fw = ""
aw = ""
N = len(Ans)
for i in range(N):
    if Ans[i][2] == 1:
        fw += Ans[i][1]
    else:
        aw += Ans[i][1]

if sum(rev)%2 == 1:
    S = S[::-1]
fw = fw[::-1]

print(fw+S+aw)
### BUGGY CODE ###

N,K=map(int,input().split())
List = list(map(int, input().split()))
strength = [1]*N
for k in range (K):
  for i in range(N):
    if List[i] == 0:
      pass
    else:
      for j in range(1,List[i]+1):
        if i-j<0 and (i+j > N or i + j == N):
          pass
        elif i-j<0 and i+j <N:
          strength[i+j] += 1
        elif i-j>=0 and (i+j > N or i + j == N):
          strength[i-j] += 1
        else:
          strength[i-j] += 1
          strength[i+j] += 1
      #print(List,strength)
  List = strength
  strength = [1]*N
print(*List)

### FIXED CODE ###

N,K=map(int,input().split())
List = list(map(int, input().split()))
 
def imosu(x,k):
  data = [0]*k
  for i in range(k):
    first = i-x[i]
    last = i+x[i]
    if first < 0:
      first = 0
    data[first] += 1
    if last+1 < k:
      data[last+1] +=-1
  ruiseki = [0]*k
  ruiseki[0] = data[0]
  for i in range(k-1):
    ruiseki[i+1] = ruiseki[i] + data[i+1]
  return ruiseki
 
for i in range(K):
  List = imosu(List,N)
  if List.count(N) == N:
    break
print(*List)
### BUGGY CODE ###

N = int(input())
nums = [int(i) for i in input().split()]
from functools import reduce
def gcd(a,b):
  while b!=0:
    a, b = b, a%b
  return a
def compute_gcd(numbers):
    return reduce(gcd, numbers)
from copy import copy
gcds = []
for i in range(len(nums)):
    n = copy(nums)
    n.pop(i)
    gcds.append(compute_gcd(n))
print(max(gcds))

### FIXED CODE ###

N = int(input())
nums = [int(i) for i in input().split()]
nums_sorted = sorted(list((set(nums))), reverse=True)
def compute_divs(n):
    divs = []
    if n == 1: return [1]
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.append(n)
    return divs
ans = 1
if len(nums_sorted) == 1: ans = nums[0]
else:
    divs1 = compute_divs(nums_sorted[0])
    divs2 = compute_divs(nums_sorted[1])
    divs = sorted(list(set(divs1+divs2)))
    for i in reversed(divs):
        c= 0
        for j in nums:
            if j % i != 0:
                c += 1
                if c == 2:
                    break
        if c <= 1:
            ans = i
            break
print(ans)
### BUGGY CODE ###

N = int(input())

NL = []
PL = []
ans = 0

for i in range(N):
  NL.append(i+1)
  PL.append(i+2)
PL[N-1] = 1
  

for i in range(N):
  ans += NL[i] % PL[i]

print(ans)

### FIXED CODE ###

N = int(input())
print(N*(N-1)//2)
### BUGGY CODE ###

from itertools import takewhile

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

# 各マスについて、横方向に照らすマスの数と縦方向に照らすマスの数を求める
x = [[0 for _ in range(W)] for _ in range(H)]
y = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if x[i][j] == 0:
            c = len(list(takewhile(lambda k: S[i][k] == '.', range(j, W))))
            for k in range(j, j + c):
                if S[i][k] == '.':
                    x[i][k] = c
for i in range(H):
    for j in range(W):
        if y[i][j] == 0:
            c = len(list(takewhile(lambda k: S[k][j] == '.', range(i, H))))
            for k in range(i, i + c):
                if S[k][j] == '.':
                    y[k][j] = c
ans = max(
    x[i][j] + y[i][j] - 1
    for i in range(H)
    for j in range(W)
)
# 出力
print(ans)


### FIXED CODE ###

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

dp1 = [[0 for _ in range(W)] for _ in range(H)]
dp2 = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if dp1[i][j] == 0 and S[i][j] == '.':
            c = 0
            for k in range(i, H):
                if S[k][j] == '.':
                    c += 1
                else:
                    break
            for k in range(i, H):
                if S[k][j] == '.':
                    dp1[k][j] = c
                else:
                    break
for i in range(H):
    for j in range(W):
        if dp2[i][j] == 0 and S[i][j] == '.':
            c = 0
            for k in range(j, W):
                if S[i][k] == '.':
                    c += 1
                else:
                    break
            for k in range(j, W):
                if S[i][k] == '.':
                    dp2[i][k] = c
                else:
                    break

ans = max(
    dp1[i][j] + dp2[i][j] - 1
    for i in range(H)
    for j in range(W)
)
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
cards=[i for i in range(1,n+1)]
for i in range(m):
  a,b=map(int,input().split())
  l=[i for i in range(a,b+1)]
  cards=list(set(l)&set(cards))
print(len(cards))

### FIXED CODE ###

import sys
input=sys.stdin.readline

n,m=map(int,input().split())
leftgate=[]
rightgate=[]
for i in range(m):
  l,r=map(int,input().split())
  leftgate.append(l)
  rightgate.append(r)
if (min(rightgate)-max(leftgate))>-1:
  print(min(rightgate)-max(leftgate)+1)
else:
  print(0)
### BUGGY CODE ###

n = int(input())
s = input()
ans = float("inf")
for i in range(n):
    move = 0
    for j in range(n):
        if j < i and s[j] == "W":
            move += 1
        elif j > i and s[j] == "E":
            move += 1
    ans = min(ans, move)
print(ans)

### FIXED CODE ###

n = int(input())
s = list(input())
for i in range(n):
    if i:
        s[i] = s[i - 1] + int(s[i] == "E")
    else:
        s[i] = int(s[i] == "E")
s.append(s[n - 1])
ans = float("inf")
for i in range(n):
    rightE = s[n] - s[i]
    if i == 0:
        ans = min(ans, rightE)
    else:
        leftW = i - s[i - 1]
        ans = min(ans, leftW + rightE)
print(ans)
### BUGGY CODE ###

import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

l = [0] * (10**5 + 1)
c = collections.Counter(A)
for key in c:
    l[key] = c[key]

for i in range(Q):
    if B[i] in c:
        c[C[i]] += c[B[i]]
        c.pop(B[i])
    ans = 0
    for item in c:
        ans += item * c[item]
    print(ans)


### FIXED CODE ###

import collections

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

l = [0] * (10**5 + 1)
# print(l)
# print(len(l))
c = collections.Counter(A)
# print(c)
for key in c:
    l[key] = c[key]
# print(l)
ans = 0
for item in c:
    ans += item * c[item]

# print(ans)  # i=0

for i in range(Q):
    if B[i] in c:
        # print(c)
        ans = ans - B[i] * c[B[i]] + C[i] * c[B[i]]
        c[C[i]] += c[B[i]]
        c.pop(B[i])
    print(ans)
### BUGGY CODE ###

import sys

def solve(M,list_PY,list_Y):
    for i in range(M):
        ken = str(list_PY[i][0]).zfill(6)
        ban = str(list_Y[list_PY[i][0]-1].index(list_PY[i][1])+1).zfill(6)
        print(ken + ban)

def readQuestion():
    N,M = map(int, sys.stdin.readline().strip().split())
    list_PY = []#[[P1,Y1],[P2,Y2]...[Pn,Yn]]のリストを作る用
    list_Y = [[] for i in range(N)]#リストの中にN（県の数）個リストを作る
    
    for i in range(M):
        P,Y = map(int, sys.stdin.readline().strip().split())
        list_PY.append([P,Y])
        list_Y[P-1].append(Y)#「県の名前-1」を添え字にしてリストに入れる

    for i in range(N):
        if len(list_Y[i]) > 1:
            list_Y[i].sort()
            #print("sort",list_Y)
    return (M, list_PY, list_Y)

def main():
    M, list_PY, list_Y = readQuestion()
    answer = solve(M, list_PY, list_Y)
    return answer

if __name__ == '__main__':
    main()



### FIXED CODE ###

N,M=map(int,input().split())
PY=[list(map(int,input().split()))+[i] for i in range(M)] #定義終了
 
PY.sort(key= lambda x:x[1])
num=[0]*N
w=[""]*M
 
for p,y,i in PY:
	num[p-1]+=1
	w[i]=str(p).zfill(6)+str(num[p-1]).zfill(6)

for i in range(M):
  	print(w[i])
### BUGGY CODE ###

import sys
read=sys.stdin.buffer.readline

class BIT:
    def __init__(self,N):
        self.N=N
        self.bit=[0]*N
    def add(self,a,w):
        x=a
        while(x<self.N):
            self.bit[x]+=w
            x|=x+1
    def get(self,a):
        ret,x=0,a-1
        while(x>=0):
            ret+=self.bit[x]
            x=(x&(x+1))-1
        return ret
    def cum(self,l,r):
        return self.get(r)-self.get(l)

def main():
    def update(x,i):
        if good[x]==-1:
            good[x]=i
            bit.add(i,1)
        else:
            bit.add(good[x],-1)
            good[x]=i
            bit.add(good[x],1)
    
    N,Q=map(int,read().split())
    c=list(map(int,read().split()))
    li=[list(map(lambda x:int(x)-1,read().split()))+[i] for i in range(Q)]
    Query=[(li[i][0],li[i][1],i) for i in range(Q)]
    Query.sort(key=lambda x:x[1])
    ans=[-1]*Q
    good=[-1]*(N+1)
    bit=BIT(N)

    i=0
    for L,R,w in Query:
        while(i<=R and i<N):
            update(c[i],i)
            i+=1
        ans[w]=bit.cum(L,R+1)

    print(*ans,sep='\n')
    
if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
read=sys.stdin.buffer.readline

class BIT:
    def __init__(self,N):
        self.N=N
        self.bit=[0]*N
    def add(self,a,w):
        x=a
        while(x<self.N):
            self.bit[x]+=w
            x|=x+1
    def get(self,a):
        ret,x=0,a-1
        while(x>=0):
            ret+=self.bit[x]
            x=(x&(x+1))-1
        return ret
    def cum(self,l,r):
        return self.get(r)-self.get(l)

def main():
    def update(x,i):
        if good[x]==-1:
            good[x]=i
            bit.add(i,1)
        else:
            bit.add(good[x],-1)
            good[x]=i
            bit.add(good[x],1)
        return
    
    N,Q=map(int,read().split())
    c=tuple(map(int,read().split()))
    Query=[]
    for i in range(Q):
        l,r=map(lambda x:int(x)-1,read().split())
        Query.append((l,r,i))
    Query.sort(key=lambda x:x[1])
    ans=[-1]*Q
    good=[-1]*(N+1)
    bit=BIT(N)

    i=0
    for L,R,w in Query:
        while(i<=R):
            update(c[i],i)
            i+=1
        ans[w]=bit.cum(L,R+1)

    print(*ans,sep='\n')
    return
    
if __name__=='__main__':
    main()
### BUGGY CODE ###

lis =[]
abc =[]
count = 0

N = int(input())
for _ in range(N):
    lis.append(input())

for i in lis:
    if any(i == j for j in abc):
        pass
    else:
        abc.append(i)
        count += 1

print(count)
    

### FIXED CODE ###

n = int(input())

ans = len(set(input() for i in range(n)))

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

import sys
from itertools import accumulate
import bisect
import numpy as np
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
H,W = inputs()
meiro = [tuple(input()) for i in range(H)]
#print(meiro)
imosw = [[0]*(W) for _ in range(H)]
imosh = [[0]*(W) for _ in range(H)]
for i in range(H):
    cnt=0
    for j in range(W):
        if meiro[i][j]=="#":
            if cnt!=0:
                imosw[i][j]-=cnt
                imosw[i][j-cnt]+=cnt
            cnt = 0
        else:
            cnt+=1
    if cnt!=0:
    	imosw[i][W-1-cnt+1]+=cnt
for j in range(W):
    cnt= 0
    for i in range(H):
        if meiro[i][j]=="#":
            if cnt!=0:
                imosh[i][j]-=cnt
                imosh[i-cnt][j]+=cnt
            cnt = 0
        else:
            cnt+=1
    if cnt!=0:
    	imosh[H-1-cnt+1][j]+=cnt
imosw = np.cumsum(imosw, axis=1)
imosh = np.cumsum(imosh, axis=0)
ans = np.max(imosw+imosh)-1
print(ans)

### FIXED CODE ###

H, W = map(int, input().split())
meiro = [list(input()) for i in range(H)]
right = [[0 for _ in range(W)] for _ in range(H)]
left= [[0 for _ in range(W)] for _ in range(H)]
up = [[0 for _ in range(W)] for _ in range(H)]
down = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    cur=0
    for j in range(W):
        if meiro[i][j]=="#":
            cur = 0
        else:
            cur +=1
        left[i][j]=cur
for i in range(H):
    cur=0
    for j in range(W-1,-1,-1):
        if meiro[i][j]=="#":
            cur = 0
        else:
            cur +=1
        right[i][j]=cur
for i in range(W):
    cur=0
    for j in range(H):
        if meiro[j][i]=="#":
            cur = 0
        else:
            cur +=1
        up[j][i]=cur
for i in range(W):
    cur=0
    for j in range(H-1,-1,-1):
        if meiro[j][i]=="#":
            cur = 0
        else:
            cur +=1
        down[j][i]=cur
res = 0
for i in range(H):
    for j in range(W):
        res = max(res,right[i][j]+left[i][j]+up[i][j]+down[i][j]-3)
print(res)
### BUGGY CODE ###

S=list(input())

i=0
while i<len(S)-1:
  if S[i]=="B" and S[i+1]=="C":
    S[i]="D"
    S.pop(i+1)
  i+=1
    
t=[]
nl=[]
for i in S:
  if i=="A" or i=="D":
    nl.append(i)
  else:
    t.append(nl)
    nl=[]
t.append(nl)

T=list(filter(lambda x:len(x)>0,t))

ans=0
for i in T:
  dn=0
  for j in range(len(i)):
    if i[j]=="D":
      ans+=j-dn
      dn+=1

print(ans)


### FIXED CODE ###

S=list(input())

nS=[]
i=0
while i<len(S)-1:
  if S[i]=="B" and S[i+1]=="C":
    nS.append("D")
    i+=1
  else:
    nS.append(S[i])
  i+=1
    
t=[]
nl=[]
for i in nS:
  if i=="A" or i=="D":
    nl.append(i)
  else:
    if nl:
      t.append(nl)
      nl=[]
if nl:
  t.append(nl)


ans=0
for i in t:
  dn=0
  for j in range(len(i)):
    if i[j]=="D":
      ans+=j-dn
      dn+=1

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

from math import gcd

n=int(input().strip())
s=input().strip()

c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] == s[j]:
            continue
        for k in range(j+1,n):
            if j - i == k - j:
                continue
            if s[i] == s[k]:
                continue
            if s[j] == s[k]:
                continue
            c += 1
print(c)


### FIXED CODE ###

from math import gcd

n=int(input().strip())
s=input().strip()

r = 0
g = 0
for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
ans = r * g * (n - r - g)

for i in range(0, n-1):
    for d in range(1, (n - i + 1) // 2):
        if s[i] != s[i+d] and s[i] != s[i+d+d] and s[i+d] != s[i+d+d]:
            ans -= 1
print(ans)
### BUGGY CODE ###

s=input()
n=len(s)

modlist=[]

for i in range(n):
  modlist.append(int(s[i:])%2019)

modlist.append(0)
 
result = 0
  
for i in range(2019):
  c = modlist.count(i)
  if c<=1:
    result += 0
  else:
    result += c*(c-1)/2

print(int(result))

### FIXED CODE ###

s = input()[::-1]

dp = [0]*2019
dp[0]=1
total = 0
a = 1

for i in list(s):
  total += int(i)*a
  total %= 2019
  dp[total] += 1
  a *= 10
  a %= 2019
count=0
  
for i in range(2019):
    count += dp[i]*(dp[i]-1)//2
 
print(count)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
import collections

def main():
    N = int(input())
    Q = [collections.deque(map(int, input().split())) for _ in range(N)]
    games = N*(N-1)//2
    L = [N-1 for _ in range(N)]

    days = 0
    while True:
        gamed = [0 for _ in range(N)]
        b = False
        for i in range(N-1):
            if gamed[i] > 0 or L[i] == 0:
                continue
            j = Q[i][0] - 1
            if gamed[j] > 0 or L[j] == 0:
                continue
            if Q[j][0] == i+1:
#                print("game:", j+1, i+1, days)
                Q[i].popleft()
                Q[j].popleft()
                gamed[i] = 1
                gamed[j] = 1
                L[i] -= 1
                L[j] -= 1
                games -= 1
                b = True
                continue
        days += 1
        if not b:
            print(-1)
            return
        if games == 0:
            break

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


### FIXED CODE ###

import sys
input=sys.stdin.readline
from collections import deque

def main():
    N = int(input())
    Q = [deque(map(int, input().split())) for _ in range(N)]
    games = N*(N-1)//2

    days = 0
    nxt = [i for i in range(N)] # 翌日に対戦相手を更新する選手のリスト
    opp = [0]*N # 選手毎の、次の対戦相手のリスト
    while 1:
        days += 1
        for i in nxt:
            opp[i] = Q[i].popleft() - 1 if Q[i] else -1

        tmp = set() # 次の日の更新のため、試合をした選手をメモ
        for i in nxt:
            if i not in tmp and i == opp[opp[i]]:
#                print("game:", i+1, opp[i]+1, days)
                tmp.add(i)
                tmp.add(opp[i])
                games -= 1
        if games == 0:
            break
        elif not tmp:
            print(-1)
            return
        nxt = tmp
    print(days)

if __name__ == '__main__':
    main()