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

a, b, c, d = map(int, input().split())
dp = [[1 for _ in range(d - b + 1)] for _ in range(c - a + 1)]

mod = 998244353
for x in range(c - a + 1):
    for y in range(d - b + 1):
        if x == 0:
            if y > 0:
                dp[x][y] = dp[x][y - 1] * (a + x) % mod
        elif y == 0:
            dp[x][y] = dp[x - 1][y] * (b + y) % mod
        else:
            dp[x][y] = (((dp[x - 1][y] * (b + y)) + (dp[x][y - 1] * (a + x))) - (dp[x - 1][y - 1] * (a + x - 1) * (b + y - 1))) % mod

print(dp[-1][-1])

### FIXED CODE ###

a, b, c, d = map(int, input().split())
dp = [[1 for _ in range(d - b + 1)] for _ in range(c - a + 1)]

mod = 998244353
for x in range(c - a + 1):
    for y in range(d - b + 1):
        if x == 0:
            if y > 0:
                dp[x][y] = dp[x][y - 1] * (a + x) % mod
        elif y == 0:
            dp[x][y] = dp[x - 1][y] * (b + y) % mod
        else:
            dp[x][y] = (((dp[x - 1][y] * (b + y)) + (dp[x][y - 1] * (a + x))) - (dp[x - 1][y - 1] * (a + x - 1) * (b + y - 1))) % mod

print(dp[-1][-1])
### BUGGY CODE ###

N = int(input())
L = [int(i) for i in input().split()]

L = sorted(L, reverse=True)
ans = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if L[i] < L[j] + L[k]:
                ans += 1
            else:
                break

print(ans)


### FIXED CODE ###

import bisect
N = int(input())
L = [int(i) for i in input().split()]

SL = sorted(L)
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        right = bisect.bisect_left(SL, SL[i] + SL[j])
        left = j + 1
        ans += right - left

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

n, m = map(int, input().split())
broken_list = [int(input()) for _ in range(m)]

a = 1
b = 0 if 1 in broken_list else 1

if n == 1:
  print(1)
  exit()
if n == 2:
  if broken_list:
    print(1)
  else:
    print(2)
  exit()
  
for i in range(2, n+1):
  if i in broken_list:
    a, b = b, 0
  else:
    a, b = b, a + b

print(b%1000000007)

### FIXED CODE ###

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

a = 1
b = 1

i = 2

for j in range(m):
  ind = int(input())
  if ind == 1:
    b = 0
    continue
  while i < ind:
    a, b = b, a+b
    i += 1
  else:
    a, b = b, 0
    i += 1
    
while i < n+1:
  a, b = b, a+b
  i += 1
  
  
print(b%1000000007)
### BUGGY CODE ###

from math import gcd
n=int(input())
A=list(map(int,input().split()))
m=max(A)
l=[0 for _ in range(m)]
fp=True
for a in A:
    l[a-1]+=1
for i in range(2,m):
    cnt=0
    for j in range(i-1,m,i):
        cnt+=l[j]
        if cnt>1:
            fp=False
            break
g=0
fs=False
for a in A:
    g=gcd(g,a)
if g==1:
    fs=True

if fp:
    print("pairwise coprime")
elif fs:
    print("setwise coprime")
else:
    print("not coprime")

### FIXED CODE ###

from math import gcd
def main():
    n=int(input())
    A=list(map(int,input().split()))
    m=max(A)
    l=[0 for _ in range(m)]
    fp=True
    for a in A:
        l[a-1]+=1
    for i in range(2,m):
        cnt=0
        for j in range(i-1,m,i):
            cnt+=l[j]
            if cnt>1:
                fp=False
                break
    g=0
    fs=False
    for a in A:
        g=gcd(g,a)
    if g==1:
        fs=True

    if fp:
        print("pairwise coprime")
    elif fs:
        print("setwise coprime")
    else:
        print("not coprime")
if __name__=="__main__":
    main()
### BUGGY CODE ###

num = int(input())
dic = [input() for i in range(num)]

sdic = []
ans = 0
for i in range(num):
    sdic.append("".join(sorted(dic[i])))
while len(sdic) > 0:
    now = sdic[0]
    cnt = sdic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for i in range(cnt):
        sdic.remove(now)
print(ans)

### FIXED CODE ###

num = int(input())
li = [input() for i in range(num)]

dic = {}
ans = 0
for i in range(num):
    now = "".join(sorted(li[i]))
    if now in dic:
        dic[now] += 1
    else:
        dic[now] = 1
for i in dic:
    n = dic[i]
    ans += int((n*(n-1))/2)

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

N,K=map(int,input().split(" "))
p_list=list(map(int,input().split(" ")))
def expect(i):
    return 0.5*(p_list[i]+1)

e_list=[expect(i) for i in range(N)]

expect_list=[sum(e_list[i:K+i]) for i in range(0,N-K+1+1)]

print(max(expect_list))

### FIXED CODE ###

import numpy as np
N,K=map(int,input().split(" "))
p_list=list(map(int,input().split(" ")))
def expect(i):
    return 0.5*(p_list[i]+1)

e_list=[expect(i) for i in range(N)]
accum_expect=[0]+list(np.cumsum(e_list))

n=N-K+1
expect_list=[accum_expect[i+K]-accum_expect[i] for i in range(0,n)]

print(max(expect_list))
### BUGGY CODE ###

def main():
    n, k = map(int, input().split())
    ds = set()
    for _ in range(k):
        l, r = map(int, input().split())
        ds = ds | {i for i in range(l, r + 1)}
    dp = [0] * (n + 1)
    dp[1] = 1

    for i in range(2, n + 1):
        for d in ds:
            if i - d >= 0:
                dp[i] += dp[i - d]

    print(dp[-1] % 998244353)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    lr = [list(map(int, input().split())) for _ in range(k)]
    dp = [0] * (n + 1)
    dp[1] = 1
    dpsum = [0] * (n + 1)
    dpsum[1] = 1
    mod = 998244353

    for i in range(2, n + 1):
        for j in range(k):
            li = i - lr[j][1]
            ri = i - lr[j][0]
            if ri < 0:
                continue
            dp[i] = (dp[i] + dpsum[ri] - dpsum[li - 1]) % mod
        dpsum[i] = dpsum[i - 1] + dp[i]

    print(dp[-1] % mod)


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

N = int(input())
S = input()

rcount = 0
gcount = 0
bcount = 0

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

count = rcount * gcount * bcount

for i in range(N-1):
    for j in range(i+1,N):
        if S[i] == "R" and S[j] == "G":
            if j+j-i < N and S[j+j-i] == "B":
                count -= 1
            
        if S[i] == "R" and S[j] == "B":
            if j+j-i < N and S[j+j-i] == "G":
                count -= 1

        if S[i] == "G" and S[j] == "R":
            if j+j-i < N and S[j+j-i] == "B":
                count -= 1

        if S[i] == "G" and S[j] == "B":
            if j+j-i < N and S[j+j-i] == "R":
                count -= 1

        if S[i] == "B" and S[j] == "R":
            if j+j-i < N and S[j+j-i] == "G":
                count -= 1

        if S[i] == "B" and S[j] == "G":
            if j+j-i < N and S[j+j-i] == "R":
                count -= 1

print(count)

### FIXED CODE ###

N = int(input())
S = input()

rcount = S.count("R")
gcount = S.count("G")
bcount = N-rcount-gcount



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

input()
ip = "-".join(list(input().split()))
for _ in range(int(input())):
    x,y = input().split()
    ip = ip.replace(x,y)
    print(sum(list(map(int, ip.split('-')))))

### FIXED CODE ###

def freq(my_list):
    count = {} 
    for i in my_list: 
        count[i] = count.get(i, 0) + 1
    return count

n = int(input())
l = list(map(int, input().split()))
s,f = sum(l), freq(l)
for _ in range(int(input())):
    x, y = map(int, input().split())
    if x in f.keys():
        v = f[x]
        if y in f.keys():
            f[y]+=v
            f.pop(x)
        else:
            f[y]=f.pop(x)
        s += (y-x)*v
    print(s)
### BUGGY CODE ###

n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
while m>0:
    l[0]//=2
    m-=1
    l.sort(reverse=True)
print(sum(l))

### FIXED CODE ###

import sys
input = sys.stdin.readline

import heapq

n,m=map(int,input().split())
a=list(map(lambda x: int(x)*-1,input().split()))
heapq.heapify(a)

for _ in range(m):
    Min=heapq.heappop(a)
    Min=(-Min//2)*-1
    heapq.heappush(a,Min)
print(sum(a)*-1)
### BUGGY CODE ###

s=input()
check=list(s)
n=len(s)
cnt=0
if n==1:
    print(0)
else:
    flag=False
    while 1:
        for i in range(n-1):
            if check[i]=='B' and check[i+1]=='W':
                cnt+=1
                check[i]='W'
                check[i+1]='B'
                break
            if i==n-2:
                flag=True
        if flag:
            break
    print(cnt)

### FIXED CODE ###

s=input()
check=list(s)
n=len(s)
cntb=0
for i in check:
    if i=='B':
        cntb+=1
minus=sum([i+1 for i in range(n) if check[i]=='B' ])
plus=sum(range(n-cntb+1,n+1))
print(plus-minus)
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
mod = 10**9+7

def comb(n, r):
    if n < r or n < 0 or r < 0: return 0
    if n < 2*r: comb(n, n-r)
    return fac[n] * inv[r] * inv[n-r] % mod

def dfs(v, Pa=-1):
    for u in to[v]:
        if u == Pa: continue
        dfs(u, v)
        size[v] += size[u]
        dp[v] *= dp[u] % mod
        dp[v] *= comb(size[v], size[u]) % mod
    size[v] += 1

def bfs(v, Pa=-1, P_val=1, P_sz=0):
    ans[v] = P_val * dp[v] * comb(n-1, P_sz) % mod
    for u in to[v]:
        if u == Pa: continue
        val = ans[v] * INV(dp[u]*comb(n-1, size[u])) % mod
        bfs(u, v, val, n-size[u])

n = int(input())
to = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(lambda x : int(x)-1, input().split())
    to[a].append(b)
    to[b].append(a)

fac = [1] * (n+2)
inv = [1] * (n+2)

for i in range(2, n+1):
    fac[i] = fac[i-1] * i % mod
INV = lambda x: pow(x, mod-2, mod)
inv[n] = INV(fac[n])
for i in range(n-1, 1, -1):
    inv[i] = inv[i+1] * (i+1) % mod

dp = [1] * n
size = [0] * n
ans = [0] * n

dfs(0)
bfs(0)
print(*ans, sep='\n')

### FIXED CODE ###

import sys

def solve():
    input = lambda: sys.stdin.readline().rstrip()
    sys.setrecursionlimit(10 ** 7)
    mod = 10 ** 9 + 7

    def comb(n, r):
        if r > n: return 0
        return fac[n] * inv[r] * inv[n - r] % mod

    def dfs(v, Pa=-1):
        for u in to[v]:
            if u == Pa: continue
            dfs(u, v)
            size[v] += size[u]
            dp[v] *= dp[u] % mod
            dp[v] *= inv[size[u]] % mod
        dp[v] *= fac[size[v]] % mod
        size[v] += 1

    def bfs(v, Pa=-1, P_val=1, P_sz=0):
        ans[v] = P_val * dp[v] * comb(n - 1, P_sz) % mod
        for u in to[v]:
            if u == Pa: continue
            val = ans[v] * INV(dp[u] * comb(n - 1, size[u])) % mod
            bfs(u, v, val, n - size[u])

    n = int(input())
    to = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        to[a].append(b)
        to[b].append(a)

    fac = [1] * (n + 2)
    inv = [1] * (n + 2)

    for i in range(2, n + 1):
        fac[i] = fac[i - 1] * i % mod
    INV = lambda x: pow(x, mod - 2, mod)
    inv[n] = INV(fac[n])
    for i in range(n - 1, 1, -1):
        inv[i] = inv[i + 1] * (i + 1) % mod

    dp = [1] * n
    size = [0] * n
    ans = [0] * n

    dfs(0)
    bfs(0)
    print(*ans, sep='\n')

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

inf = 1145141919810364364
start = 10**15
import heapq

def di(s,fl):
    d = [inf] * n
    used = [1] * n
    d[s] = 0
    used[s] = 0
    lis = []
    
    for q in edge[fl][s]:
        heapq.heappush(lis,q)
        
    while lis:
        minedge = heapq.heappop(lis)
        
        if used[minedge[1]] == 0:
            continue

        v = minedge[1]
        d[v] = minedge[0]
        used[v] = 0

        for q in edge[fl][v]:
            if used[q[1]] == 1:
                heapq.heappush(lis,[q[0]+d[v],q[1]])
    return d

n,m,s,t = map(int,input().split())
#0は円、1はスヌーク
edge = [[[] for i in range(n)] for _ in range(2)]

for i in range(m):
    u,v,a,b = map(int,input().split())
    edge[0][u-1].append([a,v-1])
    edge[0][v-1].append([a,u-1])
    edge[1][u-1].append([b,v-1])
    edge[1][v-1].append([b,u-1])
    
a = di(s-1,0)
b = di(t-1,1)
k = start - a[n-1] - b[n-1]
ans = [0] * n

for i in range(n):
    k = max(k , start - (a[n-1-i] + b[n-1-i]))
    ans[n-1-i] = k
    
for i in range(n):
    print(ans[i])

### FIXED CODE ###

inf = 1145141919810364364
start = 10**15
import heapq

def di(s,fl):
    d = [inf] * n
    used = [1] * n
    d[s] = 0
    used[s] = 0
    lis = []
    
    for a,b in edge[fl][s]:
        heapq.heappush(lis,a*(10**6)+b)
        
    while lis:
        minedge = heapq.heappop(lis)
        
        if used[minedge%(10**6)] == 0:
            continue

        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = 0

        for q in edge[fl][v]:
            if used[q[1]] == 1:
                heapq.heappush(lis,(q[0]+d[v])*(10**6)+q[1])
    return d

n,m,s,t = map(int,input().split())
#0は円、1はスヌーク
edge = [[[] for i in range(n)] for _ in range(2)]

for i in range(m):
    u,v,a,b = map(int,input().split())
    edge[0][u-1].append([a,v-1])
    edge[0][v-1].append([a,u-1])
    edge[1][u-1].append([b,v-1])
    edge[1][v-1].append([b,u-1])
    
a = di(s-1,0)
b = di(t-1,1)
k = start - a[n-1] - b[n-1]
ans = [0] * n

for i in range(n):
    k = max(k , start - (a[n-1-i] + b[n-1-i]))
    ans[n-1-i] = k
    
for i in range(n):
    print(ans[i])
### BUGGY CODE ###

from bisect import bisect_left

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

c = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    c += bisect_left(l[j+1:], l[i]+l[j])

print(c)


### FIXED CODE ###

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

n, p = list(map(int, input().split()))
if(n == 1):
  print(p)
elif(p == 1):
  print(1)
else:
  ans = 1
  tmp = 2
  while(tmp**n <= p):
    if((p%(tmp**n)) == 0): ans = tmp
    tmp+=1
  print(ans)

### FIXED CODE ###

n, p = list(map(int, input().split()))
if(n == 1):
  print(p)
elif(p == 1):
  print(1)
elif(n > 64):
  print(1)
else:
  ans = 1
  tmp = 2
  while(tmp**n <= p):
    if((p%(tmp**n)) == 0): ans = tmp
    tmp+=1
  print(ans)
### BUGGY CODE ###

H, W = map(int, input().split())
A = list()
blacks = list()
for i in range(H):
    s = input()
    for j, c in enumerate(s):
        if c == '#':
            blacks.append((i, j))
    A.append(s)

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == '.':
            dist = float('inf')
            for bi, bj in blacks:
                dist = min(dist, abs(bi - i) + abs(bj - j))
            ans = max(ans, dist)
print(ans)



### FIXED CODE ###

import sys
sys.setrecursionlimit(300000)
from collections import deque

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


H, W = MI()
grid = [list(input()) for _ in range(H)]

seen = set()
q = deque()
for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            q.append((i, j, 0))
            seen.add(i * W + j)
while len(q) > 0:
    h, w, d = q.popleft()
    for dh, dw in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
        if 0 <= h + dh < H and 0 <= w + dw < W and (h + dh) * W + w + dw not in seen:
            q.append((h + dh, w + dw, d + 1))
            seen.add((h + dh) * W + w + dw)
print(d)
### BUGGY CODE ###

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            A[i][j] = 0
        else:
            A[i][j] = -1


def chg(i, j, c):
    if i < 0 or j < 0 or H <= i or W <= j: return
    A[i][j] = A[i][j] if A[i][j] >= 0 else c


def f(c):
    for i in range(H):
        for j in range(W):
            if 0 <= A[i][j] < c:
                A[i][j] = c
                chg(i - 1, j, c)
                chg(i + 1, j, c)
                chg(i, j - 1, c)
                chg(i, j + 1, c)


def chk():
    for i in range(H):
        for j in range(W):
            if A[i][j] == -1: return False
    return True


ans = 0
while 1:
    if chk():
        break
    ans += 1
    f(ans)
print(ans)


### FIXED CODE ###

H, W = [int(_) for _ in input().split()]
A = [list(input()) for _ in range(H)]

from collections import deque

lst = deque()

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            lst.append((i, j, 0))


def chg(i, j):
    if i < 0 or j < 0 or H <= i or W <= j: return False
    if A[i][j] == '.':
        A[i][j] = '#'
        return True
    return False


ans = 0
while lst:
    h, w, v = lst.popleft()
    ans = max(v, ans)
    for i in range(-1, 2):
        for j in range(-1, 2):
            if i != 0 and j != 0: continue

            if chg(h + i, w + j):
                lst.append((h + i, w + j, v + 1))
print(ans)
### BUGGY CODE ###

n = int(input())
num = list(int(input()) for i in range(n))

i = 0

while i != n:
  t = num.pop(0)
  print(max(num))
  num.append(t)
  i += 1


### FIXED CODE ###

n = int(input())
num = list(int(input()) for i in range(n))
test = sorted(num, reverse=True)
i = 0

for i in range(n):
  if(num[i] == test[0]):
    print(test[1])
  else:
    print(test[0])
### BUGGY CODE ###

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

### FIXED CODE ###

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

#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
ans = [-1]*q
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    while l < r:
        if ans[l] == -1:
            ans[l] = x
        l += 1
print(*ans)

### FIXED CODE ###

#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
ans = [-1]*(q+1)
right = [0]*q
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    #l≦d<rを満たすdがxでぶつかる
    #各dにおいて一番最初にぶつかるxを求めたい
    while l < r:
        while ans[l] != -1:
            l = right[l]
        if r <= l:
            break
        ans[l] = x
        right[l] = r
        l += 1
for i in ans[:-1]:
    print(i)
### BUGGY CODE ###

n = input()
p = list(int(i) for i in input().split())
count = 1
for i in range(1,len(p)):
  if(p[i] <= min(p[0:i])):
    count += 1

print(count) 


### FIXED CODE ###

n = input()
p = list(int(i) for i in input().split())
count = 1
min_num = min(p[0:1])
for i in range(1,len(p)):
  if(p[i] <= min_num):
    count += 1
    min_num = p[i]

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

from collections import deque
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
adjacent_list = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
ans = [-1 for i in range(n+1)]
def bfs():
    #start at 1
    que = deque([1])
    finished = set()
    while que:
        node = que.popleft()
        finished.add(node)
        for i in adjacent_list[node]:
            if i not in finished:
                que.append(i)
                if ans[i] == -1:
                    ans[i] = node
bfs()
print("Yes")
for i in range(2,n+1):
    print(ans[i])


### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
adjacent_list = [[] for i in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
ans = [-1 for i in range(n+1)]
def bfs():
    #start at 1
    que = deque([1])
    while que:
        node = que.popleft()
        for i in adjacent_list[node]:
            if ans[i] == -1:
                que.append(i)
                ans[i] = node
bfs()
print("Yes")
for i in range(2,n+1):
    print(ans[i])
### BUGGY CODE ###

n=int(input())
a=[[0]*n]*n
l=[]
s=set()

for i in range(n):
  a[i]=[int(x)-1 for x in input().split()]
l=[int(i) for i in range(n)]

t=0
f=True
while f==True:
  f=False
  s.clear()
  for i in l:
    if len(a[i])==0:
      continue
    f=True
    j=a[i][0]

    if i==a[j][0]:
      s.add(i)
      s.add(j)
  if f==False:
    break

  l = list(s)
  s.clear()
  if len(l)!=0:
    t+=1
    for i in range(len(l)):
      a[l[i]].pop(0)
      s.add(l[i])
      if len(a[l[i]])>0:
        s.add(a[l[i]][0])
  else:
    t = -1
    break
  l=list(s)

print(t)


### FIXED CODE ###

from collections import deque

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

  P,W=[0]*N,[-1]*N
  c=deque(range(N))

  while c:
    i=c.popleft()
    j=A[i].popleft()
    W[i]=j

    if W[j]==i:
      P[i]=P[j]=max(P[i],P[j])+1
      if A[i]:
        c.append(i)
      if A[j]:
        c.append(j)

  print(-1 if any(len(a) for a in A) else max(P))

main()
### BUGGY CODE ###

import sys
import math
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import itertools
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()
A = sorted(A)

for i in range(N):
    count = 0
    for j in range(i, N - 1):
        if int(A[j]) == i + 1:
            count += 1
    print(count)


### FIXED CODE ###

import sys
import math
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import itertools
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

c = Counter(A)
for i in range(N):
    print(c[str(i + 1)])