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

N = int(input())

A = list(map(int, input().split()))
Ad = {}
for i in range(N):
    Ad[i] = A[i]

def get_keys_from_value(d, val):
    return [k for k, v in d.items() if v == val][0]

ans = ''
for j in range(len(Ad)):
    ans += ' ' + str(get_keys_from_value(Ad, j + 1) + 1)

print(ans.strip())

### FIXED CODE ###

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

Ad = {}
for i in range(N):
    Ad[i] = A[i]

Ad_sorted = sorted(Ad.items(), key=lambda x:x[1])

ans = ''
for Adi in Ad_sorted:
    ans += ' ' + str(Adi[0] + 1)

print(ans.strip())
### BUGGY CODE ###

l = list()
for _ in range(int(input())):
    c = input()
    if c not in l:
        l.append(c)
print(len(l))
l.append(c)

### FIXED CODE ###

l = set()
for _ in range(int(input())):
    l.add(input())
print(len(l))
### BUGGY CODE ###

n,p= map(int,input().split())
res=1
if n==1:
    res=p
else:
    for i in range(int(p**(1/n))+1,1,-1):
        if p%(i**n)==0:
            res=i
            break
print(res)

### FIXED CODE ###

n,p= map(int,input().split())
for i in range(round(p**(1/n)),0,-1):
    if p%(i**n)==0:
        print(i)
        exit()
### BUGGY CODE ###

s=input()
n=int(input())
for i in range(n):
    k= input().split()
    if len(k)==1:
        s = s[::-1] 
    else:
        if k[1]=="2":
            s=s+k[2]
        else:
            s=k[2]+s
print(s)

### FIXED CODE ###

S = input()
Q = int(input())
reverseCount = 0
pre = ""
pro = ""
for _ in range(Q):
    query = input()
    if len(query) == 1:
        reverseCount += 1
    else:
        _, F, C = query.split(" ")
        if (int(F) + reverseCount) % 2 == 1:
            pre = C + pre
        else:
            pro = pro + C
S = pre + S + pro
if reverseCount % 2 == 0:
    print(S)
else:
    print(S[::-1])
### BUGGY CODE ###

def score_search(sc, idx):
    if idx == len(f):
        if sc % 10 == 0:
            sc = 0
        return sc

    sc_lst = [0, 0]
    sc_lst[0] = score_search(sc, idx+1)
    if sc_lst[0] % 10 == 0:
        sc_lst[0] = 0
    sc += s[f[idx]]
    sc_lst[1] = score_search(sc, idx+1)
    if sc_lst[1] % 10 == 0:
        sc_lst[1] = 0
    return max(sc_lst)


n = int(input())
s = [int(input()) for i in range(n)]
f, score = [], 0

for i in range(len(s)):
    if s[i] % 10:
        f.append(i)
    else:
        score += s[i]


best_score = score + score_search(0, 0)
if best_score % 10 == 0:
    best_score = 0

print(best_score)


### FIXED CODE ###

def main():
    n = int(input())
    s = [int(input()) for i in range(n)]

    sum_max = sum(s)

    if sum_max % 10 == 0:
        min_p = 101
        for i in s:
            if i % 10 != 0 and i < min_p:
                min_p = i

        if min_p == 101:
            sum_max = 0
        else:
            sum_max -= min_p

    print(sum_max)


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

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))

dp = [[0]*N for i in range(N)]
flag = [[0]*N for i in range(N)]

def f(left, right) :
    if flag[left][right] :
        return dp[left][right]
    elif left == right :
        flag[left][right] = 1
        dp[left][right] = A[left]
        return dp[left][right]
    else :
        flag[left][right] = 1
        dp[left][right] = max(A[left] - f(left+1, right), A[right] - f(left, right-1))
        return dp[left][right]

ans = f(0,N-1)
print(ans)


### FIXED CODE ###

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

dp = [[0]*N for i in range(N)]

for i,a in enumerate(A) :
    dp[i][i] = a

for i in range(N-2, -1, -1) :
    for j in range(i+1, N) :
        left = A[i] - dp[i+1][j]
        right = A[j] - dp[i][j-1]
        dp[i][j] = max(left, right)

ans = dp[0][N-1]

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

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

i = 0
r = 0

while i<len(a):
    if a[i] == i+1:
        i += 1
    else:
        a.pop(i)

if len(a) == 0:
    print(-1)
else:
    print(n-len(a))

### FIXED CODE ###

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

i = 0

for j in range(n):
    if a[j] == j+1-i:
        continue
    else:
        i += 1

if i == n:
    print(-1)
else:
    print(i)
### BUGGY CODE ###

k = int(input())

import math 
from functools import reduce

sum = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            sum += reduce(math.gcd, (a, b, c))

print(sum)

### FIXED CODE ###

k = int(input())
 
import math
total = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        gcd2 = math.gcd(a, b)
        for c in range(1, k+1):
            total += math.gcd(gcd2, c)
print(total)
### BUGGY CODE ###

import math
a,b,n = map(int,input().split())
maxx = n//b
ans = 0
for i in range(maxx):
    x = b*(i+1)-1
    ans = max(math.floor(a*x/b)-a*(math.floor(x/b)),ans)
ans = max(math.floor(a*n/b)-a*(math.floor(n/b)),ans)
print(ans)

### FIXED CODE ###

a,b,n=map(int,input().split())
x=min(b-1,n) #上記よりxとしてmin(B-1,N)を選ぶのが最善
print((a*x)//b-a*(x//b))
### BUGGY CODE ###

n,k = map(int, input().split())
h = list(map(int,input().split()))
sort_h = sorted(h, reverse=True)
if len(h) <= k:
  ans = 0
else:
  for i in range(0, k):
    del sort_h[0]
  ans = sum(sort_h)
print(ans)

### FIXED CODE ###

n,k = map(int, input().split())
h = list(map(int,input().split()))
sort_h = sorted(h)
if len(h) <= k:
  ans = 0
else:
  for i in range(0, k):
    sort_h.pop()
  ans = sum(sort_h)
print(ans)
### BUGGY CODE ###

import sys

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

i = 1
l = [1] * N
n = 1
while True:
    n = A[n-1]
    if n in l:
        l = l[:i]
        mod = i - l.index(n)
        init_len = l.index(n)
        break
    else:
        l[i] = n
        i += 1

if K < init_len:
    print(l[K])
else:
    rest = ((K-init_len) % mod)
    print(l[init_len+rest])


### FIXED CODE ###

import sys

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

i = 1
l = [1] * N
s = set([1])
n = 1
while True:
    n = A[n-1]
    if n in s:
        l = l[:i]
        mod = i - l.index(n)
        init_len = l.index(n)
        break
    else:
        l[i] = n
        s.add(n)
        i += 1

if K < init_len:
    print(l[K])
else:
    rest = ((K-init_len) % mod)
    print(l[init_len+rest])
### BUGGY CODE ###

a,b=map(int,input().split(" "))
for i in range(a+1,b+1):
    a^=i
print(a)

### FIXED CODE ###

def z_to_n(n):
    m4=n%4
    if m4==0:
        return n
    elif m4==1:
        return 1
    elif m4==2:
        return n+1
    else:
        return 0
a,b=map(int,input().split(" "))
print(z_to_n(a-1)^z_to_n(b))
### BUGGY CODE ###

def Calculator(n, K):
    ans = 1
    for i in range(K):
        ans = ans* n[i]
    return ans

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

product = [0] * (N - K + 1)
product[0] = Calculator(A[0:K], K)
for i in range(K+1, N+1):
    product[i - K]= Calculator(A[i-K:i], K)
    if product[i - K] > product[i - K - 1]:
        print("Yes")
    else:
        print("No")


### FIXED CODE ###

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

for i in range(K, N):
    if A[i] > A[i-K]:
        print("Yes")
    else:
        print("No")
### 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

    days = 0
    while 1:
        gamed = [0]*N
        for i in range(N-1):
            if gamed[i] or not len(Q[i]):
                continue
            j = Q[i][0] - 1
            if gamed[j] or not len(Q[j]):
                continue
            if Q[j][0] == i+1:
#                print("game:", j+1, i+1, days)
                Q[i].popleft()
                Q[j].popleft()
                gamed[i] = gamed[j] = 1
                games -= 1
        days += 1
        if not 1 in gamed:
            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()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
    
n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

ok = False
tag = [-1] * n


def dfs(i=0, c=0):
    global ok, tag
    if tag[i] != -1:
        if tag[i] != c:
            ok = True
        return
    tag[i] = c
    for j in e[i]:
        dfs(j, (c + 1) % 2)


dfs()

if ok:
    print(n * (n - 1) // 2 - m)
else:
    s = sum(tag)
    print(s * (n - s) - m)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()


n, m = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    e[a].append(b)
    e[b].append(a)

ok = False
tag = [-1] * n


def dfs(i=0, c=0, r=-1):
    global ok, tag
    if tag[i] != -1:
        if tag[i] != c:
            ok = True
        return
    tag[i] = c
    for j in e[i]:
        if j == r:
            continue
        dfs(j, (c + 1) % 2, i)


dfs()

if ok:
    print(n * (n - 1) // 2 - m)
else:
    s = sum(tag)
    print(s * (n - s) - m)
### BUGGY CODE ###

n,k,q=map(int,input().split())
ls=[k]*n
for _ in range(q):
  a=int(input())
  
  for i in range(n):
    if i+1==a:
      ls[i]+=1
      break
    
for i in ls:
  if i<=q:
    print("No")
  else:
    print("Yes")

### FIXED CODE ###

n,k,q=map(int,input().split())
ls=[0]*n

for _ in range(q):
  a=int(input())
  ls[a-1]+=1
  
for i in ls:
  print("Yes"if k+i>q else "No")
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
    xor = 0
    for j in range(N):
        if i != j:
            xor ^= a[j]
    ans.append(xor)
print(*ans)

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(N):
    s ^= a[i]

ans = []
for i in range(N):
    ans.append(a[i] ^ s)
print(*ans)
### BUGGY CODE ###

from collections import defaultdict as d
s=d(int)
s[0]=0
n,w=map(int,input().split())
for i in range(n):
    q,v=map(int,input().split())
    c=s.copy()
    for p,r in c.items():
        if p+q<=w:
            s[p+q]=max(s[p+q],r+v)
print(max(s.values()))

### FIXED CODE ###

import numpy as np
n,a=map(int,input().split())
s=np.full(n*1000+1,a+1)
s[0]=0
for i in range(n):
    w,v=map(int,input().split())
    s[v:]=np.minimum(s[v:],s[:-v]+w)
print(np.max(np.where(s<=a)))
### BUGGY CODE ###

X = int(input())

sosu = [2]

for i in range(3, 10**5+100, 2):
    if(all(i % num != 0 for num in sosu)):
        sosu.append(i)   
        if(i >= X):
            print(i if X > 2 else 2)
            break

### FIXED CODE ###

import math

X = int(input())

def isprime(num):
    if(num==2):
        return True
    elif(num%2 == 0):
        return False
    
    for i in range(3, int(math.sqrt(num)+1), 2):
        if(num%i == 0):
            return False
        
    return True

def prime(n):
    ans = 2
    for i in range(n, 10**5+4):
        if(isprime(i)):
            ans = i        
            break
    return ans
 
print(prime(X))
### BUGGY CODE ###

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

#まだ左端を選択していない状態(状態 0)。この時は和が0の時1通りでそれ以外は0。
#左端は選択済みだけど右端は選択していない状態(状態 1)
#右端も選択済みの状態(状態 2)

dp = [[[0 for _ in range(3)] for _ in range(S+1)] for _ in range(N+1)]
dp[0][0][0] = 1
#i個目までで和がjとなる場合の数
ans = 0

for i in range(N):
  for j in range(S+1):
    #from 0
    #if j == 0: #j==0の時以外は基本0なのであってもなくても良い。
    dp[i+1][j][0] += dp[i][j][0]%MOD
    if j+A[i] <= S:# and j == 0: #j==0の時以外は基本0なのであってもなくても良い。
      dp[i+1][j+A[i]][1] += dp[i][j][0] * (i+1)%MOD
      dp[i+1][j+A[i]][2] += dp[i][j][0] * (i+1) * (N-i)%MOD
    #from 1
    dp[i+1][j][1] += dp[i][j][1]%MOD
    if j+A[i] <= S:
      dp[i+1][j+A[i]][1] += dp[i][j][1]%MOD
      dp[i+1][j+A[i]][2] += dp[i][j][1] * (N-i)%MOD
    #from 2
    dp[i+1][j][2] += dp[i][j][2]%MOD
#print(dp)MODDD
print(dp[N][S][2]%MOD)
      

### FIXED CODE ###

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

Q = [0 for _ in range(S+1)]
ans = 0
for i in range(N):
  Q[0] += 1
  Q2 = [0 for _ in range(S+1)]
  for j in range(S+1):
    Q2[j] += Q[j]%MOD
    if j+A[i] <= S: #(1+x^A[i])をかけてもx^sを超えないときに限り。
      Q2[j+A[i]] += Q[j]%MOD
  Q = Q2
  ans += Q[S]%MOD
ans = ans %MOD
print(ans)
### BUGGY CODE ###

S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
follow = 0

for i in range(N):
  Amari_ = (int(S[N-i-1]) * pow(10, i) + follow) % 2019
  #ans += amari[Amari_]
  amari[Amari_] += 1
  follow = Amari_
  
ans = sum(list( i * (i-1)//2 for i in amari ))
ans += amari[0]

print(ans)

### FIXED CODE ###

S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

sum = 0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            sum += gcd(a,b,c)

print(sum)


### FIXED CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())

sum = 0

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            if a == b == c:
                sum += gcd(a,b,c)
            elif a == b or b == c:
                sum += gcd(a,b,c) * 3
            else:
                sum += gcd(a,b,c) * 6
print(sum)
### BUGGY CODE ###

def main():  
  import sys
  input = sys.stdin.readline
  n,p = [int(i) for i in input().split()]
  s = input()
  ans = 0
  
  import math
  def nCr(n, r):
    if n < r:
      return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

  if p == 2 or p == 5:
      for i in range(n):
          if int(s[i]) % p == 0:
              ans += i + 1
      print(ans)
      exit()

  else:
    chk = [0]*p
    chk[0] = 1
    m = 0
    for i in range(n)[::-1]:
      m = (int(s[i])*pow(10,n-1-i)+m)%p
      chk[m] += 1
    for i in chk:
      ans += nCr(i,2)
    print(ans)
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,p = [int(i) for i in input().split()]
s = input()
ans = 0

import math
def nCr(n, r):
  if n < r:
    return 0
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
    print(ans)
    exit()

else:
  chk = [0]*p
  chk[0] = 1
  m = 0
  for i in range(n)[::-1]:
    m = (int(s[i])*pow(10,n-1-i,p)+m)%p
    chk[m] += 1
  for i in chk:
    ans += nCr(i,2)
  print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
Rindexes = []
Gindexes = []
Bindexes = []
for i in range(N):
  if S[i] == 'R':
    Rindexes.append(i)
  elif S[i] == 'G':
    Gindexes.append(i)
  elif S[i] == 'B':
    Bindexes.append(i)

total = len(Rindexes) * len(Gindexes) * len(Bindexes)
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if S[i] != S[j]:
      if S[i] != 'R' and S[j] != 'R' and k in Rindexes:
        count += 1
      elif S[i] != 'G' and S[j] != 'G' and k in Gindexes:
        count += 1
      elif S[i] != 'B' and S[j] != 'B' and k in Bindexes:
        count += 1
print(total - count)


### FIXED CODE ###

N = int(input())
S = input()
rcount = 0
gcount = 0
bcount = 0
for i in range(N):
  if S[i] == 'R':
    rcount += 1
  elif S[i] == 'G':
    gcount += 1
  elif S[i] == 'B':
    bcount += 1

total = rcount * gcount * bcount
count = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j - i
    if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
      count += 1
print(total - count)
### BUGGY CODE ###

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

ans=1000000000

for i in a:
  print(i)
  count=0
  while i%2==0:
    count+=1
  
  ans = min(ans, count)

print(ans)


### FIXED CODE ###

import sys
def p(s):
  sys.stderr.write(str(s)+"\n")

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

ans=1000000000

for i in a:
  p(i)
  count=0
  while i%2==0:
    count+=1
    if count>ans:
      break
    i /= 2
    p("i="+str(i))
  
  ans = min(ans, count)

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

import bisect

def solve():
    N, Q = [int(_) for _ in raw_input().split()]
    STX = []
    for i in range(N):
        Si, Ti, Xi = [int(_) for _ in raw_input().split()]
        STX.append((Si - Xi, Ti - Xi, Xi))
    D = [None] * Q
    for i in range(Q):
        D[i] = int(raw_input())
    STX.sort(key = lambda x:x[2], reverse=True)
    # D have already been sorted based on settings on problem
    ans = [-1] * Q
    for i in range(N):
        Li, Ri, Xi = STX[i]
        if len(D) == 0:
            break
        it = bisect.bisect_left(D, Li)
        while it < len(D):
            if D[it] >= Ri:
                break
            ans[it] = Xi
            it += 1
    for i in range(Q):
        print ans[i]

if __name__ == '__main__':
    solve()


### FIXED CODE ###

import bisect

def solve():
    N, Q = [int(_) for _ in raw_input().split()]
    STX = []
    for i in range(N):
        Si, Ti, Xi = [int(_) for _ in raw_input().split()]
        STX.append((Si - Xi, Ti - Xi, Xi))
    D = []
    for i in range(Q):
        D.append((int(raw_input()), i))
    STX.sort(key = lambda x:x[2])
    # D have already been sorted based on settings on problem
    ans = [-1] * Q
    l = [None] * Q
    for i in range(N):
        Li, Ri, Xi = STX[i]
        lit = bisect.bisect_left(D, (Li, -1))
        rit = bisect.bisect_left(D, (Ri, -1))
        while lit < rit:
            if l[lit] is not None:
                lit = l[lit]
            else:
                ans[D[lit][1]] = Xi
                l[lit] = rit
                lit += 1
    for i in range(Q):
        print ans[i]

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

n, m = map(int,input().split())
xs = [0]*m
pre = [0]*m
for x in range(m):
    xs[x] = list(list(map(int,input().split())) + [x] + [x])
xs.sort()

for p in range(1,n+1):
    cnt = 1
    for x in xs:
        if x[0] == p:
            x[3] = cnt
            cnt += 1

for x in sorted(xs, key=lambda x:x[2]):
    print('{0:06d}'.format(x[0]) + '{0:06d}'.format(x[3]))

### FIXED CODE ###

n, m = map(int,input().split())
xs = [0]*m
pre = [0]*m
for x in range(m):
    xs[x] = list(list(map(int,input().split())) + [x] + [x])
xs.sort()

skip = 0
for p in range(1,n+1):
    cnt = 1
    flag = 0
    for x in range(skip,len(xs)):
        if xs[x][0] <= p:
            xs[x][3] = cnt
            cnt += 1
            skip += 1
        else:
            flag = 1
        if flag:
            break


for x in sorted(xs, key=lambda x:x[2]):
    print('{0:06d}'.format(x[0]) + '{0:06d}'.format(x[3]))
### BUGGY CODE ###

import queue

# match of  a vs b
def match(a, b):
    """
    :type a: int
    :type b: int
    :rtype: int
    """
    return min(a,b) + N * max(a,b)

N = int(input())
A = []
for i in range(N):
    A.append( [ int(n)-1 for n in input().split() ] )

# NEXT[ match(a,b) ]  must be held after  match(a,b)
NEXT = [ [] for i in range(N*N) ]
# How many matches must be held before  match(a,b)
before = [ 0 for i in range(N*N) ]

for i in range(N):
    for j in range(N-2):
        # i vs A[i][j+1]  must be held after  i vs A[i][j]
        NEXT[ match(i,A[i][j]) ].append( match(i,A[i][j+1]) )
        before[ match(i,A[i][j+1]) ] += 1
        
q  = queue.Queue()
q0 = queue.Queue()

for i in range(N):
    for j in range(i+1,N):
        if before[ match(i,j) ] == 0:
            q.put( match(i,j) )
            
day = 0

while True:
    day += 1
    while not q.empty():
        M = q.get()
        for m in NEXT[M]:
            before[m] -= 1
            if before[m] == 0:
                q0.put(m)
        NEXT[M] = []
    q = q0
    q0 = queue.Queue()
    #print(NEXT)
    #print(before)
    if q.empty():
        break

if NEXT == [ [] for i in range(N*N) ]:
    print(day)
else:
    print(-1)


### FIXED CODE ###

# match of  a vs b
def match(a, b):
    """
    :type a: int
    :type b: int
    :rtype: int
    """
    return min(a,b) + N * max(a,b)

N = int(input())
A = []
for i in range(N):
    A.append( [ int(n)-1 for n in input().split() ] )

# NEXT[ match(a,b) ]  must be held after  match(a,b)
NEXT = [ [] for i in range(N*N) ]
# How many matches must be held before  match(a,b)
before = [ 0 for i in range(N*N) ]

for i in range(N):
    for j in range(N-2):
        # i vs A[i][j+1]  must be held after  i vs A[i][j]
        NEXT[ match(i,A[i][j]) ].append( match(i,A[i][j+1]) )
        before[ match(i,A[i][j+1]) ] += 1
        
q  = []
q0 = []

for i in range(N):
    for j in range(i+1,N):
        if before[ match(i,j) ] == 0:
            q.append( match(i,j) )
            
day = 0

while True:
    day += 1
    for M in q:
        for m in NEXT[M]:
            before[m] -= 1
            if before[m] == 0:
                q0.append(m)
        NEXT[M] = []
    q = q0
    q0 = []
    #print(NEXT)
    #print(before)
    if q == []:
        break

if NEXT == [ [] for i in range(N*N) ]:
    print(day)
else:
    print(-1)