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

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, AB):
    c = Counter(reduce(add, AB))
    for v in c.values():
        if v % 2 != 0:
            return 'NO'
    return 'YES'


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    print(slv(N, M, AB))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, AB):
    c = Counter()
    for a, b in AB:
        c[a] += 1
        c[b] += 1
    for v in c.values():
        if v % 2 != 0:
            return 'NO'
    return 'YES'


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    print(slv(N, M, AB))


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

N = int(input())

d = 0
C = 0 # SUM

for j in range(1,N):
    d = 0 
    divisors = []
    for i in range(1, int(j**0.5)+1):
        if j % i == 0:
            divisors.append(i)
            if i != j // i:
                divisors.append(j//i)
           
    #d= len(set(divisors))
    C = C + len(set(divisors))
print(C)

### FIXED CODE ###

from sys import stdin
input = stdin.buffer.readline

N = int(input())
tmp = 0

for a in range(1,N):
    tmp = tmp + (N-1) // a
    
print(tmp)
### BUGGY CODE ###

import math

K = int(input()) + 1
ans = 0
for a in range(1,K):
    for b in range(1,K):
        for c in range(1,K):
            ab = math.gcd(a,b)
            part = math.gcd(ab,c)            
            ans += part
    
print(ans)

### FIXED CODE ###

import math

K = int(input()) + 1
ans = 0
for a in range(1,K):
    for b in range(a,K):
        for c in range(b,K):
            ab = math.gcd(a,b)
            part = math.gcd(ab,c)
            if a == b or b == c:
                if not (a == b and b == c):
                    part = part * 3
            else:
                    part = part * 6                   
            ans += part
print(ans)
### BUGGY CODE ###

N=int(input())
a=[0]*N
for i in range(N):
  a[i]=int(input())
count=0

#loopの定義→同じインデックスを使用したら
loop=[]

# tmp=a[0]
# if tmp==2:
#   print(1)
#   exit()
tmp=1
while True:  
  tmp=a[tmp-1]
  count+=1
  if tmp==2:
    print(count)
    exit()
  if tmp-1 in loop:
    print(-1)
    exit()
  loop.append(tmp-1)
  

### FIXED CODE ###

N=int(input())
a=[0]*N
for i in range(N):
  a[i]=int(input())
count=0

#loopの定義→同じインデックスを使用したら
#loop=[]
loop=set()

tmp=1
while True:  
  tmp=a[tmp-1]
  count+=1
  if tmp==2:
    print(count)
    exit()
  if tmp-1 in loop:
    print(-1)
    exit()
  loop.add(tmp-1)
### BUGGY CODE ###

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

for i in range(K):
    H[H.index(max(H))] = 0

print(sum(H))

### FIXED CODE ###

N,K = map(int, input().split())
H =  list(map(int, input().split()))
H.sort(reverse=True)
sum = 0

for i in range(N):
    if i < K:
        pass
    else:
        sum += H[i]

print(sum)
### BUGGY CODE ###

a,b,k=map(int,input().split())
num=[i for i in range(a,b+1)]
ans=[]
ans.extend(num[:k])
ans.extend(num[-k:])
ans=sorted(list(set(ans)))
for ansi in ans:
    print(ansi)

### FIXED CODE ###

a,b,k=map(int,input().split())
ans=[i for i in range(a,min(b,a+k))]
ans.extend([i for i in range(max(a,b-k+1),b+1)])
ans=sorted(list(set(ans)))
for ansi in ans:
    print(ansi)
### BUGGY CODE ###

N = int(input())
numbers = [int(i) for i in input().split()]
numbers = sorted(numbers)
counter = 0

for a in range(len(numbers)-2):
    for b in range(a+1, len(numbers)-1):
        for c in range(b+1, len(numbers)):
            if numbers[c] < numbers[a] + numbers[b]:
                counter += 1

print(counter)

### FIXED CODE ###

import bisect

N = int(input())
numbers = [int(i) for i in input().split()]
numbers = sorted(numbers)
counter = 0

for a in range(N):
    for b in range(a+1, N):
        c = bisect.bisect_left(numbers, numbers[a] + numbers[b])
        if c > b:
            counter += c - b -1
        
print(counter)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for _ in range(n)]
num1=max(a)
for i in range(n):
    if a[i]==num1:
        if i==0:
            print(max(a[1:]))
        elif i==n-1:
            print(max(a[:n-1]))
        else:
            print(max(max(a[:i]),max(a[i+1:])))
    else:
        print(num1)


### FIXED CODE ###

def solve():
    n=int(input())
    num=[]
    def append(num1):
        num.append(num1)
    def count1(num2):
        return num.count(num2)
    for i in range(n):
        a=int(input())
        append(a)
    max1=max(num)
    count=count1(max1)
    if count>1:
        for i in range(n):
            print(max1)
    else:
        for i in range(n):
            if num[i]==max1:
                if i==0:
                    print(max(num[1:]))
                elif i==n-1:
                    print(max(num[:n-1]))
                else:
                    print(max(max(num[:i]),max(num[i+1:])))
            else:
                print(max1)
solve()
### BUGGY CODE ###

def main(A,B,C,D):
    count = 0    
    for i in range(A,B+1):
        if i % C != 0 and i % D !=0:
            count += 1
    return count
A,B,C,D = map(int, input().split())
print(main(A,B,C,D))

### FIXED CODE ###

import fractions
def main(A,B,C,D):
    allAB = B - A + 1
    divC = B // C - (A-1) // C
    divD = B // D - (A-1) // D
    lcmCD = lcm(C,D)
    divCD = B // (lcmCD) - (A-1) // (lcmCD)
    count = allAB - divC - divD + divCD
    return count

def lcm(x, y):
    return (x*y) // fractions.gcd(x,y)
    
A,B,C,D = map(int, input().split())
print(main(A,B,C,D))
### BUGGY CODE ###

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

index = 1
route = [index]
node = [index]

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print(route[route_idx])
        break
    else:
        route.append(index)
        node.append(index)
else:
    print(index)

### FIXED CODE ###

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

index = 1
route = [index]
node = {index}

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print(route[route_idx])
        break
    else:
        route.append(index)
        node.add(index)
else:
    print(index)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().rstrip().split(" ")))
bit = [0 for i in range(32)]
for i in range(32):
    for i2 in A:
        if (i2 >> i) & 1:
            bit[i] += 1
ans = [0 for i in range(len(A))]
for i in range(32):
    for i2 in range(len(A)):
        if bit[i] % 2 == 0:
            if (A[i2] >> i) & 1:
                ans[i2] += 2 ** i
        else:
            if not (A[i2] >> i) & 1:
                ans[i2] += 2 ** i
print(" ".join(map(str,ans)))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().rstrip().split(" ")))
bit = [0 for i in range(32)]
for i in range(32):
    for i2 in A:
        if (i2 >> i) & 1:
            bit[i] += 1
ans = [0 for i in range(len(A))]
for i in range(32):
    for i2 in range(len(A)):
        if bit[i] % 2 == 0:
            if (A[i2] >> i) & 1:
                ans[i2] += 2 ** i
        else:
            if not (A[i2] >> i) & 1:
                ans[i2] += 2 ** i
print(" ".join(map(str,ans)))
### BUGGY CODE ###

def main():
  s = input()
  ls = len(s)
  ss = set(s)
  t = input()
  lt = len(t)
  st = set(t)
  td = {x:list() for x in ss}
  if not st.issubset(ss):
    print(-1)
    exit()
  for i in range(lt-1):
    td[t[i]].append(t[i+1])
  md = [0]*ls
  cd = dict()
  for i in range(ls-1,-1,-1):
    cd[s[i]] = i + ls
  for i in range(ls-1,-1,-1):
    md[i] = {x:k for x,k in cd.items() if x in td[s[i]]}
    cd[s[i]] = i
  ans = 0
  cur = cd[t[0]]
  for i in range(lt-1):
    cur = md[cur][t[i+1]]
    ans += (cur//ls)
    cur %= ls
  print(1 + ans*ls+cur)

if __name__ == "__main__":
  main()

### FIXED CODE ###

def main():
  s = list(map(lambda x:ord(x)-97, list(input())))
  ls = len(s)
  ss = set(s)
  t = list(map(lambda x:ord(x)-97, list(input())))
  lt = len(t)
  st = set(t)
  td = [list() for _ in range(26)]
  if not st.issubset(ss):
    print(-1)
    exit()
  for i in range(lt-1):
    td[t[i]].append(t[i+1])
  md = [None for _ in range(ls)]
  cd = [0]*26
  for i in range(ls-1,-1,-1):
    cd[s[i]] = i + ls
  for i in range(ls-1,-1,-1):
    md[i] = cd.copy()
    cd[s[i]] = i
  ans = 0
  cur = cd[t[0]]
  for i in range(lt-1):
    cur = md[cur][t[i+1]]
    ans += (cur//ls)
    cur %= ls
  print(1 + ans*ls+cur)

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

N = int(input())
S = input()
ans = 0
count = [[0 for i in range(N)] for j in range(3)]
for i in range(N):
    if S[i] == 'R':
        count[0][i] = 1
    if S[i] == 'G':
        count[1][i] = 1
    if S[i] == 'B':
        count[2][i] = 1
for i in range(3):
    for j in range(N-1,0,-1):
        count[i][j-1] += count[i][j]
for i in range(N-2):
    a = S[i]
    for j in range(i+1,N-1):
        b = S[j]
        if a != b:
            if a != 'R' and b != 'R':
                ans += count[0][j]
                if 2*j-i < N and S[j+j-i] == 'R':
                    ans -= 1
            if a != 'G' and b != 'G':
                ans += count[1][j]
                if 2*j-i < N and S[j+j-i] == 'G':
                    ans -= 1
            if a != 'B' and b != 'B':
                ans += count[2][j]
                if 2*j-i < N and S[j+j-i] == 'B':
                    ans -= 1
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = 0
count = [[0 for i in range(N)] for j in range(3)]
for i in range(N):
    if S[i] == 'R':
        count[0][i] = 1
    if S[i] == 'G':
        count[1][i] = 1
    if S[i] == 'B':
        count[2][i] = 1
for i in range(3):
    for j in range(N-1,0,-1):
        count[i][j-1] += count[i][j]
for i in range(N-2):
    a = S[i]
    for j in range(i+1,N-1):
        b = S[j]
        if a != b:
            if a != 'R' and b != 'R':
                ans += count[0][j]
                if 2*j-i < N and S[j+j-i] == 'R':
                    ans -= 1
            if a != 'G' and b != 'G':
                ans += count[1][j]
                if 2*j-i < N and S[j+j-i] == 'G':
                    ans -= 1
            if a != 'B' and b != 'B':
                ans += count[2][j]
                if 2*j-i < N and S[j+j-i] == 'B':
                    ans -= 1
print(ans)
### BUGGY CODE ###

import numpy as np

n = int(input())
a = list(map(int,input().split()))
a = np.array(a,dtype=np.int64)
b = [((a>>i)&1).sum() for i in range(61)]
li = []
for i in a:
    c = np.array([((i>>j)&1) for j in range(61)],dtype=np.int64)
    d = b-c
    point = 0
    for i in range(61):
        if d[i]%2 == 1:
            point += 2**(i)
    li.append(point)

print(*li)

### FIXED CODE ###

import numpy as np

n = int(input())
a = list(map(int,input().split()))
now = 0
for i in a:
    now ^= i
li = []
for i in a:
    li.append(i^now)

print(*li)
### BUGGY CODE ###

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

memo = {1: 1, 0: 0}
def dfs(n):
    if n in memo:
        return memo[n]

    y = 1
    res = n
    while y*y <= n:
        y += 1
        if y + A >= res:
            break
        res = min(res, y + A + dfs((n + y - 1) // y))
    memo[n] = res
    return res
print(dfs(N))

### FIXED CODE ###

# seishin.py
N, A = map(int, input().split())

ans = N
if N > 1:
    for k in range(1, 41):
        left = 0; right = N+1
        while left+1 < right:
            mid = (left + right) // 2
            if mid**(k+1) < N:
                left = mid
            else:
                right = mid
        m = right
        v = (m-1)**(k+1)
        for i in range(k+1):
            v //= m-1
            v *= m
            if N <= v:
                ans = min(ans, A*k + (m-1)*(k+1) + (i+1))
                break
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
ans = [-1] * N

def find(x):
    global ans
    if ans[x] == -1:
        return x
    else:
        return find(ans[x])
    
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    xx = find(x)
    yy = find(y)
    if ans[x] == ans[y] == -1:
        ans[y] = x
    elif xx == yy:
        continue
    else:
        ans[yy] = xx

n = 0
for i in ans:
    if i == -1:
        n += 1

print(n)

### FIXED CODE ###

N, M = map(int, input().split())
ans = [-1] * N

def find(x):
    global ans
    if ans[x] == -1:
        return x
    else:
        ans[x] = find(ans[x])
        return ans[x]
    
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    xx = find(x)
    yy = find(y)
    if ans[x] == ans[y] == -1:
        ans[y] = x
    elif xx == yy:
        continue
    else:
        ans[yy] = xx

n = 0
for i in ans:
    if i == -1:
        n += 1

print(n)
### BUGGY CODE ###

S = input()
Q = int(input())
Que = (input() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if len(elem) == 1:
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S = elem[4] + S
    elif s == 2 and flag == 0:
      S += elem[4]
    elif s == 1 and flag == 1:
      S += elem[4]
    else:
      S = elem[4] + S

if flag == 1:
  S = S[::-1]
print(S)

### FIXED CODE ###

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

S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4])
    else:
      S.appendleft(elem[4])

if flag == 1:
  S.reverse()
print(''.join(S))
### BUGGY CODE ###

from bisect import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans = 0
b_c= [0]*n
for i  in range(n-2):
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        max_c = a+b-1
        ans += bisect(l[j+1:],max_c)
print(ans)

### FIXED CODE ###

from bisect import bisect_left
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans = 0
for i  in range(n-2):
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        k = bisect_left(l,a+b)
        ans += k-j-1
print(ans)
### BUGGY CODE ###

from collections import Counter

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

if len(a) == len(set(a)):
    for i in range(n):
        print(0)
else:
    for i in range(n):
        ans = 0
        temp = a[:i] + a[i + 1:]
        kw = Counter(temp)
        for k in kw.values():
            if k != 1:
                ans += k * (k - 1) // 2

        print(ans)


### FIXED CODE ###

from collections import Counter

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

if len(a) == len(set(a)):
    for i in range(n):
        print(0)
else:
    kw = Counter(a)
    ans = sum([x * (x - 1) // 2 for x in kw.values()])

    for i in range(n):
        print(ans - kw[a[i]] + 1)
### BUGGY CODE ###

from collections import deque

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# print(N, M, K)
# print(A)
# print(B)


consumptions_A = []
for i in range(len(A) + 1):
    consumptions_A.append(sum(A[:i]))

consumptions_B = []
for i in range(len(B) + 1):
    consumptions_B.append(sum(B[:i]))

answer = 0
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    for j in range(len(consumptions_B)):
        consumption = consumptions_A[i] + consumptions_B[j]
        if (consumption > K): break
    
        num_books = i + j
        answer = max(answer, num_books)

print(answer)


### FIXED CODE ###

from collections import deque

N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# print(N, M, K)
# print(A)
# print(B)


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)
### BUGGY CODE ###

from sys import stdin
data = stdin.readlines()

a = int(data[0])
b = [int(s) for s in data[1].split()]

ans = 1
for i in range(0,a):
    ans = ans * b[i]
if ans > 10 ** 18:
    ans = -1

print(ans)

### FIXED CODE ###

from sys import stdin
data = stdin.readlines()

a = int(data[0])
b = [int(s) for s in data[1].split()]

if 0 in b:
    print(0)
else:
    ans = 1
    for i in range(0,a):
        ans = ans * b[i]
        if ans > 10**18:
            print(-1)
            break
        else:
            continue
    else:
        print(ans)
### BUGGY CODE ###

# D

x = int(input())

a = int(x**(1/5))
b = int(abs(x-a**5)**(1/5))
i = 1
while True:
    if a**5 - b**5 != x and a**5 - (-b)**5 != x:
        a += i
        b = int(abs(x-a**5)**(1/5))
        if a**5 - b**5 == x:
            print(a,b)
            break
        elif a**5 - (-b)**5 == x:
            print(a,-b)
            break
        else:
            pass
        
    elif a**5 - b**5 == x:
        print(a,b)
        break

    else:
        print(a,-b)
        break

    


### FIXED CODE ###

# D

x = int(input())

a = int(x**(1/5))
b = int(abs(x-a**5)**(1/5))
i = 1
while True:
    if a**5 - b**5 != x and a**5 - (-b)**5 != x:
        if a**5 - x > (a+1)**5 - x:
            a += i
            b = int(abs(x-a**5)**(1/5))
            if a**5 - b**5 == x:
                print(a,b)
                break
            elif a**5 - (-b)**5 == x:
                print(a,-b)
                break
            else:
                pass
        else:
            a -= 1
            b = int(abs(x-a**5)**(1/5))
            if a**5 - b**5 == x:
                print(a,b)
                break
            elif a**5 - (-b)**5 == x:
                print(a,-b)
                break
            else:
                pass
    elif a**5 - b**5 == x:
        print(a,b)
        break

    else:
        print(a,-b)
        break
### BUGGY CODE ###

n = int(input())
s = input()
sum =0

for  i in range(n):
    for j in range(i+1,n):
        flag = 0
        if s[i] == s[j]:
            continue
        if 2*j-i < n and s[2*j-i] != s[i] and s[2*j-i] != s[j]:
            flag = 1
        
        s_new = s[j+1:]
        sum += n - j-1 - s_new.count(s[i]) - s_new.count(s[j]) - flag
        #print(s_new, flag, sum)

print(sum)


### FIXED CODE ###

def main():
    n = int(input())
    s = input()
    r = s.count("R")
    g = s.count("G")
    b = s.count("B")
    ans = r*g*b

    for i in range(n-2):
        for j in range(i+1,n-1):
            if s[i] != s[j]:
                if 2*j-i < n:
                    if s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                        ans-=1

    
    print(ans)

main()
### BUGGY CODE ###

import queue


def make_state(N):
    state = [[-1 for j in range(N+1)] for i in range(N+1)]
    min_state = 0
    s = min_state
    for i in range(1, N+1):
        for j in range(1, i):
            state[i][j] = s
            state[j][i] = s
            s += 1
    return state


def solve(N, A):
    state = make_state(N)
    max_state = N * (N-1) // 2
    prev_states = [[] for i in range(max_state)]
    next_states = [[] for i in range(max_state)]
    for i in range(1, N+1):
        for k in range(N-2):
            ps = state[i][A[i][k]]
            ns = state[i][A[i][k+1]]
            prev_states[ns].append(ps)
            next_states[ps].append(ns)
    
    n_days = 0
    visited = [False for i in range(max_state)]
    q = queue.Queue()
    while not all(visited):
        n_days += 1
        for s in range(max_state):
            if not visited[s] and len(prev_states[s]) == 0:
                q.put(s)
        if q.empty():
            return -1
        while not q.empty():
            s = q.get()
            for ns in next_states[s]:
                prev_states[ns].remove(s)
            visited[s] = True
    return n_days


def main():
    N = int(input())
    A = list()
    A.append([])
    for i in range(N):
        a = list(map(int, input().strip().split()))
        A.append(a)
    print(solve(N, A))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def make_state(N):
    state = [[-1 for j in range(N+1)] for i in range(N+1)]
    min_state = 0
    s = min_state
    for i in range(1, N+1):
        for j in range(1, i):
            state[i][j] = s
            state[j][i] = s
            s += 1
    return state


def solve(N, A):
    state = make_state(N)
    max_state = N * (N-1) // 2
    n_prev_states = [0 for i in range(max_state)]
    next_states = [set() for i in range(max_state)]
    for i in range(1, N+1):
        for k in range(N-2):
            ps = state[i][A[i][k]]
            ns = state[i][A[i][k+1]]
            n_prev_states[ns] += 1
            next_states[ps].add(ns)
    
    today_states = set()
    for s in range(max_state):
        if n_prev_states[s] == 0:
            today_states.add(s)
    
    n_days = 0
    n_states_left = max_state
    while len(today_states) > 0:
        n_days += 1
        if len(today_states) == 0:
            break
        n_states_left -= len(today_states)
        nextday_states = set()
        for s in today_states:
            for ns in next_states[s]:
                n_prev_states[ns] -= 1
                if n_prev_states[ns] == 0:
                    nextday_states.add(ns)
        today_states = nextday_states
    return n_days if n_states_left == 0 else -1


def main():
    N = int(input())
    A = list()
    A.append([])
    for i in range(N):
        a = list(map(int, input().strip().split()))
        A.append(a)
    print(solve(N, A))


if __name__ == "__main__":
    main()