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

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

root = [[pow(10,9)]*n for _ in range(n)]

from collections import deque

for _ in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1

    root[a][b]=1
    root[b][a]=1

dist =[pow(10,9)]*n
dist[0] = 0

q = deque([0])
prev=[-1] * n

while len(q)!=0:
    v = q[0]
    q.popleft()

    for j in range(n):
        if dist[j] > dist[v] + 1 and root[v][j]!=pow(10,9):
            dist[j] = dist[v] + 1
            prev[j] = v
            q.append(j)


for i in range(n):
    if i==0:
        print('Yes')
    else:
        print(prev[i]+1)


# print(dist)
# print(prev)



# print(*root,sep="\n")

### FIXED CODE ###

n,m = map(int,input().split())
from collections import deque
r=[[] for i in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    r[a].append(b)
    r[b].append(a)

# dist =[-1]*n
# dist[0] = 0

q = deque([0])
prev=[-1] * n

while q:
    v = q.popleft()

    for j in r[v]:
        if prev[j]==-1:
            prev[j] = v
            q.append(j)
            # dist[j] = dist[v] + 1
            

for i in range(n):
    if i==0:
        print('Yes')
    else:
        print(prev[i]+1)
### BUGGY CODE ###

[x,y]=list(map(int,input().split()))
if ((x%3)+(y%3))%3!=0:
	print(0)
else:
	dansu=int((x+y)/3)
	r=y-dansu
	if r>dansu-r:
		r=dansu-r
	mod=1000000007
	d=1
	rr=1
	nr=1
	for i in range(1,dansu+1):
		d=d*i
	for i in range(1,r+1):
		rr=rr*i
	for i in range(1,dansu-r+1):
		nr=nr*i
	
	kotae=int((d%mod)*pow(rr,mod-2,mod)*pow(nr,mod-2,mod))
	kotae=int(kotae%(10**9+7))
	
	print(kotae)

### FIXED CODE ###

[x,y]=list(map(int,input().split()))
if ((x%3)+(y%3))%3!=0:
	print(0)
else:
	n=int((x+y)/3)
	r=y-n
	if r<0 or r>n:
		print(0)
	else:
		if r>n-r:
			r=n-r
		mod=1000000007
		kaijo=[1]
		for i in range(1,n+1):
			kaijo.append(kaijo[-1]*i%mod) #これで、kaijo[i]=i!となる。
		gyakugen=[pow(kaijo[n-r],mod-2,mod)]
		for i in reversed(range(1,n-r+1)):
			gyakugen.append(gyakugen[-1]*i%mod) #これで、gyakugen[i]=n-r-iの逆元となる
		kotae=kaijo[n]*gyakugen[0]*gyakugen[n-2*r]%mod

		print(kotae)
### BUGGY CODE ###

# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B
# awesome answer: 

def merge(A, left, mid, right):
  cnt = 0
  n1 = mid - left
  n2 = right - mid
  L, R = [0]*(n1+1), [0]*(n2+1)
  for i in range(n1):
    L[i] = A[left + i]
  for i in range(n2):
    R[i] = A[mid + i]
  L[n1] = float("inf")
  R[n2] = float("inf")
  i = 0
  j = 0
  for k in range(left, right):
    cnt = cnt + 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1
  return cnt

def mergeSort(A, left, right, cnt):
  if left+1 < right:
    mid = int((left + right)/2)
    mergeSort(A, left, mid, cnt)
    mergeSort(A, mid, right, cnt)
    cnt[0] = cnt[0] + merge(A, left, mid, right)

if __name__ == "__main__":
  n = int(input())
  S = list(map(int, input().split()))
  cnt = [0]
  mergeSort(S, 0, len(S), cnt)
  print(" ".join(map(str, S)))
  print(cnt[0])

### FIXED CODE ###

count = 0

def merge(A, left, mid, right):
  global count
  n1 = mid - left
  n2 = right - mid
  L = A[left:left+n1]
  R = A[mid:mid+n2]
  L.append(float("inf"))
  R.append(float("inf"))
  i = 0
  j = 0
  for k in range(left, right):
    count += 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 = int((left + right)/2)
    mergeSort(A, left, mid)
    mergeSort(A, mid, right)
    merge(A, left, mid, right)

if __name__ == "__main__":
  n = int(input())
  S = list(map(int, input().split()))
  mergeSort(S, 0, len(S))
  print(" ".join(map(str, S)))
  print(count)
### BUGGY CODE ###

def main():
    N, P = map(int, input().split())

    left = 0
    right = 10**12
    while left + 1 < right:
        mid = (left + right) // 2
        if mid**N <= P:
            left = mid
        else:
            right = mid

    cnt = 0
    for j in range(left, 0, -1):
        if P % (j**N) == 0:
            print(j)
            break
        else:
            cnt += 1

    j = left
    cnt = 0
    while P % (j**N) != 0:
        cnt += 1
        j = left // cnt


main()


### FIXED CODE ###

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def main():
    N, P = map(int, input().split())
    A = factorization(P)

    B = []
    for a, b in A:
        if b >= N:
            B.append((a, b // N))

    ans = 1
    for a, b in B:
        ans *= a**b
    print(ans)


main()
### BUGGY CODE ###

R,G,B,N = list(map(int, input().split()))
ans = 0
for r in range(int(N/R)+1):
    for g in range(int(N/G)+1):
        for b in range(int(N/B)+1):
            if r*R+g*G+b*B == N:
                ans += 1
print(ans)
    

### FIXED CODE ###

R,G,B,N = list(map(int, input().split()))
ans = 0
for r in range(N//R+1):
    for g in range((N-r*R)//G+1):
        if (N-r*R-g*G) % B == 0:
             ans += 1
print(ans)
### BUGGY CODE ###

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

### FIXED CODE ###

import math
print(math.factorial(int(input()))%(10**9+7))
### BUGGY CODE ###

n = input()
a = [i for i in n]
ans = 0
for j in range(20000):
    flag = 1
    for i in range(len(n)-2,-1,-1):
        if a[i+1] == "W" and a[i] == "B":
            a[i] = "W"
            a[i+1] = "B"
            ans += 1
            flag = 0
    if flag ==1:
        break
print(ans)

### FIXED CODE ###

n = input()
a = [i for i in n]
ans = 0
n = len(n)
B=0
W = 0
for i in range(n):
    if a[i] == "W":
        ans += i-W
        W+=1
print(ans)
### BUGGY CODE ###

x, y, z, k = list(map(int, input().split()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
clist = list(map(int, input().split()))
alist.sort(reverse=True)
blist.sort(reverse=True)
clist.sort(reverse=True)
delist = []
for a in range(x) :
    for b in range(y) :
        if a+b > k :
            break
        for c in range(z) :
            if a+b+c > k :
                break
            else :
                delist.append(alist[a]+blist[b]+clist[c])
delist.sort(reverse=True)
for n in delist[:k] :
    print(n)

### FIXED CODE ###

x, y, z, k = list(map(int, input().split()))
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
clist = list(map(int, input().split()))
alist.sort(reverse=True)
blist.sort(reverse=True)
clist.sort(reverse=True)
delist = []
for a in range(x) :
    for b in range(y) :
        if a*b > k :
            break
        for c in range(z) :
            if a*b*c > k :
                break
            else :
                delist.append(alist[a]+blist[b]+clist[c])
delist.sort(reverse=True)
for n in delist[:k] :
    print(n)
### BUGGY CODE ###

N = int(input())
S = [("R", "G", "B").index(c) for c in input()]

sums = [[0] * (N + 1) for _ in range(3)]
for i, c in enumerate(S):
    for x in sums:
        x[i+1] = x[i]
    sums[c][i+1] += 1

ans = 0
for i in range(N - 2):
    si = S[i]
    for j in range(i + 1, N - 1):
        sj = S[j]
        if si == sj:
            continue
        sk = (set(range(3)) - {si, sj}).pop()
        count = sums[sk][N] - sums[sk][j+1]
        if j - i <= N - (j + 1):
            count -= (sums[sk][j+1+j-i] - sums[sk][j+1+j-i-1])
        ans += count
print(ans)

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
S = input()
X = {"R": [], "G": [], "B": []}
Xset = {"R": set(), "G": set(), "B": set()}
for i, c in enumerate(S):
    X[c].append(i)
    Xset[c].add(i)

ans = 0
for i in range(N - 2):
    si = S[i]
    for j in range(i + 1, N - 1):
        sj = S[j]
        if si == sj:
            continue
        x = ["R", "G", "B"]
        x.remove(si)
        x.remove(sj)
        sk = x[0]
        ks = X[sk]
        count = len(ks) - bisect_left(ks, j)
        if 2 * j - i in Xset[sk]:
            count -= 1
        ans += count
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
c={}
d=[]
for i in range(n):
  a,b=map(int,input().split())
  if a not in c:
    c[a]=0
  c[a]+=b
  if a not in d:
    d.append(a)
  
d.sort()

ans=0
for i in range(n):
  if m > c[d[i]]:
    m-=c[d[i]]
    ans+=d[i]*c[d[i]]
  else:
    ans+=d[i]*m
    break
    
print(ans)

  

### FIXED CODE ###

n,m=map(int,input().split())
c={}
d=[]
for i in range(n):
  a,b=map(int,input().split())
  if a not in c:
    c[a]=0
    d.append(a)
  c[a]+=b
  
d.sort()

ans=0
for i in range(n):
  if m > c[d[i]]:
    m-=c[d[i]]
    ans+=d[i]*c[d[i]]
  else:
    ans+=d[i]*m
    break
    
print(ans)
### BUGGY CODE ###

n = input()
A = input().split(' ')
A.sort()
q = input()
M = input().split(' ')

A = list(map(int,A))
M = list(map(int,M))

memo = [True]*(len(A))

def search(base, m):
    if base == m:
        return True
    result = False
    for i in range(len(A)):
        if base + A[i] <= m and memo[i]:
            memo[i] = False
#           print(str(A[i]) + ',' + str(base+A[i]) + ',')
            result = result or search(base+A[i], m)
            memo[i] = True
    return result

def print_yn(result):
    if result:
        print('yes')
    else:
        print('no')

for m in M:
#   print(str(m)+':')
    print_yn(search(0,m))

### FIXED CODE ###

n = input()
A = input().split(' ')
A.sort()
A.reverse()
q = input()
M = input().split(' ')

A = list(map(int,A))
M = list(map(int,M))
A.sort()

A_sum = [0]
for a in A:
    A_sum.append(a+A_sum[-1])
A_sum.pop(0)

A.reverse()
A_sum.reverse()


#memo = [True]*(len(A))

def search(base, m, n):
    if base == m:
        return True
    if len(A)-1 < n or m - base > A_sum[n]:
        return False
    result = False
    for i in range(len(A)-1,n-1,-1):
        if base + A[i] <= m: # and memo[i]:
#           memo[i] = False
#           print(str(A[i]) + ',' + str(base+A[i]) + ',')
            if search(base+A[i], m, i+1):
                return True
#           memo[i] = True
    return result

def print_yn(result):
    if result:
        print('yes')
    else:
        print('no')

for m in M:
#   print(str(m)+':')
    print_yn(search(0,m,0))
### BUGGY CODE ###

import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)

### FIXED CODE ###

import bisect
A,B,Q = map(int,input().split())
S = [-float('inf')]+list(int(input())for i in range(A))+[float('inf')]
T = [-float('inf')]+list(int(input())for i in range(B))+[float('inf')]
x = list(int(input())for i in range(Q))

for i in x:
    si = bisect.bisect_left(S,i)
    ti = bisect.bisect_left(T,i)
    ans = min(max(S[si],T[ti])-i,i-min(S[si-1],T[ti-1]),\
            2*S[si]-i-T[ti-1],2*T[ti]-i-S[si-1],\
             T[ti]+i-2*S[si-1],S[si]+i-2*T[ti-1])
    print(ans)
### BUGGY CODE ###

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

ans = 0

for n in range(N):
    if n == 0:
        pass
    else:
        if max(H[0:n]) - H[n] >= 2:
           ans += 1

if ans >= 1:
    print('No')
else:
    print('Yes')

### FIXED CODE ###

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

ans = 'Yes'

for i in reversed(range(0, N-1)):
    if H[i] > H[i+1] + 1:
        ans = 'No'
    elif H[i] == H[i+1] + 1:
        H[i] -= 1

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

N=int(input())
list_A=[int(A) for A in input().split()]
list_A.insert(0,0)
list_A.insert(N+1,0)
for i in range(1,N+1):
  money=0
  list_B=list_A.copy()
  del list_B[i]
  for k in range(1,N+1):
    money+=abs(list_B[k]-list_B[k-1])
  print(money)
    

### FIXED CODE ###

N=int(input())
list_A=[int(A) for A in input().split()]
list_A.insert(0,0)
list_A.insert(N+1,0)
money=0
for i in range(N+1):
  money+=abs(list_A[i+1]-list_A[i])
for i in range(1,N+1):
  Money=money-abs(list_A[i]-list_A[i-1])-abs(list_A[i+1]-list_A[i])+abs(list_A[i+1]-list_A[i-1])
  print(Money)
### BUGGY CODE ###

n = int(input())

li=list(map(int,input().split()))
count = 0

for i in range(n-1): #iは0からn-1
  for j in range(n-i-1):
    if (li[n-i-1]>li[n-i-2-j]):
      #print("break "+str(li[n-i-1]))
      count+=1
      break
  
print(n-count)


### FIXED CODE ###

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

mymin = a[0]
count = 0

for i in range(len(a)):
  if min(mymin, a[i]) == a[i]:
    mymin = a[i]
    count += 1
    
print(count)
### BUGGY CODE ###

N = int(input())
count = 0
for i in range(1, N+1):
  x = str(i)
  if '1' not in x and '2' not in x and '4' not in x and '6' not in x and '8' not in x and '9' not in x and '0' not in x and '3' in x and '5' in x and '7' in x:
    count += 1
print(count)

### FIXED CODE ###

n = int(input())
count = 0
base = [[0],[],[],[],[],[],[],[],[],[],[]]
for digit in range(10):
  for i in base[digit]:
    num_3 = i+3*10**digit
    num_5 = i+5*10**digit
    num_7 = i+7*10**digit
    next_digit = digit + 1
    if num_3 <= n:
      if set(str(num_3)) == {'3','5','7'}:
        count += 1
      base[next_digit].append(num_3)
    if num_5 <= n:
      if set(str(num_5)) == {'3','5','7'}:
        count += 1
      base[next_digit].append(num_5)
    if num_7 <= n:
      if set(str(num_7)) == {'3','5','7'}:
        count += 1
      base[next_digit].append(num_7)
print(count)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b_c = [list(map(int, input().split())) for i in range(q)]

ans = 0

for i in range(q):
    before = b_c[i][0]
    after = b_c[i][1]
    while before in a:
        a[a.index(before)] = after
    ans = sum(a)
    print(ans)


### FIXED CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc =[list(map(int,input().split())) for i in range(q)]

ans = sum(a)
num = collections.Counter(a)

for i in range(q):
    before = bc[i][0]
    after = bc[i][1]
    ans += num[before]*(after-before)
    num[after] += num[before]
    num[before] = 0
    #print(a.count(before))
    #print(num(before))
    print(ans)
### BUGGY CODE ###

n, k, *p = map(int, open(0).read().split())

q = []
for p_i in p:
  q.append((p_i+1)/2)

max_e = 0
for i in range(n-k+1):
  e = sum(q[i:i+k])
  
  if e > max_e:
    max_e = e

print(max_e)

### FIXED CODE ###

n, k, *p = map(int, open(0).read().split())

q = []
for p_i in p:
  q.append((p_i+1)/2)
  
s = [0]
pre_s = 0
for q_i in q:
  pre_s += q_i
  s.append(pre_s)

ans = 0
for i in range(n-k+1):
  if ans < (s[i+k] - s[i]):
    ans = s[i+k] - s[i]
    
print(ans)
### BUGGY CODE ###

try:
	while True:
		j = 0
		n = input()
		ans = [1] * (n + 1);
		ans[0] = ans[1] = 0;
		for i in range(2, n + 1):
			if i * 2 > n:
				break
			if ans[i] != 0:
				for j in range(2 * i, n + 1, i):
					ans[j] = 0
		print sum(ans)
except EOFError:
	pass

### FIXED CODE ###

def prime_count(n):
	j = 0
	ans = [1] * (n + 1)
	ans[0] = ans[1] = 0
	for i in xrange(3, n + 1, 2):
		if i * 2 > n:
			break
		if ans[i] != 0:
			for j in xrange(2 * i, n + 1, i):
				ans[j] = 0
	for k in xrange(2 * 2, n + 1, 2):
		ans[k] = 0
	print sum(ans)

try:
	while True:
		n = input()
		prime_count(n)
except EOFError:
	pass
### BUGGY CODE ###

N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in set(a):
	cnt = a.count(i)
	if cnt >= i:
		ans += cnt - i
	else:
		ans += cnt
print(ans)


### FIXED CODE ###

import collections

N = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
ans = 0

for ai in set(a):
    if c[ai] < ai:
        ans += c[ai]
    else:
        ans += c[ai] - ai

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

[N, X, Y] = input().split()
N = int(N)
X = int(X)
Y = int(Y)
dist_list = []

for i in range(N):
    for j in range(i+1, N):
        a = j - i
        b = abs(i+1 - X) + abs(j+1 -Y) + 1
        dist_list.append(min(a, b))

for k in range(N-1):
    print(dist_list.count(k+1))



### FIXED CODE ###

N, X, Y = map(int, input().split())
dist_list = [0]*N

for i in range(N-1):
    for j in range(i+1, N):
        a = j - i
        b = abs(i+1 - X) + abs(j+1 -Y) + 1
        dist_list[min(a,b)] += 1

for k in range(N-1):
    print(dist_list[k+1])
### BUGGY CODE ###

import math
import fractions
from functools import reduce
from copy import copy

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

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

gcds = []
for i in range(N):
    A_ = copy(A)
    A_.pop(i)
    gcds.append(gcd(*A_))

print(max(gcds))


### FIXED CODE ###

from fractions import gcd


def main():
    N = int(input())
    A = list(map(int, input().split()))
    left = [0] * N
    right = [0] * N
    for i in range(1, N):
        left[i] = gcd(left[i-1], A[i-1])
        right[-1-i] = gcd(right[-i], A[-i])
    gcds = []
    for i in range(N):
        gcds.append(gcd(left[i], right[i]))
    print(max(gcds))


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

from queue import Queue
H, W = map(int, input().split())
A = [['.' for w in range(W)] for h in range(H)]
is_visited = [[False for w in range(W)] for h in range(H)]
q = Queue()
for h in range(H):
    A[h] = list(input())
    for w in range(W):
        if A[h][w] == '#':
            q.put((h, w, 0))
            is_visited[h][w] = True
ans = 0
lrud = [
  [-1, 0],
  [1, 0],
  [0, -1],
  [0, 1]
]
while not q.empty():
    x, y, c = q.get()
    for dx, dy in lrud:
        nx = min(max(0, x+dx), H-1)
        ny = min(max(0, y+dy), W-1)
        if not is_visited[nx][ny]:
            q.put((nx, ny, c+1))
            is_visited[nx][ny] = True
    ans = c
print(ans)

### FIXED CODE ###

INF = 10**9
H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
# (0, 0), (0, W-1), (H-1, 0), (H-1, W-1)
ans = [[INF for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            ans[h][w] = 0
        tmp = ans[h][w]+1
        if h < H-1:
            ans[h+1][w] = min(tmp, ans[h+1][w])
        if w < W-1:
            ans[h][w+1] = min(tmp, ans[h][w+1])
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        tmp = ans[h][w]+1
        if h > 0:
            ans[h-1][w] = min(tmp, ans[h-1][w])
        if w > 0:
            ans[h][w-1] = min(tmp, ans[h][w-1])
# print(ans)
print(max([w for h in ans for w in h]))
### BUGGY CODE ###

def maxHeapify(keys, i):
    l = i * 2 + 1
    r = i * 2 + 2
    if l < len(keys) and keys[l] > keys[i]:
        largest = l
    else:
        largest = i
    if r < len(keys) and keys[r] > keys[largest]:
        largest = r
    if largest != i:
        keys[i], keys[largest] = keys[largest], keys[i]
        maxHeapify(keys, largest)

def heapInsert(keys, key):
    i = len(keys)
    keys.append(key)
    parent = (i - 1) // 2
    while i > 0 and keys[parent] < keys[i]:
        keys[i], keys[parent] = keys[parent], keys[i]
        i = parent
        parent = (parent - 1) // 2

def heapMaxPop(keys):
    max_key = keys[0]
    if len(keys) > 1:
        keys[0] = keys.pop()
    else:
        del keys[0]
    maxHeapify(keys, 0)
    print(max_key)


S = []

import sys

for x in sys.stdin.readlines():
    if x[0] == 'i':
        k = int(x[7:])
        heapInsert(S, k)
    elif x[1] == 'x':
        heapMaxPop(S)
    else:
        pass

### FIXED CODE ###

def setHeapDown_max(heap, pos):
    targetkey = heap[pos]
    while pos > 0:
        parentpos = (pos - 1) >> 1
        parent = heap[parentpos]
        if parent < targetkey:
            heap[pos] = parent
            pos = parentpos
            continue
        break
    heap[pos] = targetkey

def setHeapUp_max(heap, pos):
    endpos = len(heap)
    targetkey = heap[pos]
    childpos = 2*pos + 1
    while childpos < endpos:
        rightpos = childpos + 1
        if rightpos < endpos and not heap[rightpos] < heap[childpos]:
            childpos = rightpos
        heap[pos] = heap[childpos]
        pos = childpos
        childpos = 2*pos + 1
    heap[pos] = targetkey
    setHeapDown_max(heap, pos)

def heapPush_max(heap, key):
    heap.append(key)
    setHeapDown_max(heap, len(heap) - 1)

def heapPop_max(heap):
    lastkey = heap.pop()
    if heap:
        returnkey = heap[0]
        heap[0] = lastkey
        setHeapUp_max(heap, 0)
        return returnkey
    return lastkey


import sys

S = []

ans = []

for x in sys.stdin.readlines():
    if x[0] == 'i':
        k = int(x[7:])
        heapPush_max(S, k)
    elif x[1] == 'x':
        ans.append(heapPop_max(S))
    else:
        pass

print(*ans, sep = '\n')
### BUGGY CODE ###

import sys
import bisect
n = int(input())
s = list(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
dict = {i:[] for i in alpha}
for i, _s in enumerate(s):
    dict[_s].append(i)
q = int(input())
for i in range(q):
    type, first, last = [i for i in sys.stdin.readline().split()]
    if type == "2":
        first = int(first)
        last = int(last)
        first -= 1
        last -= 1
        cnt = 0
        for a in alpha:
            ls = dict[a]
            if bisect.bisect_left(ls, first) != bisect.bisect_right(ls, last):
                cnt += 1
        print(cnt)
    else:
        first = int(first)
        first -= 1
        dict[s[first]].pop(bisect.bisect_left(dict[s[first]], first))
        s[first] = last
        bisect.insort_left(dict[last], first)

### FIXED CODE ###

import sys
import bisect
n = int(sys.stdin.readline().strip())
s = list(sys.stdin.readline().strip())
alpha = "abcdefghijklmnopqrstuvwxyz"
dict = {i:[] for i in alpha}
for i, _s in enumerate(s):
    dict[_s].append(i)
q = int(sys.stdin.readline().strip())
for i in range(q):
    type, first, last = [i for i in sys.stdin.readline().split()]
    if type == "2":
        first = int(first)
        last = int(last)
        first -= 1
        last -= 1
        cnt = 0
        for ls in dict.values():
            if bisect.bisect_left(ls, first) != bisect.bisect_right(ls, last):
                cnt += 1
        print(cnt)
    else:
        first = int(first)
        first -= 1
        _s = s[first]
        if _s == last:
            continue
        del dict[_s][(bisect.bisect_left(dict[_s], first))]
        s[first] = last
        bisect.insort_left(dict[last], first)
### BUGGY CODE ###

l = list(map(int, input().split()))
n = l[0]
t = l[1]

l = list(map(int, input().split()))
maxdiff = 0
count = 0
startindex = 0
endindex = 0

currentIndex = 0
for currentIndex in range(n):
    maxnum = 0
    if l[currentIndex] > l[startindex] and currentIndex <= endindex:
        continue
    for j in range(currentIndex+1, n):
        if l[j] > maxnum:
            maxnum = l[j]
        else:
            continue
        if l[j] - l[currentIndex] > maxdiff:
            maxdiff = l[j] - l[currentIndex]
            count = 1
            startindex = currentIndex
            endindex = j
        elif l[j] - l[currentIndex] == maxdiff:
            count += 1
            startindex = currentIndex
            endindex = j
print(count)


### FIXED CODE ###

l = list(map(int, input().split()))
n = l[0]
t = l[1]

l = list(map(int, input().split()))
maxdiff = 0
count = 0
currentmin = 10000000000

for i in l:
    if i - currentmin > maxdiff:
        maxdiff = i - currentmin
        count = 1
    elif i - currentmin == maxdiff:
        count += 1
    elif i < currentmin:
        currentmin = i
print(count)
### BUGGY CODE ###

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

bukaninzu_list = []
for i in range(N):
    bukaninzu_list.append(A.count(i+1))
    
for bukaninzu in bukaninzu_list:
    print(bukaninzu)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
bukaninzu_list = N * [0]
for i in range(N-1):
    bukaninzu_list[A[i]-1] += 1

for bukaninzu in bukaninzu_list:    
    print(bukaninzu)