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

n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

c = format(c,'b').zfill(30)

buf = []
for i in a:
    s = format(i,'b').zfill(30)
    ans = list(c)
    for j in range(len(s)):
        x = (int(ans[j])+int(s[j]))%2
        ans[j] = str(x)
    x = ''.join(ans)
    buf.append(int(x,2))
print(*buf)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
c = 0
for i in a:
    c ^= i

buf = []
for i in a:
    buf.append(c^i)
    
print(*buf)
### BUGGY CODE ###

import bisect

s=input()
t=input()

condition=0

index=list()
for a in range(len(t)):
 index.append([i for i, x in enumerate(s) if x == t[a]])

for i in range(len(t)):
 if index[i]==[]:
   condition=1
   break

if condition==1:
  print(-1)
else:
  #print(index)
  b=index[0][0]
  j=1
  loop=0
  if len(t)==1:
    print(b+1)
  else:
   for j in range(1,len(t)):
     c=bisect.bisect_left(index[j],b)
     #print(j,index[j],b,c,loop)
     if c<len(index[j]) and c != index[j][len(index[j])-1]:
        b=index[j][c]
        #print(j,b,loop)
     else:
        loop=loop+len(s)
        b=index[j][0]
        if loop == len(s)*(10**100):
           print(-1)
           break
   print(b+loop+1)


        



### FIXED CODE ###

import bisect

s=input()
t=input()

#index=list()
#for a in range(len(t)):
# index.append([i for i, x in enumerate(s) if x == t[a]])

char_appear = {ch: [] for ch in 'abcdefghijklmnopqrstuvwxyz'}
for i, ch in enumerate(s):
    char_appear[ch].append(i)
#print(char_appear['a'])
      
b=0
loop=0
condition=0

for j in range(len(t)):
  if len(char_appear[t[j]])<1:
    print(-1)
    condition=1
    break
  c=bisect.bisect(char_appear[t[j]],b)
 # print(j,char_appear[t[j]],b,c,loop)
  if j<1:
    b=char_appear[t[0]][0]    
  elif c == len(char_appear[t[j]]): #or c==char_appear[t[j]][len(char_appear[t[j]])-1]: 
     loop +=1
     b=char_appear[t[j]][0]
     if loop==10**100:
        print(-1)
        condition=1
        break
  else:
     b=char_appear[t[j]][c]
     #print(j,b,loop)


if condition==0:
 print(b+loop*len(s)+1)
### BUGGY CODE ###

n, mw = map(int, input().split())
w = []
v = []

for i in range(n):
    ww, vv = map(int, input().split())
    w.append(ww)
    v.append(vv)

dp = [[0] * (mw + 1) for i in range(n + 1)]

for i in range(n):
    for j in range(mw + 1):
        if j < w[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])

print(dp[n][mw])


### FIXED CODE ###

n, mw = map(int, input().split())
w = []
v = []

for i in range(n):
    ww, vv = map(int, input().split())
    w.append(ww)
    v.append(vv)

dp = [[0] * (mw + 1) for i in range(n + 1)]

for i in range(n):
    for j in range(mw + 1):
        if j < w[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i])

print(dp[n][mw])
### BUGGY CODE ###

from collections import defaultdict
n = int(input())
s = input()

dp = [defaultdict(int), defaultdict(int)]

dp[0][""] = 1
for i in range(n):
    dp[(i + 1) % 2] = dp[i % 2].copy()
    i1 = (i + 1) % 2
    i0 = (i + 0) % 2
    for j in dp[i0]:
        if len(j) < 3:
            dp[i1][j + s[i]] += dp[i0][j]

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        # print(j)
        ans += 1

print(ans)


### FIXED CODE ###

n = int(input())
s = input()

dp = [set(), set()]

dp[0].add("")
for i in range(n):
    dp[(i + 1) % 2] = dp[i % 2].copy()
    i1 = (i + 1) % 2
    i0 = (i + 0) % 2
    for j in dp[i0]:
        if len(j) < 3:
            dp[i1].add(j + s[i])

ans = 0
for j in dp[n % 2]:
    if len(j) == 3:
        # print(j)
        ans += 1

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

n = int(input())

al = [0] * (n + 10)
al[0] = 1
al[1] = 1
for i in range(2, n + 1):
    al[i] = al[i-1] * i

s = []
ans = 0
for i in range(n):
    si = input()
    si = sorted(si)
    ss = ""
    for a in si:
        ss += a
    s.append(ss)

sset = list(set(s))

if(len(sset) == len(s)):
    print(0)
else:
    for e in sset:
        if(s.count(e) == 1):
            continue
        ans += s.count(e) * (s.count(e) - 1) // 2

    print(ans)

### FIXED CODE ###

n = int(input())

s = []
dic = {}
ans = 0
for i in range(n):
    si = input()
    si = sorted(si)
    ss = ""
    for a in si:
        ss += a
    if(ss in dic):
        dic[ss] += 1
    else:
        dic[ss] = 1

for e in dic:
    if(dic[e] == 1):
        continue
    ans += dic[e] * (dic[e] - 1) // 2

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

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from collections import defaultdict
import sys
N_MAX = 100
W_MAX = 10**9
V_MAX = 10**7
INF = 10**10
def main(N, W, items):
    dp = defaultdict(lambda: INF)
    dp[0] = 0
    for i in range(N):
        iw, iv = items[i]
        for v, w in list(dp.items()):
            if w + iw <= W:
                dp[v + iv] = min(dp[v + iv], w + iw)
    print(max(dp.keys()))

if __name__ == '__main__':
    input = sys.stdin.readline
    N, W = map(int, input().split())
    items = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, W, items)


### FIXED CODE ###

# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, W, items):
    w1 = items[0][0]
    dp = [[[0] * (3 * N + 1) for _ in range(N + 1)] for __ in range(N + 1)]
    dp[0][0][0] = 0
    for i in range(N):
        iw, iv = items[i]
        iw -= w1
        for j in range(N + 1):
            for w in range(3 * N + 1):
                if j * w1 + w > W: break
                if w >= iw and j >= 1:
                    dp[i + 1][j][w] = max(dp[i][j][w], dp[i][j - 1][w - iw] + iv)
                else:
                    dp[i + 1][j][w] = dp[i][j][w]
    ans = 0
    for j in range(N + 1):
        for w in range(3 * N + 1):
            ans = max(ans, dp[N][j][w])
    print(ans)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, W = map(int, input().split())
    items = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, W, items)
### BUGGY CODE ###

import itertools
    
h,w = (int(x) for x in input().split())
ab = []
count = 0
for _ in range(h):
    a = input()
    a = a+'#'
    ab.append(list(a))
ab.append(list('#'*w))
mx = 0

for i in range(h):
    for j in range(w):
        if ab[i][j] == '.':
            dp = [[0 for a in range(w)] for b in range(h)]
            dp[i][j] = 1
            step = []

            y, x = i, j
            if ab[y+1][x] == '.' :
                step.append([y+1, x])
                dp[y+1][x] = 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1+1][x1] == '.' :
                        step.append([y1+1, x1])
                        dp[y1+1][x1] = 1
                        
            if ab[y][x+1] == '.' :
                step.append([y, x+1])
                dp[y][x+1] = 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1][x1+1] == '.' :
                        step.append([y1, x1+1])
                        dp[y1][x1+1] = 1
            if ab[y-1][x] == '.' :
                step.append([y-1, x])
                dp[y-1][x] = 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1-1][x1] == '.' :
                        step.append([y1-1, x1])
                        dp[y1-1][x1] = 1
            if ab[y][x-1] == '.' :
                step.append([y, x-1])
                dp[y][x-1] = 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1][x1-1] == '.' :
                        step.append([y1, x1-1])
                        dp[y1][x1-1] = 1
            #print(dp)

            mx = max([mx, sum(list(itertools.chain.from_iterable(dp)))])
            #print(mx, i, j)

print(mx)

### FIXED CODE ###

H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
 
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1
 
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
 
print(ans)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
B = []
result = []
for i in range(N):
    B = A
    C = B[i]
    B[i] = 0
    result.append(max(B))
    B[i] = C

for a in result:
    print(a)

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
B = max(A)
C = [B]*N
D = sorted(A)[-2]
i = A.index(B)
if A.count(B) == 1:
    C[i] = D

for a in C:
    print(a)
### BUGGY CODE ###

import sys
from fractions import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    l=A[0]
    for x in A[1:]:
        l=l*x//gcd(l,x)
    ans=0
    for x in A:
        ans+=l//x
    print(ans%MOD)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from fractions import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    def modinv(a, mod):
        b,u,v = mod,1,0
        while b:
            t=a//b
            a-=t*b
            a,b=b,a
            u-=t*v
            u,v=v,u
        u%=mod
        if u < 0:
            u+=mod
        return u
    
    
    N=int(input())
    A=list(map(int,input().split()))
    l=A[0]
    for x in A[1:]:
        l=l*x//gcd(l,x)
    l%=MOD
    ans=0
    for x in A:
        ans+=l*modinv(x,MOD)
        ans%=MOD
    print(ans)

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

n, k = map(int, input().split())
dices = list(map(int, input().split()))

max_exp_value = 0

for i in range(n - k + 1):
  exp_value = (sum(dices[i : i + k]) + k) / 2
  if exp_value > max_exp_value:
    max_exp_value = exp_value

print(max_exp_value)

### FIXED CODE ###

n, k = map(int, input().split())
dices = list(map(int, input().split()))

exp_value = (sum(dices[:k]) + k) / 2
max_exp_value = exp_value

for i in range(n - k):
  exp_value += (dices[i + k] - dices[i]) / 2
  if exp_value > max_exp_value:
    max_exp_value = exp_value

print(max_exp_value)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
t = []
for i in range(1000):
    t.append([])
for i in range(n):
    j = a[i]//1024
    t[j].append(a[i])
#print(t)
p = n
for i in range(len(t[0])):
    for j in range(len(t[0])):
        if(i != j):
            if(t[0][i] % t[0][j] == 0):
                p -= 1
                #print(t[0][i],t[0][j])
                break
for i in range(1,1000):
    for j in range(len(t[i])):
        x = 0
        for k in range(len(t[i])):
            if(j != k):
                if(t[i][j] ==  t[i][k]):
                    p -= 1
                    #print(t[i][j],t[i][k],-1)
                    x = 1
                    break
        if(x == 0):
            for k in range((i+2)//2):
                for l in range(len(t[k])):
                    if(t[i][j] % t[k][l] == 0):
                        p -= 1
                        #print(t[i][j],t[k][l])
                        x = 1
                        break
                if(x == 1):
                    break

print(p)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
m = max(a)
t = [1]*(m+1)
for i in range(n):
    if(t[a[i]] == 1):
        x = a[i]*2
        while(x <= m):
            t[x] = 0
            x += a[i]
for i in range(n):
    if(t[a[i]] == 0):
        n -= 1
    elif(t[a[i]] == 1):
        t[a[i]] = -1
    elif(t[a[i]] == -1):
        t[a[i]] = -2
        n -= 2
    else:
        n -= 1
print(n)
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int,input().split())
p = list(map(lambda x : int(x)-1,input().split()))
count = 0
uf = UnionFind(N)
for _ in range(M):
    i,j = map(lambda x : int(x)-1,input().split())
    uf.union(i,j)
dic = uf.all_group_members()
for i in range(N):
    if uf.same(p[i],i):
        count += 1
print(count)

### FIXED CODE ###

class UnionFind():
  def __init__(self, x):
    self.x=x
    self.root=[-1]*(N+1)
    self.rnk=[0]*(N+1)
  
  def Find_root(self, x):
    if self.root[x]<0:
      return x
    else:
      self.root[x]=self.Find_root(self.root[x])
      return self.root[x]
    
  def Unite(self, x, y):
    x = self.Find_root(x)
    y = self.Find_root(y)
    if x==y:
      return
    elif self.rnk[x]>self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x]==self.rnk[y]:
        self.rnk[y]+=1
  
  def isSameGroup(self, x, y):
    return self.Find_root(x)==self.Find_root(y)
  
  def Count(self, x):
    return -self.root[self.Find_root(x)]

N,M = map(int,input().split())
p = list(map(lambda x : int(x)-1,input().split()))
count = 0
uf = UnionFind(N)
for _ in range(M):
    i,j = map(lambda x : int(x)-1,input().split())
    uf.Unite(i,j)
for i in range(N):
    if uf.isSameGroup(p[i],i):
        count += 1
print(count)
### BUGGY CODE ###

import sys


H, W, M = map(int, input().split())
X = [set() for _ in range(H)]
Y = [set() for _ in range(W)]
for s in sys.stdin.readlines():
    h, w = map(lambda x: int(x) - 1, s.split())
    X[h].add(w)
    Y[w].add(h)
cntX = []
cntY = []
for x in X:
    cntX.append((len(x), x))
for y in Y:
    cntY.append((len(y), y))

cntX.sort(reverse=True)
maxX = cntX[0][0]
ans = 0
for cnt, x in cntX:
    if cnt < maxX:
        break
    for w in range(W):
        tmp = cnt + len(Y[w]) - (w in x)
        if ans < tmp:
            ans = tmp
print(ans)


### FIXED CODE ###

import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H
Y = [0] * W
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = []
C = []
for h, x in enumerate(X):
    if x == maxX:
        R.append(h)
for w, y in enumerate(Y):
    if y == maxY:
        C.append(w)

if len(R) * len(C) > M:
    ans = maxX + maxY
else:
    done = set()
    for r in R:
        for c in C:
            done.add((r, c))
    for b in bomb:
        if b in done:
            done.remove(b)
    if len(done) > 0:
        ans = maxX + maxY
    else:
        ans = maxX + maxY - 1
print(ans)
### BUGGY CODE ###

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

for _ in range(Q):
    q = input().split()
    if q[0]=='1':
        S = S[::-1]
    else:
        if q[1]=='1':
            S = q[2] + S
        else:
            S = S + q[2]
print(S)

### FIXED CODE ###

from collections import deque

S = input()
Q = int(input())
head = 1
d = deque([S])

for _ in range(Q):
    q = input().split()
    if q[0]=='1':
        head = head*-1
    else:
        if q[1]=='1':
            h = head*1
        else:
            h = head*-1
        
        if h==1:
            d.appendleft(q[2])
        else:
            d.append(q[2])
ans = "".join(list(d))
if head == -1:
    ans = ans[::-1]

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

n = int(input())

def p_factor(x):
  factor = {}
  i = 2
  while x>1:
    if x%i == 0:
      x //= i
      if factor.get(i):
        factor[i] += 1
      else:
        factor[i] = 1
      continue
    else:
      i += 1
  return factor

def divisor_count(x):
  factor = p_factor(x)
  primes = factor.keys()
  num_div = 1
  
  for p in primes:
    num_div *= factor[p]+1
  return num_div

sum_div = 1
for i in range(2,n+1):
  sum_div += i*divisor_count(i)
print(sum_div)

### FIXED CODE ###

n = int(input())

dp = [0]*(n+1)

for i in range(1,n+1):
  x = n//i
  for j in range(1,x+1):
    dp[i*j]+=1
    
sum_div = 0
for i in range(1,n+1):
  sum_div += i*dp[i]
print(sum_div)
### BUGGY CODE ###

def hantei(n,data):
    last_num = 1
    if last_num not in data:
        return -1

    while True:
        if last_num + 1 in data[data.index(last_num):]:
            last_num += 1
            data = data[data.index(last_num):]
        else:
            break
        #print(data[index_point + 1:])

    return n - last_num

n = int(input())
data = [int(x) for x in input().split()]

print(hantei(n,data))

### FIXED CODE ###

def hantei(n,data):
    v = 1

    for st in data:
        if st == v:
            v = v + 1

    if v == 1:
        return -1
    else:
        return n - v + 1

n = int(input())
data = [int(x) for x in input().split()]

print(hantei(n,data))
### BUGGY CODE ###

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

for i in range(M):
    if T[i] in D:
        D.remove(T[i])
    else:
        print("NO")
        break
else:
    print("YES")

### FIXED CODE ###


from collections import Counter

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

T_cnt = list(Counter(T).items())
D_cnt = Counter(D)

for t in T_cnt:
    if D_cnt[t[0]] < t[1]:
        print("NO")
        break

else:
    print("YES")
### BUGGY CODE ###

n = int(input())
s = [0] * n
li = []
ans = []
for i in range(n):
    s[i] = input()
    if s[i] in ans:
        li[ans.index(s[i])][1] += 1
    else:
        li.append([s[i], 1])
        ans.append(s[i])
              
li.sort(key = lambda x: x[0])
li.sort(key = lambda x: x[1] , reverse = True)

a = li[0][1]
for i in range(len(li)):
    if a == li[i][1]:
        print(li[i][0])
    else:
        break

### FIXED CODE ###

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

dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

max_dic = max(dic.values())
ans = [i for i, j in dic.items() if j == max_dic]
ans.sort()

for i in range(len(ans)):
    print(ans[i])
### BUGGY CODE ###

N = int(input())
A,B = [],[]
for _ in range(N-1):
    array = list(map(int,input().split()))
    A.append(array[0])
    B.append(array[1])
from collections import defaultdict as ddict
children = ddict(list)
for a,b in zip(A,B):
    children[a].append(b)
ans = ddict(int)
col = 0
for child in sorted(children.keys()):
    used = set({ans[child]})
    for j in sorted(children[child]):
        temp = min(set(range(1,max(used)+2))-used)
        ans[j] = temp
        col = max(col,temp)
        used.add(temp)
print(col)
print("\n".join(str(ans[b]) for b in B))

### FIXED CODE ###

N = int(input())
AB = [[]]*(N-1)
for i in range(N-1):
    AB[i] = list(map(int,input().split()))
from collections import defaultdict as ddict
from collections import deque
tree = ddict(list)
B = [0]*(N-1)
for i,ab in enumerate(AB):
    tree[ab[0]].append(ab[1])
    B[i] = ab[1]
# 各エッジの色を格納する変数の初期化
# C[0]は使わない
C = [0]*N
# 幅優先探索用のcue
Q = deque([1])
while Q:
    q = Q.popleft()
    c = 0
    for w in tree[q]:
        # 色をインクリメントした際に親の色とかぶったら更に1を加算する
        # 他は単純なインクリメント
        c += 1 + int(C[q-1] == c+1)
        # エッジの色を格納
        C[w-1] = c
        # 子供をcueに追加
        Q.append(w)
print(max(C))
for b in B:
    print(C[b-1])
### BUGGY CODE ###

import sys


n, x, y = map(int, sys.stdin.readline().split())
dist = []
for i in range(n):
    dist.append([])
    for j in range(n):
        dist[i].append(abs(j - i))

dist[x-1][y-1] = 1
def get_dist(a,b):
    if a < b:
        return dist[a][b]
    else:
        return dist[b][a]

for k in range(n):
    for i in range(n-1):
        for j in range(i+1, n):
            dist[i][j] = min(dist[i][j], get_dist(i, k) + get_dist(k, j))

final = [0]*(n-1)
for i in range(n-1):
    for j in range(i+1, n):
        final[dist[i][j]-1] += 1

for one in final:
    print(one)

### FIXED CODE ###

import sys
n, x, y = map(int, sys.stdin.readline().split())

x -= 1
y -= 1
    
final = [0]*(n-1)


for i in range(n-1):
    for j in range(i+2, n):
        if j < x or i > y:
            dist = j-i
        else:
            dist = min([j - i, abs(x-i) + 1 + abs(y-j), abs(y-i) + 1 + abs(x-j)])
        final[dist-1] += 1 
final[0] = n
res = [str(one) for one in final]
print ("\n".join(res))
### BUGGY CODE ###

# 試合を頂点とした有向グラフを書く
# 対戦2チームを元に試合ID(頂点番号)に変換できるようにする
# 閉路があるとNGなので-1
# 閉路がない場合は最長経路が答え

import sys
readline = sys.stdin.readline

N = int(readline())

id_dic = {}
next_id = 0
def to_id(a,b):
  if a > b:
    a,b = b,a
  return id_dic[(a,b)]
def convert_to_id(a,b,next_id):
  if a > b:
    a,b = b,a
  if (a,b) not in id_dic:
    id_dic[(a,b)] = next_id
    return next_id + 1
  return next_id

G = [[] for i in range((N * (N - 1)) // 2)] # 試合グラフ
indegree = [0 for i in range((N * (N - 1)) // 2)] # 入次数
for i in range(N):
  A = list(map(int,readline().split()))
  cur = None
  for a in A:
    # i と a - 1の試合
    next_id = convert_to_id(i,a - 1,next_id)
    game = to_id(i,a - 1)
    if cur != None:
      G[cur].append(game)
      indegree[game] += 1 # 試合に対する入次数が1
    cur = game

done = set()
# 各日付ごとに、入次数が0の試合から行っていく
# 入次数が0になった試合を翌日の試合リスト
stack = []
for i in range(len(indegree)):
  if indegree[i] == 0:
    stack.append(i)

if len(stack) == 0:
  print(-1)
  exit(0)
  
day = 0
while stack:
  day += 1
  nextday = []
  while stack:
    game = stack.pop()
    if game in done: # 既に終わっている試合の場合　閉路と見なす
      print(-1)
      exit(0)
    done.add(game)
    for child in G[game]: # 翌日のゲームを探索
      indegree[child] -= 1
      if indegree[child] == 0: # 入次数が0になれば翌日試合できる
        nextday.append(child)
  stack = nextday

if len(done) != ((N * (N - 1)) // 2):
  print(-1)
  exit(0)
print(day)

### FIXED CODE ###

N=int(input())
a=[[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
  line=list(map(int,input().split()))
  for j in range(N-1):
    a[i][j]=line[j]-1
  a[i]=a[i][::-1]
    
q=[]

#seen=[[False for j in range(N)] for i in range(N)]

# 選手nが試合できるならqueに入れる
def check(i):
  if len(a[i])==0:
    return False
  j=a[i][-1]
  if a[j][-1]==i:
    q.append([i,j])
  
for i in range(N):
  check(i)
  
from collections import defaultdict

day=0
while q:
  day+=1
 # q=sorted(q)
  prevQ=q.copy()
  q=[]
  matched=defaultdict(list)
  for p in prevQ:
    i=p[0]
    j=p[1]
    if i>j:
      i,j=j,i
    if matched[i]:
      continue
    a[i].pop()
    a[j].pop()
    check(i)
    check(j)
    matched[i].append(j)
    
for i in range(N):
  if len(a[i])!=0:
    print(-1)
    break
else:
  print(day)