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

hist = [0 for i in range(N)]
route = []
loop = []

jump = 1
cur = A[0] - 1
route.append(0)
hist[0] = jump
while hist[cur] == 0:
    jump = jump + 1
    route.append(cur)
    hist[cur] = jump
    cur = A[cur] - 1

loop = route[cur:]

if K < len(route):
    print(route[K] + 1)
else:
    K = K - len(route) - 1
    K = K % len(loop)
    print(loop[K] + 1)

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

hist = [-1 for i in range(N)]
route = []
loop = []

jump = 0
cur = A[0] - 1
route.append(0)
hist[0] = jump
while hist[cur] == -1:
    jump = jump + 1
    route.append(cur)
    hist[cur] = jump
    cur = A[cur] - 1

loop = route[hist[cur] :]

# print(cur, hist, route, loop)

if K < len(route):
    print(route[K] + 1)
else:
    K = K - len(route)
    # print(K)
    K = K % len(loop)
    # print(K)
    print(loop[K] + 1)


import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    went = [0] * N
    went[0] = 1
    Flag = True
    check = [0]
    cnt = 1
    now = 0
    while Flag and (cnt <= K):
        now = A[now] - 1
        if went[now] == 1:
            ind = check.index(now) - 1
            cnt = cnt - ind - 1
            Flag = False
        else:
            check.append(now)
            went[now] = 1
            cnt += 1
            continue
    if len(check) >= K:
        print(check[K] + 1)
    else:
        K = (K - ind) % cnt
        print(check[ind + K] + 1)

if __name__ == "__main__":
    main()

import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    went = [0] * N
    went[0] = 1
    Flag = True
    check = [0]
    cnt = 1
    now = 0
    while Flag and (cnt <= K + 1):
        now = A[now] - 1
        if went[now] == 1:
            ind = check.index(now)
            if ind == 0:
                cnt = len(check)
            else:
                cnt = len(check) - ind

            Flag = False
        else:
            check.append(now)
            went[now] = 1
            cnt += 1
            continue

    if len(check) > K:
        print(check[K] + 1)
    else:
        if ind == 0:
            K = K % cnt
            print(check[K] + 1)
        else:
            ind -= 1
            K = (K - ind - 1) % cnt
            print(check[ind + K + 1] + 1)

if __name__ == "__main__":
    main()


def dfs(v):
    path.append(v)
    visited[v] = 1
    nv = A[v]
    if visited[nv] == 1:
        return nv
    return dfs(nv)

N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
visited = [-1] * N
path = []
cycle_start = dfs(0)
cycle_len = len(path) - path.index(cycle_start)
head_len = len(path) - cycle_len
if K <= head_len:
    print(path[K] + 1)
else:
    K -= head_len
    print(path[head_len + K % cycle_len] + 1)

import sys

sys.setrecursionlimit(10**6)

def dfs(v):
    path.append(v)
    visited[v] = 1
    nv = A[v]
    if visited[nv] == 1:
        return nv
    return dfs(nv)

N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
visited = [0] * N
path = []
cycle_start = dfs(0)
cycle_len = len(path) - path.index(cycle_start)
head_len = len(path) - cycle_len
if K <= head_len:
    print(path[K] + 1)
else:
    K -= head_len
    print(path[head_len + K % cycle_len] + 1)


# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

# マイナス1した値を返却
def int1(x):
    return int(x) - 1

# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())

# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))

# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))

def main():
    n, k = input_to_int_map()
    a = {i + 1: int(val) for i, val in enumerate(input().split())}

    place = 1
    place_goneds = [place]
    i = 0
    loop_start_index = 0
    while i < n:
        place = a[place]
        goned = False
        for j, place_goned in enumerate(place_goneds):
            if place_goned == place:
                loop_start_index = j
                goned = True
                break

        if goned:
            break

        place_goneds.append(place)
        i += 1

    if k < len(place_goneds):
        return place_goneds[k]

    move_cnt = k - loop_start_index
    loop_list = place_goneds[loop_start_index:]
    return loop_list[move_cnt % len(loop_list)]

if __name__ == "__main__":
    print(main())

# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

# マイナス1した値を返却
def int1(x):
    return int(x) - 1

# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())

# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))

# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))

def main():
    n, k = input_to_int_map()
    a = {i + 1: int(val) for i, val in enumerate(input().split())}

    place = 1
    visit = {place}
    place_visits = [place]
    for i in range(k):
        place = a[place]
        if place in visit:
            left = place_visits.index(place)
            return place_visits[left + (k - left) % (i + 1 - left)]
        else:
            visit.add(place)
            place_visits.append(place)

    return place

if __name__ == "__main__":
    print(main())


import numpy as np

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

table = np.zeros((64, n), dtype=np.int64)
table[0] = a

for i in range(61):
    for j in range(n):
        table[i + 1][j] = table[i][table[i][j]]

ans = 0
for i in range(61, -1, -1):
    if k >> i & 1:
        ans = table[i][ans]
print(ans + 1)

n, k = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))

table = [[0] * n for _ in [0] * 64]
table[0] = a

for i in range(61):
    for j in range(n):
        table[i + 1][j] = table[i][table[i][j]]

ans = 0
for i in range(61, -1, -1):
    if k >> i & 1:
        ans = table[i][ans]
print(ans + 1)


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

B = [A[0]]

for _ in range(1, N + 10):
    b = A[B[-1] - 1]
    if b in B:
        B += [b]
        break
    else:
        B += [b]
        continue

if len(B) >= K:
    print(B[K])
else:
    ind = [i for i, x in enumerate(B) if x == b]

    K = K - ind[0]
    mod = K % (ind[1] - ind[0])

    print(B[ind[0] + mod - 1])

import sys

readline = sys.stdin.buffer.readline

def solver(N, K, A):
    i = 0
    i_list = [0]
    reached = [False for _ in range(N)]

    while True:
        next_i = A[i]

        if reached[next_i]:
            break

        reached[next_i] = True

        i_list.append(next_i)
        i = next_i

    m = i_list.index(next_i)

    if m >= K:
        return i_list[K] + 1

    le = len(i_list) - m
    K -= m
    ind = K % le

    return i_list[m + ind] + 1

def run():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    A = [a - 1 for a in A]

    ans = solver(N, K, A)
    print(ans)

run()


n, k = map(int, input().split())
a = list(map(int, input().split()))
rec = [0]
i = 0
flag = [0 for _ in range(n + 1)]
while True:
    if flag[rec[i]] == 0:
        flag[rec[i]] = 1
        rec.append(a[rec[i]] - 1)
    else:
        start = rec.index(a[rec[i]] - 1)
        loop = rec[start:]
        pre = rec[:start]
        break
    i += 1
count = (k - len(pre)) % len(loop)
if k < len(pre):
    print(loop[k])
else:
    print(loop[count] + 1)

n, k = map(int, input().split())
a = list(map(int, input().split()))
rec = [0]
i = 0
flag = [0 for _ in range(n + 1)]
while True:
    if flag[rec[i]] == 0:
        flag[rec[i]] = 1
        rec.append(a[rec[i]] - 1)
    else:
        start = rec.index(a[rec[i]] - 1)
        loop = rec[start:]
        pre = rec[:start]
        break
    i += 1
count = (k - len(pre)) % len(loop)
if k <= len(pre):
    print(pre[k] + 1)
else:
    print(loop[count] + 1)


n, m, k = [int(t) for t in open(0).read().split()]
mod = 998244353

def solve(n):
    if n <= k + 1:
        return pow(m, n, mod)
    elif n == k + 2:
        return (pow(m, n, mod) + mod - m) % mod
    else:
        return (m * solve(n - 1) - (m - 1) * solve(n - k - 2)) % mod

print(solve(n))

n, m, k = [int(t) for t in open(0).read().split()]
mod = 998244353
mem = [0] * max(k + 3, n + 1)
for i in range(k + 2):
    mem[i] = pow(m, i, mod)
c = 1
for i in range(k + 2, n + 1):
    mem[i] = (m * mem[i - 1] - m * c * pow(m - 1, i - k - 2, mod)) % mod
    c = (c * (i - 1) * pow(i - k - 1, -1, mod)) % mod
print(mem[n])


def cmb(n, r, p):
    return (fac[n] * pow(fac[r], p - 2, p) * pow(fac[n - r], p - 2, p)) % p

p = 998244353
N, M, K = map(int, input().split())
fac = [1] * (N + 1)
for i in range(1, N + 1):
    fac[i] = (fac[i - 1] * i) % p

ans = 0
for k in range(K + 1):
    ans += M * pow(M - 1, N - k - 1, p) * cmb(N - 1, k, p)
    ans %= p
print(ans)

p = 998244353
N, M, K = map(int, input().split())

ans = 0
cmb = 1
for k in range(K + 1):
    ans += M * pow(M - 1, N - k - 1, p) * cmb
    ans %= p
    cmb *= (N - 1 - k) * pow(k + 1, p - 2, p)
    cmb %= p
print(ans)


ABC = input("The element of S: ")
ARC = input("The element of S: ")
if ABC == "S":
    print("ABC")
if ARC == "S":
    print("ARC")

s = input()
if s == "ABC":
    print("ARC")
if s == "ARC":
    print("ABC")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02687/Python/s038660380.py", line 2, in <module>
    ARC = input("The element of S: ")
EOFError: EOF when reading a line


N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0] * N
B = [0] * N
for i in range(M):
    A[i], B[i] = map(int, input().split())

ans = 0
for i in range(N):
    count = 0
    good = 0
    for j in range(M):
        if A[j] == i + 1:
            count += 1
            if H[B[j] - 1] < H[i]:
                good += 1
        if B[j] == i + 1:
            count += 1
            if H[A[j] - 1] < H[i]:
                good += 1
    if count == good:
        ans += 1

print(ans)

#!/usr/bin/env python3
import sys

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    A = [0] * M
    B = [0] * M
    for i in range(M):
        A[i], B[i] = map(int, input().split())

    l = [1] * N
    for i in range(M):
        if H[A[i] - 1] < H[B[i] - 1]:
            l[A[i] - 1] -= 1
        elif H[A[i] - 1] > H[B[i] - 1]:
            l[B[i] - 1] -= 1
        else:
            l[A[i] - 1] -= 1
            l[B[i] - 1] -= 1
    print(l.count(1))

if __name__ == "__main__":
    main()


n, m = map(int, input().split())
li_h = list(map(int, input().split()))
li_route = list()
remove_idx_set = set()

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

    h_a = li_h[a - 1]
    h_b = li_h[b - 1]

    if h_a <= h_b:
        if h_a in li_h:
            remove_idx_set.add(a - 1)
    if h_a >= h_b:
        if h_b in li_h:
            remove_idx_set.add(b - 1)
for s in remove_idx_set:
    li_h[s] = 0
print(len([v for v in li_h if v != 0]))

n, m = map(int, input().split())
li_h = list(map(int, input().split()))
li_route = list()
remove_idx_set = set()

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

    h_a = li_h[a - 1]
    h_b = li_h[b - 1]

    if h_a <= h_b:
        remove_idx_set.add(a - 1)
    if h_a >= h_b:
        remove_idx_set.add(b - 1)
for s in remove_idx_set:
    li_h[s] = 0
print(len([v for v in li_h if v != 0]))


N, M = map(int, input().split())
H_i = list(map(int, input().split()))
U = [list(map(int, input().split())) for i in range(M)]

high_max = []
ans = 0

for i in range(N):
    Highes = []
    for j in range(M):
        if U[j][0] == i + 1:
            Highes.append(H_i[U[j][1] - 1])
        if U[j][1] == i + 1:
            Highes.append(H_i[U[j][0] - 1])

    if Highes == []:
        high_max.append(0)
    else:
        high_max.append(max(Highes))

for i in range(N):
    if H_i[i] > high_max[i]:
        ans += 1

print(ans)

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

good = [True] * N

for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    if H[A] >= H[B]:
        good[B] = False
    if H[A] <= H[B]:
        good[A] = False
print(sum(good))


#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
H = [int(str) for str in input().strip().split()]
AB = [[int(str) - 1 for str in input().strip().split()] for _ in range(M)]

def solve():
    G = [[False] * N for _ in range(N)]
    for a, b in AB:
        G[a][b] = True
        G[b][a] = True

    ans = 0
    visited = [False] * N
    for start in range(N):
        if visited[start]:
            continue
        nexts = [i for i in range(N) if G[start][i]]
        if all([H[start] > H[next] for next in nexts]):
            ans += 1
            for next in nexts:
                visited[next] = True

    print(ans)

solve()

#!/usr/bin/env python3
N, M = [int(str) for str in input().strip().split()]
H = [int(str) for str in input().strip().split()]
AB = [[int(str) - 1 for str in input().strip().split()] for _ in range(M)]

def solve():
    G = [0] * N
    for a, b in AB:
        G[a] = max(G[a], H[b])
        G[b] = max(G[b], H[a])

    ans = 0
    for i in range(N):
        if H[i] > G[i]:
            ans += 1

    print(ans)

solve()


n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(m)]
dic = {}
ban = {}
for i in range(m):
    a = ab[i][0]
    b = ab[i][1]
    if h[a - 1] < h[b - 1]:
        ban[a] = True
    elif h[a - 1] == h[b - 1]:
        ban[a] = True
        ban[b] = True
    else:
        ban[b] = True

    if dic.get(a):
        dic[a].append(b)
    else:
        dic[a] = [b]

    if dic.get(b):
        dic[b].append(a)
    else:
        dic[b] = [a]
    dic[a] = list(set(dic[a]))
    dic[b] = list(set(dic[b]))
ans = 0
for i in range(n):
    if dic.get(i + 1):
        if ban.get(i + 1):
            if ban[i + 1]:
                continue
        flg = True
        for j in range(len(dic[i + 1])):
            if h[i] <= h[dic[i + 1][j] - 1]:
                flg = False
                break
        if flg:
            ans += 1
    else:
        ans += 1
print(ans)

n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(m)]
dic = {}
ban = {}
for i in range(m):
    a = ab[i][0]
    b = ab[i][1]

    if dic.get(a):
        dic[a] = max(dic[a], h[b - 1])
    else:
        dic[a] = h[b - 1]

    if dic.get(b):
        dic[b] = max(dic[b], h[a - 1])
    else:
        dic[b] = h[a - 1]
ans = 0
for i in range(n):
    if dic.get(i + 1):
        if dic[i + 1] < h[i]:
            ans += 1
    else:
        ans += 1
print(ans)


from itertools import product

x = int(input())
num = [i**5 for i in range(-1000, 1000)]

for a, b in product(num, repeat=2):
    if a - b == x:
        print(int(a**0.2), int(b**0.2))
        break

from itertools import combinations

x = int(input())
num = [i**5 for i in range(1000)]

for a, b in combinations(num, 2):
    if a - b == x:
        print(int(a**0.2), int(b**0.2))
    elif a + b == x:
        print(int(a**0.2), -int(b**0.2))
    elif b - a == x:
        print(int(b**0.2), int(a**0.2))
    else:
        continue
    break

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02690/Python/s068916445.py", line 8, in <module>
    print(int(a**0.2), int(b**0.2))
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'complex'


x = int(input())

for a in range(9999):
    for b in range(9999):
        if a**5 - b**5 == x:
            print(a, b)
            exit()


x = int(input())
for i in range(x // 2 + 1):
    if pow(x - pow(i, 5), 1 / 5).is_integer():
        print(i, int(-pow(x - pow(i, 5), 1 / 5)))
        exit()

import numpy as np

def main():
    x = int(input())
    A = np.arange(-120, 120)
    a = A**5
    for i, a_1 in enumerate(a):
        for j, a_2 in enumerate(a):
            if a_1 - a_2 == x:
                print(A[i], A[j])
                return

if __name__ == "__main__":
    main()


x = int(input())

i = 0

while i**5 < x:
    i += 1
for k in range(i):
    for j in range(-i, i + 1):
        if k**5 - j**5 == x:
            a, b = k, j
print(a, b)

x = int(input())

i = 0
a, b = 0, 0
while i**5 < x:
    i += 1
mx = i
for k in range(2 * (mx + 1)):
    for j in range(-k, k + 1):
        if k**5 - j**5 == x:
            a, b = k, j
print(a, b)


# 暴力即可
# 範囲指定 A=100 B=-100で20000000000とかになるしどっちも|100|程度でいいのではないか
x = int(input())
for a in range(-100, 101):
    for b in range(-100, 101):
        if a**5 - b**5 == x:
            print(a, b)
            exit()
print(3 / 0)  # はい

# 暴力即可
# 範囲指定 A=100 B=-100で20000000000とかになるしどっちも|100|程度でいいのではないか
# なんか足りんみたい（なんで？）なので4X^2<=10^9なる最大のXを求めよう
# 2X = 1000ちょい だから500くらいあればいいのか
# 1000^2なので時間的には間に合いそう
x = int(input())
for a in range(-500, 501):
    for b in range(-500, 501):
        if a**5 - b**5 == x:
            print(a, b)
            exit()
print(3 / 0)  # はい


x = int(input())
det = 1001001001
for i in range(1000000):
    if abs(i**5 - x) < abs(det):
        det = i**5 - x
        a = i
    else:
        break

if det < 0:
    for i in range(-1, -1000000, -1):
        if i**5 == det:
            b = i
            break
elif det == 0:
    b = 0
else:
    for i in range(1000000):
        if i**5 == det:
            b = i
            break

print(a, b)

x = int(input())

for i in range(1000):
    for j in range(1000):
        if i**5 - j**5 == x:
            print(i, j)
            exit()
        elif i**5 - (-j) ** 5 == x:
            print(i, -j)
            exit()


def get_divisor(n: int) -> list:
    divisor = []
    for i in range(1, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            divisor.append(i)
            if n // i != i:
                divisor.append(n // i)
    # divisor.sort() # if you want sorted divisors
    return divisor

x = int(input())
cand = get_divisor(x)
# print(cand)
for d in cand:
    a = d
    b = 0
    while a**5 - b**5 < x:
        a += 1
        b += 1
    if a**5 - b**5 == x:
        print(a, b)
        break

    is_found = False
    for i in range(1, d):
        a = i
        b = i - d
        if a**5 - b**5 == x:
            print(a, b)
            is_found = True
            break
    if is_found:
        break

    a = 0
    b = -d
    while a**5 - b**5 < x:
        a -= 1
        b -= 1
    if a**5 - b**5 == x:
        print(a, b)
        break

def get_divisor(n: int) -> list:
    divisor = []
    for i in range(1, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            divisor.append(i)
            if n // i != i:
                divisor.append(n // i)
    # divisor.sort() # if you want sorted divisors
    return divisor

x = int(input())
cand = get_divisor(x)
# print(cand)
for d in cand:
    if d**5 == x:
        print(d, 0)
    elif d**5 < x:
        a = d
        b = 0
        while a**5 - b**5 < x:
            a += 1
            b += 1
        if a**5 - b**5 == x:
            print(a, b)
            break

        a = 0
        b = -d
        while a**5 - b**5 < x:
            a -= 1
            b -= 1
        if a**5 - b**5 == x:
            print(a, b)
            break
    else:
        if d % 2 == 0 and (d // 2) ** 5 + (d // 2) ** 5 > x:
            continue
        if d % 2 == 1 and ((d + 1) // 2) ** 5 + (d // 2) ** 5 > x:
            continue
        a = d
        b = 0
        while a**5 - b**5 > x:
            a -= 1
            b -= 1
            # print(a, b, a**5 - b**5)
        if a**5 - b**5 == x:
            print(a, b)
            break

        a = 0
        b = -d
        while a**5 - b**5 > x:
            a += 1
            b += 1
        if a**5 - b**5 == x:
            print(a, b)
            break


X = int(input())

go = [i**5 for i in range(1000)]

def foo():
    for i in range(1000):
        for j in range(i, 1000):
            if go[i] - go[j] == X:
                return i, j
        for j in range(1000):
            if go[i] + go[j] == X:
                return i, -j

A, B = foo()
print(A, B)

X = int(input())

R = 3000
go = [i**5 for i in range(R)]

def foo():
    for i in range(R):
        for j in range(R):
            if go[i] - go[j] == X:
                return i, j
        for j in range(i, R):
            if go[i] + go[j] == X:
                return i, -j

    return 0, 0

A, B = foo()
print(A, B)


def f(X):
    for i in range(1, 120):
        for j in range(-63, 119):
            if i**5 - j**5 == X:
                return i, j

X = int(input())
print(*f(X))


x = int(input())
a = int(x**0.2)
b = 0
while a**5 - b**5 != x:
    b -= 1
print(a, b)

x = int(input())
for a in range(-1000, 1000):
    for b in range(-1000, 1000):
        if a**5 - b**5 == x:
            print(a, b)
            quit()


X = int(input())

numbers = dict()

for i in range(-101, 101):
    numbers.setdefault(i, i**5)

for i in range(-101, 101):
    for j in range(-101, 101):
        if numbers[i] - numbers[j] == X:
            output = [i, j]
            break
print(output[0], output[1])

X = int(input())

numbers = dict()

for i in range(-200, 200):
    numbers.setdefault(i, i**5)

for i in range(-200, 200):
    for j in range(-200, 200):
        if numbers[i] - numbers[j] == X:
            output = [i, j]
            break

print(output[0], output[1])


X = int(input())

for a in range(0, 10**9):
    a *= a
    bb = X + a**5
    B = bb**0.2

    if isinstance(B, float):
        if B.is_integer():
            print(int(B), a)
            break

    a *= -1
    bb = X + a**5
    B = bb**0.2
    if isinstance(B, float):
        if B.is_integer():
            print(int(B), a)
            break

def f(B):
    if isinstance(B, float):
        if abs(B - int(B)) < 10**-6:
            return True
        else:
            return False
    return False

X = int(input())

for a in range(0, 10**5):
    bb = X + a**5
    B = bb**0.2
    if f(B):
        print(int(B), a)
        break

    a *= -1
    bb = X + a**5
    B = bb**0.2
    if f(B):
        print(int(B), a)
        break


n = int(input())
A = list(map(int, input().split()))
A_i = {}
A_j = {}
for i, a in enumerate(A):
    A_i[i] = a + i
    A_j[i] = i - a

r = 0
for i in range(n):
    for j in range(i + 1, n):
        if A_i[i] == A_j[j]:
            r += 1

print(r)

n = int(input())
A = list(map(int, input().split()))
A_j = {}
for i, a in enumerate(A):
    if A_j.get(i - a):
        A_j[i - a] += 1
    else:
        A_j[i - a] = 1

r = 0
for i, a in enumerate(A):
    t = A_j.get(a + i)
    if t:
        r += t

print(r)


N = int(input())
A = list(map(int, input().split()))
diff_i = [A[i] + i + 1 for i in range(N)]
diff_j = [i + 1 - A[i] for i in range(N)]
diff = set(diff_i) & set(diff_j)
ans = 0
for d in diff:
    ans += diff_i.count(d) * diff_j.count(d)
print(ans)

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

cnt1 = {}
cnt2 = {}

for i in range(N):
    tmp1 = A[i] + i + 1
    tmp2 = i + 1 - A[i]
    if tmp1 not in cnt1:
        cnt1[tmp1] = 1
    else:
        cnt1[tmp1] += 1
    if tmp2 not in cnt2:
        cnt2[tmp2] = 1
    else:
        cnt2[tmp2] += 1

diff = set(list(cnt1.keys())) & set(list(cnt2.keys()))

ans = 0
for d in diff:
    ans += cnt1[d] * cnt2[d]
print(ans)


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

# i < j
# j - i = a[i] + a[j]
# a[i] + i = j - a[j]

count = 0
candidate = []
for i in range(n):
    sa = i - a[i]
    count += candidate.count(sa)
    wa = i + a[i]
    candidate.append(wa)

print(count)

from collections import defaultdict

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

d = defaultdict(int)
ans = 0
for i in range(n):
    ans += d[i - a[i]]
    d[a[i] + i] += 1

print(ans)


N = int(input())
tmp_A = list(map(int, input().split()))
A = [0] + tmp_A

tmp_A = sorted(tmp_A)
min_h = sum(tmp_A[0:2])
max_h = sum(tmp_A[-2:])

ans = 0
for n in range(1, N + 1):
    now_h = A[n]
    min_i = max(n + 1, min(min_h, N))
    max_i = min(max_h + n + 1, N + 1)
    for i in range(min_i, max_i):
        if A[n] + A[i] is abs(n - i):
            ans += 1

print(ans)

from collections import defaultdict

N = int(input())
A = [0] + list(map(int, input().split()))
d = defaultdict(int)

ans = 0
for i in range(1, N + 1):
    d[A[i] + i] += 1  # Ai + iを数える
    ans += d[i - A[i]]

print(ans)


n = int(input())
a = [int(x) for x in input().split()]
c = 0
for i in range(n):
    for j in range(i - 1):
        if i - j == a[i] + a[j]:
            c += 1
print(c)

n = int(input())
l = {}
r = {}
xc = 0
for x in input().split():
    xi = int(x)
    lx = xc + xi
    if lx in l:
        l[lx] += 1
    else:
        l[lx] = 1
    rx = xc - xi
    if rx in r:
        r[rx] += 1
    else:
        r[rx] = 1
    xc += 1
c = 0
for x in l:
    if x in r:
        c += l[x] * r[x]
print(c)


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

cnt = 0
for i in range(n - 1):
    for j in range(i + a[i], n):
        if j - i == a[i] + a[j]:
            cnt += 1
print(cnt)

from collections import Counter

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

a_plus_idx = Counter([a[i] + i for i in range(n)])
a_minus_idx = Counter([i - a[i] for i in range(n)])

total = 0
for k, v in a_plus_idx.items():
    total += v * a_minus_idx[k]

print(total)


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

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

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

c1 = {}
c2 = {}

for i in range(N):
    c1.setdefault(i + A[i], 0)
    c1[i + A[i]] += 1
    c2.setdefault(i - A[i], 0)
    c2[i - A[i]] += 1

result = 0
for k in set(c1).intersection(c2):
    result += c1[k] * c2[k]
print(result)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    d = [0] * n
    ans = 0
    for i in range(n):
        ai = a[i]
        l, r = i + ai, i - ai
        if 0 <= l < n:
            d[l] += 1
        if 0 <= r < n:
            ans += d[r]
        print(d)
    print(ans)

if __name__ == "__main__":
    main()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    d = [0] * n
    ans = 0
    for i in range(n):
        ai = a[i]
        l, r = i + ai, i - ai
        if 0 <= l < n:
            d[l] += 1
        if 0 <= r < n:
            ans += d[r]
    print(ans)

if __name__ == "__main__":
    main()


N = int(input())
A = list(map(int, input().split()))
count = 0
l_array = []
r_array = []
for i, X in enumerate(A):
    l_array.append(i + X)
    r_array.append(i - X)

for x in l_array:
    count += r_array.count(x)
print(count)

from collections import Counter

N = int(input())
A = list(map(int, input().split()))
count = 0
l_array = []
r_array = []
for i, X in enumerate(A):
    l_array.append(i + X)
    r_array.append(i - X)

counter = Counter(r_array)

for x in l_array:
    count += counter.get(x, 0)
print(count)


N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    a = A[i]
    for j in range(min(A[i] + i, N), N):
        if a + A[j] == j - i:
            ans += 1

print(ans)

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

d = {}

for i, a in enumerate(A):
    tmp = i + 1 - a
    if tmp in d.keys():
        d[tmp] += 1
    else:
        d[tmp] = 1

# print(d)

for i, a in enumerate(A):
    tmp = a + i + 1
    tmptmp = i + 1 - a
    if tmp in d.keys():
        ans += d[tmp]
    if tmptmp in d.keys():
        d[tmptmp] = max(0, d[tmptmp] - 1)

print(ans)


n = int(input().strip())
a = list(map(int, input().split()))
left = {}
for i in range(len(a)):
    if left.get(a[i] + i):
        left[a[i] + i].append(i)
    else:
        left[a[i] + i] = [i]
ans = 0
for i in range(len(a)):
    if left.get(i - a[i]):
        ans += len(list(filter(lambda x: x < i, left[i - a[i]])))
print(ans)

n = int(input().strip())
a = list(map(int, input().split()))
dic = {}
ans = 0
for i in range(len(a)):
    if dic.get(i - a[i]):
        ans += dic[i - a[i]]
    if dic.get(a[i] + i):
        dic[a[i] + i] += 1
    else:
        dic[a[i] + i] = 1
print(ans)


# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0

for i in range(n):
    a_height = h_list[i]
    n_aa = i + a_height + 1000000000 + 1
    if n_aa > n:
        n_aa = n
    for k in range(i + 1 + a_height, n_aa):
        b_height = h_list[k]
        if k - i == a_height + b_height:
            count += 1

print(count)

# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0
result_dict = {}

for i in range(n):
    key = (i + 1) + h_list[i]
    value = result_dict.get(key, 0)
    result_dict[key] = value + 1

for j in range(n):
    key = (j + 1) - h_list[j]
    count += result_dict.get(key, 0)

print(count)


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

n = int(input())
A = [int(x) for x in input().split()]
backward = [0] * n
forward = [0] * n
for i, a in enumerate(A):
    if i + a < n:
        forward[i + a] += 1
    if i - a >= 0:
        backward[i - a] += 1
ans = 0
for x, y in zip(forward, backward):
    ans += x * y
print(ans)


import sys

def input():
    return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    answer = 0
    for i in range(N):
        for j in range(i + A[i] + 1, N):
            if A[i] + A[j] == j - i:
                answer += 1
    print(answer)

if __name__ == "__main__":
    main()

import sys
from collections import defaultdict

def input():
    return sys.stdin.readline().strip()

def main():
    N = int(input())
    A = list(map(int, input().split()))
    L = defaultdict(list)
    R = defaultdict(list)
    for i in range(N):
        L[A[i] + i].append(i)
        R[i - A[i]].append(i)
    K = list(L.keys())

    answer = 0
    for k in K:
        l = len(L[k])
        r = len(R[k])
        answer += l * r
    print(answer)

if __name__ == "__main__":
    main()


import numpy as np

N = int(input())
A = np.array(input().split(), np.int32)
S = np.array([A[i] - i for i in range(N)])
T = np.array([-A[i] - i for i in range(N)])
# j > i
# S[j] == T[i]
ans = 0
for j in range(N):
    for i in range(j - 1, -1, -1):
        if S[j] == T[i]:
            ans += 1
print(ans)

from _collections import defaultdict
import sys

read = sys.stdin.buffer.read
N = int(input())
A = [int(i) for i in input().split()]
D = defaultdict(int)

for i, a in enumerate(A, 1):
    D[i - a] += 1

ans = 0
for i, a in enumerate(A, 1):
    ans += D[i + a]
print(ans)


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

li = []
for i in range(N):
    li.append(A[i] + i)

li.sort()

cnt = 0
for j in range(N):
    cnt += li.count(j - A[j])

print(cnt)

from bisect import bisect_left, bisect_right

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

li = []
for i in range(N):
    li.append(A[i] + i)

li.sort()

cnt = 0
for j in range(N):
    target = j - A[j]
    cnt += bisect_right(li, target) - bisect_left(li, target)

print(cnt)


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

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if j - i == a[i] + a[j]:
            ans += 1
print(ans)

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

ans = 0
dic1 = {}
dic2 = {}
for i in range(n):
    tmp1 = a[i] + (i + 1)
    tmp2 = -a[i] + (i + 1)
    if tmp1 in dic1:
        dic1[tmp1] += 1
    else:
        dic1[tmp1] = 1
    if tmp2 in dic2:
        dic2[tmp2] += 1
    else:
        dic2[tmp2] = 1
for key in dic1.keys():
    if key in dic2:
        ans += dic1[key] * dic2[key]
print(ans)


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

from collections import defaultdict

n = int(input())
height = list(map(int, input().split()))
add_set = defaultdict(int)
ans = 0
for i in range(n):
    add_set[i + height[i] + 1] += 1
    if i + 1 - height[i] in add_set:
        ans += add_set[i + 1 - height[i]]

print(ans)


from collections import Counter

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

R = [None] * (N + 1)
R[N] = Counter()
L = [None] * (N + 1)
L[0] = Counter()

# n < i
# for i in range(N):
#     c = Counter()
#     c[A[i] + i] = 1
#     L[i + 1] = L[i] | c

# n >= i
c = Counter()
for n in range(N - 1, -1, -1):
    R[n] = R[n + 1] | c
    R[n][(n + 1) - A[n]] += 1

ans = 0
for i, Ai in enumerate(A):
    # n < a
    # c0 = i - a
    # l = L[i][c0]

    # n >= a
    c1 = Ai + (i + 1)
    r = R[i + 1][c1]

    ans += r

print(ans)

from collections import Counter

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

# R = [None] * (N + 1)
# R[N] = Counter()

R = Counter()
cnt = 0
for n in range(N - 1, 0, -1):
    R[(n + 1) - A[n]] += 1
    c = A[n - 1] + ((n - 1) + 1)
    cnt += R[c]

# ans = 0
# for i, Ai in enumerate(A):
#     # n < a
#     # c0 = i - a
#     # l = L[i][c0]

#     # n >= a
#     c1 = Ai + (i + 1)
#     r = R[i + 1][c1]

#     ans += r

print(cnt)


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

i_plus_Ai = [0 for i in range(N)]
dict = {}
for i in range(N):
    i_plus_Ai[i] = i + As[i]
    tmp = i - As[i]
    if tmp not in dict:
        dict[tmp] = [i]
    else:
        dict[tmp].append(i)
    dict[tmp].sort()

count = 0
for i in range(N):
    if i_plus_Ai[i] in dict:
        kouho = dict[i_plus_Ai[i]]
        for j in range(len(kouho)):
            if kouho[j] > i:
                count += len(kouho) - j
                break

print(count)

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

i_plus_Ai = [0 for i in range(N)]
dict = {}
for i in range(N):
    i_plus_Ai[i] = i + As[i]
    tmp = i - As[i]
    if tmp not in dict:
        dict[tmp] = [i]
    else:
        dict[tmp].append(i)

count = 0
for i in range(N):
    if i_plus_Ai[i] in dict:
        kouho = dict[i_plus_Ai[i]]
        for j in range(len(kouho)):
            if kouho[j] > i:
                count += len(kouho) - j
                break

print(count)


from collections import defaultdict

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

memo = defaultdict(int)
ans = 0
for i, x in enumerate(a, 1):
    print(memo)
    ans += memo[i - x]
    memo[x + i] += 1

print(ans)

from collections import defaultdict

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

memo = defaultdict(int)
ans = 0
for i, x in enumerate(a, 1):
    ans += memo[i - x]
    memo[x + i] += 1

print(ans)


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

b = [j - i for i, j in enumerate(a, start=1)]
c = [-j - i for i, j in enumerate(a, start=1)]
result = sum([c.count(i) for i in b])
print(result)

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

b = [j - i for i, j in enumerate(a, start=1)]
# c = [-j - i for i, j in enumerate(a, start=1)]
count = {}
for i, j in enumerate(a, start=1):
    num = -i - j
    if num not in count:
        count[num] = 0
    count[num] += 1
result = sum([count.get(i, 0) for i in b])
print(result)


n, a, b, c = (int(x) for x in input().split())
d = {"A": a, "B": b, "C": c}
S = [input() for _ in range(n)]
ANS = []

for i, s in enumerate(S):
    if d[s[0]] == 0 and d[s[1]] == 0:
        print("No")
        exit()
    else:
        if d[s[0]] > d[s[1]] or (d[s[0]] == d[s[1]] == 1 and i < n and s[1] in S[i + 1]):
            d[s[1]] += 1
            d[s[0]] -= 1
            ANS.append(s[1])
        else:
            d[s[0]] += 1
            d[s[1]] -= 1
            ANS.append(s[0])
print("Yes")
for ans in ANS:
    print(ans)

n, a, b, c = (int(x) for x in input().split())
d = {"A": a, "B": b, "C": c}
S = [input() for _ in range(n)]
ANS = []

for i, s in enumerate(S):
    if d[s[0]] == 0 and d[s[1]] == 0:
        print("No")
        exit()
    else:
        if d[s[0]] > d[s[1]] or (
            d[s[0]] == d[s[1]] == 1 and i < n - 1 and s[1] in S[i + 1]
        ):
            d[s[1]] += 1
            d[s[0]] -= 1
            ANS.append(s[1])
        else:
            d[s[0]] += 1
            d[s[1]] -= 1
            ANS.append(s[0])
print("Yes")
for ans in ANS:
    print(ans)


# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
h_list = input().split()
h_list = [int(h) for h in h_list]

count = 0

for i in range(n):
    a_height = h_list[i]
    if i + 21 < n:
        n_aa = i + 21
    else:
        n_aa = n
    for k in range(i + 1 + a_height, n_aa):
        b_height = h_list[k]
        if k - i == a_height + b_height:
            count += 1

print(count)

# -*- coding: utf-8 -*-
n, a, b, c = map(int, input().split())

value_dict = {"A": a, "B": b, "C": c}
result_list = []
input_list = []
flag = True

for i in range(n):
    input_list.append(input())

for next, input in enumerate(input_list, 1):
    if value_dict[input[0]] < value_dict[input[1]]:
        value_dict[input[0]] += 1
        value_dict[input[1]] -= 1
        result_list.append(input[0])
    elif value_dict[input[1]] < value_dict[input[0]]:
        value_dict[input[1]] += 1
        value_dict[input[0]] -= 1
        result_list.append(input[1])
    else:
        if value_dict[input[0]] == 0:
            flag = False
            break
        elif next == len(input_list):
            result_list.append(input[0])
        elif input[0] in input_list[next]:
            value_dict[input[0]] += 1
            value_dict[input[1]] -= 1
            result_list.append(input[0])
        else:
            value_dict[input[1]] += 1
            value_dict[input[0]] -= 1
            result_list.append(input[1])

if flag:
    print("Yes")
    for result in result_list:
        print(result)

else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02692/Python/s154887579.py", line 3, in <module>
    n = int(input())
ValueError: invalid literal for int() with base 10: '2 1 3 0'


def main():
    N, A, B, C = map(int, input().split())
    S = [input() for _ in range(N)]
    res = []
    if A + B + C == 2:
        for i in range(N):
            s = S[i]
            if s == "AB":
                if A == 0 and B == 0:
                    print("No")
                    return 1
                if A > B:
                    A -= 1
                    B += 1
                    res.append("B")
                elif A < B:
                    A += 1
                    B -= 1
                    res.append("A")
                else:
                    if S == N - 1:
                        res.append("A")
                        break
                    elif S[i + 1] == "BC":
                        A -= 1
                        B += 1
                        res.append("B")
                    else:
                        A += 1
                        B -= 1
                        res.append("A")
            if s == "AC":
                if A == 0 and C == 0:
                    print("No")
                    return 1
                if A > C:
                    A -= 1
                    C += 1
                    res.append("C")
                elif A < C:
                    A += 1
                    C -= 1
                    res.append("A")
                else:
                    if S == N - 1:
                        res.append("A")
                        break
                    elif S[i + 1] == "BC":
                        A -= 1
                        C += 1
                        res.append("C")
                    else:
                        A += 1
                        C -= 1
                        res.append("A")
            if s == "BC":
                if B == 0 and C == 0:
                    print("No")
                    return 1
                if B > C:
                    B -= 1
                    C += 1
                    res.append("C")
                elif B < C:
                    B += 1
                    C -= 1
                    res.append("B")
                else:
                    if S == N - 1:
                        res.append("B")
                        break
                    elif S[i + 1] == "AC":
                        B -= 1
                        C += 1
                        res.append("C")
                    else:
                        B += 1
                        C -= 1
                        res.append("B")
        print("Yes")
        print("\\n".join(map(str, res)))
        return 0
    if A == 0 and B == 0:
        if S[0] == "AB":
            print("No")
            return 1
    if A == 0 and C == 0:
        if S[0] == "AC":
            print("No")
            return 1
    if C == 0 and B == 0:
        if S[0] == "BC":
            print("No")
            return 1

    for s in S:
        if s == "AB":
            if A == 0 and B == 0:
                print("No")
                return 1
            if A >= B:
                A -= 1
                B += 1
                res.append("B")
            else:
                A += 1
                B -= 1
                res.append("A")
        elif s == "AC":
            if A == 0 and C == 0:
                print("No")
                return 1
            if A >= C:
                A -= 1
                C += 1
                res.append("C")
            else:
                A += 1
                C -= 1
                res.append("A")

        elif s == "BC":
            if B == 0 and C == 0:
                print("No")
                return 1
            if B >= C:
                B -= 1
                C += 1
                res.append("C")
            else:
                B += 1
                C -= 1
                res.append("B")
        else:
            print("ERROR")
    print("Yes")
    print("\\n".join(map(str, res)))
    return 0

main()

def main():
    N, A, B, C = map(int, input().split())
    S = [input() for _ in range(N)]
    res = []
    if A + B + C == 2:
        for i in range(N):
            s = S[i]
            if s == "AB":
                if A == 0 and B == 0:
                    print("No")
                    return 1
                if A > B:
                    A -= 1
                    B += 1
                    res.append("B")
                elif A < B:
                    A += 1
                    B -= 1
                    res.append("A")
                else:
                    if i == N - 1:
                        res.append("A")
                        break
                    elif S[i + 1] == "BC":
                        A -= 1
                        B += 1
                        res.append("B")
                    else:
                        A += 1
                        B -= 1
                        res.append("A")
            if s == "AC":
                if A == 0 and C == 0:
                    print("No")
                    return 1
                if A > C:
                    A -= 1
                    C += 1
                    res.append("C")
                elif A < C:
                    A += 1
                    C -= 1
                    res.append("A")
                else:
                    if i == N - 1:
                        res.append("A")
                        break
                    elif S[i + 1] == "BC":
                        A -= 1
                        C += 1
                        res.append("C")
                    else:
                        A += 1
                        C -= 1
                        res.append("A")
            if s == "BC":
                if B == 0 and C == 0:
                    print("No")
                    return 1
                if B > C:
                    B -= 1
                    C += 1
                    res.append("C")
                elif B < C:
                    B += 1
                    C -= 1
                    res.append("B")
                else:
                    if i == N - 1:
                        res.append("B")
                        break
                    elif S[i + 1] == "AC":
                        B -= 1
                        C += 1
                        res.append("C")
                    else:
                        B += 1
                        C -= 1
                        res.append("B")
        print("Yes")
        print("\\n".join(map(str, res)))
        return 0
    if A == 0 and B == 0:
        if S[0] == "AB":
            print("No")
            return 1
    if A == 0 and C == 0:
        if S[0] == "AC":
            print("No")
            return 1
    if C == 0 and B == 0:
        if S[0] == "BC":
            print("No")
            return 1

    for s in S:
        if s == "AB":
            if A == 0 and B == 0:
                print("No")
                return 1
            if A >= B:
                A -= 1
                B += 1
                res.append("B")
            else:
                A += 1
                B -= 1
                res.append("A")
        elif s == "AC":
            if A == 0 and C == 0:
                print("No")
                return 1
            if A >= C:
                A -= 1
                C += 1
                res.append("C")
            else:
                A += 1
                C -= 1
                res.append("A")

        elif s == "BC":
            if B == 0 and C == 0:
                print("No")
                return 1
            if B >= C:
                B -= 1
                C += 1
                res.append("C")
            else:
                B += 1
                C -= 1
                res.append("B")
        else:
            print("ERROR")
    print("Yes")
    print("\\n".join(map(str, res)))
    return 0

main()


N, A, B, C = map(int, input().split())
opts = []
for _ in range(N):
    opt = input()
    opts.append((ord(opt[0]) - ord("A"), ord(opt[1]) - ord("A")))

choices = []
nums = [A, B, C]
for i, opt in enumerate(opts):
    if nums[opt[0]] == 0 and nums[opt[1]] == 0:
        print("No")
        break
    if nums[opt[0]] == 1 and nums[opt[1]] == 1:
        if i < N - 1 and opt != opts[i + 1]:
            choice = next(set(opt) ^ set(opts[i + 1]))
            nums[opt] += 1
            nums[opt ^ opt[0] ^ opt[1]] -= 1
            choices.append(choice)
            continue
    if nums[opt[0]] >= nums[opt[1]]:
        choices.append(opt[1])
        nums[opt[1]] += 1
        nums[opt[0]] -= 1
    else:
        choices.append(opt[0])
        nums[opt[0]] += 1
        nums[opt[1]] -= 1
else:
    print("Yes")
    for c in choices:
        print(chr(c + ord("A")))

N, A, B, C = map(int, input().split())
opts = []
for _ in range(N):
    opt = input()
    opts.append((ord(opt[0]) - ord("A"), ord(opt[1]) - ord("A")))

choices = []
nums = [A, B, C]
for i, opt in enumerate(opts):
    if nums[opt[0]] == 0 and nums[opt[1]] == 0:
        print("No")
        break
    if nums[opt[0]] == 1 and nums[opt[1]] == 1:
        if i < N - 1 and opt != opts[i + 1]:
            choice = (set(opt) & set(opts[i + 1])).pop()
            nums[choice] += 1
            nums[choice ^ opt[0] ^ opt[1]] -= 1
            choices.append(choice)
            continue
    if nums[opt[0]] >= nums[opt[1]]:
        choices.append(opt[1])
        nums[opt[1]] += 1
        nums[opt[0]] -= 1
    else:
        choices.append(opt[0])
        nums[opt[0]] += 1
        nums[opt[1]] -= 1
else:
    print("Yes")
    for c in choices:
        print(chr(c + ord("A")))


K = int(input())
A, B = map(int, input().slice())
print("OK" if B - A >= K else "NG")

K = int(input())
A, B = map(int, input().split())
large = (B // K) * K
if A <= large:
    print("OK")
else:
    print("NG")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02693/Python/s877795440.py", line 2, in <module>
    A, B = map(int, input().slice())
AttributeError: 'str' object has no attribute 'slice'


K = int(input())
A = int(input().split()[0])
B = int(input().split()[1])

for i in range(A, B + 1):
    if i % K == 0:
        print("OK")
        break
        exit()
print("NG")

K = int(input())
S = input().split()
A = int(S[0])
B = int(S[1])

for i in range(A, B + 1):
    if i % K == 0:
        print("OK")
        exit()
print("NG")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02693/Python/s140867426.py", line 3, in <module>
    B = int(input().split()[1])
EOFError: EOF when reading a line


K = int(input())

A, B = map(int, input())

if A // K <= B // K and B % K == 0:
    print("OK")
else:
    print("NG")

K = int(input())

A, B = map(int, input().split())

if A // K == B // K:
    if A % K == 0 or B % K == 0:
        print("OK")
    else:
        print("NG")
elif A // K < B // K:
    print("OK")
else:
    print("NG")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02693/Python/s485760562.py", line 3, in <module>
    A, B = map(int, input())
ValueError: too many values to unpack (expected 2)


k = int(input())
a, b = map(int, input().split())
i = 1
flag = False

while i < b:
    dis = i * k
    if dis >= a and dis <= b:
        flag = True
        break

if flag:
    print("OK")
else:
    print("NG")

k = int(input())
a, b = map(int, input().split())
i = 1
flag = False

while i < b:
    if k == 1:
        flag = True
        break
    dis = i * k
    if dis >= a and dis <= b:
        flag = True
        break

    i += 1

if flag:
    print("OK")
else:
    print("NG")


K = int(input())
arr = list(map(int, input()))
a = arr[1] % K
b = arr[1] - arr[0]
if a > b:
    print("OK")
else:
    print("NG")

K = int(input())
arr = list(map(int, input().split()))
a = arr[1] % K
b = arr[1] - arr[0]
if a <= b:
    print("OK")
else:
    print("NG")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02693/Python/s995721766.py", line 2, in <module>
    arr = list(map(int, input()))
ValueError: invalid literal for int() with base 10: ' '


mon = 100
nen = 0
moku = int(input())

while mon < moku:
    mon = mon // 100
    nen += 1

print(nen)

x = int(input())
nen = 0
a = 100
while a < x:
    a = int(a * 1.01)
    nen += 1
print(nen)


from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
L = []
for _ in range(Q):
    L.append(tuple(map(int, input().split())))

ans = 0
for A in combinations_with_replacement(range(1, M + 1), min(N, M)):
    tmp = 0
    for a, b, c, d in L:
        if A[b - 1] - A[a - 1] == c:
            tmp += d

    if tmp > ans:
        ans = tmp

print(ans)

from itertools import combinations_with_replacement

N, M, Q = map(int, input().split())
L = []
for _ in range(Q):
    L.append(tuple(map(int, input().split())))

ans = 0
_N = N
if N < M:
    _N = M

for A in combinations_with_replacement(range(1, M + 1), _N):
    tmp = 0
    for a, b, c, d in L:
        if a <= _N and b <= _N and A[b - 1] - A[a - 1] == c:
            tmp += d

    if tmp > ans:
        ans = tmp

print(ans)


import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, M, Q, *abcd = map(int, read().split())
cand = [[0, 1]]

for _ in range(M):
    new_cand = []
    for j in cand:
        for k in range(j[-1], M + 1):
            new_cand.append(j[:] + [k])
    cand = new_cand[:]

answer = 0
abcd = tuple(zip(*[iter(abcd)] * 4))
for seq in cand:
    t = 0
    for a, b, c, d in abcd:
        if seq[b] - seq[a] == c:
            t += d

    answer = max(answer, t)

print(answer)

import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, M, Q, *abcd = map(int, read().split())
cand = [[0, 1]]

for _ in range(N - 1):
    new_cand = []
    for j in cand:
        for k in range(j[-1], M + 1):
            new_cand.append(j[:] + [k])
    cand = new_cand[:]

answer = 0
abcd = tuple(zip(*[iter(abcd)] * 4))
for seq in cand:
    t = 0
    for a, b, c, d in abcd:
        if seq[b] - seq[a] == c:
            t += d
    answer = max(answer, t)

print(answer)


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

ans = 0
if b > n:
    x = n
    ans = int(a * x // b) - int(a * (x // b))
else:
    m = 0
    for i in range(b):
        if int(a * (n - i) // b) - int(a * ((n - i) // b)) > m:
            m = int(a * (n - i) // b) - int(a * ((n - i) // b))
    ans = m
print(ans)

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

ans = 0
if b > n:
    x = n
    ans = int(a * x // b) - int(a * (x // b))
else:
    x = n
    ans1 = int(a * x // b) - int(a * (x // b))
    x = (n // b) * b - 1
    ans2 = int(a * x // b) - int(a * (x // b))
    ans = max(ans1, ans2)
print(ans)


from math import floor

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

x = None
if N < B:
    x = N

answer = floor(A * x / B) - A * floor(x / B)

print(answer)

from math import floor

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

x = None
if N < B:
    x = N
else:
    x = B
    x = B - 1
    # max_diff = 0
    # for _x in range(B, N + 1):
    #     diff = (x / B) - floor(x / B)
    #     if max_diff <= diff:
    #         max_diff = diff
    #         x = _x

answer = floor(A * x / B) - A * floor(x / B)

print(answer)


# coding:utf-8
def main():
    import math

    a, b, n = map(int, input().split())
    ans = 0

    for x in range(n, 0, -1):
        tmp = math.floor((a * x) / b) - a * (math.floor(x / b))
        ans = max(tmp, ans)

    print(ans)

if __name__ == "__main__":
    main()

# coding:utf-8

import math

a, b, n = map(int, input().split())
x = min(b - 1, n)

ans = math.floor((a * x) / b) - a * (math.floor(x / b))

print(ans)


A, B, N = map(int, input().split())
c = 0
t = -10
if N > 100000000:
    for i in range(100000000, N + 1):
        a = (i * A) // B - A * (i // B)
        c = max(c, a)
        if t > a or i > 1100000000:
            print(c)
            break
        t = a
    else:
        print(c)
else:
    for i in range(N + 1):
        a = (i * A) // B - A * (i // B)
        c = max(c, a)
        if t > a or i > 100000000:
            print(c)
            break
        t = a
    else:
        print(c)

A, B, N = map(int, input().split())
X = min(N, B - 1)
print(A * X // B - A * (X // B))


a, b, n = map(int, input().split())
ans = 0
# floor(a * x / b)
# = floor(a * floor(x / b) + a * (x / b - floor(x / b)))
# = a * floor(x / b) + floor(a * (x / b - floor(x / b))))
for i in range(min(b, n + 1)):
    ans = max(ans, int(a * i / b))
print(ans)

a, b, n = map(int, input().split())
ans = 0
# floor(a * x / b)
# = floor(a * floor(x / b) + a * (x / b - floor(x / b)))
# = a * floor(x / b) + floor(a * (x / b - floor(x / b))))
print(int(a * min(b - 1, n) / b))


from sys import stdin, setrecursionlimit

def main():
    input = stdin.buffer.readline
    a, b, n = map(int, input().split())

    ans = 0

    for x in range(min(b, n + 1)):
        ans = max(int(a * x / b) - a * int(x / b), ans)

    print(ans)

if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

from sys import stdin, setrecursionlimit

def main():
    input = stdin.buffer.readline
    a, b, n = map(int, input().split())

    ans = 0

    x = min(b - 1, n)
    ans = max(int(a * x / b) - a * int(x / b), ans)

    print(ans)

if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

Max = 0
for x in range(1, n + 1):
    Max = max(Max, (a * x) // b - a * (x // b))
print(Max)

def f(a, b, n):
    if b == 1:
        print(0)
    else:
        Max = 0
        step = 1 if b // a == 0 else b // a
        for x in range(b // a, n + step, step):
            res = (a * x) // b - a * (x // b)
            if res > Max:
                Max = res
        print(Max)

a, b, n = map(int, input().split())
f(a, b, n)


def m():
    a, b, n = map(int, input().split())

    def calc(x):
        return int((a * x) / b) - (a * int(x / b))

    if calc(1) < calc(n // 2):
        return max([calc(i) for i in range(n // 2, n + 1)])
    else:
        return max([calc(i) for i in range(1, n // 2 + 1)])

print(m())

def m():
    a, b, n = map(int, input().split())

    def calc(x):
        return int((a * x) / b) - (a * int(x / b))

    return calc(min(n, b - 1))

print(m())


A, B, N = map(int, input().split())
maxFloor = 0

def floor(x):
    num = int(x // 1)
    return num

for x in range(N + 1):
    check = floor(A * x / B) - A * floor(x / B)
    maxFloor = max(maxFloor, check)
print(maxFloor)

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

maxFloor = 0

def floor(x):
    num = int(x // 1)
    return num

if B - 1 <= N:
    check = floor(A * (B - 1) / B) - A * floor((B - 1) / B)
    print(check)
else:
    check = floor(A * N / B) - A * floor(N / B)
    print(check)


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

ans = 0

for i in range(1, N + 1):
    tmp = (A * i) // B - A * (i // B)
    ans = max(ans, tmp)

print(ans)

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

x = min(B - 1, N)
ans = (A * x) // B - A * (x // B)
print(ans)


a, b, n = map(int, input().split())
ans = 0

for i in range(1, n + 1):
    num = (a * i) // b - a * (i // b)
    if ans < num:
        ans = num

print(ans)

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

if b > n:
    x = n
else:
    x = b - 1

print((a * x) // b)


import math

def f(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x / B)

def main(A, B, N):
    last = 0
    x = 0
    while x <= N:
        tmp = f(A, B, x)
        if tmp < last:
            print(last)
            return
        else:
            last = tmp
            x += 1
    else:
        print(last)
        return

A, B, N = map(int, input().split())
main(A, B, N)

import math

def f(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x / B)

def main(A, B, N):
    if N < B:
        return f(A, B, N)
    else:
        return f(A, B, B - 1)

A, B, N = map(int, input().split())
print(main(A, B, N))


def f(x):
    return (a * x) // b - a * (x // b)

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

k = (n + 1) // b

ans = 0
for x in range(max(0, k * b - 1), n + 1):
    ans = max(ans, f(x))

print(ans)

def f(x):
    return (a * x) // b - a * (x // b)

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

k = (n + 1) // b

x = max(k * b - 1, 0)
ans = f(x)
ans = max(ans, f(n))
print(ans)


n, m = map(int, input().split())
if n % 2 == 1:
    for i in range(1, m + 1):
        print(i, n + 1 - i)
else:
    used = [False] * (n + 1)
    i = 1
    count = 0
    while count < m:
        while used[i]:
            i += 1
        print(i, i + count + 1)
        used[i] = True
        used[i + count + 1] = True
        count += 1

n, m = map(int, input().split())
if n % 2 == 1:
    for i in range(1, m + 1):
        print(i, n + 1 - i)
else:
    turning_point = (m + 1) // 2
    for i in range(1, turning_point + 1):
        print(i, n + 1 - i)
    for i in range(turning_point + 1, m + 1):
        print(i, n - i)


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

sieve = [0] * (100000 + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, 100000 + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, 100000 + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

p = []
for i in range(N - 1, -1, -1):
    if sieve[i] == i:
        p.append(i)
p.append(1)

t = set()
pp = 0
for i in range(M):
    x = i + 1
    y = x + p[pp]
    while y in t:
        pp += 1
        y = x + p[pp]
    t.add(x)
    t.add(y)
    print(x, y)
    pp += 1


import bisect

N = int(input())
a = list(map(int, input().split()))
to = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    to[u].append(v)
    to[v].append(u)
del u, v

ans = [-1] * N

def dfs(v, prev_dp):
    dp = [*prev_dp]
    if len(dp) == 0 or a[v] > dp[-1]:
        dp.append(a[v])
    else:
        pos = bisect.bisect_left(dp, a[v])
        dp[pos] = a[v]
    ans[v] = len(dp)

    for u in to[v]:
        if ans[u] == -1:
            dfs(u, dp)

dfs(0, [])

for an in ans:
    print(an)

import bisect
import sys

N = int(input())
a = list(map(int, input().split()))
to = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    to[u].append(v)
    to[v].append(u)
del u, v

ans = [-1] * N

def dfs(v, dp):
    # dp は参照渡し
    if len(dp) == 0 or a[v] > dp[-1]:
        dp.append(a[v])
        back = -1
    else:
        pos = bisect.bisect_left(dp, a[v])
        back = dp[pos]
        dp[pos] = a[v]
    ans[v] = len(dp)

    for u in to[v]:
        if ans[u] == -1:
            dfs(u, dp)
    if back == -1:
        dp.pop()
    else:
        dp[pos] = back

sys.setrecursionlimit(10**6)
dfs(0, [])

for an in ans:
    print(an)


s, w = map(int, input().split(""))
res = "safe"
if w >= s:
    res = "unsafe"
print(res)

s, w = map(int, input().split(" "))
res = "safe"
if w >= s:
    res = "unsafe"
print(res)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02699/Python/s552737943.py", line 1, in <module>
    s, w = map(int, input().split(""))
ValueError: empty separator


A, B, C, D = list(map(int, input().split()))
while A and C:
    A -= D
    C -= B
    if C <= 0:
        print("Yes")
    elif A <= 0:
        print("No")

A, B, C, D = list(map(int, input().split()))
t1 = (A + D - 1) // D
t2 = (C + B - 1) // B
print("Yes" if t2 <= t1 else "No")


a, b, c, d = map(int, input().split())
while True:
    c -= b
    if c == 0:
        print("Yes")
        break
    a -= d
    if a == 0:
        print("No")
        break

a, b, c, d = map(int, input().split())
while True:
    c -= b
    if c <= 0:
        print("Yes")
        break
    a -= d
    if a <= 0:
        print("No")
        break


N = int(input())
L = []
for _ in range(N):
    s = input()
    if s in L:
        pass
    else:
        L.append(s)

print(len(L))

N = int(input())
L = set()
for _ in range(N):
    s = input()
    if s in L:
        pass
    else:
        L.add(s)

print(len(L))


n = int(input())

unique_list = list()
for _ in range(n):
    s = input()
    if s not in unique_list:
        unique_list.append(s)

print(len(unique_list))

n = int(input())

gacha_set = set()
for _ in range(n):
    s = input()
    gacha_set.add(s)

print(len(gacha_set))


import pandas as pd

N = int(input())
S = [input() for i in range(N)]

data = pd.Series(S)

print(data.nunique())

import numpy as np

N = int(input())
S = [input() for i in range(N)]

print(len(np.unique(S)))


n = int(input())
s = []
p = []
ans = 0
for i in range(n):
    s.append(input())
    if s[i] in p:
        pass
    else:
        p.append(s[i])
        ans += 1
print(ans)

n = int(input())
s = []
p = set()
ans = 0
for i in range(n):
    s.append(input())
    if s[i] in p:
        pass
    else:
        p.add(s[i])
        ans += 1
print(ans)


N = int(input())
D = []
ans = 0

for _ in range(N):
    S = input()
    if S not in D:
        D.append(S)
        ans += 1

print(ans)

N = int(input())
D = {}
ans = 0

for _ in range(N):
    S = input()
    if S not in D:
        D[S] = True
        ans += 1

print(ans)


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

print(len(set(s)))

a = int(input())
s = [input() for i in range(a)]

print(len(set(s)))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02701/Python/s227226698.py", line 2, in <module>
    s = list(map(int, input().split()))
ValueError: invalid literal for int() with base 10: 'apple'


n = int(input())
s = [int(input()) for _ in range(n)]
ans = set()

for i in s:
    ans.add(i)

print(len(ans))

n = int(input())
s = [input() for _ in range(n)]
ans = set()

for i in s:
    ans.add(i)

print(len(ans))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02701/Python/s962277082.py", line 2, in <module>
    s = [int(input()) for _ in range(n)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02701/Python/s962277082.py", line 2, in <listcomp>
    s = [int(input()) for _ in range(n)]
ValueError: invalid literal for int() with base 10: 'apple'


N = int(input())
S_list = [input() for i in range(N)]
count = 0
while len(S_list) > 0:
    S_list = [s for s in S_list if s != S_list[0]]
    count += 1
print(count)

import collections

N = int(input())
S_list = [input() for i in range(N)]
c = collections.Counter(S_list)
print(len(c))


n = int(input())

ans = 0
u_l = []
for _ in range(n):
    s = input()
    if s not in u_l:
        u_l.append(s)
        ans += 1
print(ans)

n = int(input())

l = [input() for _ in range(n)]
print(len(set(l)))


n = int(input())
s = (input() for _ in range(n))
print(len(s))

n = int(input())
s = {input() for _ in range(n)}
print(len(s))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02701/Python/s709317664.py", line 3, in <module>
    print(len(s))
TypeError: object of type 'generator' has no len()


N = input()
List = list(input() for i in range(N))
print(len(set(List)))

N = int(input())
List = list(input() for i in range(N))
print(len(set(List)))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02701/Python/s903293880.py", line 2, in <module>
    List = list(input() for i in range(N))
TypeError: 'str' object cannot be interpreted as an integer


N = int(input())
S = []
for _ in range(N):
    i = input()
    if i not in S:
        S.append(i)

print(len(S))

N = int(input())
S = []
for _ in range(N):
    S.append(input())

print(len(set(S)))


n = int(input)
lis = [input() for i in range(n)]
print(len(set(lis)))

n = int(input())
lis = [input() for i in range(n)]
print(len(set(lis)))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02701/Python/s310001383.py", line 1, in <module>
    n = int(input)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'


n = int(input())
s = [""] * n
t = []
for i in range(n):
    s[i] = input()
for i in range(n):
    if s[i] not in t:
        t.append(s[i])
print(len(t))

n = int(input())
s = [""] * n
for i in range(n):
    s[i] = input()
s = set(s)
print(len(s))


import collections

n = int(input())
a = [list(input() for i in range(n))]
b = collections.Counter(a)
print(len(b))

import collections

n = int(input())
a = [input() for i in range(n)]
b = collections.Counter(a)
print(len(b))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02701/Python/s293744193.py", line 5, in <module>
    b = collections.Counter(a)
  File "/usr/lib/python3.10/collections/__init__.py", line 577, in __init__
    self.update(iterable, **kwds)
  File "/usr/lib/python3.10/collections/__init__.py", line 670, in update
    _count_elements(self, iterable)
TypeError: unhashable type: 'list'


import sys

def main():
    readline = sys.stdin.readline
    N = int(readline())
    li = []
    for _ in range(N):
        S = readline()
        if S not in li:
            li.append(S)
    print(len(li))

if __name__ == "__main__":
    main()

import sys

def main():
    readline = sys.stdin.readline
    N = int(readline())
    se = set([readline() for _ in range(N)])
    print(len(se))

if __name__ == "__main__":
    main()


def solve(s):
    dp = [0] * 2019
    dp[0] = 1
    r = 0
    for i in range(1, len(s) + 1):
        r += int(s[-i]) * (10 ** (i - 1))
        r %= 2019
        dp[r] += 1
    res = 0
    for r in range(2019):
        res += dp[r] * (dp[r] - 1) // 2
    return res

def main():
    s = input()
    res = solve(s)
    print(res)

def test():
    assert solve("1817181712114") == 3
    assert solve("14282668646") == 2
    assert solve("2119") == 0

if __name__ == "__main__":
    test()
    main()

def solve(s):
    dp = [0] * 2019
    dp[0] = 1
    r = 0
    for i in range(1, len(s) + 1):
        r += int(s[-i]) * pow(10, i - 1, 2019)
        r %= 2019
        dp[r] += 1
    res = 0
    for r in range(2019):
        res += dp[r] * (dp[r] - 1) // 2
    return res

def main():
    s = input()
    res = solve(s)
    print(res)

def test():
    assert solve("1817181712114") == 3
    assert solve("14282668646") == 2
    assert solve("2119") == 0

if __name__ == "__main__":
    test()
    main()


S = input()
digits = list(map(int, S))
divisor = 2019

rem_count = [0] * divisor
rem_count[0] = 1
num = 0
pow10 = 1
total = 0

for digit in reversed(digits):
    num = digit * pow10 + num
    total += rem_count[num % divisor]
    pow10 *= 10
    rem_count[num % divisor] += 1

print(total)

S = input()
digits = list(map(int, S))
divisor = 2019

rem_count = [0] * divisor
rem_count[0] = 1
num = 0
pow10 = 1
total = 0

for digit in reversed(digits):
    num = digit * pow10 + num
    num %= divisor
    total += rem_count[num % divisor]
    pow10 *= 10
    pow10 %= divisor
    rem_count[num % divisor] += 1

print(total)


s = str(input())

num = [int(s[-1])]
for i in range(1, len(s)):
    num.append(num[-1] + pow(10, i) * int(s[-i - 1]))

mod = [1] + [0] * 2018
ans = 0
for i in num:
    m = i % 2019
    ans += mod[m]
    mod[m] += 1
print(ans)

s = str(input())

num = [int(s[-1])]
for i in range(1, len(s)):
    tmp = num[-1] + pow(10, i, 2019) * int(s[-i - 1])
    num.append(tmp % 2019)

mod = [1] + [0] * 2018
ans = 0
for i in num:
    m = i % 2019
    ans += mod[m]
    mod[m] += 1
print(ans)


# D - Multiple of 2019

s = input()

# pow[k] = 10 ** k % 2019
pow = [1]
while len(pow) <= 1 or pow[-1] > 1:
    pow.append(pow[-1] * 10 % 2019)
n = len(pow) - 1  # 10 ** n == 1 mod 2019

# memo[i % n][m] = (int(s[:i+1]) % 2019 == mであるiの個数)
memo = [{} for i in range(n)]
memo[n - 1][0] = 1  # memo[-1][0] = 1

count = 0  # int(s[i:j+1]) == 0 mod 2019 である(i,j)の個数
mod = 0
for j, c in enumerate(s):
    mod = (mod * 10 + int(c)) % 2019  # mod = int(s[:j+1]) % 2019
    for i in range(1, n + 1):
        m = mod * pow[n - i] % 2019  # m == mod * 10 ** (-i) mod 2019
        if m in memo[(j - i + n) % n]:
            count += memo[(j - i + n) % n][m]
    if mod not in memo[j % n]:
        memo[j % n][mod] = 0
    memo[j % n][mod] += 1

print(count)


def main():
    A = input()[::-1]
    A = "0" + A
    # lis_num = [int(s) for s in A]

    # print(lis_num)

    # S = [0] * len(lis_num)
    S = [0] * len(A)
    cnt = [0] * 2019
    cnt[0] = 1

    for i in range(len(A) - 1):
        S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i)) % 2019
        cnt[S[i + 1] % 2019] += 1

    # print(S)

    # for i in S:
    #     cnt[i % 2019] += 1

    ans = 0

    for i in cnt:
        ans += i * (i - 1) // 2

    print(ans)

if __name__ == "__main__":
    main()


from collections import defaultdict

S = input()

d = defaultdict(int)

d[0] += 1

mod = 0
for i in range(len(S))[::-1]:
    mod = (mod + int(S[i]) * 10 ** (len(S) - i - 1)) % 2019
    # mod = int(S[i:]) % 2019
    d[mod] += 1

ans = 0
for i in d.values():
    if i > 1:
        ans += i * (i - 1) / 2

print(int(ans))

from collections import defaultdict

S = input()

d = defaultdict(int)

d[0] += 1

mod = 0
R = 1
for i in range(len(S)):
    mod = (mod + R * int(S[len(S) - i - 1])) % 2019
    R = R * 10 % 2019
    d[mod] += 1
ans = 0
for i in d.values():
    if i > 1:
        ans += i * (i - 1) / 2

print(int(ans))


import numpy as np

mod = 2019
mods_count = np.zeros(2019, dtype=np.int64)
indexes = list(range(2019))
indexes_10 = [index * 10 % mod for index in indexes]

mod = 2019
ans = 0
S = input()
for s in S:
    num = int(s)
    new = np.roll(mods_count, num)
    new[num] += 1

    ans += new[0]
    mods_count = np.zeros(2019, dtype=np.int64)
    mods_count[indexes_10] += new[indexes]

print(ans)

from collections import Counter

mod = 2019
S = map(int, reversed(input()))

mods = [0]
num = 0
digit = 1
for s in S:
    num += s * digit
    num %= mod
    mods.append(num)
    digit = digit * 10 % mod

counter = Counter(mods)
ans = 0
for count in counter.values():
    ans += count * (count - 1) // 2
print(ans)


S = input()
N = len(S)

cnt = 0
for i in range(N - 3):
    for j in range(i + 4, N + 1):
        if int(S[i:j]) % 2019 == 0:
            # print(i, j)
            cnt += 1
print(cnt)


s = list(input())
sur_list = [0 for i in range(2019)]
sur = 0
ans = 0

s.reverse()

for i in range(len(s)):
    sur_list[sur] += 1
    sur = (int(s[i]) * (10**i) + sur) % 2019
    ans += sur_list[sur]

print(ans)

s = list(input())
sur_list = [0 for i in range(2019)]
sur = 0
keta = 1
ans = 0

s.reverse()

for i in range(len(s)):
    keta = (keta * 10) % 2019
    sur_list[sur] += 1
    sur = (int(s[i]) * keta + sur) % 2019
    ans += sur_list[sur]

print(ans)


s = list(input())
s.reverse()
n = len(s)
now = 0
mods = [0] * 2019
mods[0] += 1
for i in range(n):
    now += pow(10, i) * int(s[i])
    now %= 2019
    mods[now] += 1
ans = 0
for i in mods:
    ans += (i * (i - 1)) // 2
print(ans)

if __name__ == "__main__":

    s = list(input())
    s.reverse()
    n = len(s)
    now = 0
    mods = [0] * 2019
    mods[0] += 1
    ten = 1
    for i in range(n):
        now += ten * int(s[i])
        now %= 2019
        ten *= 10
        ten %= 2019
        mods[now] += 1
    ans = 0
    for i in mods:
        ans += (i * (i - 1)) // 2
    print(ans)


from collections import defaultdict

S = input()
ans = 0
N = len(S)
mod = 2019
dp = defaultdict(int)
cur = 0
for i in range(N, -1, -1):
    if i == N:
        dp[0] += 1
    else:
        cur += ((10 ** (N - i - 1)) * int(S[i])) % mod
        cur %= mod
        dp[cur] += 1
for v in dp.values():
    if v > 1:
        ans += v * (v - 1) // 2
print(ans)

from collections import defaultdict

def solve(input_s: str):
    ans = 0
    n = len(input_s)
    mod = 2019
    dp = defaultdict(int)
    cur = 0
    for i in range(n, -1, -1):
        if i == n:
            dp[0] += 1
        else:
            # cur += ((10 ** (n - i - 1)) * int(input_s[i])) % mod これはnがでかくなるとめちゃめちゃ遅い
            cur += pow(10, n - i - 1, 2019) * int(input_s[i]) % mod
            cur %= mod
            dp[cur] += 1
    for v in dp.values():
        if v > 1:
            ans += v * (v - 1) // 2
    return ans

if __name__ == "__main__":
    S = input()
    print(solve(S))


S = input()

ans = 0
lists = [0 for i in range(2019)]
lists[0] += 1

tmp = 1
num = 0
for i in range(len(S) - 1, -1, -1):
    num += tmp * int(S[i])
    lists[num % 2019] += 1
    tmp *= 10

for i in range(2019):
    if lists[i] >= 2:
        ans += (lists[i] * (lists[i] - 1)) // 2

print(ans)

S = input()

ans = 0
lists = [0 for i in range(2019)]
lists[0] += 1

num = 0
for i in range(len(S) - 1, -1, -1):
    num += pow(10, len(S) - 1 - i, 2019) * int(S[i])
    lists[num % 2019] += 1

for i in range(2019):
    if lists[i] >= 2:
        ans += (lists[i] * (lists[i] - 1)) // 2

print(ans)


S = str(input())
# 余りのリスト
counts = [0] * 2019
n, d = 0, 1

for s in S[::-1]:
    n += int(s) * d
    d *= 10
    n %= 2019
    counts[n] += 1
ans = counts[0]
for count in counts:
    ans += count * (count - 1) // 2
print(ans)

S = str(input())
# 余りのリスト
counts = [0] * 2019
n, d = 0, 1

for s in S[::-1]:
    n += int(s) * d
    d *= 10
    n %= 2019
    d %= 2019
    counts[n] += 1
ans = counts[0]
for count in counts:
    ans += count * (count - 1) // 2
print(ans)


s = input()[::-1]

cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in s:
    total += int(i) * x
    total %= 2019
    x *= 10 % 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)

s = input()[::-1]

n = len(s)
cnt = [0] * 2019
cnt[0] = 1
total = 0
ans = 0
x = 1

for i in range(n):
    total += int(s[i]) * x
    total %= 2019
    x *= 10
    x %= 2019
    ans += cnt[total]
    cnt[total] += 1

print(ans)


S = input()

ans = 0
for i in range(len(S)):
    m = int(S[i])
    for j in range(i + 1, len(S)):
        m = (10 * m + int(S[j])) % 2019
        if m == 0:
            ans += 1

print(ans)

from collections import Counter

S = input()

ans = 0
mod_list = [0] * len(S)
mod_list[-1] = int(S[-1])
m = 1
for i in range(2, len(S) + 1):
    m = (10 * m) % 2019
    mod_list[-i] = (mod_list[-i + 1] + (int(S[-i]) * m)) % 2019

mod_counter = Counter(mod_list)
mod_counter[0] += 1

ans = 0
for _, v in mod_counter.items():
    ans += v * (v - 1) // 2

print(ans)


S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)


s = input()
m = [0 for _ in range(2019)]
m[0] = 1
for i in range(len(s)):
    t = int(s[i:])
    m[t % 2019] += 1
print(sum([int(x * (x - 1) / 2) for x in m if x > 1]))


from collections import defaultdict

S = input()
N = len(S)

M = [0] * N
A = [0] * N
SUM = [0] * (N + 1)
MOD = 2019

x = 1
for i in range(N):
    M[i] = x % 2019
    x *= 10
for i, x in enumerate(S[::-1]):
    A[i] = M[i] * int(x) % MOD
for i in range(N):
    SUM[i + 1] = (SUM[i] + A[i]) % MOD

D = defaultdict(int)
ans = 0
for x in SUM:
    ans += D[x]
    D[x] += 1
print(ans)

S = input()
N = len(S)
SUM = [0] * (N + 1)
MOD = 2019

r = 1  # 10のi乗を2019で割った余り
S = S[::-1]
for i in range(N):
    A = r * int(S[i])
    SUM[i + 1] = (SUM[i] + A) % MOD
    r = r * 10 % MOD

cnt = [0] * 2019
ans = 0
for x in SUM:
    ans += cnt[x]
    cnt[x] += 1
print(ans)


S = input()
S = list(map(int, S))

nums = [0] * (len(S) + 1)
pow10 = 1
counter = dict({0: 1})
for i in range(1, len(S) + 1):
    nums[i] = (nums[i - 1] + pow10 * S[-i]) % 2019
    if nums[i] not in counter:
        counter[nums[i]] = 1
    else:
        counter[nums[i]] += 1

    pow10 *= 10

ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)


S = input()
S = list(map(int, S))

r = 0
pow10 = 1
counter = [0] * 2019
counter[0] = 1
for i in range(1, len(S) + 1):
    r = (r + pow10 * S[-i]) % 2019
    counter[r] += 1
    pow10 *= 10

ans = 0
for count in counter:
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)


import heapq

def inpl():
    return list(map(int, input().split()))

N, M, S = inpl()
A = 51  # max A
S = min(S, M * A - 1)

lines = [[] for _ in range(N * (M * A))]
for _ in range(M):
    in_s, in_t, cost, time = inpl()
    in_s -= 1
    in_t -= 1

    for n in range(cost, M * A):
        s = in_s + n * N
        t = in_t + (n - cost) * N
        lines[s].append((t, time))

        s = in_s + (n - cost) * N
        t = in_t + n * N
        lines[t].append((s, time))

for i in range(N):
    cost, time = inpl()
    for n in range(0, M * A):
        s = i + n * N
        if n + cost >= M * A:
            t = i + (M * A - 1) * N
        else:
            t = i + (n + cost) * N
        lines[s].append((t, time))

INF = 10**20

def dijkstra(N, S):
    weight = [INF] * N
    weight[S] = 0
    q = [[0, S]]
    heapq.heapify(q)
    while q:
        w0, s = heapq.heappop(q)
        for t, w in lines[s]:
            w += w0
            if weight[t] > w:
                heapq.heappush(q, [w, t])
                weight[t] = w

    return weight

weight = dijkstra(N * (M * A), 0 + S * N)

for i in range(1, N):
    ans = INF
    for n in range(M * A):
        ans = min(ans, weight[i + n * N])
    print(ans)

import heapq

INF = 10**20
A = 50  # max A

def inpl():
    return list(map(int, input().split()))

def main():
    N, M, S = inpl()
    S = min(S, M * A)

    lines = [[] for _ in range(N * (M * A + 1))]
    for _ in range(M):
        in_s, in_t, cost, time = inpl()
        in_s -= 1
        in_t -= 1

        for n in range(cost, M * A + 1):
            s = in_s + n * N
            t = in_t + (n - cost) * N
            lines[s].append((t, time))

            s = in_s + (n - cost) * N
            t = in_t + n * N
            lines[t].append((s, time))

    for i in range(N):
        cost, time = inpl()
        for n in range(0, M * A + 1):
            s = i + n * N
            if n + cost > M * A:
                t = i + (M * A) * N
            else:
                t = i + (n + cost) * N
            lines[s].append((t, time))

    def dijkstra(N, S):
        weight = [INF] * N
        weight[S] = 0
        q = [[0, S]]
        heapq.heapify(q)
        while q:
            w0, s = heapq.heappop(q)
            for t, w in lines[s]:
                w += w0
                if weight[t] > w:
                    heapq.heappush(q, [w, t])
                    weight[t] = w

        return weight

    weight = dijkstra(N * (M * A + 1), 0 + S * N)

    ansl = [INF] * N
    for i, w in enumerate(weight):
        n = i % N
        if n == 0:
            continue
        else:
            ansl[n] = min(w, ansl[n])

    print("\\n".join(map(str, ansl[1:])))

if __name__ == "__main__":
    main()


import heapq

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

uvab = [list(map(int, input().split())) for _ in range(M)]
cd = [list(map(int, input().split())) for _ in range(N)]

for i in range(M):
    uvab[i][0] -= 1
    uvab[i][1] -= 1

railways = [[] for _ in range(N)]
max_a = 0
for u, v, a, b in uvab:
    railways[u].append((v, a, b))
    railways[v].append((u, a, b))
    max_a = max(max_a, a)
del uvab

max_silver = max_a * (N - 1)

ans = [-1] * N
d = dict()
d[(S, 0)] = 0  # silver, station
Q = [(0, S, 0)]  # time, silver, station
sum_reached = 0
reached = [False] * N

while Q:
    t, sv, st = heapq.heappop(Q)
    if not reached[st]:
        ans[st] = t
        reached[st] = True
        sum_reached += 1
        if sum_reached == N:
            break

    new_key = (sv + cd[st][0], st)
    new_value = t + cd[st][1]
    if new_key not in d or d[new_key] > new_value:
        d[new_key] = t + cd[st][1]
        heapq.heappush(Q, (new_value, *new_key))

    for dist, a, b in railways[st]:
        if sv >= a:
            new_key = (sv - a, dist)
            new_value = t + b
            if new_key not in d or d[new_key] > new_value:
                d[new_key] = new_value
                heapq.heappush(Q, (new_value, *new_key))

print(*ans[1:], sep="\\n")

import heapq

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

uvab = [list(map(int, input().split())) for _ in range(M)]
cd = [list(map(int, input().split())) for _ in range(N)]

for i in range(M):
    uvab[i][0] -= 1
    uvab[i][1] -= 1

railways = [[] for _ in range(N)]
max_a = 0
for u, v, a, b in uvab:
    railways[u].append((v, a, b))
    railways[v].append((u, a, b))
    max_a = max(max_a, a)
del uvab

max_silver = max_a * (N - 1)

ans = [-1] * N
d = dict()
d[(S, 0)] = 0  # silver, station
Q = [(0, S, 0)]  # time, silver, station
sum_reached = 0
reached = [False] * N

while Q:
    t, sv, st = heapq.heappop(Q)
    if not reached[st]:
        ans[st] = t
        reached[st] = True
        sum_reached += 1
        if sum_reached == N:
            break

    new_key = (min(max_silver, sv + cd[st][0]), st)
    new_value = t + cd[st][1]
    if new_key not in d or d[new_key] > new_value:
        d[new_key] = t + cd[st][1]
        heapq.heappush(Q, (new_value, *new_key))

    for dist, a, b in railways[st]:
        if sv >= a:
            new_key = (sv - a, dist)
            new_value = t + b
            if new_key not in d or d[new_key] > new_value:
                d[new_key] = new_value
                heapq.heappush(Q, (new_value, *new_key))

print(*ans[1:], sep="\\n")


n, m = map(int, input().split())
a = list(map(int, input().split()))
if n - sum(a) >= 0:
    print(n - sum(a))
else:
    print(-1)

import math

r = int(input())
print(2 * r * math.pi)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02705/Python/s499723334.py", line 1, in <module>
    n, m = map(int, input().split())
ValueError: not enough values to unpack (expected 2, got 1)


import math

print(int(input()) * 2 * math.pi())

import math

print(int(input()) * 2 * math.pi)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02705/Python/s976752979.py", line 3, in <module>
    print(int(input()) * 2 * math.pi())
TypeError: 'float' object is not callable


# coding: utf-8

def main():
    R = input(int())
    return R * 2 * 3.1415

print(main())

# coding: utf-8

def main():
    R = int(input())

    return R * 2 * 3.1415

print(main())

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02705/Python/s656493829.py", line 9, in <module>
    print(main())
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02705/Python/s656493829.py", line 6, in main
    return R * 2 * 3.1415
TypeError: can't multiply sequence by non-int of type 'float'


summer_vacation, amount_of_homework = map(int, input().split())
a = map(int, input().split())
homework_list = list[a]

total_days = 0

for i in homework_list:
    total_days += i

if summer_vacation >= total_days:
    print(summer_vacation - total_days)
else:
    print(-1)

summer_vacation, amount_of_homework = map(int, input().split())
a = map(int, input().split())
homework_list = list(a)

total_days = 0

for i in homework_list:
    total_days += i

if summer_vacation >= total_days:
    print(summer_vacation - total_days)
else:
    print(-1)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02706/Python/s080879362.py", line 7, in <module>
    for i in homework_list:
TypeError: 'types.GenericAlias' object is not iterable


n, m = map(int, input().split())
print(max(n - sum(list(map(int, input().split())))), -1)

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

if n >= sum(A):
    print(n - sum(A))
else:
    print("-1")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02706/Python/s791039988.py", line 2, in <module>
    print(max(n - sum(list(map(int, input().split())))), -1)
TypeError: 'int' object is not iterable


n, m = map(int, input().split)
a = list(map(int, input().split()))
ct = 0
for i in range(m):
    ct += a[i]

if n - ct >= 0:
    print(n - ct)
else:
    print(-1)

n, m = map(int, input().split())
a = list(map(int, input().split()))
ct = 0
for i in range(m):
    ct += a[i]

if n - ct >= 0:
    print(n - ct)
else:
    print(-1)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02706/Python/s941071070.py", line 1, in <module>
    n, m = map(int, input().split)
TypeError: 'builtin_function_or_method' object is not iterable


# abc163B
# https://atcoder.jp/contests/abc163/tasks/abc163_b

# 夏休みはN日間
# 夏休みの宿題はM個
# 宿題は同じ日に複数できない、宿題の時は遊ぶことはできない
# 最大何日間遊ぶことが出来るか
# 夏休み中に終わらせられない場合は、"-1"

# 入力
n = int(input())
m = int(input())
a = list(map(int, input().split()))

# 処理
answer = n - sum(a)

if answer > 0:
    print(answer)
else:
    print("-1")

# abc163B
# https://atcoder.jp/contests/abc163/tasks/abc163_b

# 夏休みはN日間
# 夏休みの宿題はM個
# 宿題は同じ日に複数できない、宿題の時は遊ぶことはできない
# 最大何日間遊ぶことが出来るか
# 夏休み中に終わらせられない場合は、"-1"

# 入力
n, m = map(int, input().split())
a = list(map(int, input().split()))

# 処理
# 宿題にかかる合計日数
answer = n - sum(a)

if answer < 0:
    print("-1")
else:
    print(answer)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02706/Python/s871946506.py", line 11, in <module>
    n = int(input())
ValueError: invalid literal for int() with base 10: '41 2'


n, m = map(int, input().split())
a = [0] * m
for i in range(m):
    a[i] = int(input())

ans = n - sum(a)
if ans > 0:
    print(ans)
else:
    print(-1)

# ABC163B

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

ans = n - sum(a)
if ans >= 0:
    print(ans)
else:
    print(-1)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02706/Python/s373162453.py", line 4, in <module>
    a[i] = int(input())
ValueError: invalid literal for int() with base 10: '5 6'


#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import Counter

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

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

if __name__ == "__main__":
    main()

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)

    for i in range(N):
        print(count[i + 1])

if __name__ == "__main__":
    main()


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

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

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

ans = [0] * n

for i in a:
    ans[i - 1] += 1

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


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    print(a.count(i + 1))

n = int(input())
a = list(map(int, input().split()))
result = [0] * n
for x in a:
    result[x - 1] += 1
for v in result:
    print(v)


n = int(input())
a = list(int(i) for i in input().split())

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

n = int(input())
a = list(int(i) for i in input().split())
lst = [0] * (n + 1)

for i in a:
    lst[i] += 1

for i in range(1, n + 1):
    print(lst[i])


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

m = 0
t = 0

for i in range(1, n):
    count = A.count(i)
    print(count)
    m += count
    t = i
    if m == n - 1:
        break
for _ in range(t, n):
    print(0)

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

# m = 0
# t = 0

# for i in range(1, n):
#     count = A.count(i)
#     print(count)
#     m += count
#     t = i
#     if m == n - 1:
#         break
# for _ in range(t, n):
#     print(0)

B = [0] * n
for i in A:
    B[i - 1] += 1
for i in B:
    print(i)


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

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

lis = [0] * N
for i in range(N - 1):
    lis[(A[i] - 1)] += 1

for i in range(N):
    print(lis[i])


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

for i in a:
    b[i - 1] += 1

for i in b:
    print(i)


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

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


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

    for i in range(1, N + 1):
        print(A.count(i))

if __name__ == "__main__":
    main()

from collections import Counter

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

    c = Counter(A)

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

if __name__ == "__main__":
    main()


n = int(input())

ls = list(map(int, input().split()))

rg = range(1, n + 1)

for i in rg:
    c = ls.count(i)
    print(c)

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

ls2 = [0 for x in range(n)]
# 0がn個のリストを用意する

for x in ls:
    ls2[x - 1] += 1

for x in range(n):
    print(ls2[x])


N = int(input())
A_i = list(map(int, input().split()))
uq_A_i = list(set(A_i))
C = ["0\\n"] * N
for i in uq_A_i:
    C[i - 1] = "{}".format(A_i.count(i)) + "\\n"
print("".join(C))

N = int(input())
A_i = list(map(int, input().split()))
C = [0] * N
for i in A_i:
    C[i - 1] += 1
print(*C)


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

a = list(a)
for i in range(n):
    count = 0
    for j in range(i, n - 1):
        if a[j] == i + 1:
            count += 1
    print(count)

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

a = list(a)
result = [0] * n
for i in range(n - 1):
    result[a[i] - 1] += 1

print(*result, sep="\\n")


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

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

from collections import Counter

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

c = Counter(a)

for i in range(1, n + 1):
    if i in c:
        print(c[i])
    else:
        print(0)


import collections

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

c = collections.Counter(a)

for i in range(1, n + 1):
    if i in c:
        print(c[i])
    else:
        print(0)


N = int(input())
a = list(input().split())
for i in range(N):
    s = str(i + 1)
    print(a.count(s))

N = int(input())
a = list(map(int, input().split()))
li = [0] * N

for i in range(N - 1):
    li[a[i] - 1] = li[a[i] - 1] + 1

for i in range(N):
    print(li[i])


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

set_a = set(li_a)

for i in range(1, n + 1):
    if i in set_a:
        print(li_a.count(i))
    else:
        print(0)

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

dic = {}
for a in li_a:
    dic[a] = dic.get(a, 0) + 1

for i in range(1, n + 1):
    print(dic.get(i, 0))


n = int(input())

line = list(map(int, input().strip().split(" ")))

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

n = int(input())

line = list(map(int, input().strip().split(" ")))

ans = [0 for s in range(n)]

for i in line:
    ans[i - 1] += 1

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


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

import collections

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
for i in range(1, N + 1):
    if c[i]:
        print(c[i])
    else:
        print(0)


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

N = int(input())
s = [0 for i in range(N)]
A = list(map(int, input().split()))
for i in A:
    s[i - 1] += 1
print(*s, sep="\\n")


num_of_employee = int(input())
employeenos = list(map(int, input().split()))

for i in range(1, num_of_employee + 1):
    print(employeenos.count(i))

import collections

num_of_employee = int(input())
employeenos = list(map(int, input().split()))

c = collections.Counter(employeenos)
for i in range(1, num_of_employee + 1):
    print(c[i])


import numpy as np

from sys import stdin

def main():
    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))

    a2 = [[a[i], i] for i in range(n)]
    a2.sort(reverse=True)

    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

    ans = 0

    for i in range(n + 1):
        for j in range(n + 1 - i):
            s1 = s2 = 0
            if i > 0:
                s1 = dp[i - 1][j] + a2[i + j - 1][0] * (a2[i + j - 1][1] - (i - 1))
            if j > 0:
                s2 = dp[i][j - 1] + a2[i + j - 1][0] * ((n - j) - a2[i + j - 1][1])
            dp[i][j] = np.max([s1, s2])
        ans = np.max([ans, dp[i][n - i]])

    print(ans)

if __name__ == "__main__":
    main()

from sys import stdin

def main():
    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))

    a2 = [[a[i], i] for i in range(n)]
    a2.sort(reverse=True)

    dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

    ans = 0

    for i in range(n + 1):
        for j in range(n + 1 - i):
            s1 = s2 = 0
            if i > 0:
                s1 = dp[i - 1][j] + a2[i + j - 1][0] * (a2[i + j - 1][1] - (i - 1))
            if j > 0:
                s2 = dp[i][j - 1] + a2[i + j - 1][0] * ((n - j) - a2[i + j - 1][1])
            dp[i][j] = max(s1, s2)
        ans = max(ans, dp[i][n - i])

    print(ans)

if __name__ == "__main__":
    main()


from copy import deepcopy

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

index = [i for i in range(N)]
index = sorted(index, key=lambda i: A[i], reverse=True)

def LorR(index, res):
    i = index[0]
    dist = max(i, N - 1 - i)
    end = False
    cand1 = cand2 = 0
    while not end:
        j = i + dist
        if 0 <= j and j < N and not res[j]:
            r = deepcopy(res)
            r[j] = True
            cand1 = A[i] * dist + loop(index[1:], r)
            end = True

        j = i - dist
        if 0 <= j and j < N and not res[j]:
            r = deepcopy(res)
            r[j] = True
            cand2 = A[i] * dist + loop(index[1:], r)
            end = True

        dist -= 1
    return max(cand1, cand2)

def loop(index, res):
    if not index:
        return 0

    return LorR(index, res)

print(loop(index, [False] * N))

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

A = sorted([(val, pos) for pos, val in enumerate(A)], reverse=True)

dp = [0]
for i, (val, pos) in enumerate(A):
    ldp = [e + val * abs(pos - (i - r)) for r, e in enumerate(dp)]
    rdp = [e + val * abs(N - 1 - r - pos) for r, e in enumerate(dp)]
    dp = [max(L, R) for L, R in zip(ldp + [0], [0] + rdp)]

print(max(dp))


# 解説AC
n = int(input())
A = list(map(int, input().split()))
B = []
for i, e in enumerate(A):
    B.append((e, i + 1))
B.sort(reverse=True)
# dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値
dp = [[-1] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(i + 1):  # 左の個数
        k = i - j  # 右の個数
        ni = i + 1
        val, idx = B[i]
        dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val)
        dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val)
ans = 0
for i in range(n + 1):
    ans = max(ans, dp[n][i])
print(ans)

# 解説AC
import sys

input = sys.stdin.buffer.readline

n = int(input())
A = list(map(int, input().split()))
B = []
for i, e in enumerate(A):
    B.append((e, i + 1))
B.sort(reverse=True)
# dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値
dp = [[-1] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(i + 1):  # 左の個数
        k = i - j  # 右の個数
        ni = i + 1
        val, idx = B[i]
        dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val)
        dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val)
ans = 0
for i in range(n + 1):
    ans = max(ans, dp[n][i])
print(ans)