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

import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
r,c,k=map(int,input().split())
dp = [[[0,0,0,0] for y in range(c)] for z in range(r)] 
m=[]
for i in range(r):
  m.append([])
  for j in range(c):
    m[i].append(0)
for i in range(k):
  ri,ci,v=map(int,input().split())
  m[ri-1][ci-1]=v
dp[0][0][0]=0
dp[0][0][1]=m[0][0]
dp[0][0][2]=m[0][0]
dp[0][0][3]=m[0][0]
for i in range(r):
  for j in range(c):
    if j+1<c:
      dp[i][j+1][0]=max(dp[i][j+1][0],dp[i][j][0])
      dp[i][j+1][1]=max(dp[i][j][1],max(dp[i][j+1][1],dp[i][j][0]+m[i][j+1]))
      dp[i][j+1][2]=max(dp[i][j][2],max(dp[i][j+1][2],dp[i][j][1]+m[i][j+1]))
      dp[i][j+1][3]=max(dp[i][j][3],max(dp[i][j+1][3],dp[i][j][2]+m[i][j+1]))
    if i+1<r:
      dp[i+1][j][0]=dp[i][j][3]
      dp[i+1][j][1]=dp[i][j][3]+m[i+1][j]
      dp[i+1][j][2]=dp[i][j][3]+m[i+1][j]
      dp[i+1][j][3]=dp[i][j][3]+m[i+1][j]
print(dp[r-1][c-1][3])
    

### FIXED CODE ###

import os,io
import sys
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
r,c,k=map(int,input().split())
dp = [[[0 for y in range(c)] for z in range(r)] for P in range(4)]
m=[]
for i in range(r):
  m.append([])
  for j in range(c):
    m[i].append(0)
for i in range(k):
  ri,ci,v=map(int,input().split())
  m[ri-1][ci-1]=v
dp[0][0][0]=0
dp[1][0][0]=m[0][0]
dp[2][0][0]=m[0][0]
dp[3][0][0]=m[0][0]
for i in range(r):
  for j in range(c):
    if j+1<c:
      dp[0][i][j+1]=max(dp[0][i][j+1],dp[0][i][j])
      dp[1][i][j+1]=max(dp[1][i][j],max(dp[1][i][j+1],dp[0][i][j]+m[i][j+1]))
      dp[2][i][j+1]=max(dp[2][i][j],max(dp[2][i][j+1],dp[1][i][j]+m[i][j+1]))
      dp[3][i][j+1]=max(dp[3][i][j],max(dp[3][i][j+1],dp[2][i][j]+m[i][j+1]))
    if i+1<r:
      dp[0][i+1][j]=dp[3][i][j]
      dp[1][i+1][j]=dp[3][i][j]+m[i+1][j]
      dp[2][i+1][j]=dp[3][i][j]+m[i+1][j]
      dp[3][i+1][j]=dp[3][i][j]+m[i+1][j]
print(dp[3][r-1][c-1])
### BUGGY CODE ###

n,m = map(int, input().split())
gatelist = [0] * n
for i in range(m):
    l,r = map(int, input().split())
    for j in range(l-1,r):
        gatelist[j] += 1
cnt = 0
for item in gatelist:
    if item == m:
        cnt +=1
print(cnt)

### FIXED CODE ###

n,m = map(int, input().split())
maxl = 0
minr = 100000
for i in range(m):
    l,r = map(int, input().split())
    maxl = max(maxl,l)
    minr = min(minr,r)
ans = max(minr - maxl + 1, 0)
print(ans)
### BUGGY CODE ###

N = int(input())
number = list(map(int,input().split()))
count = 0
if not 1 in number:
    print(-1)
else:
    for i in range(N):
        now = i+1
        if now in number:
            indexnumber = number.index(now)
            #number.index(now)が左から数えたときのnowのindex番号
            count += indexnumber
            number[:indexnumber+1]=[]

        else:
            count += len(number)
            break
    print(count)

### FIXED CODE ###

N = int(input())
number = list(map(int,input().split()))
count = 0
if not 1 in number:
    print(-1)
else:
    nownumber = 1
    nowindex = 0
    for i in range(N):
        if number[i]  == nownumber:
            count += 1
            nownumber += 1
        else:
            pass
    print(N-count)
### BUGGY CODE ###

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

    pattern = 0

    if s > 3 * k:
        print(pattern)
        return

    for x in range(k + 1):
        for y in range(min(k + 1, s - x + 1)):
            for z in range(min(k + 1, s - x - y + 1)):
                if x + y + z == s:
                    pattern += 1

    print(pattern)


if __name__ == "__main__":

    main()


### FIXED CODE ###

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

    pattern = 0

    for x in range(k + 1):
        for y in range(k + 1):
            if (s - x - y >= 0) and (s - x - y <= k):
                pattern += 1

    # Wrong Anser
    # 
    # # 3,4 --> 0 start
    # # 3,5 --> 0 start
    # # 3,7 --> 1 start
    # # 3,8 --> 2 start
    # # 3,9 --> 3 start 
    # # 4,8 --> 0 start
    # # 4,9 --> 1 start
    # # 4,10 --> 2 start
    # # s // k * 2
    # 
    # for x in range(s // 3, k + 1):
    #     for y in range(s // 3, min(k + 1, s - x + 1)):
    #         for z in range(s // 3, min(k + 1, s - x - y + 1)):
    #             if x + y + z == s:
    #                 pattern += 1
    # 

    print(pattern)


if __name__ == "__main__":

    main()
### BUGGY CODE ###

n, m = map(int, input().split())
mod = 1000000007
d = 1
divisor = []
while d * d <= m:
    if m % d == 0:
        divisor.append(d)
        if d != m // d:
            divisor.append(m // d)
    d += 1
divisor = sorted(divisor)
l = len(divisor)
matrix = [[0] * l for _ in range(l)]
for i in range(l):
    for j in range(l):
        matrix[i][j] = 1 if divisor[i] % divisor[j] == 0 else 0

dp = [1] * l
t = n - 1
while t > 0:
    if t % 2 == 1:
        newdp = [0] * l
        for i in range(l):
            for j in range(l):
                newdp[i] = (newdp[i] + matrix[i][j] * dp[j]) % mod
        dp = newdp
    newmatrix = [[0] * l for _ in range(l)]
    for i in range(l):
        for j in range(i + 1):
            newmatrix[i][j] = sum(matrix[i][k] * matrix[k][j] for k in range(j, i + 1)) % mod
    matrix = newmatrix
    t //= 2

print(dp[-1])


### FIXED CODE ###

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

def cmb(n, k):
    ret = 1
    for i in range(k):
        ret *=  n - i
        ret //= i + 1
    return ret % mod

primes = [2]
for p in range(3, 1000):
    if all(p % q for q in primes):
        primes.append(p)

ret = 1
for p in primes:
    q = 0
    while m % p == 0:
        m //= p
        q += 1
    if q > 0:
        ret = (ret * cmb(n + q - 1, q)) % mod
if m > 1:
    ret = (ret * cmb(n, 1)) % mod

print(ret)
### BUGGY CODE ###

import sys

Z = 998244353


def input():
    return sys.stdin.readline().rstrip('\n')


def calc(N, K, LR):
    c = []
    for (l, r) in LR:
        for i in range(l, r + 1):
            c += [i]
    d = [0] * N
    d[0] = 1
    for i in range(N):
        if d[i] == 0:
            continue
        for e in c:
            if i + e < N:
                d[i + e] = (d[i + e] + d[i]) % Z
    return d[N - 1]


(N, K) = tuple([int(s) for s in input().split()])
LR = [tuple([int(s) for s in input().split()]) for _ in range(K)]
print(calc(N, K, LR))

### FIXED CODE ###

import sys

Z = 998244353


def input():
    return sys.stdin.readline().rstrip('\n')


def calc(N, K, LR):
    f = [0] * N
    a = [0] * N
    f[0] = 1
    a[0] = -1
    for i in range(N - 1):
        for (l, r) in LR:
            if i + l - 1 < N:
                a[i + l - 1] = a[i + l - 1] + f[i]
            if i + r < N:
                a[i + r] = a[i + r] - f[i]
        f[i + 1] = (a[i] + f[i]) % Z
    return f[N - 1]


(N, K) = tuple([int(s) for s in input().split()])
LR = [tuple([int(s) for s in input().split()]) for _ in range(K)]
print(calc(N, K, LR))
### BUGGY CODE ###

import collections
import string
s=input()
n = len(s)
k = int(input())

subs = collections.defaultdict(set)
for i in range(n):
    for j in range(i+1,n+1):
        subs[s[i]].add(s[i:j])
for c in string.ascii_lowercase:
    l = len(subs[c])
    if k <= l:
        t = sorted(list(subs[c]))[k-1]
        print(t)
        exit()
    else:
        k -= l


### FIXED CODE ###

import collections
import string
import heapq
s=input()
n = len(s)
k = int(input())

m = ['zzzzzzz','zzzzzzz','zzzzzzz','zzzzzzz','zzzzzzz']
subs = []
for i in range(n):
    for j in range(i+1, min(i+6, n+1)):
        sub = s[i:j]
        if sub not in subs:
            subs.append(sub)
            subs.sort()
            subs = subs[:5]
print(subs[k-1])
### BUGGY CODE ###

import sys

N,K=map(int,input().split())
ZET=N
b=(10**18)
c=N
b1=N
for i in range(int(b)):
  if K==1:
    b1=0
    break
  c=abs(b1-K)
  if int(b)<=c:
    break
  b1=c
  b=c
print(b1)

### FIXED CODE ###

import sys

N,K=map(int,input().split())
ZET=N
b=(10**18)
c=N
b1=N
for i in range(int(b)):
  if K==1:
    b1=0
    break
  if N>10**17 and K<10**9:
    b1=N%K
    c=abs(b1-K)
    if b1>c:
      b1=c
    break
  c=abs(b1-K)
  if int(b)<=c:
    break
  b1=c
  b=c
print(b1)
### BUGGY CODE ###

# 解説AC
from collections import deque

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

def bfs(s:int, g:int):
    """ 始点sから終点gまでのパスを求める """
    path = [0] * N
    visited = [False] * N
    
    que = deque([s])
    visited[s] = True
    while que:
        v = que.popleft()
        for w, n in edge[v]:
            if visited[w]: continue
            path[w] = path[v] | (1 << n)
            if w == g: return path[g]
            que.append(w)
    return path[g]

def popcount(x:int):
    """ return bin(x).count('1') """
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f

M = int(input())
path = [0] * M # 各制約で使用するパス
for i in range(M):
    u,v = map(int, input().split())
    path[i] = bfs(u - 1, v - 1)

ans = 0
# 包除原理
for bit in range(1 << M):
    val = 0
    for i in range(M):
        if (bit >> i) & 1:
            val |= path[i]
    if popcount(bit) % 2 == 0:
        ans += 1 << (N - 1 - popcount(val))
    else:
        ans -= 1 << (N - 1 - popcount(val))

print(ans)

### FIXED CODE ###

# 解説AC
from collections import deque

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

def bfs(s:int, g:int):
    """ 始点sから終点gまでのパスを求める """
    in_edge = [-1] * N
    par = [-1] * N
    flag = False # 終点到着フラグ
    
    que = deque([s])
    while que:
        v = que.popleft()
        for w, n in edge[v]:
            if w == par[v]: continue
            in_edge[w] = n
            par[w] = v
            if w == g:
                flag = True
                break
            que.append(w)
        if flag: break
    path = 0
    cur = g
    while in_edge[cur] >= 0:
        path |= 1 << in_edge[cur]
        cur = par[cur]
    return path


M = int(input())
path = [0] * M # 各制約で使用するパス
for i in range(M):
    u,v = map(int, input().split())
    path[i] = bfs(u - 1, v - 1)

ans = 0
# 包除原理
for bit in range(1 << M):
    val = 0
    for i in range(M):
        if (bit >> i) & 1:
            val |= path[i]
    if bin(bit).count("1") % 2 == 0:
        ans += 1 << (N - 1 - bin(val).count("1"))
    else:
        ans -= 1 << (N - 1 - bin(val).count("1"))

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

import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import Counter
def div10(d):
    return d//10
def rem2019(d):
    return d%2019
def resolve():
    S = [s for s in sr()]
    N = len(S)
    a = ['']
    for i in range(N):
        s = S.pop()
        a.append(int(s+str(a[i])))
    a = a[::-1]
    a[-1] = 0
    ans = 0
    for i in range(N):
        t = list(map(rem2019, a))
        ans += Counter(t)[0]-1
        a = list(map(div10, a))
        g = a.pop()
    print(ans)
resolve()

### FIXED CODE ###

import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    S = sr()
    N = len(S)
    a = [0]*2019
    a[0] += 1
    t = 0
    r = 1
    for s in reversed(S):
        t += int(s)*r
        t %= 2019
        r *= 10
        r %= 2019
        a[t] += 1
    ans = 0
    for i in range(2019):
        ans += a[i]*(a[i]-1)//2
    print(ans)
resolve()
### BUGGY CODE ###

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

ans = 1
for i in range(N):
  ans = ans*A[i]

if ans > 10**18:
  print(-1)
else:
  print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
a = 0
for i in range(N):
  if A[i] == 0:
    a = 1
    break
  elif A[i] > 10**18:
    a = 2
    break

if a == 1:
  print(0)
elif a == 2:
  print(-1)
else:
  b = 0
  ans = 1
  for i in range(N):
    ans = ans*A[i]
    if ans > 10**18:
      b = 1
      break

  if b == 0:
    print(ans)
  else:
    print(-1)
### BUGGY CODE ###

from bisect import bisect_left
ub = 50000
primes = {2} | set(range(3, ub, 2))
du = primes.difference_update
for n in range(3, ub, 2):
    if n in primes:
        du(range(n*3, ub, n*2))

primes = list(primes)

while True:
    n = int(input())
    if n == 0:
        break
    l, r = 0, bisect_left(primes, n-2)
    ans = 0
    while l <= r:
        if primes[l]+primes[r] > n:
            r -= 1
        ans += (primes[l]+primes[r] == n)
        l += 1
    print(ans)


### FIXED CODE ###

import sys
from bisect import bisect_right
from itertools import chain, compress

ub = 50000
is_prime = [0, 0, 1, 1] + [0]*(ub-3)
is_prime[5::6] = is_prime[7::6] = [1]*int(ub/6)
primes = [2, 3]
append = primes.append

for n in chain(range(5, ub, 6), range(7, ub, 6)):
    if is_prime[n]:
        append(n)
        is_prime[n*3::n*2] = [0]*((ub-n)//(n*2))
primes.sort()

for n in map(int, sys.stdin):
    if not n:
        break
    if n%2:
        print(is_prime[n-2])
    else:
        print(len([1 for p in primes[:bisect_right(primes, n/2)] if is_prime[n-p]]))
### BUGGY CODE ###

from itertools import product
N, K = map(int, input().split())
XY = []
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append([x, y])
X.sort()
Y.sort()

ans = 10 ** 19
for l, r, t, b in product(X, X, Y, Y):
    if l > r or t > b:
        continue
    area = (r - l) * (b - t)
    if area >= ans:
        continue
    cnt = -K
    for x, y in XY:
        if l <= x <= r and t <= y <= b:
            cnt +=1
            if cnt >= 0:
                break
    if cnt >= 0:
        ans = area

print(ans)

### FIXED CODE ###

from itertools import product
from operator import itemgetter
N, K = map(int, input().split())
XY = []
X, Y = [], []
for _ in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    XY.append([x, y])
X.sort()
Y.sort()
XY.sort(key=itemgetter(1))

ans = 10 ** 19
for l, r, t in product(X, X, Y):
    if l > r:
        continue
    cnt = -K
    for x, y in XY:
        if y < t:
            continue
        if l <= x <= r:
            cnt += 1
            if cnt >= 0:
                area = (r - l) * (y - t)
                if area < ans:
                    ans = area
                break

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

S = list(map(int,input().split()))
N = S[0]
M = S[1]

for x in range(N,M+1):
    if M % x == 0:
        ans = M // x
        break

print(ans) 

### FIXED CODE ###

import math

S = list(map(int,input().split()))
N = S[0]
M = S[1]
div = list()
z = math.sqrt(M)
z = math.ceil(z)

for x in range(1,z):
    if M % x == 0:
        div.append(x)
        div.append(M//x)
div.append(M)
div.append(N)

sorted_div = sorted(div)
n = sorted_div.index(N)

y =sorted_div[n+1]

ans = M // y

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

H, W = map(int,input().split())
s = [list(input()) for i in range(H)]
num_of_point = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            num_of_point += 1

counter = 0
position = [[0,0]]
while True:
    counter += 1
    new_position =[]
    for i,j in position:
        for i_,j_ in [[-1,0],[0,1],[0,1],[1,0]]:
            i_new = i+i_
            j_new = j+j_
            if i_new >=0 and i_new <= H-1 and j_new >= 0 and j_new <= W-1:
                if s[i_new][j_new] == '.':
                    new_position.append([i_new,j_new])
                    s[i_new][j_new] = counter
    if [H-1,W-1] in new_position:
        break
    position = new_position

print(num_of_point-counter-1)

### FIXED CODE ###

H, W = map(int,input().split())
s = [list(input()) for i in range(H)]
num_of_point = 0
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            num_of_point += 1
 
counter = 0
position = [[0,0]]
while True:
    counter += 1
    new_position =[]
    for i,j in position:
        for i_,j_ in [[-1,0],[1,0],[0,1],[0,-1]]:
            i_new = i+i_
            j_new = j+j_
            if i_new >=0 and i_new <= H-1 and j_new >= 0 and j_new <= W-1:
                if s[i_new][j_new] == '.':
                    new_position.append([i_new,j_new])
                    s[i_new][j_new] = counter
    if [H-1,W-1] in new_position:
        print(num_of_point-counter-1)
        break
    if counter >= H*W:
      	print(-1)
      	break
    position = new_position
### BUGGY CODE ###

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

i = 0
test = []
b = None
while i < n:
    test.append(a_l[i])
    if len(test) > k:
        test = test[len(test)-k:]
    if len(test) == k:
        p = 1
        for m in test:
            p *= m
        if b is not None:
            if p > b:
                print('Yes')
            else:
                print('No')
        b = p
    i+=1

### FIXED CODE ###

n, k = map(int, input().split())
a_l = list(map(int, input().split()))
i = 0
while i < n:
    if i >= k:
        if a_l[i] > a_l[i-k]:
            print('Yes')
        else:
            print('No')
    i+=1
### BUGGY CODE ###

def main():
    s = input()
    c = 0
    while True:
        n = s.count('ABC')
        if n == 0:
            break
        c += n
        s = s.replace('ABC', 'BCA')
    print(c)
        


main()


### FIXED CODE ###

def main():
    s = input()
    c = 0
    pos = 0
    a = 0

    while pos < len(s):
        if s[pos] == 'A':
            a += 1
            pos += 1
        elif s[pos:pos+2] == 'BC':
            c += a
            pos += 2
        else:
            a = 0
            pos += 1

    print(c)
        


main()
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
BC=[input() for __ in range(M)]

for bc in BC:
    b,c=map(int,bc.split())

    for i in range(len(A)):
        if A[i]<c:
            A=A[:i]+[c]*b+A[i:]
            break
    A=A[:N]

print(sum(A))

### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for __ in range(M)]
BC.sort(key=lambda x: x[1],reverse=True)

l=[]
for b,c in BC:
    if len(l)+b>N:
        l.extend(list([c]*b))
        break
    else:
        l.extend(list([c]*b))
A.extend(l)
A.sort(reverse=True)
print(sum(A[:N]))
### BUGGY CODE ###

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

ret = []

for i in range(n):
    a,b = map(int, input().split())
    ret += [a] * b

ret.sort()

print(ret[k-1])


### FIXED CODE ###

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

ret = {}

for i in range(n):
    a,b = map(int, input().split())
    ret[a] = ret.get(a, 0) + b

for i in sorted(ret.keys()):
    k -= ret[i]
    if k <= 0:
        print(i)
        break
### BUGGY CODE ###

from bisect import bisect_left
from bisect import bisect_right

n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)

ans = 0
visited = [False]*n

while a:
    s = a.pop()
    if visited.pop():
        continue
    m = 1
    while m <= s:
        m *= 2
    r = bisect_right(a, m-s)
    l = bisect_left(a, m-s)
    if r-l > 0:
        a.pop(r-1)
        ans += 1

print(ans)


### FIXED CODE ###

from bisect import bisect_left
from bisect import bisect_right

n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)

ans = 0
visited = [False]*n

while a:
    s = a.pop()
    if visited.pop():
        continue
    m = 1
    while m <= s:
        m *= 2
    r = bisect_right(a, m-s)
    l = bisect_left(a, m-s)
    for x in range(l, r)[::-1]:
        if not visited[x]:
            visited[x] = True
            ans += 1
            break

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

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

c = [0]*n
flag = 0
c[0] = a[0]
for i in range(n):
  for j in range(i):
    if c[j] == a[i]:
      flag = 1
      break
  if flag == 1:
    break
  else:
    c[i] = a[i]

#print(c)
if flag == 0:
  print("YES")
else:
  print("NO")
  

### FIXED CODE ###

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

a.sort()
flag = 0

for i in range(n-1):
  if a[i] == a[i+1]:
    flag = 1
    break
    
if flag == 0:
  print("YES")
else:
  print("NO")
### BUGGY CODE ###

n = input()
a = map(int, raw_input().split())
b = []
for i in range(n):
    b.append(a[i])
    b = b[::-1]
print " ".join(map(str, b))

### FIXED CODE ###

n = input()
a = map(int, raw_input().split())
b = [-1] * n
for i in range(n):
    b[n/2 - (2*(i%2) - 1) * ((i+1)/2)] = a[i]
if n % 2 == 1:
    b = b[::-1]
print " ".join(map(str, b))
### BUGGY CODE ###

S = list(input())
N = len(S)
count = 0
for i in range(N):
  if S[i] == 'W':
    count+=S[:i].count('B')
print(count)

### FIXED CODE ###

S = list(input())
N = len(S)
ans = 0
count = 0
for i in range(N):
  if S[i] == 'B':
    count+=1
  if S[i] == 'W':
    ans+=count
print(ans)
### BUGGY CODE ###

def up(n):
	if n == 0: return 1
	if n < 0: return 0
	return up(n-1)+up(n-2)+up(n-3)
	
while True:
	n = int(raw_input())
	if n == 0: break
	print (up(n)//10+1)//365+1

### FIXED CODE ###

def up(n):
	goal = [0 for i in range(n)]
	goal[:3] = [1,2,4]
	for i in range(3,n):
		goal[i] = sum(goal[i-3:i])
	return goal[-1]
	
while True:
	n = int(raw_input())
	if n == 0: break
	print (up(n)//10+1)//365+1
### BUGGY CODE ###

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

    for i in range(n):
        ans = As.count(i+1)
        print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

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

    anss = [0]*n
    for A in As:
        anss[A-1] += 1
    for ans in anss:
        print(ans)


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

from functools import lru_cache, reduce
from sys import stdin


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def mygcd(lst):
    result = lst[0]
    for x in lst[1:]:
        result = gcd(result, x)
    return result


def main():
    _ = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    max_ = 0
    for a in As:
        tmp = As[:]
        tmp.remove(a)
        max_ = max(max_, reduce(gcd, tmp))
    print(max_)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from functools import lru_cache
from sys import stdin


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def make_acc_gdbs(As):
    result = []
    tmp = 0
    for x in As:
        tmp = gcd(tmp, x)
        result.append(tmp)
    return result


def main():
    N = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    lAs = make_acc_gdbs(As)
    rAs = make_acc_gdbs(As[::-1])[::-1]
    max_ = 0
    for i in range(N):
        left = 0 if i == 0 else lAs[i - 1]
        right = 0 if i == (N - 1) else rAs[i + 1]
        max_ = max(max_, gcd(left, right))
    print(max_)


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

s = input()
q = int(input())

rev = False
for i in range(q):
  inp = list(input().split())
  if inp[0] == '1':
    rev = not rev
  else:
    f = inp[1]
    c = inp[2]
    if rev:
      if f == '1':
        f = '2'
      else:
        f = '1'
    if f == '1':
      s = c + s
    else:
      s = s + c
if rev:
  s = s[::-1]
print(s)

### FIXED CODE ###

s = input()
q = int(input())

rev = False
before = []
after = []
for i in range(q):
  inp = list(input().split())
  if inp[0] == '1':
    rev = not rev
  else:
    f = inp[1]
    c = inp[2]
    if rev:
      if f == '1':
        f = '2'
      else:
        f = '1'
    if f == '1':
      before.append(c)
    else:
      after.append(c)
ans = ''
if rev:
  after.reverse()
  ans = ''.join(after) + s[::-1] + ''.join(before)
else:
  before.reverse()
  ans = ''.join(before) + s + ''.join(after)
print(ans)