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

import sys

import numpy as np

sys.setrecursionlimit(2 ** 31 - 1)
INF = float('inf')

N = int(sys.stdin.readline())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N - 1)]

graph = [set() for _ in range(N + 1)]
for a, b in AB:
    graph[a].add(b)
    graph[b].add(a)


def dfs(to, path):
    if path[-1] == to:
        return path
    v = path[-1]
    prev = path[-2] if len(path) >= 2 else None

    ret = None
    for u in graph[v]:
        if u != prev:
            ret = ret or dfs(to, path + [u])
    return ret


# 1 から N までのパス
path = dfs(N, [1])
cut = (len(path) - 1) // 2
fennec = path[:cut + 1]
snuke = path[cut + 1:]

fixed = np.zeros(N + 1, dtype=str)
fixed[fennec] = 'f'
fixed[snuke] = 's'

while fennec:
    v = fennec.pop()
    for u in graph[v]:
        if not fixed[u]:
            fixed[u] = 'f'
            fennec.append(u)
while snuke:
    v = snuke.pop()
    for u in graph[v]:
        if not fixed[u]:
            fixed[u] = 's'
            snuke.append(u)

if sum(fixed == 'f') > sum(fixed == 's'):
    print('Fennec')
else:
    print('Snuke')


### FIXED CODE ###

import sys

import numpy as np

sys.setrecursionlimit(2 ** 31 - 1)
INF = float('inf')

N = int(sys.stdin.readline())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)

s1 = [1]
s2 = [N]
fennec = 0
snuke = 0
fixed = np.zeros(N + 1, dtype=bool)
while s1 or s2:
    u1 = []
    for v in s1:
        if fixed[v]:
            continue
        fixed[v] = True
        fennec += 1
        u1.extend(graph[v])
    s1 = u1

    u2 = []
    for v in s2:
        if fixed[v]:
            continue
        fixed[v] = True
        snuke += 1
        u2.extend(graph[v])
    s2 = u2

if fennec > snuke:
    print('Fennec')
else:
    print('Snuke')
### BUGGY CODE ###

H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
s=[[] for _ in range(H)]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  s[h-1].append(w-1)

maxh=maxw=0
qh=[]
qw=[]
for i in range(H):
  maxh=max(maxh, sumh[i])
for i in range(H):
  if maxh==sumh[i]:
    qh.append(i)

for i in range(W):
  maxw=max(maxw, sumw[i])
for i in range(W):
  if maxw==sumw[i]:
    qw.append(i)

#print(s,H,W,sumh,sumw,qh,qw)
for i in qh:
  for j in qw:
    if j not in s[i]:
      print(maxh+maxw)
      exit()

print(maxh+maxw-1)

### FIXED CODE ###

H,W,M=map(int, input().split())
sumh=[0]*H
sumw=[0]*W
bomb=[]
for i in range(M):
  h,w=map(int, input().split())
  sumh[h-1]+=1
  sumw[w-1]+=1
  bomb.append((h,w))

maxh=max(sumh)
maxw=max(sumw)
ch=sumh.count(maxh)
cw=sumw.count(maxw)

cnt=0
for h,w in bomb:
  if sumh[h-1]==maxh and sumw[w-1]==maxw:
    cnt+=1

if cnt==ch*cw:
  print(maxh+maxw-1)
else:
  print(maxh+maxw)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
import copy
li=[0]
ans=0
temp=0

for j in range(N):
    ans+=A[j]
    li.append(copy.copy(ans))


for k in range(N):
    for l in range(k+1,N+1):
        if li[l]-li[k]==0:
            temp+=1
print(temp)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
import copy
li=[0]
ans=0

for j in range(N):
    ans+=A[j]
    li.append(copy.copy(ans))

li.sort()
ans=0
temp=1
for i in range(N):

    if li[i]==li[i+1]:
        temp+=1
    else:
        ans+=temp*(temp-1)//2
        temp=1
ans+=temp*(temp-1)//2
print(ans)
### BUGGY CODE ###

MOD = 10 ** 9 + 7
fac = [1] * (10 ** 5 + 10)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD


def comb(n, k):
    if k < 0 or k > n:
        return 0
    return fac[n] * pow(fac[n - k], MOD - 2, MOD) * pow(fac[k], MOD - 2, MOD) % MOD


n = int(input())
a = list(map(int, input().split()))
d = [-1] * n
for i, x in enumerate(a):
    if d[x - 1] != -1:
        p = d[x - 1]
        q = i
    else:
        d[x - 1] = i
print(n)
for k in range(2, n + 2):
    ans = 0
    ans += comb(n - 1, k - 2)
    ans += comb(n - 1, k - 1) * 2 - comb(p + n - q, k - 1)
    ans += comb(n - 1, k)
    print(ans % MOD)


### FIXED CODE ###

MOD = 10 ** 9 + 7
fac = [1] * (10 ** 5 + 10)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD


def comb(n, k):
    if k < 0 or k > n:
        return 0
    return fac[n] * pow(fac[n - k], MOD - 2, MOD) * pow(fac[k], MOD - 2, MOD) % MOD


n = int(input())
a = list(map(int, input().split()))
d = [-1] * n
for i, x in enumerate(a):
    if d[x - 1] != -1:
        p = d[x - 1]
        q = i
    else:
        d[x - 1] = i
print(n)
for k in range(2, n + 2):
    ans = 0
    ans += comb(n - 1, k - 2)
    ans += comb(n - 1, k - 1) * 2 - comb(p + n - q, k - 1)
    ans += comb(n - 1, k)
    print(ans % MOD)
### BUGGY CODE ###

import copy
 
n, t = map(int, input().split())
L = [int(i) for i in input().split()]
LL = copy.deepcopy(L)
 
minvalue = L[0]
maxvalue = max(LL)
subt = maxvalue - minvalue
count = 1
flag = 0
j = 0
for i in range(n-1):
  if minvalue > L[i]:
    minvalue = L[i]
    flag = 1
    LL = LL[i-j+1:]
    maxvalue = max(LL)
    j = i+1    
 
  tsubt = maxvalue - minvalue
  if tsubt > subt:
    subt = tsubt
    count = 1
  elif tsubt == subt and flag == 1:
    count += 1
  flag = 0
#  print("L[i]:{0}, min:{1}, max:{2}, subt:{3}, count:{4}".format(L[i], minvalue, maxvalue, subt, count))

print(count)

### FIXED CODE ###

import copy
 
n, t = map(int, input().split())
L = [int(i) for i in input().split()]

LL = [[0] for i in range(n)]
tmax = L[-1]
for i in range(n):
  if tmax <= L[-i-1]:
    tmax = L[-i-1]
  LL[-i-1] = tmax
 
minvalue = L[0]
maxvalue = LL[0]
subt = 0
count = 1
flag = 0
flagg = 0
j = 0
for i in range(n-1):
  if minvalue > L[i]:
    minvalue = L[i]
    flag = 1
  
  maxvalue = LL[i]
 
  #if maxvalue == L[i]:
    #LL = LL[i-j+1:]
    #maxvalue = max(LL)
    #j = i+1
 
  tsubt = maxvalue - minvalue
  if tsubt > subt:
    subt = tsubt
    count = 1
  elif tsubt == subt and flag == 1:
    count += 1
  flag = 0
  #print("L[i]:{0}, min:{1}, max:{2}, subt:{3}, count:{4}".format(L[i], minvalue, maxvalue, subt, count))
 
print(count)
### BUGGY CODE ###

a, b, n = map(int,input().split())
for i in range(a, b+1):
    if i <= a + n -1 or i >= b - n + 1:
        print(i)

### FIXED CODE ###

a, b, n = map(int,input().split())
for i in range(a, a + n + 1):
    if i > b - n:
        break
    if i <= a + n - 1:
        print(i)
    
for j in range(b - n, b + 1):
    if i > b:
        break
    if j >= b - n + 1 and a <= j:
        print(j)
### BUGGY CODE ###

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
    
n,a,b = map(int,input().split())

res = pow(2,n,10**9+7)
res -= 1


res -= combinations_count(n,a)
res %= 10**9+7

res -= combinations_count(n ,b)
res %= 10**9+7

print(res)

### FIXED CODE ###

n,a,b = map(int,input().split())
mod = 10**9+7

def C(n, r, mod):
    x=y=1
    for i in range(r):
        x *= n; y *= r
        x %= mod; y %= mod
        n -= 1; r -= 1
    return x * pow(y, mod - 2, mod) % mod


res = pow(2,n,mod) - 1


comb_a = C(n,a,mod)
comb_b = C(n,b,mod)

print((res-(comb_a+comb_b))%mod)
### BUGGY CODE ###

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

wa_count = { i+1: 0 for i in range(N) }
ac_count = []
wa,ac = 0,0

for i in range(M):
  p,s = map(str,input().split())
  p = int(p)
  if s == "AC" and p not in ac_count:
    ac += 1
    wa += wa_count[p]
    ac_count.append(p)
  else:
    wa_count[p] += 1

print(ac, wa)

### FIXED CODE ###

num_of_probs, num_of_submission = [ int(i) for i in input().split(" ") ]

solution_table = {}

for i in range(0, num_of_submission):
  prob, result = [ i for i in input().split(" ") ]

  if solution_table.get(int(prob)) == None:
    solution_table[int(prob)] = {"WA": 0, "AC": 0}

  if result == "WA":
    if solution_table[int(prob)]["AC"] == 0:
      solution_table[int(prob)]["WA"] += 1
  else:
    if solution_table[int(prob)]["AC"] == 0:
      solution_table[int(prob)]["AC"] += 1

total_ac = 0
total_wa = 0
for value in solution_table.values():
  if value['AC'] > 0:
    total_wa += value['WA']
    total_ac += value['AC']

print( total_ac, total_wa )
### BUGGY CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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 = I()
p = LI()

ans = 0
dp = [[min(i, j, n - (i + 1), n - (j + 1)) for j in range(n)] for i in range(n)]
dp2 = [[False]*n for _ in range(n)]
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]
for i in p:
    q = (i-1) % n
    r = (i-1) // n
    ans += dp[r][q]
    dp2[r][q] = True
    h = []
    heappush(h, (dp[r][q], r, q))
    while h:
        d, y, x = heappop(h)
        if not dp2[y][x]:
            d += 1
        for j in range(4):
            ny, nx = y + dy[j], x + dx[j]
            if 0 <= ny < n and 0 <= nx < n:
                if dp[ny][nx] > d:
                    dp[ny][nx] = d
                    heappush(h, (d, ny, nx))
print(ans)
    
    

### FIXED CODE ###

#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
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 = I()
p = LI()
p = [((i-1)%n, (i-1)//n) for i in p]
ans = 0
dp = [[min(i, j, n - (i + 1), n - (j + 1)) for j in range(n)] for i in range(n)]
dp2 = [[False]*n for _ in range(n)]
for (q, r) in p:
    ans += dp[r][q]
    dp2[r][q] = True
    h = [(dp[r][q], r, q)]
    while h:
        d, y, x = h.pop()
        if not dp2[y][x]:
            d += 1
        if x != 0:
            if dp[y][x-1] > d:
                dp[y][x-1] = d
                h.append((d, y, x-1))
        if x != n-1:
            if dp[y][x+1] > d:
                dp[y][x+1] = d
                h.append((d, y, x+1))
        if y != 0:
            if dp[y-1][x] > d:
                dp[y-1][x] = d
                h.append((d, y-1, x))
        if y != n-1:
            if dp[y+1][x] > d:
                dp[y+1][x] = d
                h.append((d, y+1, x))
print(ans)
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
R = sorted(L)
var = 0
for i in range(N-2):
  for j in range(N-i-1-1):
    for k in range(N-i-1-j-1):
      if R[i] + R[i+1+j] > R[i+1+j+1+k]:
        var = var+1
      else:
        break
print(var)

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):  # １番短い棒
    for j in range(i + 1, N):  # 真ん中の長さの棒
        ans += bisect_left(L, L[i] + L[j]) - (j + 1)

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

from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for i in range(N)]
for i in range(N):
  copy_A = A[:i]+A[i+1:]
  copy_A.sort(reverse=True)
  print(copy_A[0])

### FIXED CODE ###

import copy
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for i in range(N)]
copy_A = copy.copy(A)
copy_A.sort(reverse=True)
max_a, sec_a = copy_A[0], copy_A[1]
for i in range(N):
  if A[i] == max_a:
    print(sec_a)
  else:
    print(max_a)
### BUGGY CODE ###

import queue

H, W = map(int, input().split())
A = []
D = [[-1 for _ in range(W)] for _ in range(H)]
q = queue.Queue()
for i in range(H):
    S = input()
    for j in range(W):
        if S[j] == "#":
            q.put((i, j))
            D[i][j] = 0
    A.append(S)

ans = 0
while not q.empty():
    pos = q.get()
    py, px = pos[0], pos[1]
    for (y, x) in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
        ny = py + y
        nx = px + x
        if nx < 0 or W <= nx or ny < 0 or H <= ny:
            continue
        if D[ny][nx] < 0:
            D[ny][nx] = D[py][px] + 1
            ans = max(ans, D[ny][nx])
            q.put((ny, nx))
print(ans)


### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
A = []
D = [[-1 for _ in range(W)] for _ in range(H)]
q = deque([])
for i in range(H):
    S = input()
    for j in range(W):
        if S[j] == "#":
            q.append((i, j))
            D[i][j] = 0
    A.append(S)

while q:
    pos = q.popleft()
    py, px = pos[0], pos[1]
    for (y, x) in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
        ny = py + y
        nx = px + x
        if nx < 0 or W <= nx or ny < 0 or H <= ny:
            continue
        if D[ny][nx] < 0:
            D[ny][nx] = D[py][px] + 1
            q.append((ny, nx))

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, D[i][j])
print(ans)
### BUGGY CODE ###

import collections

n,k=map(int,input().split())
g=[[] for _ in range(n+1)]
e=[]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
  e.append((a,b))
ans=0
if k%2==0:
  for i in range(1,n+1):
    tmp=0
    checked=[0]*(n+1)
    checked[i]=1
    q=collections.deque()
    q.append((i,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=k//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    ans=max(ans,tmp)
  print(n-ans)
if k%2==1:
  for v1,v2 in e:
    tmp=0
    checked=[0]*(n+1)
    checked[v1]=1
    checked[v2]=1
    q=collections.deque()
    q.append((v1,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=k//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    checked=[0]*(n+1)
    checked[v1]=1
    checked[v2]=1
    q=collections.deque()
    q.append((v2,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=(k-1)//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    ans=max(ans,tmp)
  print(n-ans)    

### FIXED CODE ###

import collections

n,k=map(int,input().split())
g=[[] for _ in range(n+1)]
e=[]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
  e.append((a,b))
ans=0
if k%2==0:
  for i in range(1,n+1):
    tmp=0
    checked=[0]*(n+1)
    checked[i]=1
    q=collections.deque()
    q.append((i,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=k//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    ans=max(ans,tmp)
  print(n-ans)
if k%2==1:
  for v1,v2 in e:
    tmp=0
    checked=[0]*(n+1)
    checked[v1]=1
    checked[v2]=1
    q=collections.deque()
    q.append((v1,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=k//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    checked=[0]*(n+1)
    checked[v1]=1
    checked[v2]=1
    q=collections.deque()
    q.append((v2,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=(k-1)//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    ans=max(ans,tmp)
  print(n-ans)
### BUGGY CODE ###

def main():
    s = input()
    n = len(s)
    dp = [[0] * 13 for _ in range(n)]
    mod = 10**9 + 7

    if s[n-1] == '?':
        for i in range(10):
            dp[0][i] = 1
    else:
        dp[0][int(s[n-1])] = 1

    for i in range(1,n):
        a = len(s) - i
        if s[a-1] == '?':
            for j in range(13):
                for k in range(10):
                    b = (k * 10 ** i + j) % 13
                    dp[i][b] += dp[i-1][j]
        else:
            k = int(s[a-1])
            for j in range(13):
                b = (k * 10 ** i + j) % 13
                dp[i][b] += dp[i-1][j]
        for j in range(13):
            dp[i][j] %= mod

    print(dp[n-1][5]%mod)

if __name__ == '__main__':
    main()


### FIXED CODE ###

s = input()
n = len(s)
dp = [[0] * 13 for _ in range(n)]
mod = 10**9 + 7

if s[0] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(s[0])] = 1

for i in range(1,n):
    if s[i] == '?':
        for j in range(13):
            for k in range(10):
                dp[i][(j * 10 + k) % 13] += dp[i-1][j]
    else:
        k = int(s[i])
        for j in range(13):
            dp[i][(j * 10 + k) % 13] += dp[i-1][j]
    for j in range(13):
        dp[i][j] %= mod

print(dp[n-1][5]%mod)
### BUGGY CODE ###

import numpy as np

H, W, D = map(int, input().split())
pos = [None]*(H*W)

for i in range(H):
    row = list(map(int, input().split()))
    for j in range(W):
        pos[row[j]-1] = (i, j)

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    if L == R:
        print(0)
    else:
        to_be_checked = [i for i in range(L, R+1, D)]
        moves = len(to_be_checked)
        pos_list = [pos[i-1] for i in to_be_checked]

        MP = sum([np.absolute(pos_list[i][0] - pos_list[i+1][0]) for i in range(moves-1)]) + sum([np.absolute(pos_list[i][1] - pos_list[i+1][1]) for i in range(moves-1)])

        print(MP)

### FIXED CODE ###

H, W, D = map(int, input().split())
pos = [None]*(H*W)

for i in range(H):
    row = list(map(int, input().split()))
    for j in range(W):
        pos[row[j]-1] = (i, j)

costs = [0]*(H*W)
for i in range(1, D+1):
    current = i + D
    while current <= H*W:
        costs[current - 1] = costs[current - 1 - D] + abs(pos[current - 1][0] - pos[current - 1 - D][0]) + abs(pos[current - 1][1] - pos[current - 1 - D][1])
        current += D

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    MP = costs[R-1] - costs[L-1]
    print(MP)
### BUGGY CODE ###

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

L.sort()
ans=0
for i in range(n):
  for j in range(i+1,n):
    cnt=0
    for k in range(j+1,n):
      if L[i]+L[j]<=L[k]:
        ans+=cnt
        break
      cnt+=1
    else:
      ans+=cnt
print(ans)

### FIXED CODE ###

import bisect
n=int(input())
L=list(map(int,input().split()))

L.sort()
ans=0
for i in range(n):
  for j in range(i+1,n):
    index=bisect.bisect_left(L,L[i]+L[j])
    ans+=index-(j+1)
    
print(ans)
### BUGGY CODE ###

cnt = 0
def merge(A,left,mid,right):
	n1 = mid - left
	n2 = right - mid
	L = []
	R = []
	for i in range(0,n1):
		L.append(A[left+i])

	for i in range(0,n2):
		R.append(A[mid+i])
	L.append(1000000001)
	R.append(1000000001)


	i = 0
	j = 0
	global cnt
	for k in range(left,right):
		cnt += 1
		if L[i] <= R[j]:
			A[k]=L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1

def mergeSort(A,left,right):
	if left+1 < right:
		mid = (left+right)//2
		mergeSort(A,left,mid)
		mergeSort(A,mid,right)
		merge(A,left,mid,right)


if __name__ == '__main__':
	n = (int)(input())
	a = list(map(int,input().split()))
	
	mergeSort(a,0,len(a))
	print(*a)
	print(cnt)

### FIXED CODE ###

cnt = 0
def merge(A,left,mid,right):
	'''n1 = mid - left
	n2 = right - mid
	L = []
	R = []
	for i in range(0,n1):
		L.append(A[left+i])

	for i in range(0,n2):
		R.append(A[mid+i])
	L.append(1000000001)
	R.append(1000000001)
	'''
	L = A[left:mid]+[1000000001]
	R = A[mid:right]+[1000000001]

	i = 0
	j = 0
	global cnt
	for k in range(left,right):
		cnt += 1
		if L[i] <= R[j]:
			A[k]=L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1

def mergeSort(A,left,right):
	if left+1 < right:
		mid = (left+right)//2
		mergeSort(A,left,mid)
		mergeSort(A,mid,right)
		merge(A,left,mid,right)


if __name__ == '__main__':
	n = (int)(input())
	a = list(map(int,input().split()))
	
	mergeSort(a,0,n)
	print(*a)
	print(cnt)
### BUGGY CODE ###

n = int(input())

rgb = input()

r = []
g = []
B = []

for i in range(n):
    if rgb[i] == "R":
        r.append(i + 1)
    elif rgb[i] == "G":
        g.append(i + 1)
    elif rgb[i] == "B":
        B.append(i + 1)

ans = 0
for a in r:
    for b in g:
        for c in B:
            aaa = sorted(list([a,b,c]))

            if (aaa[0] + aaa[2]) / 2  == aaa[1]:continue
            ans += 1

print(ans)

### FIXED CODE ###

n = int(input())

rgb = input()

r = rgb.count("R")
g = rgb.count("G")
b = rgb.count("B")

ans = r * g * b

for i in range(n):
    for k in range(n):
        a = i + k
        b = a + k
        if b >= n:break
        if rgb[i] != rgb[a] and rgb[i] != rgb[b] and rgb[a] != rgb[b]:
            ans -= 1 
print(ans)
### BUGGY CODE ###

import sys
from collections import defaultdict

def dfs(start, dest, pre, d):
    if d[start][dest] > 0:
        return d[start][dest]

    for i in range(len(d)):
        if d[start][i] > 0 and i != pre:
            c = dfs(i, dest, start, d)
            if c > 0:
                return d[start][i] + dfs(i, dest, start, d)

    return 0

def main():
    input = sys.stdin.readline
    N = int(input())
    
    tree = defaultdict(lambda: [])
    d = [[0 for _ in range(N)] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        a, b = a - 1, b - 1
        
        d[a][b] = c
        d[b][a] = c

    Q, K = map(int, input().split())
    k_dist = [0 for _ in range(N)]
    for i in range(N):
        k_dist[i] = dfs(K-1, i, -1, d)

    for _ in range(Q):
        x, y = map(int, input().split())
        x, y = x - 1, y - 1

        print(int(k_dist[x] + k_dist[y]))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import deque

def dfs(start, dest, pre, d):
    if d[start][dest] > 0:
        return d[start][dest]

    for i in range(len(d)):
        if d[start][i] > 0 and i != pre:
            c = dfs(i, dest, start, d)
            if c > 0:
                return d[start][i] + dfs(i, dest, start, d)

    return 0

def main():
    input = sys.stdin.readline
    N = int(input())
    
    d = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        a, b = a - 1, b - 1
        
        d[a].append((b, c))
        d[b].append((a, c))

    Q, K = map(int, input().split())
    K -= 1

    k_dist = [0 for _ in range(N)]
    start = deque()
    start.append(K)
    while len(start) > 0:
        s = start.popleft()
        for dest, cost in d[s]:
            if k_dist[dest] > 0:
                continue

            k_dist[dest] = k_dist[s] + cost
            start.append(dest)

    for _ in range(Q):
        x, y = map(int, input().split())
        x, y = x - 1, y - 1

        print(int(k_dist[x] + k_dist[y]))


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

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9+1]*n
    dp[0] = 0
    for i in range(n-1):
        for j in range(1, k+1):
            if n <= i+j:
                break
            if dp[i] + abs(h[i] - h[i+j]) < dp[i+j]:
                dp[i+j] = dp[i] + abs(h[i] - h[i+j])
    print(dp[n-1])

if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [10**9+1]*n
    dp[0] = 0
    for i in range(1, n):
        buf = [dp[j] + abs(h[j]-h[i]) for j in range(max(i-k,0), i)]
        dp[i] = min(buf)
    print(dp[n-1])

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

n = int(input())
a=input().split()
a_int = [int(i) for i in a]

ans=[0]*n

for i in range(n-1):
    ans[i]=0

    for m in range(n-1):

        if a_int[m] == i+1:
            ans[i]=ans[i]+1

for i in range(n):
    print(str(ans[i]))

### FIXED CODE ###

n = int(input())
a=input().split()

ans=[0]*n

for i in range(n-1):
    ans[int(a[i])-1]+=1
    
print(*ans, sep='\n')