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

n,x,m = map(int, input().split()) 
ans = 0
x_list = []

for _ in range(n):
    x_list.append(x)
    x = x**2 % m
    if x == 0:
        ans = sum(x_list)
        break
    if x == 1:
        ans = sum(x_list) + (n-len(x_list))
        break
    if x_list.count(x) == 1:
        after_list = x_list[x_list.index(x):(len(x_list))]
        if x_list.index(x) == 0:
            if (n // len(x_list)) == 0:
                ans = sum(x_list) * (n // len(x_list))
            else:
                ans = sum(x_list) * (n // len(x_list)) + sum(x_list[0:((n % len(x_list)))])
        else:
            if (n-x_list.index(x)) % len(after_list) == 0:
                ans = sum(after_list) * ((n-x_list.index(x)) // len(after_list)) + sum(x_list[0:(x_list.index(x))])
            else:
                ans = sum(after_list) * ((n-x_list.index(x)) // len(after_list)) + sum(after_list[0:(((n-x_list.index(x)) % len(after_list)))]) + sum(x_list[0:(x_list.index(x))])
        break

if ans == 0 and not x == 0:
    ans = sum(x_list)

print(ans)

### FIXED CODE ###

N, X, M = map(int, input().split())
 
def next_f(a):
    return a * a % M
 
visited = [None] * M
sum_at_visit = [None] * M
loop_done = False
 
time = 1
ans = 0
x = X
while time <= N:
    if not loop_done and visited[x] is not None:
        # found cycle                                                                                                                                         
        loop_len = time - visited[x]
        loop_sum = ans + x - sum_at_visit[x]
        loops = (N-loop_len-time) // loop_len
        time += loop_len * loops
        ans += loop_sum * loops
        loop_done = True
    ans += x
    visited[x] = time
    sum_at_visit[x] = ans
    time += 1
    x = next_f(x)
print(ans)
### BUGGY CODE ###

x,y,z,N =(int(i) for i in input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]

sa=sorted(a,reverse=True)
sb=sorted(b,reverse=True)
sc=sorted(c,reverse=True)
l=[]#端点情報
n=0
i=0
j=0
k=0

while n<N:
  print(sa[i]+sb[j]+sc[k])
  l.append([i,j,k])
  maxl=0
  maxijk=[len(sa)-1,len(sb)-1,len(sc)-1]
  for w in l:
    if w[0]>=len(sa)-1:continue
    if [w[0]+1,w[1],w[2]] in l:continue
    if maxl<=sa[w[0]+1]+sb[w[1]]+sc[w[2]]:
      maxl=sa[w[0]+1]+sb[w[1]]+sc[w[2]]
      maxijk=[w[0]+1,w[1],w[2]]
  for w in l:
    if w[1]>=len(sb)-1:continue
    if [w[0],w[1]+1,w[2]] in l:continue
    if maxl<=sa[w[0]]+sb[w[1]+1]+sc[w[2]]:
      maxl=sa[w[0]]+sb[w[1]+1]+sc[w[2]]
      maxijk=[w[0],w[1]+1,w[2]]
  for w in l:
    if w[2]>=len(sc)-1:continue
    if [w[0],w[1],w[2]+1] in l:continue
    if maxl<=sa[w[0]]+sb[w[1]]+sc[w[2]+1]:
      maxl=sa[w[0]]+sb[w[1]]+sc[w[2]+1]
      maxijk=[w[0],w[1],w[2]+1]
  i=maxijk[0]
  j=maxijk[1]
  k=maxijk[2]
  n+=1

### FIXED CODE ###

#解答を見た後


x,y,z,N =(int(i) for i in input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]

sa=sorted(a,reverse=True)
sb=sorted(b,reverse=True)
sc=sorted(c,reverse=True)
answer=[]

for i in range(len(sa)):
  for j in range(len(sb)):
    if (i+1)*(j+1)>N:break
    for k in range(len(sb)):
      if (i+1)*(j+1)*(k+1)>N:break 
      answer.append(sa[i]+sb[j]+sc[k])
answer=sorted(answer,reverse=True)
for i in range(0,N):
  print(answer[i])
### BUGGY CODE ###

MOD = 10**9 + 7

Ss = input()

N = len(Ss)

dp = [[0]*(13) for _ in range(N+1)]
dp[0][0] = 1
for d, Sd in enumerate(Ss):
#    print(d, Sd)
    for mod13 in range(13):
        if Sd != '?':
            x = int(Sd)
            mod13n = (10*mod13 + x) % 13
            dp[d+1][mod13n] += dp[d][mod13]
            dp[d+1][mod13n] %= MOD
        else:
            for x in range(10):
                mod13n = (10*mod13 + x) % 13
                dp[d+1][mod13n] += dp[d][mod13]
                dp[d+1][mod13n] %= MOD

print(dp[-1][5])


### FIXED CODE ###

MOD = 10**9 + 7

Ss = input()

N = len(Ss)

dp = [[0]*(13) for _ in range(N+1)]
dp[0][0] = 1
for d, Sd in enumerate(Ss):
#    print(d, Sd)
    for mod13 in range(13):
        if Sd != '?':
            x = int(Sd)
            mod13n = (10*mod13 + x) % 13
            dp[d+1][mod13n] += dp[d][mod13]
            dp[d+1][mod13n] %= MOD
        else:
            for x in range(10):
                mod13n = (10*mod13 + x) % 13
                dp[d+1][mod13n] += dp[d][mod13]
                dp[d+1][mod13n] %= MOD

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

s = str(input())
q = int(input())
ls = [list(map(str,input().split())) for _ in range(q)]
def rev(ls):
    return ls[::-1]
def addi_f(s,t):
    return t+s
def addi_b(s,t):
    return s+t
for i in range(q):
    if ls[i] == ["1"]:
        s = rev(s)
    else:
        if ls[i][1] == "1":
            s = addi_f(s,ls[i][2])
        else:
            s = addi_b(s,ls[i][2])
print(s)
        

### FIXED CODE ###

s = str(input())
q = int(input())
ls = [list(map(str,input().split())) for _ in range(q)]
a = -1
f = []
b = []
for i in range(q):
    if ls[i] == ["1"]:
        if a == -1:
            a = -2
        else:
            a = -1
    else:
        if a+int(ls[i][1]) == 0:
            f.append(ls[i][2])
        else:
            b.append(ls[i][2])
if a == -1:
    f = f[::-1]
    print("".join(f)+s+"".join(b))
else:
    b = b[::-1]
    print("".join(b)+s[::-1]+"".join(f))
### BUGGY CODE ###

N = [int(i) for i in input().split()][0]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
B.append(0)

cnt=0
for i in range(N+1):
  while B[i]!=0 and A[i]!=0:
    A[i]-=1
    B[i]-=1
    cnt+=1
  if i!=N and B[i]>0:
    B[i+1]=B[i+1]+B[i]
    
print(cnt)

### FIXED CODE ###

n=int(input())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Bs.append(0)

ans=0
for i in range(n):
  c=As[i]+As[i+1]
  if c>Bs[i]:
    ans+=Bs[i]
    if Bs[i]>As[i]:
      As[i+1]-=Bs[i]-As[i]
  else:
    ans+=c
    As[i+1]=0
print(ans)
### BUGGY CODE ###

n = int(input())
l = []
for i in range(n):
    tmp = int(input())
    l.remove(tmp) if tmp in l else l.append(tmp)
print(len(l))


### FIXED CODE ###

n = int(input())
l = set()
for i in range(n):
    tmp = int(input())
    l.remove(tmp) if tmp in l else l.add(tmp)
print(len(l))
### BUGGY CODE ###

import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

def dpp(n):
    for i in range(2,n+1):
        if i in a:
            dp[i] = 0
        else:
            dp[i] = dp[i-1]+dp[i-2]
    return dp[n]

N,M = I()
a = []
for i in range(M):
    x = k()
    a.append(x)

dp = [0]*(N+1)
if 1 in a:
    dp[1] = 0
    dp[0] = 1
else:
    dp[0] = dp[1] =1

print(dpp(N) % mod)


### FIXED CODE ###

import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

def dpp(n):
    for i in range(2,n+1):
        if a[i] == 0:
            dp[i] = 0
        else:
            dp[i] = dp[i-1]+dp[i-2]
    return dp[n]

N,M = I()
a = [1]*(N +1)
for i in range(M):
    x = k()
    a[x] = 0

dp = [0]*(N+1)
if a[1] == 0:
    dp[1] = 0
    dp[0] = 1
else:
    dp[0] = dp[1] =1

print(dpp(N) % mod)
### BUGGY CODE ###

import math

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
num=[0,2,5,5,4,5,6,3,7,6]
dp=[0]
keta=[0]
tmp=0
tmp1=0
tmp_keta=-1
tmp1_keta=-1
for i in range(1,N+1):
    tmp=-1
    tmp_keta=-1
    for j in A:
        tmp1=-1
        tmp1_keta=-1
        if(i-num[j]>=0):
            if(dp[i-num[j]]>0):
                tmp1=dp[i-num[j]]+j*(10**keta[i-num[j]])
                tmp1_keta=keta[i-num[j]]+1
            elif(dp[i-num[j]]==0):
                tmp1=j
                tmp1_keta=1
            if(tmp1>tmp):
                tmp=tmp1
                tmp_keta=tmp1_keta
    dp.append(tmp)
    keta.append(tmp_keta)
ans=dp[N]
print(ans)

### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
if(1 in A):
    if(4 in A):
        A.remove(4)
    if(9 in A):
        A.remove(9)
    if(6 in A):
        A.remove(6)
if(5 in A):
    if(3 in A):
        A.remove(3)
    if(2 in A):
        A.remove(2)
if(3 in A):
    if(2 in A):
        A.remove(2)
if(9 in A):
    if(6 in A):
        A.remove(6)
if(7 in A):
    if(9 in A):
        A.remove(9)
    if(6 in A):
        A.remove(6)
num=[0,2,5,5,4,5,6,3,7,6]
dp=[0]
keta=[0]
tmp=0
tmp1=0
tmp_keta=-1
tmp1_keta=-1
for i in range(1,N+1):
    tmp=-1
    tmp_keta=-1
    for j in A:
        tmp1=-1
        tmp1_keta=-1
        if(i-num[j]>=0):
            if(dp[i-num[j]]>0):
                tmp1=dp[i-num[j]]+j*(10**keta[i-num[j]])
                tmp1_keta=keta[i-num[j]]+1
            elif(dp[i-num[j]]==0):
                tmp1=j
                tmp1_keta=1

            if(tmp1>tmp):
                tmp=tmp1
                tmp_keta=tmp1_keta
                
    dp.append(tmp)
    keta.append(tmp_keta)
print(dp[N])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
    for j in range(i,n+1):
        b=a[i-1]
        c=a[j-1]
        if abs(i-j)==b+c:
            ans+=1
print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
num1=[0]*(2*(10**5)+10)
num2=[0]*(2*(10**5)+10)
for i in range(n):
    if a[i]+i+1<2*(10**5)+5:
        num1[a[i]+i+1]+=1
    if a[i]+1<i+1:
        num2[-a[i]+i+1]+=1
ans=0
for i in range(len(num1)):
    ans+=num1[i]*num2[i]
print(ans)
### BUGGY CODE ###

def main():
    A, B, C, D = map(int, input().split())

    c = C - A
    d = D - B
    mod = 998244353
    dp = [[0]*(d+1) for i in range(c+1)]
    dp[0][0] = 1

    for i in range(c+1):

        for j in range(d+1):
            ret = 0
            if i == 0 and j == 0:
                continue
            if i > 0 and j > 0:
                if i == j == 1:
                    ret -= (A+i-1) * (B+j-1)
                else:
                    ret -= dp[i-1][j-1]
                    ret *= (A+i-1)*(B+j-1)
            ret += dp[i-1][j]*(B+j) + dp[i][j-1]*(A+i)

            ret %= mod
            dp[i][j] = ret
    print(dp[c][d])


main()



### FIXED CODE ###

def main():
    A, B, C, D = map(int, input().split())

    c = C - A
    d = D - B
    mod = 998244353
    dp = [[0]*(d+1) for i in range(c+1)]
    dp[0][0] = 1

    for i in range(c+1):

        for j in range(d+1):
            ret = 0
            if i == 0 and j == 0:
                continue
            if i > 0 and j > 0:
                if i == j == 1:
                    ret -= (A+i-1) * (B+j-1)
                else:
                    ret -= dp[i-1][j-1]
                    ret *= (A+i-1)*(B+j-1)
            ret += dp[i-1][j]*(B+j) + dp[i][j-1]*(A+i)

            ret %= mod
            dp[i][j] = ret
    print(dp[c][d])


main()
### BUGGY CODE ###

import sys

input=sys.stdin.readline
N,K=list(map(int,input().split()))
h=list(map(int,input().split()))+[0]*100000

dp=[sys.maxsize]*(N+K+10)
dp[1]=0

for i in range(1,N):
        for k in range(1,K+1):
            dp[i+k]=min(dp[i+k],dp[i]+abs(h[i+k-1]-h[i-1]))

print(dp[N])

### FIXED CODE ###

import sys
import numpy as np
# inputを高速化する。
input = sys.stdin.readline
n, k = map(int, input().split())
h = [int(i) for i in input().split()]
# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)
for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))
print(dp[n-1])
### BUGGY CODE ###

N, K = map(int, input().split())
k = 2*N // K
ans = 0
for a in range(1, N+1):
    b = 0
    c = 0
    if 2*a %K != 0:
        continue
    kmin = a//K +1
    for i in range(kmin, k+1):
        if i*K - a > N:
            break
        b += 1
    for j in range(kmin, k+1):
        if j*K -a > N:
            break
        c += 1
    ans += b*c
print(ans)
        

### FIXED CODE ###

N, K = map(int, input().split())
if K % 2 == 1:
    a = N // K
    print(a**3)
else:
    a = N//K
    a2 = N//(K//2) -a
    print(a**3 +a2**3)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()
for i in range(1,N+1):
    x=A.count(i)
    print(A.count(i))
    if i in A:
        A=A[x:]


    









### FIXED CODE ###

import collections

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

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

def main():
    x, y = map(int, input().split())
    if x == y:
        return print('-1')
    if y == 1:
        return print('-1')
    if x == 1:
        return print(y+1)
    for i in range(1000000000):
        if (i * x) % y != 0:
            return print(i*x)
main()


### FIXED CODE ###

def main():
    x, y = map(int, input().split())
    if x % y == 0:
        return print('-1')
    for i in range(1000000000):
        if (i * x) % y != 0:
            return print(i*x)
main()
### BUGGY CODE ###

N,K=input().split()
N,K=[int(N),int(K)]
 
minimum=N
N=abs(N-K)
if minimum <=N:
    print(minimum)
else:
    while minimum > N:
        minimum=N
        N=abs(N-K)
    print(minimum)

### FIXED CODE ###

N,K=input().split()
N,K=[int(N),int(K)]

minimum=N%K
while N%K>K-N%K:
    minimum=K-N%K
    N=K-N%K
print(minimum)
### BUGGY CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
for i in range(M):
    b, c = map(int, input().split())
    for j in range(b):
        q = heapq.heappop(A)
        if q > c:
            heapq.heappush(A, q)
            break
        else:
            heapq.heappush(A, c)
print(sum(A))

### FIXED CODE ###

import  heapq

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

heapq.heapify(A)
B_C_list = []
for i in range(M):
    B, C = map(int, input().split())
    B_C_list.append((B, C))

B_C_list.sort(reverse=True, key=lambda x: x[1])
# print(B_C_list)

for B_C in B_C_list:
    a = heapq.heappop(A)
    if a >= B_C[1]:
        heapq.heappush(A, a)
        break
    else:
        heapq.heappush(A, a)
        for j in range(B_C[0]):
            a = heapq.heappop(A)
            if a >= B_C[1]:
                heapq.heappush(A, a)
                break
            heapq.heappush(A, B_C[1])
print(sum(A))
### BUGGY CODE ###

from sys import stdin,stdout
n,k=list(map(int,stdin.readline().split()));l=[];s=[];M=998244353
for _ in range(k):
    x,y=list(map(int,stdin.readline().split()))
    l+=[[x,y]]
for stp in range(n+1):
    for x,y in l:
        if x<=stp<=y:s+=[stp]
dp=[0]*(n+1);dp[1]=1
for i in range(2,n+1):
     for steps in s:
         if steps>=i:break
         dp[i]=(dp[i]+dp[i-steps])%M
print(dp[n])

### FIXED CODE ###

from sys import stdin,stdout
def ws(pos,win):
    l,r=win
    l1=pos-r
    r1=pos-l
    l=max(l1,0)
    r=max(r1,0)
    # print(pos,l,r)
    sm=ps[r]-(ps[l-1] if l>=1 else 0)
    return (sm+M)%M
n,k=list(map(int,stdin.readline().split()));w=[];s=[];M=998244353
for _ in range(k):
    x,y=list(map(int,stdin.readline().split()))
    w+=[[x,y]]
dp=[0]*(n+1);dp[1]=1;ps=[0,1]
for i in range(2,n+1):
    for win in w:
        ans=ws(i,win)
        dp[i]=(dp[i]+ans)%M
    ps+=[ps[-1]+dp[i]]
# print(dp)
# print(ps)
print(dp[n])
### BUGGY CODE ###

import math

# xのn乗
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

# nCkの導出
def comb(n,k):
    nCk = 1
    # X
    for i in range(n-k+1, n+1):
        nCk *= i
        # nCk %= mod

    # Y
    for i in range(1,k+1):
        nCk *= pow(i,mod-2,mod)
        nCk %= mod
    return nCk

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

# ans = pow_k(2,n) - c(n,a) - c(n,b) - 1

ans = pow(2,n,mod) - 1 - comb(n,a) - comb(n,b)

print(ans%mod)
# print(ans%mod)

### FIXED CODE ###

import math

# xのn乗
def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

# nCkの導出
def comb(n,k):
    nCk = 1
    # X
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= mod

    # Y
    for i in range(1,k+1):
        nCk *= pow(i,mod-2,mod)
        nCk %= mod
    return nCk

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

# ans = pow_k(2,n) - c(n,a) - c(n,b) - 1

ans = pow(2,n,mod) - 1 - comb(n,a) - comb(n,b)

print(ans%mod)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    aa=[[int(c) for c in SI()] for _ in range(n-1)]
    #p2D(aa)

    dp=set()
    dp.add((1<<n)-1)
    for _ in range(n-1):
        ndp=set()
        for bit in dp:
            i=j=(bit&-bit).bit_length()-1
            while 1<<i<bit:
                i+=1
                while bit>>i&1==0 and 1<<i<=bit:i+=1
                if 1<<i>bit:break
                if aa[i-1][j]:nbit=bit^1<<j
                else:nbit=bit^1<<i
                ndp.add(nbit)
                j=i
        dp=ndp

    print(len(dp))

main()

### FIXED CODE ###

import sys

p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def pbit(aa,L):
    for a in aa:print(format(a,"b").zfill(L))
    print()

def main():
    n=II()
    aa=[[int(c) for c in SI()] for _ in range(n-1)]
    #p2D(aa)
    
    # 人iが勝てる相手をbitで管理する
    win=[0]*n
    for i,row in enumerate(aa,1):
        for j,a in enumerate(row):
            if a:win[i]|=1<<j
            else:win[j]|=1<<i
    #pbit(win,n)

    # dpl[i]...[j,i]の範囲で優勝できるjをbitで
    # dpr[i]...[i,j]の範囲で優勝できるjをbitで
    dpl=[1<<i for i in range(n)]
    dpr=[1<<i for i in range(n)]
    for d in range(1,n):
        for i in range(n):
            j=i+d
            if j<n and dpl[j] & dpr[i+1] & win[i]:dpl[j]|=1<<i
            j=i-d
            if j>=0 and dpl[i-1] & dpr[j] & win[i]:dpr[j]|=1<<i
    #pbit(dpl,n)
    #pbit(dpr,n)
    #print(format(dpl[n-1]&dpr[0],"b").zfill(n))
    print(bin(dpl[n-1]&dpr[0]).count("1"))

main()
### BUGGY CODE ###

n = int(input())
ABs = [list(map(int, input().split())) for i in range(n)]
ABs = [i for i in reversed(ABs)]

As,Bs = [],[]
for i in range(n):
    As.append(ABs[i][0])
    Bs.append(ABs[i][1])

cnt = 0
for i in range(n):
    plus = 0 if As[i] % Bs[i] == 0 else Bs[i] - As[i] % Bs[i]
    As[i:] = list(map(lambda x:x + plus , As[i:]))
    cnt += plus
    
print(cnt)

### FIXED CODE ###

n = int(input())
ABs = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
    plus = 0 if (ABs[n-i-1][0] + cnt) % ABs[n-i-1][1] == 0 else ABs[n-i-1][1] - (ABs[n-i-1][0] + cnt) % ABs[n-i-1][1]
    cnt += plus
print(cnt)
### BUGGY CODE ###

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

print(al.count(1))
for i in range(1, n):
    print(al.count(i+1))



### FIXED CODE ###

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

ans_al = [0]*n

# for i in range(n):
#     ans_al[i-1] += al.count(i)

for a in al:
    ans_al[a-1] += 1

for ans in ans_al:
    print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int( input())
    A = [ deque( map( int, input().split())) for _ in range(N)]
    cnt = N*(N-1)
    days = 0
    while cnt > 0:
        days += 1
        now = cnt
        V = [0]*N
        for i in range(N):
            if V[i] == 1 or not A[i]:
                continue
            a = A[i][0]
            a -= 1
            if V[a] == 1 or not A[a]:
                continue
            if i+1 == A[a][0]:
                V[a] = 1
                V[i] = 1
                A[a].popleft()
                A[i].popleft()
                cnt -= 2
        if now == cnt:
            print(-1)
            return
    print( days)

                        
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int( input())
    A = [deque()] + [deque( map( int, input().split())) for _ in range(N)]
    Days = [0]*(N+1)
    NOW = [0]*(N+1)
    # for i in range(1, N+1):
    #     a = A[i].popleft()
    #     if NOW[a] == i:
    #         Days[a] = Days[i] = max(Days[a], Days[i])
    q = deque( [ i+1 for i in range(N)])
    while q:
        i = q.popleft()
        if not A[i]:
            continue
        a = A[i].popleft()
        if NOW[a] == i:
            Days[a] = Days[i] = max(Days[a], Days[i])+1
            q.append(i)
            q.append(a)
            NOW[a] = NOW[i] = 0
        else:
            NOW[i] = a
    for i in range(1,N+1):
        if A[i]:
            print(-1)
            return
    print( max(Days))
if __name__ == '__main__':
    main()
### BUGGY CODE ###

def solve():
    N = int(input())
    L = []
    A = []
    B = []
    for _ in range(N):
        a, b = list(map(int, input().split(" ")))
        A.append(a)
        B.append(b)

    i = 1
    while len(A):
        if i in A:
            tmp = A.index(i)
            L.append(B[tmp])
            del A[tmp]
            del B[tmp]
        else:
            L.append(0)

        i += 1

    print(len(L) + (L[-1]))


solve()

### FIXED CODE ###

def solve():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        a, b = list(map(int, input().split(" ")))
        A.append(a)
        B.append(b)
    
    participants = max(A) + min(B)
    
    print(participants)


solve()
### BUGGY CODE ###

N, K = map(int, input().split())
A = [int(s) for s in input().split()]

ru = [None] * (N+1)
ru[0] = 0
for i in range(len(A)):
    ru[i+1] = ru[i] + A[i]

ans = 0
for m in reversed(range(40)):
    cnt = 0
    for i in range(N):
        for j in range(i+1, N+1):
            sum = ru[j] - ru[i]
            if (sum & ans) < ans:
                continue
            if sum & (1 << m):
                cnt += 1
    if cnt >= K:
        ans |= (1 << m)

print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
A = [int(s) for s in input().split()]

ru = [None] * (N+1)
ru[0] = 0
for i in range(len(A)):
    ru[i+1] = ru[i] + A[i]

ans = 0
for m in reversed(range(40)):
    cnt = 0
    for i in range(N):
        for j in range(i+1, N+1):
            sum = ru[j] - ru[i]
            if (sum & ans) < ans:
                continue
            if sum & (1 << m):
                cnt += 1
    if cnt >= K:
        ans |= (1 << m)

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

# coding: utf-8
import math
import numpy
#N = int(input())
N, K = map(int,input().split())
A = list(map(int,input().split()))
#K =int(input())
ANS = []
a = 1
for i in range(K):
    a *= A[K-i-1]
ANS.append(a)
for i in range(K,N):
    a *=A[i]
    a //= A[i-K]
    ANS.append(a)
#print(ANS)
for i in range(N-K):
    if ANS[i+1] > ANS[i]:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

# coding: utf-8
#import math
#import numpy
#N = int(input())
def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    #K =int(input())
    ANS = []
    
    #ANS.append(a)
    for i in range(K,N):
        if A[i-K] < A[i]:
            print("Yes")
        else:
            print("No")
        
        
        #ANS.append(a)
    #print(ANS)
    

if __name__ == '__main__':
    main()