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

H,W = map(int , input().split())
sh,sw = map(int , input().split())
eh,ew = map(int , input().split())
mv_a_pts = [[-1,0],[1,0],[0,-1],[0,1]]
mv_b_pts = []
for h in range(-2,3,1):
  for w in range(-2,3,1):
    if h != 0 or w != 0:
      mv_b_pts.append([h,w])
maze = []
warp_cnts = [[None]*(W) for j in range(H)]
for i in range(H):
  maze.append(input())

def mv_a(h,w):
  mv_b_tgs.append([h,w])
  warp_cnts[h][w] = cnt
  for vh,vw in mv_a_pts:
    tgh = h + vh
    tgw = w + vw
    if 0 <= tgh <= H-1 and 0 <= tgw <= W-1 :
      if warp_cnts[tgh][tgw] is None and maze[tgh][tgw] != "#":
        mv_a(tgh,tgw)
        

def mv_b(h,w):
  for vh,vw in mv_b_pts:
    tgh = h + vh
    tgw = w + vw
    if 0 <= tgh <= H-1 and 0 <= tgw <= W-1 :
      if warp_cnts[tgh][tgw] is None and maze[tgh][tgw] != "#":
        mv_a_tgs.append([tgh,tgw])
        

mv_b_tgs=[]
mv_a_tgs = [[sh-1,sw-1]]
cnt = 0
while len(mv_a_tgs)>0:
  mv_b_tgs=[]
  for tg in mv_a_tgs:
    mv_a(tg[0],tg[1])
  mv_a_tgs = []
  for wp in mv_b_tgs:
    mv_b(wp[0],wp[1])
  cnt+=1
print(-1 if warp_cnts[eh-1][ew-1] is None else warp_cnts[eh-1][ew-1])

### FIXED CODE ###

from collections import deque
 
 
walk = [(1, 0), (-1, 0), (0, 1), (0, -1)]
warp = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),
        (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),
        (0, -2), (0, -1), (0, 1), (0, 2),
        (1, -2), (1, -1), (1, 0), (1, 1), (1, 2),
        (2, -2), (2, -1), (2, 0), (2, 1), (2, 2),]
 
 
def get_warped(walked, map_):
    warped = deque()
    while walked:
        h, w = walked.popleft()
        for i, j in warp:
            h2 = h + i
            w2 = w + j
            if -1 < h2 < H and -1 < w2 < W and map_[h2][w2] == '.':
                warped.append((h2, w2))
                map_[h2][w2] = map_[h][w] + 1
    return warped, map_
 
 
def get_walked(candidate, map_):
    walked = deque()
    while candidate:
        h, w = candidate.popleft()
        walked.append((h, w))
        for i, j in walk:
            h2 = h + i
            w2 = w + j
            if -1 < h2 < H and -1 < w2 < W and map_[h2][w2] == '.':
                candidate.append((h2, w2))
                map_[h2][w2] = map_[h][w]
    return walked, map_
 
H, W = map(int, input().split())
s_h, s_w = [i-1 for i in map(int, input().split())]
d_h, d_w = [i-1 for i in map(int, input().split())]
map_ = [list(input()) for i in range(H)]
 
candidate = deque([(s_h, s_w)])
map_[s_h][s_w] = 0
 
while candidate:
    walked, map_ = get_walked(candidate, map_)
    candidate, map_ = get_warped(walked, map_)
 
for h in range(H):
    for w in range(W):
        if map_[h][w] == '.':
            map_[h][w] = -1
 
print(map_[d_h][d_w])
### BUGGY CODE ###

from collections import Counter
 
n = int(input())
aL = [list(set(Counter(input()).most_common())) for i in range(n)]
count = 0

for i in range(n-1):
    if aL[i] != "":  
      for j in range(i+1, n):
          if aL[i] == aL[j]:
            tmp = aL.count(aL[i])
            if tmp == 2:
              count += 1
            else:
              count += (tmp-1)*(tmp-2)//2
            aL = ["" if k == aL[i] else i for k in aL]
print(count)


### FIXED CODE ###

from collections import Counter
N = int(input())
S = [input() for i in range(N)]
counter = Counter()
ans = 0
for s in S:
    a = ''.join(sorted(list(s)))
    if a in counter:
        ans += counter[a]
    counter[a] += 1
print(ans)
### BUGGY CODE ###

import sys
import numpy as np
def f(j):
  if j==0:return 0
  if dp[j]!=-1:return dp[j]
  f_k=np.array([f(j-l-1)+abs(h[j]-h[j-l-1]) for l in range(k) if j-l-1>=0])
  dp[j]=np.min(f_k)
  return dp[j]
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=np.array([-1]*n)
sys.setrecursionlimit(1000000000)
print(f(n-1))

### FIXED CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
from functools import lru_cache
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())


n,k = inpl()
h = inpl()
dp = [INF] * (n)
dp[0] = 0
for i in range(min(n,k)):
    dp[i] = abs(h[i] - h[0])
for i in range(n - k):
    option=[dp[i+j]+abs(h[i+k]-h[i+j]) for j in range(k)]
    dp[i + k] = min(option)
print(dp[n - 1])
### BUGGY CODE ###

def resolve():
    N, K, Q = list(map(int, input().split()))
    A = [int(input()) for _ in range(Q)]
    points = [K] * N
    for i in range(N):
        points[i] += A.count(i+1) - Q
        if points[i] > 0:
            print('Yes')
        else:
            print('No')

    return


resolve()

### FIXED CODE ###

def resolve():
    N, K, Q = list(map(int, input().split()))
    A = [int(input()) for _ in range(Q)]
    points = [0] * N
    for i in range(Q):
        points[A[i]-1] += 1

    for i in range(N):
        if K + points[i] - Q > 0:
            print('Yes')
        else:
            print('No')

    return

resolve()
### BUGGY CODE ###

[n,k]=list(map(int,input().split()))
akarusa=list(map(int,input().split()))


for i in range(k):
    imos=[0]*n
    for j in range(n):
        kagen=max(j-akarusa[j],0)
        jogen=min(j+akarusa[j],n-1)
        imos[kagen]+=1
        if jogen+1<n:
            imos[jogen+1]-=1
    akarusanext=[imos[0]]
    for j in range(1,n):
        akarusanext.append(akarusanext[-1]+imos[j])
    
    akarusa=akarusanext
    if min(akarusa)==n:
        break

for i in range(n):
    print(akarusa[i], end=" ")


### FIXED CODE ###

[n,k]=list(map(int,input().split()))
akarusa=list(map(int,input().split()))


for i in range(k):
    imos=[0]*n
    for j in range(n):
        kagen=max(j-akarusa[j],0)
        jogen=min(j+akarusa[j],n-1)
        imos[kagen]+=1
        if jogen+1<n:
            imos[jogen+1]-=1
    akarusanext=imos
    for j in range(1,n):
        akarusanext[j]+=akarusanext[j-1]
    
    if akarusa==akarusanext:
        break
    else:
        akarusa=akarusanext

for i in range(n):
    print(akarusa[i], end=" ")
### BUGGY CODE ###

from operator import mul
from functools import reduce
N = int(input())
L = list(map(int, input().split()))
M = reduce(mul, L)
if 1000000000000000000 < M:
    M = -1
print(M)

### FIXED CODE ###

import sys
O = pow(10, 18)
N = int(input())
L = list(map(int, input().split()))
M = 1

if 0 in L:
    print(0)
    sys.exit()

for i in range(N):
    M = M * L[i]
    if O < M:
        print(-1)
        sys.exit()
    else:
        continue
print(M)
### BUGGY CODE ###

a, b, c, k = map(int, input().split())
s = 0
for i in range(k):
  if a != 0:
    s += 1
    a -= 1
  elif b != 0:
    b -= 1
  elif c != 0:
    s -= 1
    c -= 1
print(s)

### FIXED CODE ###

a, b, c, k = map(int, input().split())

if k >= a:
    r = k - a
    if r >= b:
        r = r - b
        print(a-r)
    else:
        print(a)
else:
    print(k)
### BUGGY CODE ###

n = int(input())
ans = 0
for i in range(n-1):
  ans += i+1 % (i+2)
print(ans)

### FIXED CODE ###

n = int(input())
print(n*(n-1)//2)
### BUGGY CODE ###

from collections import defaultdict
from heapq import heappop, heappush
import sys
input = sys.stdin.buffer.readline
N,M,S = map(int,input().split())
UVAB = [list(map(int,input().split())) for i in range(M)]
A = {}
B = {}
g = defaultdict(list)
for u,v,a,b in UVAB:
    A[(u+v,u*v)] = a
    B[(u+v,u*v)] = b
mc = max(A.values())* M
for u,v,a,b in UVAB:
    for i in range(a,mc+1):
        g[(u,i)].append(((v,i-a),b))
        g[(v,i)].append(((u,i-a),b))
CD = [[0,0]] + [list(map(int,input().split())) for i in range(N)]
C,D = zip(*CD)

for i in range(1,N+1):
    for c in range(mc+1-C[i]):
        g[(i,c)].append(((i,c+C[i]),D[i]))

S = min(S,mc)
dq = [((1,S),0)]

ans = [[10**15 for j in range(mc+1)] for i in range(N+1)]
while dq:
    (v, w), t = heappop(dq)
    if ans[v][w] < t:
        continue
    ans[v][w] = t
    for (nv,nw), nt in g[(v,w)]:
        if ans[nv][nw] > ans[v][w] + nt:
            ans[nv][nw] = ans[v][w] + nt 
            heappush(dq,((nv,nw),t+nt))

for i in range(2,N+1):
    print(min(ans[i]))






### FIXED CODE ###

from collections import defaultdict
from heapq import heappop, heappush,heapify
import sys
input = sys.stdin.readline

N,M,S = map(int,input().split())
UVAB = [list(map(int,input().split())) for i in range(M)]
U,V,A,B = zip(*UVAB)

'''
from itertools import combinations 
N = 14
M = N*(N-1)//2
S = 0
UVAB = [[x,y,50,10**9] for x,y in combinations(range(1,N+1),2)] 
U,V,A,B = zip(*UVAB)
'''

mc = max(A)* M
g = defaultdict(list)

for u,v,a,b in UVAB:
    for i in range(a,mc+1):
        g[(u,i)].append(((v,i-a),b))
        g[(v,i)].append(((u,i-a),b))

CD = [[0,0]] + [list(map(int,input().split())) for i in range(N)]
#CD = [[0,0]] + [[10**9,10**9] for i in range(N)]
C,D = zip(*CD)
C = [min(c,mc) for c in C]

for i in range(1,N+1):
    for c in range(mc+1-C[i]):
        g[(i,c)].append(((i,c+C[i]),D[i]))

S = min(S,mc)
dq = [(0,S,1)]

ans = [[10**15 for j in range(mc+1)] for i in range(N+1)]
while dq:
    t, w, v = heappop(dq)
    if ans[v][w] <= t:
        continue
    for i in range(w+1):
        ans[v][i] = min(t, ans[v][i])
    for (nv,nw), nt in g[(v,w)]:
        if ans[nv][nw] > t + nt:
            heappush(dq,(t+nt,nw,nv))

for i in range(2,N+1):
    print(min(ans[i]))
### BUGGY CODE ###

S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
flag = True
#print(Query)
for i in Query:
    if i[0]=="1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if (flag==True and i[1]=="1") or (flag==False and i[1]=="2"):
            S = i[2]+S
        elif (flag==True and i[1]=="2") or (flag==False and i[1]=="1"):
            S = S+i[2]
if flag:
    print(S)
else:
    print(S[::-1])

### FIXED CODE ###

S = input()
Q = int(input())
Query = [list(map(str,input().split())) for _ in range(Q)]
from collections import deque 
flag = True
f = ""
l = ""
#print(Query)
for i in Query:
    if i[0]=="1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if (flag==True and i[1]=="1") or (flag==False and i[1]=="2"):
            f += i[2] 
        elif (flag==True and i[1]=="2") or (flag==False and i[1]=="1"):
            l += i[2]
S = f[::-1]+S+l
if flag:
    print(S)
else:
    print(S[::-1])
### BUGGY CODE ###

import math
import bisect
import heapq
from collections import deque

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

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

d = [float('inf')] * n
d[0] = 0
d[1] = abs(h[0] - h[1])


for i in range(2,n):

    p = [float('inf')] * (k + 1)

    for j in range(1, min(k+1,i+1)):
        # print(i-j)
        p[j] = d[i-j] + abs(h[i-j]-h[i])

    d[i] = min(p)

print(d[n-1])


### FIXED CODE ###

# import math
# import bisect
# import heapq
# from collections import deque

def main():
    n, k = map(int, input().split())

    h = list(map(int, input().split()))
    inf = 10**7
    d = [inf] * n
    d[0] = 0

    for j in range(1, n):
        p = [d[i] + abs(h[j] - h[i]) for i in range(max(0, j - k), j)]

        d[j] = min(p)

    print(d[-1])

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

N,M,x=map(int,input().split())
a=[]
for i in range(N):
    ai=list(map(int,input().split()))
    a.append(ai)
def cal(b):
    d=[]
    k=0
    c=0
    for i in range(M):
        d.append(0)
    for i in b:
        c+=a[i][0]
        for j in range(M):
            d[j]+=a[i][j+1]
    for i in d:
        if i<x:
            k=1
    if k==0:
        return c
    else:
        return 10000000

mini=10000000
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            for l in range(k,N):
                for m in range(l,N):
                    for n in range(m,N):
                        for o in range(n,N):
                            for p in range(o,N):
                                for q in range(p,N):
                                    for r in range(q,N):
                                        for s in range(r,N):
                                            for t in range(s,N):
                                                b={i,j,k,l,m,n,o,p,q,r,s,t}
                                                mini=min(mini,cal(b))

if mini==10000000:
    print(-1)
else: print(mini)

### FIXED CODE ###

#bit全探索
n,m,x=map(int,input().split())
a=[]
for i in range(n):
    ai=list(map(int,input().split()))
    a.append(ai)

#可能判定
maxi=[0 for i in range(m)]
for i in range(n):
    for j in range(m):
        maxi[j]+=a[i][j+1]
for i in range(m):
    if maxi[i]<x:
        print(-1)
        exit()

mini=100000000
#全探索
for i in range(2**n):
    d=[]
    for j in range(n):
        if((i>>j)& 1):
            d.append(j)
    b=[0 for j in range(m)]
    #得た能力
    c=0
    #お金
    for j in d:
        c+=a[j][0]
        for k in range(m):
            b[k]+=a[j][k+1]
    l=0
    for j in b:
        if j<x:
            l=1
    if l==0:
        mini=min(mini,c)

print(mini)
### BUGGY CODE ###

from collections import deque
h, w = map(int, input().split())
wall = '/'
grid = [[wall] * (w + 2)]
wn = 0

q = deque()
for y in range(1, h+1):
    grid.append([wall] + [c for c in input()] + [wall])
    for x in range(1, w+1):
        if grid[y][x] == '.':
            wn += 1
        if grid[y][x] == '#':
            q.append((y, x, 0))
grid.append([wall] * (w + 2))

move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
while q:
    y, x, i = q.popleft()
    for dy, dx in move:
        if grid[y + dy][x + dx] == '.':
            grid[y + dy][x + dx] = '#'
            q.append((y + dy, x + dx, i + 1))
    
print(i)


### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
wall = '/'
grid = [[wall] * (w + 2)]
wn = 0

q = deque()
for y in range(1, h+1):
    grid.append([wall] + [c for c in input()] + [wall])
    for x in range(1, w+1):
        if grid[y][x] == '.':
            wn += 1
        if grid[y][x] == '#':
            q.append((y, x, 0))
grid.append([wall] * (w + 2))

move = [(-1, 0), (1, 0), (0, -1), (0, 1)]

while q:
    y, x, i = q.popleft()
    grid[y][x] = '#'
    for dy, dx in move:
        if grid[y + dy][x + dx] == '.':
            grid[y + dy][x + dx] = '#'
            q.append((y + dy, x + dx, i + 1))
    
print(i)
### BUGGY CODE ###

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

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

print(ans)

### FIXED CODE ###

import math

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

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

N=int(input())
S=[input() for _ in range(N)]

cnt=[]
ans=0
for i in range(N):
    if S[i][0]=='M':
        cnt.append('M')
    elif S[i][0]=='A':
        cnt.append('A')
    elif S[i][0]=='R':
        cnt.append('R')
    elif S[i][0]=='C':
        cnt.append('C')
    elif S[i][0]=='H':
        cnt.append('H')
        
import math
import itertools
c_list = list(itertools.combinations(cnt, 3))

for v in itertools.combinations(cnt, 3):
    if len(set(v))==3:
        ans+=1

print(ans)


### FIXED CODE ###

N=int(input())
S=[input() for _ in range(N)]
cnt=[0]*N
cnt2=[]
flag=0

if len(S)>1:
    for i in range(N):
        if S[i][0]=='M':
            cnt[0]+=1
        elif S[i][0]=='A':
            cnt[1]+=1
        elif S[i][0]=='R':
            cnt[2]+=1
        elif S[i][0]=='C':
            cnt[3]+=1
        elif S[i][0]=='H':
            cnt[4]+=1

for i in range(N):
    if cnt[i]!=0:
        cnt2.append(cnt[i])
        
import math
import itertools
ans=0

for v in itertools.combinations(cnt2, 3):
    ans+=v[0]*v[1]*v[2]

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

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

S = list(input())
slice_list = []
for _ in range(Q):
    l , r =map(int,input().split())
    slice_list.append([l - 1,r])
for i in range(Q):
    cnt = 0
    work_s = S[slice_list[i][0] : slice_list[i][1]]
    for i in range(len(work_s) - 1):
        if work_s[i] == "A" and work_s[i + 1] == "C":
            cnt += 1
    print(cnt)

### FIXED CODE ###

N , Q = map(int,input().split())
S = list(input())
slice_list = []
for _ in range(Q):
    l , r =map(int,input().split())
    slice_list.append([l - 1,r - 1])
cnt_list = [0] * (N + 1)

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

for i in range(Q):

    print(cnt_list[slice_list[i][1]] - cnt_list[slice_list[i][0]])
### BUGGY CODE ###

n, q = map(int, input().split())
gu = [set() for _ in range(n)]
gl = [set() for _ in range(n)]

def upper(a,b):
  if gu[a] == {}:
    gl[a].add(b)
  else:
    gl[a].add(b)
    for l in gu[a]:
      upper(l, b)

for i in range(n-1):
  a, b = map(int,input().split())
  a, b = a-1, b-1
  gu[b].add(a)

for b in range(n):
  for a in gu[b]:
    upper(a,b)

#print(gu)
#print(gl)

c = [0]*n
for j in range(q):
  x, p = map(int, input().split())
  x = x-1
  c[x] += p
  for k in gl[x]:
    c[k] += p

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

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  g[a].append(b)
  #g[b].append(a)

ans = [0]*n  
for j in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
  
from collections import deque
s = deque()
s.append(0)

while s:
  v = s.pop()
  for v_ in g[v]:
    ans[v_] += ans[v]
    s.append(v_)

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

import sys
sys.setrecursionlimit(1000000)
n, q = map(int,input().split())
ab = [[0 for i in range(n)] for j in range(n)]
d = [[] for i in range(n)]
for i in range(n-1):
    ai, bi = map(int,input().split())
    ab[ai-1][bi-1] = 1
    ab[bi-1][ai-1] = 1
    d[ai-1].append(bi-1)
    d[bi-1].append(ai-1)

#parentを返す
p = [0 for i in range(n)]
#訪問済
x = [0 for i in range(n)]
def f(v):
    x[v] = 1
    for di in d[v]:
        if x[di] == 0:
            p[di] = v
            f(di)
f(0)

#point
px = [0 for i in range(n)]
for i in range(q):
    pi,xi = map(int,input().split())
    px[pi-1] +=xi

def g(v):
    if v == 0:
        return px[v]
    else:
        return px[v]+g(p[v])
for i in range(n):
    if i ==0:
        print(px[0])
    else:
        print(g(i))


### FIXED CODE ###

from collections import deque
n, q = map(int,input().split())
d = [[] for i in range(n)]
for i in range(n-1):
    ai, bi = map(int,input().split())
    d[ai-1].append(bi-1)
    d[bi-1].append(ai-1)
#point
px = [0 for i in range(n)]
for i in range(q):
    pi,xi = map(int,input().split())
    px[pi-1] += xi
sp = [0 for i in range(n)]
s = deque()
s.append(0)
visited = [False for i in range(n)]
while len(s) > 0:
    x = s.popleft()
    visited[x] = True
    sp[x] += px[x]
    for xc in d[x]:
        if not visited[xc]:
            s.append(xc)
            sp[xc] += sp[x]
for i in range(n):
    print(sp[i])
### BUGGY CODE ###

import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)

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

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

ans = 0
for k in dic:
  if dic[k] >= 2:
    ans += C(dic[k], 2)

for i in range(N):
  if dic[A[i]] == 1:
    print(ans)
  if dic[A[i]] == 2:
    print(ans - 1)
  if dic[A[i]] > 2:
    print(ans - (C(dic[A[i]], 2) - C(dic[A[i]]-1, 2)))

### FIXED CODE ###

import math

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

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

memo = [0 for i in range(10 ** 6)]
ans = 0
for k in dic:
  tmp  =dic[k]
  if tmp >= 2:
    if memo[tmp] == 0:
      memo[tmp] = tmp * (tmp - 1) // 2
      ans += memo[tmp]
    else:
      ans += memo[tmp]

for i in range(N):
  tmp = dic[A[i]]
  if tmp == 1:
    print(ans)
  elif tmp == 2:
    print(ans - 1)
  else:
    print(ans - tmp * (tmp - 1) // 2 + (tmp - 1) * (tmp - 2) // 2)
### BUGGY CODE ###

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

m=len(a)
c=list(set(a))
sum1=0

for i in range(len(c)):
    k=a.count(c[i])
    sum1+=k*(k-1)//2



for j in range(m):
    g=a.count(a[j])
    t=sum1-(g-1)
    print(t)


### FIXED CODE ###

import collections
from collections import defaultdict

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

dict = defaultdict(int)
for i in l:
    dict[i]+=1

ans = 0
for v in dict.values():
    ans += int((v*(v-1)) // 2)

for k in l:
    print(ans - (dict[k] - 1))
### BUGGY CODE ###

s = input()
ans = 0
while len(set(s)) == 2:
    c = s[0]
    for i in range(len(s)):
        if s[i] != c:
            idx = i
            break
    s = s[i:]
    ans += 1
print(ans)


### FIXED CODE ###

s = input()
ans = 0
while len(s):
    c = s[0]
    for i in range(len(s)):
        if s[i] != c:
            idx = i
            break
        idx2 = i
    if idx2 == len(s)-1:
        break
    s = s[idx:]
    ans += 1

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

a, b, x = map(int, input().split())

r = 0

for i in range(a, b + 1):
  if i % x == 0:
    r += 1

print(r)

### FIXED CODE ###

a, b, x = map(int,input().split())

r = b // x - a // x
if a % x == 0:
  r += 1

print(int(r))
### BUGGY CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
L=[]
for i in A:
  if i in L:
    L.remove(i)
  else:
    L.append(i)
print(len(L))

### FIXED CODE ###

from collections import defaultdict
N,*A = map(int,open(0).read().split())
d = defaultdict(int) #初期値１
for a in A:
    d[a] ^= 1 #0と1を反転
print(sum(d.values()))
### BUGGY CODE ###

from sys import exit
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
ilist = [0] * n
days = 1
while True:
  booked = set()
  books = 0
  for i in range(n):
    if ilist[i] == n - 1:
      continue
    j = a[i][ilist[i]] - 1
    if a[j][ilist[j]] - 1 != i:
      continue
    if (i in booked) or (j in booked):
      continue
    books += 1
    booked.add(i)
    booked.add(j)
    ilist[i] += 1
    ilist[j] += 1
  if books == 0:
    print(-1)
    exit()
  if all(i == n - 1 for i in ilist):
    break
  days += 1
print(days)


### FIXED CODE ###

from sys import exit, setrecursionlimit
setrecursionlimit(1000000)

def dfs(v, dp, to):
  t = dp[v]
  if t >= 0:
    return t
  dp[v] = 0
  t = 0
  for u in to[v]:
    res = dfs(u, dp, to)
    if res == 0:
      print('-1')
      exit()
    if res > t:
      t = res
  t += 1
  dp[v] = t
  return t

def toId(i, j, id_db):
  if i < j:
    return id_db[i][j]
  else:
    return id_db[j][i]

def main():
  N = int(input())
  a = [[int(e) - 1 for e in input().split()] for _ in range(N)]

  id_db = [[0] * N for _ in range(N)]

  dp = [-1] * (N * (N - 1) // 2)
  to = [[] for _ in range(N * (N - 1) // 2)]

  v = 0
  for i in range(N):
    for j in range(i + 1, N):
      id_db[i][j] = v
      v += 1

  for i in range(N):
    for j in range(N - 1):
      a[i][j] = toId(i, a[i][j], id_db)
    for j in range(N - 2):
      to[a[i][j + 1]].append(a[i][j])

  print(max(dfs(i, dp, to) for i in range(N * (N - 1) // 2)))

main()