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

n = int(input())
dp = [0]*n
cnt = 0
L = []
flag = True
for i in range(n):
  T = []
  N = list(map(int,input().split()))
  for j in range(n-1):
    T.append((i+1,N[j]))
  L.append(T)
while dp != [n-1]*n:
  B = [0]*n
  act = 0
  for i in range(n):
    if B[i] == 0:
      B[i] = 1
      if dp[i] != n-1:
        miru = L[i][dp[i]][1]
        if dp[miru-1] == n-1:
          flag = False
          break
        else:
          if B[miru-1] != 1:
            if L[miru-1][dp[miru-1]][1] == i+1:
              dp[i] += 1
              dp[miru-1] += 1
              B[miru-1] = 1
              act += 1
  if act == 0:
    dp = [n-1]*n
    flag = False
  if cnt >= 100000:
      dp = [n-1]*n
  cnt += 1
if flag == False:
  print(-1)
else:
  print(cnt)

### FIXED CODE ###

import time
start = time.time()
n = int(input())
dp = [0]*n
cnt = 0
L = []
flag = True
for i in range(n):
  T = []
  N = list(map(int,input().split()))
  for j in range(n-1):
    T.append((i+1,N[j]))
  L.append(T)
while dp != [n-1]*n:
  B = [0]*n
  act = 0
  for i in range(n):
    if B[i] == 0:
      B[i] = 1
      if dp[i] != n-1:
        miru = L[i][dp[i]][1]-1
        if dp[miru] == n-1:
          flag = False
          dp = [n-1]*n
        else:
          if B[miru] != 1:
            if L[miru][dp[miru]][1] == i+1:
              dp[i] += 1
              dp[miru] += 1
              B[miru] = 1
              if act == 0:
                act = 1
  if act == 0:
    dp = [n-1]*n
    flag = False
  cnt += 1
  ela = time.time()-start
  if ela > 1.7:
    dp = [n-1]*n
if flag == False:
  print(-1)
else:
  if ela < 1.7:
    print(cnt)
  else:
    print(n*(n-1)//2)
### BUGGY CODE ###

n, k, c = map(int, input().split())
s = input()
left_dp = []
right_dp = []

i = 0
while len(left_dp)<k:
    if s[i] == "o":
        left_dp.append(i+1)
        i += c+1
    else: i += 1
        
i = n-1
while len(right_dp)<k:
    if s[i] == "o":
        right_dp.append(i+1)
        i -= c+1
    else: i -= 1

for i in left_dp:
    for j in right_dp:
        if i == j: 
            print(i)

### FIXED CODE ###

n, k, c = map(int, input().split())
s = input()
left_dp = []
right_dp = []

i = 0
while len(left_dp)<k:
    if s[i] == "o":
        left_dp.append(i+1)
        i += c+1
    else: i += 1
        
i = n-1
while len(right_dp)<k:
    if s[i] == "o":
        right_dp.append(i+1)
        i -= c+1
    else: i -= 1

for i in range(k):
    if left_dp[i] == right_dp[k-i-1]:
        print(left_dp[i])
### BUGGY CODE ###

N = int(input())

i = 2
N_ = N
ans = 0

divisor = {}
while(N_>1):
    if N_ % i == 0:
        divisor[i] = 0
        while(N_ % i == 0):
            divisor[i] += 1
            N_ //= i
    i += 1

ans += 0
def solve(dic,keys,n,i):
    if i == len(keys):
 #       print(n)
        if n-1 != 0 and N == (N % (n-1))*n:
            global ans
            ans += n-1

    else:
        for j in range(dic[keys[i]]+1):
            solve(dic,keys,n*keys[i]**j,i+1)

#print(divisor)
ans = 0 
solve(divisor,list(divisor.keys()),1,0)
print(ans)


### FIXED CODE ###

N = int(input())

i = 2
N_ = N
ans = 0

divisor = {}
for i in range(2,N):
    if N_ % i == 0:
        divisor[i] = 0
        while(N_ % i == 0):
            divisor[i] += 1
            N_  //= i
#;            print(N_,i)
    if i *i > N_:
        if N_ != 1:
            if N_ in divisor.keys():
                divisor[N_] += 1
            else:
                divisor[N_] = 1
        break

ans += 0
def solve(dic,keys,n,i):
    if i == len(keys):
#        print(n)
        if n-1 != 0 and N == (N % (n-1))*n:
            global ans
            ans += n-1

    else:
        for j in range(dic[keys[i]]+1):
            solve(dic,keys,n*keys[i]**j,i+1)

#print(divisor)
ans = 0 
solve(divisor,list(divisor.keys()),1,0)
print(ans)
### BUGGY CODE ###

n, q = map(int, input().split())
listS = list(input())
index=0
listA=[]
while index < q:
    l, r = map(int, input().split())
    listQ = listS[l-1: r]
    index2=0
    count=0
    while index2 < len(listQ)-1:
        if listQ[index2]=="A" and listQ[index2+1]=="C":
            count+=1
        index2+=1
    listA.append(count)
    index+=1
for ans in listA:
    print(ans)

### FIXED CODE ###

n, q = map(int, input().split())
listS = list(input())
index=0
listA=[]
listM=[0]*n
index2=1
countM=0
while index2 < len(listS):
    if listS[index2-1]=="A" and listS[index2]=="C":
        countM+=1
    listM[index2] = countM               
    index2+=1

while index < q:
    l, r = map(int, input().split())
    listA.append(listM[r-1]-listM[l-1])
    index+=1
for ans in listA:
    print(ans)
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()
lr = []
for i in range(Q):
    lr.append(list(map(int,input().split())))

for l,r in lr:
    substr = S[l-1:r]
    res = 0
    for i in range(len(substr)-1):
        if substr[i] == 'A' and substr[i+1] == 'C':
            res += 1
    print(res)

### FIXED CODE ###

def main():
    N,Q = map(int,input().split())
    S = input()
    lr = []
    for i in range(Q):
        lr.append(list(map(int,input().split())))

    cl = [0 for _ in range(len(S))]

    for i in range(1,len(S)):
        if S[i] == 'C' and S[i-1] == 'A':
            cl[i] = cl[i-1] + 1
        else:
            cl[i] = cl[i-1]


    #print(cl) 
    #print(S)

    for l,r in lr:
        res = cl[r-1] - cl[l-1] 
        print(res)


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

s = input()

rev = False

for _ in range(int(input())):
    ty = input().split()

    if ty[0] == '1':
        rev = not rev
    else:
        f, c = ty[1:]

        if rev:
            if f == '1':
                f = '2'

            else:
                f = '1'

        if f == '1':
            s = c + s
        else:
            s += c

if rev:
    print(s[::-1])
else:
    print(s)


### FIXED CODE ###

from collections import deque

s = input()

d = deque(list(s))

rev = False

for i in range(int(input())):
    tp = input().split()

    if tp[0] == '1':
        rev = not rev
    else:
        f, c = tp[1:]

        if rev:
            f = '12'[f == '1']

        if f == '1':
            d.appendleft(c)
        else:
            d.append(c)

if rev:
    print(*list(d)[::-1], sep='')
else:
    print(*list(d), sep='')
### BUGGY CODE ###

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

C=0

for i in range(N-1):
	if A.count(A[i])==1:
		C=C+0
	else:
		C=C+1

if C==0:
	print('YES')
else:
	print('NO')


### FIXED CODE ###

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

C=0

A.sort()

for i in range(N-1):
    if A[i] == A[i+1]:
        C = C+1
    else:
        C = C

if C == 0:
	print('YES')
else:
	print('NO')
### BUGGY CODE ###

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

# if N >= sum(A):
#     print(N-sum(A))
# else:
#     print(-1)

for i in range(1,N+1):
    print(A.count(i))

### FIXED CODE ###

# R = int(input()) 
N= int(input())
A = list(map(int, input().split()))



# if N >= sum(A):
#     print(N-sum(A))
# else:
#     print(-1)
count= [0] * N

for x in A:
    count[x-1] +=1
for i in range(N):
    print(count[i])

# def count_defaultdict(it):
#     counter = collections.defaultdict(int)
#     for x in it:
#         counter[x] += 1
#     return dict(counter)
### BUGGY CODE ###

def diff(a,b):
    if a>b:
        return(a-b)
    else:
        return(b-a)
n=int(input())
l=list(map(int,input().split()))
new=[]
count=0
for i in range(0,len(l)):
    new.append((l[i],i+1))
new.sort()
for i in range(0,len(new)):
    for j in range(i+1,len(new)):
        if new[i][0]+new[j][0]>2*10**5:
            break
        if new[i][0]+new[j][0]==diff(new[i][1],new[j][1]):
            count+=1
print(count)




        



### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
count=0
new=[]
s=set()
d={}
for i in range(0,len(l)):
    new.append(i+1-l[i])
    s.add(i+1+l[i])
    if i+1+l[i] in d.keys():
        d[i+1+l[i]]+=1
    else:
        d[i+1+l[i]]=1
for i in range(0,len(new)):
    if new[i] in s:
        count+=d[new[i]]
print(count)
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    a = LI()

    t = [[0]*(k+1) for _ in range(n)]
    z = t[-1]
    for i in range(a[-1]+1):
        z[i] = 1

    for i in range(n-2,-1,-1):
        s = 0
        z = t[i]
        y = t[i+1]
        c = a[i] + 1
        for j in range(c):
            s += y[j]
            s %= mod
            z[j] = s

        for j in range(c,k+1):
            s += y[j] - y[j-c]
            s %= mod
            z[j] = s

    return t[0][-1]


print(main())


### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    a = LI()
    l = k + 1

    y = [1] * (a[-1]+1) + [0] * (l-a[-1]-1)

    for i in range(n-2,-1,-1):
        z = [None] * l
        s = 0
        c = a[i] + 1
        for j in range(c):
            z[j] = s = (s + y[j]) % mod

        for j in range(c,l):
            z[j] = s = (s + y[j] - y[j-c]) % mod

        y = z

    return (y[-1] + mod) % mod


print(main())
### BUGGY CODE ###

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}
S = {}

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

for c in C.values():
    if c < 1:
        continue
    S.setdefault(c, c * (c - 1) // 2)
    if c < 2:
        continue
    S.setdefault(c - 1, (c - 1) * (c - 2) // 2)

for i, a in enumerate(A):
    C[a] -= 1
    sum_ = sum([S[n] for n in C.values() if n > 1])
    C[a] += 1
    print(sum_)


### FIXED CODE ###

from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}


@lru_cache(maxsize=None)
def pair(k):
    return k * (k - 1) // 2

@lru_cache(maxsize=None)
def calc(s, a):
    return s - pair(C[a]) + pair(C[a] - 1)

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

S = sum([pair(v) for v in C.values()])

for a in A:
    print(calc(S, a))
### BUGGY CODE ###

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

P = 0
for i in range(1, N+1):
    if i < K:
        cnt = 0
        X = 0
        while True:
            X = i*2
            cnt += 1
            if X >= K:
                P += 1/2**cnt + 1/N
                break
    else:
        P += 1/N

print(P)

### FIXED CODE ###

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

P = 0
for i in range(1, N+1):
    if i < K:
        cnt = 0
        while True:
            i *= 2
            cnt += 1
            if i >= K:
                P += 1 / (2 ** cnt)
                break
    else:
        P += 1

print(P / N)
### BUGGY CODE ###

import itertools
import sys
input = sys.stdin.readline

S = input().rstrip('\n')
N = len(S)

for i in itertools.count():
    # print(S)
    S = S.replace('01', '').replace('10', '')
    if not S:
        break
    if S.count('0') == 0 or S.count('1') == 0:
        break

print(N-len(S))


### FIXED CODE ###

import itertools
import sys
input = sys.stdin.readline

S = input().rstrip('\n')
N = len(S)

print(2*min(S.count('0'), S.count('1')))

# for i in itertools.count():
#     # print(S)
#     S = S.replace('01', '').replace('10', '')
#     if not S:
#         break
#     if S.count('0') == 0 or S.count('1') == 0:
#         break

# print(N-len(S))
### BUGGY CODE ###

import sys
from collections import *
import heapq
import math
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(n)]
lst=[0]*n
lst2=[0]*n
for i in range(n):
    x,y=xy[i]
    lst[i],lst2[i]=x,y
lst,lst2=list(permutations(lst,2)),list(permutations(lst2,2))
ans=float('inf')
for i in range(len(lst)):
    xl,xr=min(lst[i]),max(lst[i])
    for j in range(len(lst2)):
        yl,yr=min(lst2[j]),max(lst2[j])
        cnt=0
        for l in range(n):
            x,y=xy[l]
            if xl<=x<=xr and yl<=y<=yr:
                cnt+=1
        if cnt>=k:
            ans=min(ans,(xr-xl)*(yr-yl))
print(ans)

### FIXED CODE ###

import sys
from collections import *
import heapq
import math
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(n)]
ru=[[0]*(n+1) for i in range(n+1)]
lst=sorted(xy)
lst2=sorted(xy,key=lambda x: x[1])

for i in range(n):
    for j in range(n):
        flag=0
        for l in range(n):
            if xy[l]==[lst[i][0],lst2[j][1]]:
                flag=1
        if flag:
            ru[i+1][j+1]=1
        ru[i+1][j+1]+=ru[i+1][j]+ru[i][j+1]-ru[i][j]
# print(ru)
xdic=defaultdict(int)
ydic=defaultdict(int)
for i in range(n):
    xdic[lst[i][0]]=i+1
    ydic[lst2[i][1]]=i+1
# print(xdic)
# print(ydic)
lst=[0]*n
lst2=[0]*n
for i in range(n):
    x,y=xy[i]
    lst[i],lst2[i]=x,y
lst,lst2=list(permutations(lst,2)),list(permutations(lst2,2))
ans=float('inf')
for i in range(len(lst)):
    xl,xr=min(lst[i]),max(lst[i])
    for j in range(len(lst2)):
        yl,yr=min(lst2[j]),max(lst2[j])
        # print(ru[xdic[xr]][ydic[yr]]-ru[xdic[xr]][ydic[yl]-1]-ru[xdic[xl]-1][ydic[yr]]+ru[xdic[xl]-1][ydic[yl]-1])
        if ru[xdic[xr]][ydic[yr]]-ru[xdic[xr]][ydic[yl]-1]-ru[xdic[xl]-1][ydic[yr]]+ru[xdic[xl]-1][ydic[yl]-1] >=k:
            ans=min(ans,(xr-xl)*(yr-yl))
print(ans)
### BUGGY CODE ###

n, k, q = map(int, input().split())
l = [int(input())-1 for _ in range(q)]

for i in range(n):
  print(('No','Yes')[k > q - l.count(i)])

### FIXED CODE ###

n, k, q = map(int, input().split())
l = [int(input())-1 for _ in range(q)]
l.sort()

for i in range(n):
  cnt = 0
  if l and l[0] == i:
    while l and l[0] == i:
      l.pop(0)
      cnt += 1
  print(('No','Yes')[k > q - cnt])
### BUGGY CODE ###

n,y=map(int,input().split())
for i in range(y//10000+1):
    a=y-10000*i
    for j in range(a//5000+1):
        p=a-5000*j
        for f in range(p//1000+1):
            o=p-1000*f
            if o==0 and i+j+f==n:
                print(i,j,f)
                exit()
print(-1,-1,-1)

### FIXED CODE ###

n,y=map(int,input().split())
i,j,f=0,0,0
for i in range(y//10000+1):
    a=y-10000*i
    for j in range(a//5000+1):
        p=a-5000*j
        if i+j+p//1000==n:
            print(i,j,p//1000)
            exit()
print(-1,-1,-1)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
for i in range(1,n+1):
    if i in a:
        print(a.count(i))
    else:
        print(0)

### FIXED CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))
x = collections.Counter(a)
for i in range(1,n+1):
    print(x[i])
### BUGGY CODE ###

# CODE FESTIVAL 2016 予選 A: B – 仲良しうさぎ / Friendly Rabbits
N = int(input()) - 1
a = [int(s) - 1 for s in input().split()]

friends = []

for i in range(N):
    if a[a[i]] == i and ([i, a[i]] not in friends and [a[i], i] not in friends):
        friends.append([i, a[i]])

print(len(friends))

### FIXED CODE ###

# CODE FESTIVAL 2016 予選 A: B – 仲良しうさぎ / Friendly Rabbits
N = int(input()) - 1
a = [int(s) - 1 for s in input().split()]

pairs = 0

for i in range(N):
    if a[i] != 0 and a[a[i]] == i:
        pairs += 1
        a[i] = 0
        a[a[i]] = 0

print(pairs)
### BUGGY CODE ###

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

for i in range(N-K+1):
    max_total = max(max_total, sum(P[i:i+K]))

ans = (max_total + K) / 2

print(ans)

### FIXED CODE ###

from itertools import accumulate

N, K = map(int, input().split())
P = map(int, input().split())
acc_P = list(accumulate(P))
ans = (acc_P[K-1] + K) / 2

for i in range(N-K):
    ans = max(ans, (acc_P[i+K] - acc_P[i] + K) / 2)

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

# coding: utf-8

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

b = []
if n % 2 == 0:
    for i in range(n):
        if i % 2 != 0:
            b.insert(0, a[i])
        else:
            b.append(a[i])
else:
    for i in range(n):
        if i % 2 != 0:
            b.append(a[i])
        else:
            b.insert(0, a[i])

print(' '.join(map(str, b)))


### FIXED CODE ###

# coding: utf-8
from collections import deque

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

b = deque()
for i in range(n):
    if i % 2 == (n-1) % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

print(' '.join(map(str, b)))
### BUGGY CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[69]:


#import copy
import numpy as np

N, M = map(int, input().split())
As = np.sort(np.array(list(map(int, input().split()))))[::-1]
"""
3 3
2 13 8

4 4
1 9 3 5
"""


# In[70]:


As


# In[71]:


#As[0] = As[0] // 2
#arg = 0
As[0] = As[0] // 2
for i in range(1, M):
    arg = np.argmax(As[:i+1])
    #print(arg)
    As[arg] = As[arg] // 2
    #As[:i+1] = np.sort(As[:i+1])[::-1]
    #As[0] = As[0] // 2


# In[72]:


#print(As)
print(sum(As))


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[8]:


# import copy
#import numpy as np
import heapq

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

def int_minus(s):
    return -int(s)

As = list(map(int_minus, input().split()))
"""
3 3
2 13 8

4 4
1 9 3 5
"""


# In[10]:


heapq.heapify(As)


# In[17]:


for i in range(M):
    mx = heapq.heappop(As)
    heapq.heappush(As, -(-mx//2))


# In[19]:


#print(As)
print(-sum(As))


# In[ ]:
### BUGGY CODE ###

def f(n):
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    dp = [0] * (n + 1)
    for i in range(1, n + 1):
        mx = i
        for a, b in zip(aa, bb):
            if a>=b:continue
            if i >= a:
                tmp = dp[i - a] + b
                if tmp > mx:
                    mx = tmp
        dp[i] = mx
    n = dp[-1]
    dp = [0] * (n + 1)
    for i in range(1, n + 1):
        mx = i
        for a, b in zip(aa, bb):
            if a <= b: continue
            if i >= b:
                tmp = dp[i - b] + a
                if tmp > mx:
                    mx = tmp
        dp[i] = mx
    print(dp[-1])

n = int(input())
f(n)


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)

def don(dk, rate, amin):
    if not rate:
        return dk
    if len(rate)==1:
        a,b=rate[0]
        p,m=divmod(dk,a)
        return p*b+m
    if len(rate)==2:
        a0,b0=rate[0]
        a1,b1=rate[1]
        if b0/a0<b1/a1:
            a0,b0,a1,b1=a1,b1,a0,b0
        p0,m=divmod(dk,a0)
        re=b0*p0
        p1,m=divmod(m,a1)
        re+=b1*p1+m
        while p0>0 and m>0:
            p0-=1
            m+=a0
            p2,m=divmod(m,a1)
            p1+=p2
            tmp=p0*b0+p1*b1+m
            if tmp>re:
                re=tmp
        return re
    if dk < amin:
        return dk
    if dp[dk] != -1:
        return dp[dk]
    mx = 0
    for a, b in rate:
        if a > dk: continue
        tmp = don(dk - a, rate, amin) + b
        if tmp > mx:
            mx = tmp
    dp[dk] = mx
    return mx

n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
atob = []
btoa = []
amin = 10 ** 7
bmin = 10 ** 7
for a, b in zip(aa, bb):
    if a < b:
        atob.append([a, b])
        if a < amin:
            amin = a
    elif a > b:
        btoa.append([b, a])
        if b < bmin:
            bmin = b
dp = [-1] * (n + 1)
n = don(n, atob, amin)
dp = [-1] * (n + 1)
print(don(n, btoa, bmin))
### BUGGY CODE ###

n,m=map(int,input().split())
ans=1
for i in range(1,m+1):
  if m%i==0 and m//i>=n:
    ans=i
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
ans=1
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    if i>=n:
      ans=max(ans,m//i)
    elif m//i>=n:
      ans=max(ans,i)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
from queue import Queue

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()

match = [0 for i in range((n*(n-1))//2)]
child = [[] for i in range((n*(n-1))//2)]
isroot = [True for i in range((n*(n-1))//2)]


def bfs(root):
    q = Queue()
    q.put(root)
    match[root] = 1
    while(not q.empty()):
        item = q.get()
        # print(q, item)
        for ch in child[item]:
            # print(ch)
            if match[ch] < match[item] + 1:
                match[ch] = match[item] + 1
                q.put(ch)




for idd in range(n):
    nums = getList()
    i = idd + 1
    for j,k in zip(nums, nums[1:]):
        ii, j = min(i, j), max(i,j)
        iii, k = min(i, k), max(i,k)
        idx1 = ((j-1)*(j-2))//2 + (ii-1)
        idx2 = ((k - 1) * (k - 2)) // 2 + (iii - 1)
        isroot[idx2] = False
        child[idx1].append(idx2)
        # print(i, j, k)
        # print(idx1, idx2)

#
# print(child)
# print(isroot)
# sys.exit()

for idx, flag in enumerate(isroot):
    if flag:
        bfs(idx)
ans = 1
for m in match:
    if m > ans:
        ans = m
    if m == 0:
        print(-1)
        sys.exit()

print(ans)



### FIXED CODE ###

import sys

input = sys.stdin.readline
sys.setrecursionlimit(100000)
from collections import deque


def getN():
    return int(input())


def getList():
    return list(map(int, input().split()))


import math

n = getN()

match = [0 for i in range((n * (n - 1)) // 2)]
child = [[] for i in range((n * (n - 1)) // 2)]
iriji = [0 for i in range((n * (n - 1)) // 2)]


def toposo(n, iriji, child):
    order = [0 for i in range((n*(n+1))//2)]
    q = deque([])
    for i, iri in enumerate(iriji):
        if iri == 0:
            q.append(i)
            order[i] = 1
    while(q):
        start = q.popleft()
        target = child[start]
        for tgt in target:
            iriji[tgt] -= 1
            if iriji[tgt] == 0:
                q.append(tgt)
                order[tgt] = order[start] + 1

    if sum(iriji) != 0:
        return -1

    else:
        return max(order)


for idd in range(n):
    nums = getList()
    i = idd + 1
    for j, k in zip(nums, nums[1:]):
        ii, j = min(i, j), max(i, j)
        iii, k = min(i, k), max(i, k)
        idx1 = ((j - 1) * (j - 2)) // 2 + (ii - 1)
        idx2 = ((k - 1) * (k - 2)) // 2 + (iii - 1)
        iriji[idx2] += 1
        child[idx1].append(idx2)
        # print(i, j, k)
        # print(idx1, idx2)

#
# print(child)
# print(isroot)
# # sys.exit()
#
# bfs()
# # print("gg")
# ans = 1
# for m in match:
#     if m > ans:
#         ans = m
#     if m == 0:
#         print(-1)
#         sys.exit()
# print(iriji, child)

print(toposo(n, iriji, child))