Harryxun/stf_run huggingface dataset:
import bisect


def CumulativeSum(l):
    a = [0]
    for i in l:
        a.append(a[-1] + i)
    return a[1:]


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    b = CumulativeSum(a)
    s = b[-1]
    h = s // 2
    x = bisect.bisect_left(b, h)
    m1, m2 = b[x], b[x + 1]
    if s % 2 == 0 and h in (m1, m2):
        print(0)
        return
    a = []
    for (i, j) in ((m1, x), (m2, x + 1)):
        t = 0
        n = s
        while True:
            if i * 2 == n:
                a.append(t)
                break
            t += 1
            if i * 2 < n:
                i += 1
                n += 1
            elif j < i:
                i -= 1
                n -= 1
            else:
                n += 1
    print(min(a))


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import bisect


def CumulativeSum(l):
    a = [0]
    for i in l:
        a.append(a[-1] + i)
    return a[1:]


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    b = CumulativeSum(a)
    s = b[-1]
    h = s // 2
    x = bisect.bisect_left(b, h)
    try:
        m = (b[x], b[x + 1], b[x - 1])
    except:
        m = (b[x], b[x - 1])
    if s % 2 == 0 and h in m:
        print(0)
        return

    print(min([abs(x * 2 - s) for x in m]))


if __name__ == '__main__':
    resolve()
import numpy
def DP():
  n,m=map(int,input().split())
  dp=[0]*(m+2)
 
  for i in range(n):  #商品を一つずつ見ていく。
    w,v=(map(int,input().split()))
    for j in range(m+1,w,-1): #w~(限界-w)までのdpの箱に入れていく。(例)w,m=3,8なら3~5
      dp[j]=max(dp[j-w]+v,dp[j])
  return max(dp)
print(DP())


### FIXED CODE ###

def DP():
    n,W = map(int, input().split(' '))
    WV = (map(int, input().split(' ')) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in WV:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(DP())
S = input()
remove_x = S.replace('x','')

count = 0
index = 0
left = 0
right = 0
ans = 0
s_len = len(S)

if remove_x != remove_x[::-1]:
    print(-1)
else:
    if len(remove_x) % 2 == 0:
        center = len(remove_x) // 2
        for i, s in enumerate(S):
            if s != 'x':
                count += 1
            if count == center:
                index = i
                break
        left = index
        x_count = 0
        j = left+1
        while S[j] == 'x' and j < s_len:
            x_count += 1
            j += 1
        if x_count % 2 != 0:
            ans += 1
        right = j
        #print(f'{right=}')
    else:
        center = len(remove_x) // 2 + 1
        for i, s in enumerate(S):
            if s != 'x':
                count += 1
            if count == center:
                index = i
                break
        left = index - 1
        right = index + 1 


    #print(f'{left}, {right}')
    while left >= 0 and right < s_len:
        if S[left] != S[right]:
            if S[left] == 'x':
                ans += 1
                left -= 1
            elif S[right] == 'x':
                ans += 1
                right += 1
        else:
            left -= 1
            right += 1

    if right != s_len:
        ans += s_len - right
    else:
        ans += left + 1

    print(ans)

### FIXED CODE ###

from collections import deque

S = input()

d = deque(S)


left = 0
right = len(d) - 1

count = 0
while left < right:
    #print(f'{left=}, {right=}')
    if d[right] == d[left]:
        left += 1
        right -= 1
    else:
        if d[right] == 'x':
            count += 1
            right -= 1
        elif d[left] == 'x':
            count += 1
            left += 1
        else:
            count = -1
            print(-1)
            break

if count != -1:
    print(count)
N, A, B, C, D = map(int, input().split())
 
S = input()
 
S = S + '#'
 
def continuous_rock_search(S, C, D):
    target = max(C, D)
    for i in range(target - 1):
        if S[i] == '#' and S[i+1] == '#':
            return True
    return False
  
def validation_funuke_move(S, B, D):
    '''
    ふぬけ君が両隣に岩がなくなるまで移動したとき、Dより向こうにはイカないことを確認する。
    True/False and ふぬけの移動後の位置
    '''
    funuke_position = B
    while (B <= D):
        if (S[B-2] == '#' or S[B] == '#'):
            if S[B] == '.' :
                B = B + 1
            else:
                B = B + 2
        elif (S[B-2] == '.' and S[B] == '.'):
            return True, B
    
    return False, -1
  
def KenKenRace(S, A, B, C, D):
    if continuous_rock_search(S):
        return False
    
    if C < D:
        return True
    
    if D < C:
        valid , _ = validation_funuke_move(S, B, D)
        if valid:
            return True
        else:
            return False
          
if KenKenRace(S, A, B, C, D):
    print('Yes')
else:
    print('No')


### FIXED CODE ###

N, A, B, C, D = map(int, input().split())
 
S = input()
 
S = S + '#'
 
def continuous_rock_search(S, A, B, C, D):
    begin = min(A, B)
    target = max(C, D)
    for i in range(begin, target - 1):
        if S[i] == '#' and S[i+1] == '#':
            return True
    return False
  
def validation_funuke_move(S, B, D):
    '''
    ふぬけ君が両隣に岩がなくなるまで移動したとき、Dより向こうにはイカないことを確認する。
    True/False and ふぬけの移動後の位置
    '''
    funuke_position = B
    while (B <= D):
        if (S[B-2] == '#' or S[B] == '#'):
            if S[B] == '.' :
                B = B + 1
            else:
                B = B + 2
        elif (S[B-2] == '.' and S[B] == '.'):
            return True, B
    
    return False, -1
  
def KenKenRace(S, A, B, C, D):
    if continuous_rock_search(S, A, B, C, D):
        return False
    
    if C < D:
        return True
    
    if D < C:
        valid , _ = validation_funuke_move(S, B, D)
        if valid:
            return True
        else:
            return False
          
if KenKenRace(S, A, B, C, D):
    print('Yes')
else:
    print('No')
N, K = input().strip().split()
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))

### FIXED CODE ###

N, K = map(int, input().split())
h = list(map(int, input().split()))
count = [i for i in h if i >= K]
print(len(count))
import numpy as np
H,W,A,B = map(int, input().split())

mat = np.zeros((H,W))

if H==1 and W!=1:
    for i in range(A):
        mat[0][i]=1
    
elif H!=1 and W!=1: 
    for i in range(B):
        mat[i][0]=1
else:
    for y in range(H):
        for x in range(W):

            if sum(mat[:,x]) < A:
                mat[y][x] = 1

            if sum(mat[y]) == B:
                break


### FIXED CODE ###

import numpy as np
H,W,A,B = map(int, input().split())

mat = np.zeros((H,W))

for y in range(B):
    for x in range(A,W):
        mat[y][x]=1

for y in range(B,H):
    for x in range(A):
        mat[y][x]=1

for row in mat:
    row=list(map(int, row))
    print("".join(list(map(str, row))))
N = int(input())
dL = []

for n in ranege(N+1):
  dL.append(int(input()))

dL.sort()
counter = 0

for n in range(N+1):
  if dL[n] == dL[n+1]:
    pass
  else:
    counter += 1

if counter == 0:
  counter = 1

print(counter)

### FIXED CODE ###

N = int(input())
dL = [0]*N
for n in range(N):
  dL[n] = int(input())
print(len(list(set(dL))))
a, b = list(map(int, input().split()))
print((a*3+p)//2)

### FIXED CODE ###

a, b = list(map(int, input().split()))
print((a*3+b)//2)
def is_9(arr):
    s = []
    for i in range(len(arr)):
        if arr[i] != '9':
            return False
        s.append(arr[i])
    return sum(s)


n = list(input())
fd = int(n.pop(0))
if is_9(n):
    print(fd + int(is_9(n)))
print(fd - 1 + int(9 * len(n)))


### FIXED CODE ###

def is_9(arr):
    s = []
    for i in range(len(arr)):
        if arr[i] != '9':
            return False
        s.append(arr[i])
    return True


n = list(input())
fd = int(n.pop(0))
if is_9(n):
    print(fd + int(9 * len(n)))
else:
    print(fd - 1 + int(9 * len(n)))
s = input()
k = 0
ans = 0
for i in range(s):
    if s[i] == "A" or "G" or "C" or "T":
        k += 1
    else:
        ans = max(ans, k)
        k = 0
ans = max(ans, k)
print(ans)

### FIXED CODE ###

s = input()
k = 0
ans = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "G" or s[i] == "C" or s[i] == "T":
        k += 1
    else:
        ans = max(ans, k)
        k = 0

ans = max(ans, k)
print(ans)
s = input()
if s == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit(0)
l = list('abcdefghijklmnopqrstuvwxyz')
for i in range(26):
    if l[i] != s[i]:
        print(s[:i-1] + l[i])
        exit(0)

### FIXED CODE ###

s = list(input())
m = list('zyxwvutsrqponmlkjihgfedcba')
if len(s) < 26:
    for i in m[::-1]:
        if not i in s:
            s.append(i)
            break
    print(''.join(s))
else:
    x = s[-1]

    for i in range(25)[::-1]:
        if x > s[i]:
            y = m.index(s[i])
            s = s[:i]
            for j in range(y)[::-1]:
                if not m[j] in s:
                    s.append(m[j])
                    break
            break
        else:
            x = s[i]
        if i == 0:
            print(-1)
            exit(0)
    print(''.join(s))
n=input()
s=len(n)
d=int((s-1)/2)
p=int(s+3)/2
m=n[::-1]
n1=n[0:d-1]
n2=n1[::-1]
n3=n[p-1:]
n4=n3[::-1]
if n==m and n1==n2 and n3==n4:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n=input()
s=len(n)
d=int((s-1)/2)
p=int((s+3)/2)
m=n[::-1]
n1=n[0:d]
n2=n1[::-1]
n3=n[p-1:]
n4=n3[::-1]
if n==m and n1==n2 and n3==n4:
    print("Yes")
else:
    print("No")
N, K = list(map(int, input().split()))

def c(n, k):
    result = 1
    for i in range(k):
        result *= n - i
    for i in range(k):
        result /= i + 1
    return int(result)

denom = (10 ** 9 + 7)
total = 0
for i in range(K):
    ni = (c(K-1, i) % denom) * (c(N-K+1, i+1) % denom)
    print(ni % denom)



### FIXED CODE ###

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

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(K):
    ni = (cmb(K-1, i, mod)) * (cmb(N-K+1, i+1, mod))
    print(ni % mod)
X, N = map(int, input().split())

if N == 0:
    print(X)

else:
    p = list(map(int, input().split()))
    q = [i for i in range(-1, 102)]

    for r in p:
        idx = q.index(r)
        del q[idx]

    if X in q:
        print(X)

    else:
        q.sort()
        mindif = 100

        for num in q:
            dif = abs(X - num)
            if mindif <= dif:
                break
            else:
                mindif = dif
                ans = num
        print(ans)


### FIXED CODE ###

X, N = map(int, input().split())

if N == 0:
    print(X)

else:
    p = list(map(int, input().split()))
    q = [i for i in range(-1, 102)]

    for r in p:
        idx = q.index(r)
        del q[idx]

    if X in q:
        print(X)

    else:
        q.sort()
        mindif = 1000

        for num in q:
            dif = abs(X - num)
            if mindif <= dif:
                break
            else:
                mindif = dif
                ans = num
        print(ans)
def isOver(a,b):
    return True if (a[0]-b[0])**2 + (a[1]-b[1])**2 <= 4.0 else False
 
def largestGroup(mtrx,num):
    mx = 1
    ls = [num]
    #for i in mtrx[num]:
    #    if i == num:
    #    	continue
    #   	m = youKnow(mtrx,ls,i)
    #    mx = max(mx,m)
    return mx
 
def youKnow(mtrx,ls,num):
    mx = len(ls)
    if set(ls) <= set(mtrx[num]):
        if num not in ls:
            ls.append(num)
        for i in list(set(mtrx[num])-set(ls)):
            m = youKnow(mtrx,ls,i)
            mx = max(mx,m)
    return mx
 
while True:
    max_over = 0
    n = int(raw_input())
    if n == 0: break
    seals = [map(float, raw_input().split(",")) for i in range(n)]
 
    overs = []
    for i in range(n):
        over = []
        for j in range(n):
            if isOver(seals[i],seals[j]):
                over.append(j)
        overs.append(over)
         
    ref = [i for i in range(n)]
    for i in ref:
       num_over = largestGroup(overs,i)
       for j in overs[i]:
           ref.remove(j)
       if num_over > max_over:
           max_over = num_over
    print max_over

### FIXED CODE ###

def isOver(array,x,y):
	return True if (array[0]-x)**2+(array[1]-y)**2 <= 1.01 else False
	
while True:
    mx = 0
    n = int(raw_input())
    if n == 0: break
    seals = [map(float, raw_input().split(",")) for i in range(n)]
    x = 0
    while x < 10.0:
    	y = 0.0
    	while y < 10.0:
    		num = 0
    		for seal in seals:
    			if isOver(seal,x,y):
    				num += 1
    		mx = max(mx,num)
    		y += 0.1
        x += 0.1
    print mx
A,B,N = list(map(int,input().split()))
if N <= 10000:
    C = [A*i//B-(A*(i//B)) for i in range(0,N+1)]
    print(max(C))
    exit()
C = [A*i//B-(A*(i//B)) for i in range(100)]
D = [A*i//B-(A*(i//B)) for i in range(N,N-100,-1)]
print(max(max(C),max(D),max(E)))


### FIXED CODE ###

import math
A,B,N = list(map(int,input().split()))
if B > N:
    print(math.floor(A*N/B)-A*math.floor(N/B))
else:
    print(math.floor(A*(B-1)/B)-A*math.floor((B-1)/B))
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
import statistics
import heapq

input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = getInputInt()
data = getInputListInt()
l = len(data)

ans = []

for i in range(l-1, -1, -1):
    cnt = 0
    for j in ans:
        if j % (i+1) == 0:
            cnt += 1
    if data[i] != cnt % 2:
        ans.append(i+1)

if len(ans) == 0:
    print(0)
else:
    print(len(ans))
    print(*ans, sep=" ")




### FIXED CODE ###

import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()

    b = [0 for i in range(n)]
    ans = []

    for i in range(n // 2, n):
        if a[i] == 1:
            b[i] = a[i]
            ans.append(i + 1)

    for i in range(n // 2 - 1, -1, -1):
        cnt = 0
        for j in range(i * 2 + 1, n, i + 1):
            cnt ^= b[j]
        if cnt != a[i]:
            b[i] = 1
            ans.append(i + 1)

    tmp = len(ans)
    print(tmp)
    if tmp > 0:
        print(*ans, sep=" ")


if __name__ == '__main__':
    main()
a,b = int(raw_input().split())
print (a*b),(a*2+b*2)

### FIXED CODE ###

a,b = map(int,raw_input().split())
print ("{0} {1}").format(a*b,2*a+2*b)
S = input()
if S[0] == S[1] and S[2] ==S[3]:
  print("Yes")
elif S[0] == S[2] and S[1] ==S[3]:
  print("Yes")
elif S[0] == S[3] and S[2] ==S[1]:
  print("Yes")
else:
  prnt("No")

### FIXED CODE ###

S = input()
if S[0] == S[1] and S[2] == S[3] and S[0] == S[2]:
    print("No")
elif S[0] == S[1] and S[2] == S[3]:
    print("Yes")
elif S[0] == S[2] and S[1] == S[3]:
    print("Yes")
elif S[0] == S[3] and S[2] == S[1]:
    print("Yes")
else:
    print("No")
import math
def C(n,r,mod):
  #a=math.factorial(n)/(math.factorial(r)*math.factorial(n-r))
  print(n,r)
  r=min(r,n-r)
  numer=1
  for i in range(n,n-r,-1):
    numer*=i
  denom=1
  for i in range(r,1,-1):
    denom*=i
  a=int(numer/denom)
  return int(a%mod)

x,y=map(int,input().split())
mod=1e9+7

if (x+y)%3!=0:
  print(0)
  exit()
n=int((2*x-y)/3)
m=int((2*y-x)/3)
if n<0 and m<0:
  print(0)
  exit()
print(C(n+m,n,mod))


### FIXED CODE ###

a=int(input())
a=a*a
print(a)
import numpy as np
import sys
from functools import lru_cache

def main():
    n, q = map(int, input().split())
    ab = [[],[]]
    
    for i in range(n-1):
        na,nb = map(int, input().split())
        ab[0].append(na)
        ab[1].append(nb)

    px = [[],[]]
    for i in range(q):
        np,nx = map(int, input().split())        
        px[0].append(np)
        px[1].append(nx)
    
    # print(n,q,ab,px)
    count = [0 for i in range(n)]

    lgth = max(ab[0])
    node =[[] for i in range(lgth)]
    for i in range(n-1):
        index = ab[0][i]-1
        put = ab[1][i]
        node[index].append(put)

    # print(node)
    @lru_cache(maxsize = 1000)
    def calc(idx,val):
        count[idx] += val

        if idx <= lgth-1:
            for j in node[idx]:
                calc(j-1,val)
        
    for i in range(len(px[0])):    
        calc(px[0][i]-1, px[1][i])
    
    print(' '.join(map(str,count)))


if __name__ == '__main__':
    main()

### FIXED CODE ###

import numpy as np
import sys
from functools import lru_cache

def main():
    n, q = map(int, input().split())
    ab = [[],[]]
    
    for i in range(n-1):
        na,nb = map(int, input().split())
        ab[0].append(na)
        ab[1].append(nb)

    px = [[],[]]
    for i in range(q):
        np,nx = map(int, input().split())        
        px[0].append(np)
        px[1].append(nx)
    
    # print(n,q,ab,px)
    count = [0 for i in range(n)]

    oya_list = [0 for i in range(n)]
    for i in range(len(ab[1])):
        oya_list[ab[1][i]-1] = ab[0][i]
    
    for i in range(len(px[1])):
        count[px[0][i]-1] += px[1][i]
        
    for i in range(1,n):

        count[i] += count[oya_list[i]-1]
    
    print(' '.join(map(str,count)))


if __name__ == '__main__':
    main()
n,k=map(int,input().split())
lst_1=list(map(int,input().split()))
# print(lst_1)
lst_2=[]
for i in range(n-k+1):
    temp=1
    temp=lst_1[i+k]/lst_1[i]
    lst_2.append(temp)
print(lst_2)
for i in range(len(lst_2)-1):
    if lst_2[i]<lst_2[i+1]:
        print("Yes")
    else:print("No")


### FIXED CODE ###

n,k=map(int,input().split())
lst_1=list(map(int,input().split()))
# print(lst_1)
lst_2=[]
for i in range(n-k):
    temp=1
    temp=lst_1[i+k]/lst_1[i]
    lst_2.append(temp)
for i in lst_2:
    if i>1:
        print("Yes")
    else:print("No")
N = int(input())
A = int(input())

print("Yes" if N % A and N % 500 else "No")

### FIXED CODE ###

N = int(input())
A = int(input())

print("Yes" if N % 500 <= A else "No")
import numpy as np
a, b, n = map(int, input().split())
x = np.arange(1, n + 1)
y = np.floor(a * x / b) - a * np.floor(x / b)
print(int(y.max()))

### FIXED CODE ###

import math
a, b, n = map(int, input().split())
x = min(b - 1, n)
print(math.floor(a * x / b) - a * math.floor(x / b))
seq = input()
seq_list = []
for char in seq :
    if char == "A":
        char2 = "T"
    elif char == "T":
        char2 = "A"
    elif char == "G":
        char2 = "C"
    elif char == "C":
        char2 = "G"
    seq_list.append(char2)
return("".join(seq_list))

### FIXED CODE ###

char = input()
if char == "A":
    char2 = "T"
elif char == "T":
    char2 = "A"
elif char == "G":
    char2 = "C"
elif char == "C":
    char2 = "G"
print(char2)
M = int(input())
A = list(map(int,input().split()))
B = [0]*(M+1)
C = [0]*2
D = [0]*2

for i in range(len(A)):
		B[ A[i] ] += 1 # カウント

		# Ai = 1, 1, 2, 3, 2, 4
		# B[1] = 2
		# B[2] = 2
		# B[3] = 1
		# B[4] = 1
		# B[100000] = ***

for i in range(len(B)):
	# 一個しかなかったら条件を満たさないのでするー
	if B[i] < 2: continue

	# 2個以上あれば長方形にスタック
	C.append(i)

	# 4個以上あれば正方形にスタック
	if B[i] >= 4: D.append(i)
# C を降順でソート
C = sorted(C, reverse=True)

rect = C[0] * C[1]
s = max(D)
square = s * s

print(max(rect,square))

### FIXED CODE ###

M = int(input())
A = list(map(int,input().split()))
B = {}
C = [0]*2
D = [0]*2

for i in range(len(A)):
	a = str(A[i])
	# 存在したらカウントアップ
	if (a in B): B[ str(A[i]) ] += 1 # カウント
	# 存在しなかったら 1 で初期化
	else: B[ str(A[i]) ] = 1 # カウント
	# {"1":2, "2":3, "3":1}

for i in B:
	# 一個しかなかったら条件を満たさないのでスルー
	# i: string, B[i] = count
	if B[i] < 2: continue

	# 2個以上あれば長方形にスタック
	C.append(int(i))

	# 4個以上あれば正方形にスタック
	if B[i] >= 4: D.append(int(i))

# C を降順でソート
C = sorted(C, reverse=True)

rect = C[0] * C[1]
s = max(D)
square = s * s

print(max(rect,square))
s = input()
k = int(input())
t = sorted(s)[k-1]
data = []
for i in range(len(s)):
    if s[i] <= t:
        data.append(s[i:])
data.sort()
if len(data) > k:
    data = data[:k]

ndata = []
for ss in data:
    for i in range(len(ss)):
        ndata.append(ss[:i+1])
ndata = list(set(ndata))
ndata.sort()
print(ndata[k-1])

### FIXED CODE ###

s = input()
k = int(input())
t = sorted(s)[min(k-1,len(s)-1)]
data = []
for i in range(len(s)):
    if s[i] <= t:
        data.append(s[i:])
data.sort()
if len(data) > k:
    data = data[:k]

ndata = []
for ss in data:
    for i in range(len(ss)):
        ndata.append(ss[:i+1])
ndata = list(set(ndata))
ndata.sort()
print(ndata[k-1])
n = int(input())

A = [0]*n
for i in range(n):
    a = list(map(int, input().split()))
    a = [a_-1 for a_ in a]
    A[i] = a

g = [[] for i in range(n*(n-1)//2)]
id = [[[-1] for i in range(n)] for j in range(n)]

temp = 0
for i in range(n-1):
    for j in range(i+1, n):
        id[i][j] = temp
        id[j][i] = temp
        temp += 1

for i in range(n):
    for j in range(n-2):
        g[id[i][A[i][j]]].append(id[i][A[i][j+1]])

visit = [-1]*(n*(n-1)*2)
clc = [-1]*(n*(n-1)*2)
dp = [1]*(n*(n-1)*2)
def dfs(v):
    if visit[v] != -1:
        if clc[v] == -1:
            return -1
        return dp[v]
    visit[v] = 0
    for u in g[v]:
        res = dfs(u)
        if res == -1:
            return -1
        dp[v] = max(dp[v], res+1)
    clc[v] = 0
    return dp[v]

ans = 0
for i in range(n*(n-1)//2):
    res = dfs(i)
    if res == -1:
        print(-1)
        exit()
    ans = max(ans, res)
print(ans)

### FIXED CODE ###

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

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

    A = [0]*n
    for i in range(n):
        a = list(map(int, input().split()))
        a = [a_-1 for a_ in a]
        A[i] = a

    g = [[] for i in range(n*(n-1)//2)]
    id = [[[-1] for i in range(n)] for j in range(n)]

    temp = 0
    for i in range(n-1):
        for j in range(i+1, n):
            id[i][j] = temp
            id[j][i] = temp
            temp += 1

    for i in range(n):
        for j in range(n-2):
            g[id[i][A[i][j]]].append(id[i][A[i][j+1]])

    visit = [-1]*(n*(n-1)*2)
    clc = [-1]*(n*(n-1)*2)
    dp = [1]*(n*(n-1)*2)
    def dfs(v):
        if visit[v] != -1:
            if clc[v] == -1:
                return -1
            return dp[v]
        visit[v] = 0
        for u in g[v]:
            res = dfs(u)
            if res == -1:
                return -1
            dp[v] = max(dp[v], res+1)
        clc[v] = 0
        return dp[v]

    ans = 0
    for i in range(n*(n-1)//2):
        res = dfs(i)
        if res == -1:
            print(-1)
            exit()
        ans = max(ans, res)
    print(ans)

if __name__ == '__main__':
    main()