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

import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors


def solve():
    N = int(rl())
    A = list(map(int, rl().split()))
    
    a_set = set()
    memo = set()
    for ai in A:
        if ai in a_set:
            memo.add(ai)
            if ai == 1:
                print(0)
                return
        else:
            a_set.add(ai)
    if 1 in a_set:
        print(1)
        return
    
    se = set()
    A.sort()
    ans = 0
    for ai in A:
        flg = True
        divs = make_divisors(ai)
        for div in divs:
            if div in se:
                flg = False
                break
        if ai in memo:
            flg = False
        se.add(ai)
        ans += flg
    print(ans)


if __name__ == '__main__':
    solve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors


def solve():
    _ = int(rl())
    A = list(map(int, rl().split()))
    
    a_set = set()
    memo = set()
    for ai in A:
        if ai in a_set:
            memo.add(ai)
            if ai == 1:
                print(0)
                return
        else:
            a_set.add(ai)
    if 1 in a_set:
        print(1)
        return
    
    counter = [0] * (10 ** 6 + 1)
    for ai in A:
        for m in range(ai, 10 ** 6 + 1, ai):
            counter[m] += 1
    
    ans = 0
    for ai in A:
        if counter[ai] == 1:
            ans += 1
    print(ans)


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

n = int(input())
sum_n = 0
while n > 0:
    sum_n += n % 10
    n //= 10
flag = 'Yes' if sum_n % 9 == 0 else 'No'
print(flag)

### FIXED CODE ###

n = input()
sum_n = 0
for i in n:
    sum_n += int(i)

flag = 'Yes' if sum_n % 9 == 0 else 'No'
print(flag)
### BUGGY CODE ###

import math
n=int(input())
l=[int(x) for x in input().split()]
for k in range(n):
  L=l.pop(k)
  ans=0
  for i in range(n+1):
    c=l.count(i)
    if c>1:
      ans=ans+math.factorial(c) // (math.factorial(c- 2) * 2)
  print(ans)
  l.insert(k,L)

### FIXED CODE ###

N = int(input())
A = [int(x) for x in input().split()]
l = [0]*N
ans = 0
for a in A:
    l[a-1] += 1
for j in l:
    ans += int(j*(j-1)/2)
for k in range(N):
    print(ans - l[A[k]-1] + 1)
### BUGGY CODE ###

K, S = map(int,input().split())
yz = []
for y in range(K+1):
  for z in range(y,K+1):
    if y == z:
      yz.append([y+z,1])
    else:
      yz.append([y+z,2])
cnt = 0
for x in range(K+1):
  for i in range(len(yz)):
    if x + yz[i][0] == S and yz[i][1] == 1:
      cnt += 1
    elif x + yz[i][0] == S and yz[i][1] == 2:
      cnt += 2
print(cnt)

### FIXED CODE ###

K, S = map(int,input().split())
cnt=0
for y in range(K+1):
  for z in range(y,K+1):
    if y == z and 0 <= S-y-z <=K:
      cnt+=1      
    elif 0 <= S-y-z <=K:
      cnt += 2
      
print(cnt)
### BUGGY CODE ###

#!/usr/bin/env python3


N = int(input())
power = 1
for i in range(1,N+1):
    power *= i
print(power % (10**9+7))


### FIXED CODE ###

#!/usr/bin/env python3


N = int(input())
power = 1
for i in range(1,N+1):
    power *= i
    power %= 10**9+7
print(power)
### BUGGY CODE ###

n=int(input())
if(n%2==0):
    print(-1)
else:
    a=7 
    ans=1
    flag=1  
    while(flag):
        if(a%n==0):
            print(ans)
            flag=0
            break 
        else:
            ans+=1 
            s=str(a)
            s1='7'
            s2=int(s+s1)
            a=int(s2)
            
         


### FIXED CODE ###

n=int(input())
if(n%2==0 or n%5==0):
    print(-1)
else:
    a=7 
    ans=1
    flag=1  
    while(flag):
        if(a%n==0):
            print(ans)
            flag=0
            break 
        else:
            ans+=1 
            s=str(a)
            s1='7'
            s2=int(s+s1)
            a=(int(s2))%n
### BUGGY CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n) :
  at = a[i]
  a[i] = 0
  print(max(a))
  a[i] = at

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
a_max = max(a)
max_c = a.count(a_max)

for i in range(n) :
  if a[i] != a_max :
    print(a_max)
  else :
    if max_c == 1 :
      a[i] = 0
      print(max(a))
    else :
      print(a_max)
### BUGGY CODE ###

N, K = map(int, input().split())
sushi = []
for i in range(N):
    s = list(map(int, input().split()))
    sushi.append(s)


sushi.sort(key=lambda x: x[1], reverse=True)

def find_next(start, curr, point, tlist, tcount):
    if start == N:
        return [point, curr]
    max_c = curr
    max_p = point
    for s in sushi[start:]:
        if tlist[s[0]] > 0:
            continue
        for ri in range(len(curr) - 1, -1, -1):
            r = curr[ri]
            if tlist[r[0]] >= 2:
                c2 = [c for c in curr]
                t2 = [t for t in tlist]
                del c2[ri]
                c2.append(s)
                t2[r[0]] -= 1
                t2[s[0]] = 1
                p2 = point - r[1] + s[1] + (tcount + 1) * (tcount + 1) - tcount * tcount
                np, pc = find_next(start + 1, c2, p2, t2, tcount + 1)

                if np > max_p:
                    max_p = np
                    max_c = pc
                return [max_p, max_c]
    return [max_p, max_c]

result = sushi[0: K]
type_count = [0] * (N + 1)

for r in result:
    type_count[r[0]] += 1
type_num = 0
for t in type_count:
    if t > 0:
        type_num += 1
point = type_num * type_num
for r in result:
    point += r[1]
ans_p, ans_c = find_next(K, result, point, type_count, type_num)

print(ans_p)

### FIXED CODE ###

N, K = map(int, input().split())
sushi = []
for i in range(N):
    s = list(map(int, input().split()))
    sushi.append(s)


sushi.sort(key=lambda x: x[1], reverse=True)

# pick from first
point = 0
neta_set = set()
removable_idx = list()
for i in range(K):
    s = sushi[i]
    point += s[1]
    if s[0] not in neta_set:
        neta_set.add(s[0])
    else:
        removable_idx.append(i)
point += len(neta_set) **2
max_point = point

# pick latest
for s in sushi[K:]:
    if len(removable_idx) == 0:
        break
    if s[0] in neta_set:
        continue
    idx = removable_idx[-1]
    count = len(neta_set)
    point += s[1] - sushi[idx][1]
    point += (count + 1) ** 2 - count ** 2
    neta_set.add(s[0])
    removable_idx = removable_idx[:-1]

    if point > max_point:
        max_point = point
print(max_point)
### BUGGY CODE ###

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

maxpair = (-1,-1)

for i in range(N-K+1):
    ksum = sum(PP[i:i+(K)])
    if ksum > maxpair[1]:
        maxpair = (i,ksum)
        
mp = maxpair[0]        
maxrange = PP[mp:(mp+K)]

esum = 0
for m in maxrange:
    esum += (m+1)/2
    
print(esum)


### FIXED CODE ###

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


mind = -1
mmax = -1

sums = []
csum = 0

for i in range(N):
    p = PP[i]
    csum += (p+1)/2
    sums.append(csum)
    if i < K:
        if mmax < csum:
            mind = i
            mmax = csum
    else:
        ksum = csum - sums[(i-K)]
        if mmax < ksum:
            mind = i
            mmax = ksum


print(mmax)
### BUGGY CODE ###

def solve():
    n = int(input())
    a = [int(input()) for _ in range(n)]

    ans = 0
    for i in a:
        num = a.count(i)
        if num%2 == 1:
            ans += 1

    return ans

if __name__ == "__main__":
    print(solve())



### FIXED CODE ###

import collections
def solve():
    n = int(input())
    a = [int(input()) for _ in range(n)]

    c = collections.Counter(a)

    num = list(c.values())
    ans = 0
    for i in range(len(num)):
        if num[i]%2 == 1:
            ans += 1

    return ans

if __name__ == "__main__":
    print(solve())
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    *A, = map(int, input().split())
    ans = 0
    B = [0] * 61
    for k, a in enumerate(A):
        *la, = map(int, list(bin(a))[2:])
        j = 0
        for i in range(61-len(la), 61):
            B[i] += la[j]
            j += 1

    ans = 0
    mod = 10**9 + 7
    for i, b in enumerate(B):
        ans += b * (len(A)-b) * 2**(60-i) % mod
    print(ans % mod)


if __name__ == "__main__":
    main()


### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
array = [0] * 60
for a in A:
    for j in range(len(bin(a))-2):
        array[j] += (a >> j) & 1
ans = 0
for i in range(60):
    ans += array[i] * (n-array[i]) * 2**i
print(ans % mod)
### BUGGY CODE ###

def rewrite_count(vi_list):
    if len(set(vi_list)) != 1:
        vi_count_list = [(i, vi_list.count(i)) for i in set(vi_list)]
        vi_count_list = sorted(vi_count_list, key=lambda x: x[1])
        return vi_count_list[-1][0], len(vi_list) - vi_count_list[-1][1], len(vi_list) - vi_count_list[-2][1]
    else:
        return vi_list, 0, 0

N = int(input())
v_list = input().split()

if len(set(v_list)) == 1:
    print(len(v_list) // 2)
    exit()

v1_list = [v_list[i] for i in range(0, len(v_list), 2)]
v2_list = [v_list[i] for i in range(1, len(v_list), 2)]
max_v1, max_value_v1, second_value_v1 = rewrite_count(v1_list)
max_v2, max_value_v2, second_value_v2 = rewrite_count(v2_list)

if max_v1 != max_v2:
    ans = max_value_v1 + max_value_v2
elif max_value_v1 > max_value_v2:
    ans = max_value_v2 + second_value_v1
else:
    ans = max_value_v1 + second_value_v2
print(ans)

### FIXED CODE ###

from collections import *

N = int(input())
v_list = input().split()

if len(set(v_list)) == 1:
    print(len(v_list) // 2)
    exit()

v1_list = v_list[::2]
v2_list = v_list[1::2]

v1_count_list = Counter(v1_list).most_common()
v2_count_list = Counter(v2_list).most_common()

if v1_count_list[0][0] != v2_count_list[0][0]:
    print(len(v_list) - v1_count_list[0][1] - v2_count_list[0][1])
else:
    countor1 = len(v_list) - v1_count_list[1][1] - v2_count_list[0][1]
    countor2 = len(v_list) - v1_count_list[0][1] - v2_count_list[1][1]
    print(min(countor1, countor2))
### BUGGY CODE ###

N = int(input())
A = list(input() for _ in range(N))

print(len([i for i in A if A.count(i)%2 != 0]))

### FIXED CODE ###

import collections
N= int(input())
A = sorted(list(int(input()) for i in range(N)))
c = collections.Counter(A)
count = 0

for v in c.values():
    if v%2 !=0:
        count +=1 

print(count)
### BUGGY CODE ###

from collections import defaultdict
import sys
input = sys.stdin.readline
import queue




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

    link_data = defaultdict(set)
    indegree = defaultdict(int)

    for now_node in range(1, num + 1):
        data = list(map(int, input().split()))
        for j in range(num - 1):
            next_node = data[j]
            now_tuple = (min(now_node, next_node), max(now_node, next_node))
            if j == 0:
                indegree[now_tuple] += 0
            else:
                link_data[pre_tuple].add(now_tuple)
                indegree[now_tuple] += 1
            pre_tuple = now_tuple


    q = queue.Queue()
    count_node = 0

    for node, count in indegree.items():
        if count == 0:
            q.put((node, 1))
            count_node += 1

    while not q.empty():
        now_node, length = q.get()
        for next_node in link_data[now_node]:
            indegree[next_node] -= 1
            if indegree[next_node] == 0:
                q.put((next_node, length + 1))
                count_node += 1

    if count_node < (num * (num - 1)) // 2:
        print(-1)
    else:
        print(length)







if __name__ == '__main__':
    main()



### FIXED CODE ###

from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
from collections import deque

import queue

def get_ind(pre_tuple, num):
    a, b = pre_tuple
    ans = (a - 1) * num + b
    return ans



def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]

    graph_data = [set() for i in range(num * num)]
    parent_node = [0 for i in range(num * num)]

    for i in range(num):
        now_node = i + 1
        pre_tuple = (0, 0)
        for j in range(num - 1):
            next_node = data[i][j]
            now_tuple = (min(now_node, next_node), max(now_node, next_node))
            if j == 0:
                pass
                # parent_node[now_tuple] += 0
            else:
                index = get_ind(pre_tuple, num)
                # print(index, pre_tuple)
                graph_data[index].add(now_tuple)
                index2 = get_ind(now_tuple, num)
                parent_node[index2] += 1
            pre_tuple = now_tuple

    q = deque([])
    count_node, ans = 0, 0

    for i in range(1, num + 1):
        for j in range(i + 1, num + 1):
            node = (i, j)
            index = get_ind(node, num)
            if parent_node[index] == 0:
                q.append((node, 1))
                count_node += 1

    while len(q) > 0:
        now_node, length = q.popleft()
        index = get_ind(now_node, num)
        for next_node in graph_data[index]:
            index2 = get_ind(next_node, num)
            parent_node[index2] -= 1
            if parent_node[index2] == 0:
                q.append((next_node, length + 1))
                count_node += 1

    if count_node < (num * (num - 1)) // 2:
        print(-1)
    else:
        print(length)







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

from collections import deque

he,w,k = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
l = [list(input()) for i in range(he)]

sx -= 1
sy -= 1
gx -= 1
gy -= 1
q = deque([])
d = [[float("INF")]*w for i in range(he)]

d[sx][sy] = 0
q.append((0,sx,sy))
while q:
    dis,bx,by = q.popleft()
    if bx == gx and by == gy:
        print(d[gx][gy])
        exit()
    for i in range(1,k+1):
        if 0 <= bx+i < he and l[bx+i][by] != "@":
            if d[bx+i][by] > dis+1:
                d[bx+i][by] = dis+1
                q.append((dis+1,bx+i,by))
        else:
            break
    for i in range(1,k+1):
        if 0 <= bx-i < he and l[bx-i][by] != "@":
            if d[bx-i][by] > dis+1:
                d[bx-i][by] = dis+1
                q.append((dis+1,bx-i,by))
        else:
            break
    for i in range(1,k+1):
        if 0 <= by+i < w and l[bx][by+i] != "@":
            if d[bx][by+i] > dis+1:
                d[bx][by+i] = dis+1
                q.append((dis+1,bx,by+i))
        else:
            break
    for i in range(1,k+1):
        if 0 <= by-i < w and l[bx][by-i] != "@":
            if d[bx][by-i] > dis+1:
                d[bx][by-i] = dis+1
                q.append((dis+1,bx,by-i))
        else:
            break

if d[gx][gy] == float("INF"):
    print(-1)


### FIXED CODE ###

from collections import deque

he,w,k = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
l = [list(input()) for i in range(he)]

sx -= 1
sy -= 1
gx -= 1
gy -= 1
q = deque([])
d = [[float("INF")]*w for i in range(he)]
dx = [1,-1,0,0]
dy = [0,0,1,-1]
d[sx][sy] = 0
q.append((0,sx,sy))
while q:
    dis,bx,by = q.popleft()
    if bx == gx and by == gy:
        continue
    for i in range(4):
        for j in range(1,k+1):
            nx = bx+dx[i]*j
            ny = by+dy[i]*j
            if 0 > nx or 0 > ny or nx >= he  or ny >= w:
                break
            if l[nx][ny] == "@":
                break
            if d[nx][ny] <= dis:
                break
            if d[nx][ny] > dis+1:
                d[nx][ny] = dis+1
                q.append((dis+1,nx,ny))

if d[gx][gy] == float("INF"):
    print(-1)
else:
    print(d[gx][gy])
### BUGGY CODE ###

input()
x = list(map(int,input().split()))

a= x[1:]
a2= x[:1]
for i in a:a2.append(a2[-1]*i)

if a2[-1] > 1e18:
	print(-1)
else:
  	print(a2[-1])

### FIXED CODE ###

lenght = int(input())
 
x = list(map(int,input().split()))
x.sort(reverse=True)
check = False

if x[-1]==0:
  print(0)
else:
  first_value = 1
  for val in x:
    first_value *= val
    if first_value > 1e18:
      check=True
      break
  if check:
    print(-1)
  else:
  	print(first_value)
### BUGGY CODE ###

import functools,fractions
def lgcd(list):
  return functools.reduce(fractions.gcd, list)

n = int(input())
nums = list(map(int,input().split()))
cand = []
cand.append(lgcd(nums[1:]))
cand.append(lgcd(nums[:-1]))
for i in range(n-2):
  i += 1
  cand.append(lgcd(nums[:i]+nums[i+1:]))
print(max(cand))

### FIXED CODE ###

from collections import deque
from fractions import gcd
n=int(input())
a=list(map(int,input().split()));g=a[-1]
b=deque([a[0]])
for num in reversed(a[1:]):
	g=gcd(g,num)
	b.appendleft(g)
m=b[0];gg=a[0]
for i,j in enumerate(a[:n-1]):
	gg=gcd(gg,j)
	m=max(m,gcd(gg,b[i+1]))
print(m)
### BUGGY CODE ###

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

z = []
for i in range(len(a3)):
     u = a.count(a3[i])
     z.append(u)

for j in range(n):
    count = 1
    for i in z:
        count += i*(i-1)/2
    count -= z[a3.index(a[j])]
    print(int(count))

### FIXED CODE ###

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

u = collections.Counter(a)

sume = 0
for i in u.values():
    sume += int(i*(i-1)/2)

for k in range(n):
    s = u[a[k]]
    print(sume-s+1)
### BUGGY CODE ###

import numpy as np
#from numba import jit

def search(N, K, ps, ps_means, maxval):
    for i in range(N):
        ps_means[i] = ((1 + ps[i]) * ps[i])/ 2
        if i + 1 >= K:
            #print(i)
            #print(K)
            a = ps[i-K+1:i+1]
            #print(a)
            b = [np.delete(a, i).prod() for i in range(K)]
            #print(b)
            c = ps_means[i-K+1:i+1] * b
            #print(c)
            sumval = np.sum(c) / a.prod()
            if sumval > maxval:
                maxval = sumval
    #print(ps_means)
    return maxval

def main():
    N, K = map(int, input().split(" "))
    ps = np.array(input().split(" "))
    ps = ps.astype("int64")

    ps_means = np.zeros(N)
    maxval = 0
    ans = search(N, K, ps, ps_means, maxval)
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import numpy as np
 
def main():
    N, K = map(int, input().split(" "))
    ps = np.array(input().split(" "))
    ps = ps.astype("int64")
 
    ps_means = np.zeros(N)
    maxval = 0
 
    for i in range(N):
        ps_means[i] = ((1 + ps[i]) * ps[i])/ 2
        if i + 1 >= K:
            if i + 1 == K:
                sumval = np.sum(ps_means[i-K+1:i+1] / ps[i-K+1:i+1])
            else:
                sumval -= ps_means[i-K] / ps[i-K]
                sumval += ps_means[i] / ps[i]
            if sumval > maxval:
                maxval = sumval
 
    ans = maxval
    print(ans)
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

inf = input().split()
H = int(inf[0])
W = int(inf[1])
dic = {}
score = {}
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    for w in range(W+2):
      dic[(h,w)] = False
      score[(h,w)] = (0,0)
  else:
    line = input()
    dic[(h,0)] = False
    dic[(h,W+1)] = False
    score[(h,0)] = (0,0)
    score[(h, w+1)] = (0,0)
    for w in range(W):
      if line[w]=='.':
        dic[(h,w+1)] = True
      else:
        dic[(h,w+1)] = False
      
for h in range(1,H+1):
  for w in range(1,W+1):
    score[(h,w)]=(0,0)
    if dic[(h,w)]:
      s = 0
      hs = 0
      ws = 0
      if dic[(h-1,w)]:
        s += score[(h-1,w)][0]
        hs += score[(h-1,w)][0]
      else:
        i = h+1
        while dic[(i,w)]:
          s+=1
          hs+=1
          i+=1
      if dic[(h, w-1)]:
        s += score[(h, w-1)][1]
        ws += score[(h,w-1)][1]
      else:
        j = w+1
        while dic[(h,j)]:
          s+=1
          ws+=1
          j+=1
      s+=1
      score[(h,w)]=(hs, ws)
      if m < s:
        m = s
print(m)

### FIXED CODE ###

inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    score[h]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)
### BUGGY CODE ###

S = list(input())
Q = int(input())
l_list = []
r_list = []
flag = True
for i in range(Q):
    A = list(map(str, input().split()))
    if len(A)==1:
        flag = not flag
    else:
        if flag:
            if A[1]=="1":
                l_list.insert(0, A[2])
            else:
                r_list.append(A[2])
        else:
            if A[1]=="1":
                r_list.append(A[2])
            else:
                l_list.insert(0, A[2])
if flag:
    print("".join(l_list)+"".join(S)+"".join(r_list))
else:
    print("".join(r_list[::-1])+"".join(S[::-1])+"".join(l_list[::-1]))

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
flag = True
for i in range(Q):
    A = list(map(str, input().split()))
    if len(A)==1:
        flag = not flag
    else:
        if flag:
            if A[1]=="1":
                S.appendleft(A[2])
            else:
                S.append(A[2])
        else:
            if A[1]=="1":
                S.append(A[2])
            else:
                S.appendleft(A[2])
S = "".join(S)
if flag:
    print(S)
else:
    print(S[::-1])
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict,deque
import copy


def solve():
  ## input
  N = int(input())
  An = [deque([i-1 for i in list(map(int, input().split()))]) for _ in range(N)]  

  ## solve
  ret = 0
  Pn = set([i for i in range(N)])
  while len(Pn) > 0:
    Qn = set([])
    dct = defaultdict(lambda:set([]))
    for i in Pn:
      if len(An[i]) == 0:
        continue
      j = An[i][0]
      if i in dct[j]:
        An[i].popleft()
        An[j].popleft()
        Qn = Qn | set([i,j])
        if len(An[i]) > 0:
          Qn.add(An[i][0])
        if len(An[j]) > 0:
          Qn.add(An[j][0])
      else:
        dct[i].add(j)
    if len(Qn) == 0:
      if max([len(An[i]) for i in range(N)]) > 0:
        return -1
      else:
        return ret
    else:
      ret += 1
      Pn = copy.deepcopy(Qn)
  return ret


print(solve())


### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import deque,defaultdict
from sys import stdin



def solve():
  ## input
  N = int(input())
  An = [deque([i-1 for i in list(map(int, stdin.readline().rstrip().split()))]) for _ in range(N)]

  ## solve
  Pn = set([i for i in range(N)])
  count = 0
  while len(Pn) > 0:
    Qn = set([])
    dct = defaultdict(lambda:set([]))
    for i in Pn:
      j = An[i][0]
      if i in dct[j]:
        An[i].popleft()
        if len(An[i]) > 0:
          Qn.add(i)
          Qn.add(An[i][0])
        An[j].popleft()
        if len(An[j]) > 0:
          Qn.add(j)
          Qn.add(An[j][0])
      else:
        dct[i].add(j)
    Pn = Qn
    count += 1
  for i in range(N):
    if len(An[i]) > 0:
      return -1
  return count



print(solve())