import itertools

max_range, sum_ = map(int, input().split())

count = 0
for x, y, z in itertools.combinations_with_replacement(range(max_range + 1), r=3):
    if x + y + z == sum_:
        len_set = len({x, y, z})
        if len_set == 1:
            count += 1
        elif len_set == 2:
            count += 3
        else:
            count += 6

print(count)

max_range, sum_ = map(int, input().split())

count = 0
for x in range(0, min(max_range + 1, sum_ + 1)):
    for y in range(0, min(max_range + 1, sum_ - x + 1)):
        if sum_ - x - y <= max_range:
            count += 1

print(count)


from sys import stdin

def main():
    K, S = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    for X in range(S + 1):
        for Y in range(S + 1):
            Z = S - (X + Y)
            if Z < 0:
                break
            if X <= K and Y <= K and Z <= K:
                result += 1
    print(result)

if __name__ == "__main__":
    main()

from sys import stdin

def main():
    K, S = [int(x) for x in stdin.readline().rstrip().split()]
    result = 0
    for X in range(S + 1):
        if K < X:
            break
        for Y in range(S + 1):
            if K < Y:
                break
            Z = S - (X + Y)
            if Z < 0:
                break
            if X <= K and Y <= K and Z <= K:
                result += 1
    print(result)

if __name__ == "__main__":
    main()


k, s = map(int, input().split())
cnt = 0

for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                cnt += 1
print(cnt)

k, s = map(int, input().split())
cnt = 0

for i in range(k + 1):
    t = s - i
    if t >= 0:
        cnt += max(0, (t + 1) - 2 * (max(0, t - k)))
print(cnt)


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

result = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                result += 1

                break

print(result)

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

result = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            result += 1

print(result)


import math

def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins

def solve(inputs):
    points = list(map(lambda x: sp(x), inputs))
    N = len(points)
    distances = []
    for i, _ in enumerate(points):
        for j in range(i + 1, N):
            distances.append(
                math.sqrt(
                    (points[i][0] - points[j][0]) ** 2
                    + (points[i][1] - points[j][1]) ** 2
                )
            )
    max = 0
    for d in distances:
        max = d if max < d else max
    return "%.6f" % max

def sp(s):
    new_s = s.split()
    return list(map(lambda x: int(x), new_s))

if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins

def solve(inputs):
    [K, S] = list(map(lambda x: int(x), inputs[0].split()))
    pattern = 0
    for x in range(0, K + 1):
        for y in range(0, K + 1):
            tmp_z = S - x - y
            if tmp_z <= K and tmp_z >= 0:
                pattern += 1

    return pattern

if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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


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

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

cnt = 0

for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                cnt += 1

print(cnt)

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

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

cnt = 0

for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            cnt += 1

print(cnt)


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

sum_set = []
for i in range(k + 1):
    for j in range(k + 1):
        m = s - i - j
        if 0 <= m <= k:
            comb = [i, j, m]
            sum_set.append(comb)
        else:
            continue
print(len(sum_set))

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

count = 0
for i in range(k + 1):
    for j in range(k + 1):
        m = s - i - j
        if 0 <= m <= k:
            count += 1
print(count)


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

ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                ans += 1
            if x + y + z > s:
                break

print(ans)

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

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

print(ans)


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

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

print(ans)


k, s = map(int, input().split(" "))
answer = 0

for i in range(k + 1):
    for j in range(k + 1):
        rem = 3 * k - i - j
        if 0 <= rem <= k:
            answer += 1
print(answer)

k, s = map(int, input().split(" "))
answer = 0

for i in range(k + 1):
    for j in range(k + 1):
        rem = s - i - j
        if 0 <= rem <= k:
            answer += 1
print(answer)


# https://atcoder.jp/contests/abc051/tasks/abc051_b

# n n,
K, S = map(int, input().split())

# initialize
ans = 0

# logic: 全探索: 基本形
for i in range(K + 1):
    if i + K + 1 + K + 1 < S:
        continue
    for j in range(K + 1):
        if i + j + K + 1 < S:
            continue
        if 0 <= S - i - j <= K:
            ans += 1

print(ans)

k, s = map(int, input().split())
count = 0
for a in range(k + 1):
    for b in range(k + 1):
        if 0 <= s - a - b <= k:
            count += 1
print(count)


K, S = map(int, input().split())

counter = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            if S == x + y + z:
                counter += 1
print(counter)

K, S = map(int, input().split())

counter = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - x - y
        if 0 <= z and z <= K:
            counter += 1
print(counter)


# -*- coding: utf-8 -*-
K, S = map(int, input().split())
cnt = 0

for X in range(K + 1):
    for Y in range(K + 1):
        for Z in range(K + 1):
            if X + Y + Z == S:
                cnt += 1
print(cnt)

# -*- coding: utf-8 -*-
K, S = map(int, input().split())
cnt = 0

for X in range(K + 1):
    for Y in range(K + 1):
        Z = S - X - Y
        if 0 <= Z <= K:
            cnt += 1

print(cnt)


K, S = map(int, input().split())
ans = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            # print(x, y, z)
            if x + y + z == S:
                ans += 1
print(ans)

K, S = map(int, input().split())
ans = 0
for x in range(K + 1):
    for y in range(K + 1):
        ans += 1 if 0 <= S - x - y <= K else 0
print(ans)


import itertools

K, S = map(int, input().split())

cnt = 0

K = list(range(K + 1))

for i, j in itertools.product(K, repeat=2):
    if 0 <= S - i - j <= K:
        cnt += 1

print(cnt)

import itertools

K, S = map(int, input().split())

cnt = 0

l = list(range(K + 1))

for i, j in itertools.product(l, repeat=2):
    if 0 <= S - i - j <= K:
        cnt += 1

print(cnt)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03835/Python/s440098409.py", line 10, in <module>
    if 0 <= S - i - j <= K:
TypeError: '<=' not supported between instances of 'int' and 'list'


# coding: utf-8
# Your code here!

maximum, equal = map(int, input().split())
counter = 0

for i in range(maximum + 1):
    for j in range(maximum + 1):
        for k in range(maximum + 1):
            if equal == i + j + k:
                counter += 1

print(counter)

# coding: utf-8
# Your code here!

K, S = map(int, input().split())
counter = 0

for i in range(K + 1):
    for j in range(K + 1):
        if S - (i + j) >= 0 and S - (i + j) <= K:
            counter += 1
print(counter)


k, s = [int(x) for x in input().split()]
cnt = 0
for x in range(k + 1):
    if x > s:
        continue
    for y in range(x, k + 1):
        if y > s:
            break
        for z in range(y, k + 1):
            if z > s:
                break
            if x + y + z == s:
                if x == y == z:
                    cnt += 1
                elif x == y or y == z:
                    cnt += 3
                else:
                    cnt += 6
print(cnt)

k, s = [int(x) for x in input().split()]
cnt = 0
for x in range(k + 1):
    if x > s:
        continue
    for y in range(x, k + 1):
        if y > s:
            break
        z = s - x - y
        if y <= z and z <= k:
            if x + y + z == s:
                if x == y == z:
                    cnt += 1
                elif x == y or y == z:
                    cnt += 3
                else:
                    cnt += 6
print(cnt)


import sys

input = sys.stdin.readline

def ii():
    return int(input())

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

K, S = il()
c = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            if (x + y + z) == S:
                c += 1
print(c)

import sys

input = sys.stdin.readline

def ii():
    return int(input())

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

K, S = il()
c = 0
for x in range(K + 1):
    for y in range(K + 1):
        if 0 <= (S - (x + y)) <= K:
            c += 1
print(c)


k, s = map(int, input().split())
count = 0
k += 1
for x in range(k):
    for y in range(k):
        for z in range(k):
            if x + y + z == s:
                count += 1

print(count)

k, s = map(int, input().split())
count = 0
for x in range(k + 1):
    for y in range(k + 1):
        if s - x - y <= k and s - x - y >= 0:
            # print(x, y)
            count += 1

print(count)


K, S = map(int, input().split())

# a = []
ans = 0
for i in range(K + 1):
    for j in range(i + 1):
        for k in range(j + 1):
            # print(i, j, k)
            if i + j + k == S:
                # print(i, j, k)
                # tmp = [i, j, k]
                # a.append(tmp)
                if i == j and j == k:
                    ans += 1
                elif i == j or j == k:
                    ans += 3
                else:
                    ans += 6

print(ans)

K, S = map(int, input().split())

# a = []
ans = 0
for i in range(K + 1):
    for j in range(i + 1):
        k = S - i - j
        if k >= 0 and k <= j:
            # print(i, j, k)
            if i == j and j == k:
                ans += 1
            elif i == j or j == k:
                ans += 3
            else:
                ans += 6

print(ans)


K, S = list(map(int, input().rstrip().split()))

n = 0
for x in range(K + 1):
    for y in range(K + 1):
        if x + y > S:
            break

        for z in range(K + 1):
            if x + y + z > S:
                break

            if (x + y + z) == S:
                n += 1

print(n)

K, S = list(map(int, input().rstrip().split()))

n = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - x - y
        if 0 <= z and z <= K:
            n += 1

print(n)


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

k += 1

ans = 0
for x in range(k):
    for y in range(k):
        for z in range(k):
            if x + y + z == s:
                ans += 1

print(ans)

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

k += 1

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

print(ans)


import itertools

K, S = map(int, input().split())

print(sum([1 for xyz in itertools.product(range(K + 1), repeat=3) if sum(xyz) == S]))

K, S = map(int, input().split())

def f():
    if K * 3 >= S:
        for x in range(min(K, S), -1, -1):
            if K * 2 >= S - x:
                for y in range(min(K, S - x), -1, -1):
                    if K >= S - x - y:
                        yield 1

print(sum(list(f())))


k, s = map(int, input().split())
r = range(0, k + 1)
cnt = 0
for x in r:
    for y in r:
        if x + y > s:
            continue
        for z in r:
            if x + y + z == s:
                cnt += 1

print(cnt)

k, s = map(int, input().split())
r = range(0, k + 1)
cnt = 0
for x in r:
    for y in r:
        if s - k <= x + y <= s:
            cnt += 1
print(cnt)


[K, S] = map(int, input().split())
ret = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            if (x + y + z) == S:
                ret += 1
print(ret)

[K, S] = map(int, input().split())
ret = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - x - y
        if 0 <= z and z <= K:
            ret += 1
print(ret)


K, S = map(int, input().split())
n = 0
for i in range(K + 1):
    for j in range(K + 1):
        if (i + j) > S:
            continue
        elif (S - i - j) > K:
            continue
        for k in range(K + 1):
            if (i + j + k) == S:
                n += 1
print(str(n))

K, S = map(int, input().split())
n = 0
for x in range(K + 1):
    for y in range(K + 1):
        if (x + y) > S:
            break
        elif (S - (x + y)) <= K:
            n += 1
print(str(n))


K, S = map(int, input().split())
cnt = 0
for x in range(K + 1):
    pass
    for y in range(K + 1):
        pass
        for z in range(K + 1):
            if x + y + z == S:
                cnt += 1
print(cnt)

K, S = map(int, input().split())
cnt = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - x - y
        if z >= 0 and z <= K:
            cnt += 1
print(cnt)


def solve():
    k, s = map(int, input().split())
    c = 0
    for x in range(k + 1):
        for y in range(k + 1):
            for z in range(k + 1):
                if x + y + z == s:
                    c += 1
    return c

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

def solve():
    k, s = map(int, input().split())
    c = 0
    for x in range(k + 1):
        for y in range(k + 1):
            if 0 <= s - (x + y) <= k:
                c += 1
    return c

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


K, S = map(int, input().split())
count = 0
for i in range(K + 1):
    for j in range(K + 1):
        for k in range(K + 1):
            if i + j + k == S:
                count = count + 1

print(count)

K, S = map(int, input().split())
count = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - x - y
        if 0 <= z <= K:
            count = count + 1

print(count)


K, S = map(int, (input().split()))

ans = 0

for x in range(0, K + 1):
    for y in range(0, K + 1):
        for z in range(0, K + 1):
            if x + y + z == S:
                ans += 1

print(ans)

K, S = map(int, (input().split()))

ans = 0

for x in range(0, K + 1):
    for y in range(0, K + 1):

        z = S - x - y
        if z <= K and z >= 0:
            ans += 1

print(ans)


K, S = map(int, input().split())
count = 0
for i in range(S + 1):
    X = S - i
    for j in range(i + 1):
        Y = j
        Z = S - X - Y
        if K >= X >= 0 and K >= Y >= 0 and K >= Z >= 0:
            count += 1
print(count)

K, S = map(int, input().split())
count = 0
for i in range(K + 1):
    for j in range(K + 1):
        Z = S - i - j
        if K >= Z >= 0:
            count += 1
print(count)


# coding: utf-8
K, S = map(int, input().split())
ans = 0
for i in range(K + 1):
    if S > 2 * K + i:
        continue
    for j in range(K + 1):
        if S > K + i + j:
            continue
        for k in range(K + 1):
            if i + j + k == S:
                ans += 1
print(ans)

# coding: utf-8
K, S = map(int, input().split())
ans = 0
for i in range(K + 1):
    if S - i > 2 * K:
        continue
    elif S - i < 0:
        break
    if S - i > K:
        ans += 2 * K + 1 - S + i
    else:
        ans += S - i + 1
print(ans)


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

def calc_xyz(target, limit):
    xyz_list = []
    for x in range(min(limit, target) + 1):
        yz_sum = target - x
        for y in range(min(limit, yz_sum) + 1):
            z = target - x - y
            if 0 <= z <= limit:
                xyz_list.append([x, y, z])
    return xyz_list

print(len(calc_xyz(s, k)))

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

def calc_xyz(target, limit):
    cnt = 0
    for x in range(min(limit, target) + 1):
        yz_sum = target - x
        for y in range(min(limit, yz_sum) + 1):
            if 0 <= target - x - y <= limit:
                cnt += 1
    return cnt

print(calc_xyz(s, k))


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

cnt = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if s == x + y + z:
                cnt += 1

print(cnt)

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

cnt = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            cnt += 1

print(cnt)


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

ans = 0
for x in range(0, k + 1):
    for y in range(0, k + 1):
        for z in range(0, k + 1):
            if x + y + z == s:
                ans += 1
print(ans)

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

ans = 0
for x in range(0, k + 1):
    for y in range(0, k + 1):
        if 0 <= s - (x + y) <= k:
            ans += 1
print(ans)


k, s = list(map(int, input().split()))
cnt = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if s == x + y + z:
                cnt += 1
print(cnt)

k, s = list(map(int, input().split()))
cnt = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - x - y <= k:
            cnt += 1
print(cnt)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

K, S = map(int, input().split())

r = 0
for i in range(K + 1):
    for j in range(K + 1):
        for k in range(K + 1):
            if i + j + k == S:
                r += 1

print(r)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

K, S = map(int, input().split())

r = 0
for i in range(K + 1):
    for j in range(K + 1):
        k = S - i - j
        if k >= 0 and k <= K:
            r += 1

print(r)


kk, s = map(int, input().split(" "))
count = 0
for i in range(0, kk + 1):
    for j in range(0, kk + 1):
        for k in range(0, kk + 1):
            if i + j + k == s:
                count += 1

print(count)

k, s = map(int, input().split(" "))
count = 0
for i in range(0, k + 1):
    for j in range(0, k + 1):
        if 0 <= s - i - j <= k:
            count += 1

print(count)


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

    pattern = 0

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

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

    print(pattern)

if __name__ == "__main__":

    main()

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

    pattern = 0

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

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

    print(pattern)

if __name__ == "__main__":

    main()


k, s = map(int, input().split())
count = 0

for i in range(k + 1):
    for j in range(k + 1):
        if s - i - j in range(k + 1):
            count += 1

print(count)

k, s = map(int, input().split())
count = 0

for i in range(k + 1):
    for j in range(k + 1):
        if 0 <= s - i - j <= k:
            count += 1

print(count)


K, S = list(map(int, input().split()))
res = 0

for x in range(K + 1):
    tmp = S
    if tmp - x == 0:
        res += 1
        continue
    for y in range(K + 1):
        if tmp - x - y == 0:
            res += 1
            continue
        for z in range(K + 1):
            if tmp - x - y - z == 0:
                res += 1
                continue
print(res)

K, S = list(map(int, input().split()))
res = 0

for x in range(K + 1):
    for y in range(K + 1):
        if S - x - y >= 0 and S - x - y <= K:
            res += 1
print(res)


K, S = [int(v) for v in input().split()]

cnt = 0
for x in range(K + 1):
    if x > S:
        break
    for y in range(K + 1):
        if x + y > S:
            break
        for z in range(K + 1):
            if x + y + z > S:
                break
            if x + y + z == S:
                cnt += 1
print(cnt)

K, S = [int(v) for v in input().split()]

cnt = 0
for x in range(K + 1):
    for y in range(K + 1):
        if S - (x + y) >= 0 and S - (x + y) <= K:
            cnt += 1
print(cnt)


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

count = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                count += 1
                break

print(count)

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

count = 0
for x in range(k + 1):
    for y in range(k + 1):
        if x + y <= s <= x + y + k:
            count += 1

print(count)


k, s = map(int, input().split())
cnt = 0
for x in range(max(s - 2 * k, 0), k + 1):
    for y in range(k + 1):
        if s - x - y > k:
            continue
        elif s - x - y < 0:
            continue
        z = s - x - y
        if 0 <= z <= k:
            cnt += 1
print(cnt)

k, s = map(int, input().split())
cnt = 0
for x in range(max(s - 2 * k, 0), k + 1):
    for y in range(max(s - x - k, 0), min(s - x + 1, k + 1)):
        z = s - x - y
        if 0 <= z <= k:
            cnt += 1
        else:
            continue
print(cnt)


from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]

graph = [[0] * n for _ in range(n)]
for a, b, c in abc:
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

dist, pre = floyd_warshall(csr_matrix(graph), return_predecessors=True)

edges = set()
for s in range(n):
    for g in range(s + 1, n):
        while g != s:
            par_g = pre[s][g]
            edge = sorted([par_g, g])
            edge = tuple(edge)
            edges.add(edge)
            g = par_g

ans = m - len(edges)
print(ans)

from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

n, m = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]

graph = [[0] * n for _ in range(n)]
for a, b, c in abc:
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

dist = floyd_warshall(csr_matrix(graph))

ans = 0
for a, b, c in abc:
    a -= 1
    b -= 1

    if dist[a][b] != c:
        ans += 1

print(ans)


x, y = list(map(int, input().split()))
if y - x >= 0:
    ans = y - x
if y + x >= 0:
    ans = min(ans, y + x + 1)
if -1 * y - x >= 0:
    ans = min(ans, -1 * y - x + 1)
if -1 * y + x >= 0:
    ans = min(ans, -1 * y + x + 2)
print(ans)

x, y = list(map(int, input().split()))
ans = []
if y - x >= 0:
    ans.append(y - x)
if y + x >= 0:
    ans.append(y + x + 1)
if -1 * y - x >= 0:
    ans.append(-1 * y - x + 1)
if -1 * y + x >= 0:
    ans.append(-1 * y + x + 2)
print(min(ans))


# https://atcoder.jp/contests/agc008/tasks/agc008_a
# どう見ても符号反転は1回するのが最適
# ひたすら場合分け

x, y = map(int, input().split())
if x * y < 0:  # 異符号ならば答えは一つ
    print(abs(abs(x) - abs(y)) + 1)
elif 0 <= x < y:
    print(y - x)
elif 0 <= y < x:
    print(x + y + 1)
    raise ValueError()
elif x < y <= 0:
    print(y - x)
else:
    print(2 + x - y)

# https://atcoder.jp/contests/agc008/tasks/agc008_a
# どう見ても符号反転は1回するのが最適
# ひたすら場合分け

x, y = map(int, input().split())
if x * y < 0:  # 異符号ならば答えは一つ
    print(abs(abs(x) - abs(y)) + 1)
    exit()
elif 0 <= x < y:
    print(y - x)
    exit()
elif 0 < y < x:
    print(2 + x - y)
    exit()
elif y == 0 and y < x:
    print(1 + x)
    exit()
elif x < y <= 0:
    print(y - x)
    exit()
elif y < x < 0:
    print(2 + x - y)
    exit()
elif x == 0 and y < x:
    print(1 - y)
    exit()
raise ValueError()


def main():
    x, y = map(int, input().split())

    if 0 <= x <= y or x <= y <= 0:
        ans = abs(abs(x) - abs(y))

    elif x < 0 < y or y < 0 < x:
        ans = abs(abs(x) - abs(y)) + 1

    elif y < x < 0 or 0 < y < x:
        ans = abs(abs(x) - abs(y)) + 2

    print(ans)

if __name__ == "__main__":
    main()

def main():
    x, y = map(int, input().split())

    if 0 <= x <= y or x <= y <= 0:
        ans = abs(abs(x) - abs(y))

    elif x <= 0 <= y or y <= 0 <= x:
        ans = abs(abs(x) - abs(y)) + 1

    elif y < x < 0 or 0 < y < x:
        ans = abs(abs(x) - abs(y)) + 2

    print(ans)

if __name__ == "__main__":
    main()


x, y = map(int, input().split())
d = abs(abs(y) - abs(x))
if x // abs(x) == y // abs(y):
    if x > y:
        d += 2
else:
    d += 1

print(d)

x, y = map(int, input().split())

d = abs(abs(y) - abs(x))

if (x > 0 and y <= 0) or (x >= 0 and y < 0) or (x < 0 and y > 0):
    d += 1
elif x > y:
    d += 2

print(d)


def main():
    x, y = map(int, input().split())
    A = abs(abs(x) - abs(y))

    if x * y > 0:
        if x < y:
            B = 0
        else:
            B = 2
    elif x == 0:
        if x < y:
            B = 0
        else:
            B = 1
    elif y == 0:
        if x < y:
            B = 0
        else:
            B = 1

    print(A + B)

if __name__ == "__main__":
    main()

def main():
    x, y = map(int, input().split())
    A = abs(abs(x) - abs(y))

    if x * y > 0:
        if x < y:
            B = 0
        else:
            B = 2
    elif x == 0:
        if x < y:
            B = 0
        else:
            B = 1
    elif y == 0:
        if x < y:
            B = 0
        else:
            B = 1
    else:
        B = 1

    print(A + B)

if __name__ == "__main__":
    main()


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

if op == "+":
    print(A + B)

if op == "-":
    print(A - B)

A, op, B = map(str, input().split())

if op == "+":
    print(int(A) + int(B))

if op == "-":
    print(int(A) - int(B))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03844/Python/s927597638.py", line 1, in <module>
    A, op, B = map(int, input().split())
ValueError: invalid literal for int() with base 10: '+'


equa = input().split()
if equa[1] == "+":
    print(int(equa[0]) + int(equa[1]))
else:
    print(int(equa[0]) - int(equa[1]))

equa = input().split()
if equa[1] == "+":
    print(int(equa[0]) + int(equa[2]))
else:
    print(int(equa[0]) - int(equa[2]))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03844/Python/s614588163.py", line 3, in <module>
    print(int(equa[0]) + int(equa[1]))
ValueError: invalid literal for int() with base 10: '+'


A, op, B = list(map(str, input().split()))
if op == "+":
    print(A + B)
else:
    print(A - B)

A, op, B = list(map(str, input().split()))
if op == "+":
    print(int(A) + int(B))
else:
    print(int(A) - int(B))


a, op, b = [int(i) for i in input().split()]
if op == "+":
    print(int(a) + int(b))
else:
    print(int(a) - int(b))

a, op, b = [i for i in input().split()]
if op == "+":
    print(int(a) + int(b))
else:
    print(int(a) - int(b))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03844/Python/s761760339.py", line 1, in <module>
    a, op, b = [int(i) for i in input().split()]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03844/Python/s761760339.py", line 1, in <listcomp>
    a, op, b = [int(i) for i in input().split()]
ValueError: invalid literal for int() with base 10: '+'


A, op, B = input().split()
if op == "+":
    print(A + B)
else:
    print(A - B)

A, op, B = input().split()
A = int(A)
B = int(B)
if op == "+":
    print(A + B)
else:
    print(A - B)


N = int(input())
T = [int(i) for i in input().split()]
M = int(input())

PX = []

for i in range(M):
    # 0-indexed
    PX.append([int(j) for j in input().split()])
    PX[i][0] -= 1

ans = sum(T)

for i in range(M):
    print(ans - T[PX[i][0]] + T[PX[i][1]])

N = int(input())
T = [int(i) for i in input().split()]
M = int(input())

PX = []

for i in range(M):
    # 0-indexed
    PX.append([int(j) for j in input().split()])
    PX[i][0] -= 1

ans = sum(T)

for i in range(M):
    print(ans - T[PX[i][0]] + PX[i][1])

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03845/Python/s001873582.py", line 15, in <module>
    print(ans - T[PX[i][0]] + T[PX[i][1]])
IndexError: list index out of range


def main(n, t, m, p_x):
    for p, x in p_x:
        _t = t.copy()
        _t[p - 1] = x

        print(sum(_t))

if __name__ == "__main__":
    n = int(input())
    t = list(map(int, input().split()))
    m = int(input())
    p_x = [int(input()) for _ in range(m)]

    main(n, t, m, p_x)

def main(n, t, m, p_x):
    for p, x in p_x:
        _t = t.copy()
        _t[p - 1] = x

        print(sum(_t))

if __name__ == "__main__":
    n = int(input())
    t = list(map(int, input().split()))
    m = int(input())
    p_x = [list(map(int, input().split())) for _ in range(m)]

    main(n, t, m, p_x)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03845/Python/s833373985.py", line 13, in <module>
    p_x = [int(input()) for _ in range(m)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03845/Python/s833373985.py", line 13, in <listcomp>
    p_x = [int(input()) for _ in range(m)]
ValueError: invalid literal for int() with base 10: '1 1'


N = int(input())
A = [int(i) for i in input().split()]
ans = 0
if N % 2 != 0:
    num_list = [int(i) for i in range(2, N, 2)]
    for num in num_list:
        if A.count(num) != 2:
            break
    else:
        if A.count(0) == 1:
            ans = (2 ** (N // 2)) % (10**7 + 7)

else:
    num_list = [int(i) for i in range(1, N, 2)]
    for num in num_list:
        if A.count(num) != 2:
            break
    else:
        ans = 2 ** (N // 2) % (10**7 + 7)

print(ans)

import collections

N = int(input())
A = [int(i) for i in input().split()]
ans = 0
di = collections.Counter(A)
if N % 2 != 0:
    num_list = [int(i) for i in range(2, N, 2)]
    for num in num_list:
        if di[num] != 2:
            break
    else:
        if A.count(0) == 1:
            ans = (2 ** (N // 2)) % (10**9 + 7)

else:
    num_list = [int(i) for i in range(1, N, 2)]
    for i in num_list:
        if di[i] != 2:
            break
    else:
        ans = (2 ** (N // 2)) % (10**9 + 7)
print(ans)


N = int(input())
A = list(map(int, input().split()))
if N % 2 == 1:
    if A.count(0) != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    print(2 ** ((N - 1) // 2))
else:
    for i in range(1, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    print(2 ** (N // 2))


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

if N % 2 == 1:
    for i in range(N // 2):
        if A.count(i * 2) != 2 and i != 0:
            print(0)
            exit()
        if i == 0 and A.count(i) != 1:
            print(0)
            exit()

if N % 2 == 0:
    for i in range(N // 2):
        if A.count(i * 2 + 1) != 2:
            print(0)
            exit()

print(2 ** (N // 2))

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

check = True
A = sorted(A)
if N % 2 == 0:
    for i in range(N):
        if i % 2 == 0 and A[i] != i + 1:
            check = False
        if i % 2 == 1 and A[i] != i:
            check = False

if N % 2 != 0:
    for i in range(N):
        if i % 2 == 0 and A[i] != i:
            check = False
        if i % 2 == 1 and A[i] != i + 1:
            check = False

if check:
    print((2 ** (N // 2)) % (10**9 + 7))
else:
    print(0)


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

def solve():
    for a in A:
        if N % 2 == 1:
            if a % 2 == 1:
                return 0
            else:
                if a == 0 and A.count(a) != 1:
                    return 0
                elif a != 0 and A.count(a) != 2:
                    return 0
        else:
            if a % 2 == 0:
                return 0
            else:
                if A.count(a) != 2:
                    return 0
    return 2 ** (N // 2)

print(solve())

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

def solve():
    cnt = {i + (1 - N % 2): 0 for i in range(0, 2 * N // 2, 2)}
    for a in A:
        if a not in cnt:
            return 0

        if N % 2 == 1:
            if a % 2 == 1:
                return 0
            cnt[a] += 1
        else:
            if a % 2 == 0:
                return 0
            cnt[a] += 1

    for key, value in cnt.items():
        if key == 0:
            if value != 1:
                return 0
        else:
            if value != 2:
                return 0

    return 2 ** (N // 2) % (10**9 + 7)

print(solve())


c = int(input())
print("vowel" if c in "aiueo" else "consonant")

c = input()
print("vowel" if c in "aiueo" else "consonant")

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


def main():
    h, _ = map(int, input().split())
    c = [input() for _ in range(h)]
    for cn in c:
        print(cn)
        print(cn)

if __name__ == "__main__":
    main()

def main():
    print("vowel" if input() in "aeiou" else "consonant")

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03852/Python/s011405155.py", line 10, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03852/Python/s011405155.py", line 2, in main
    h, _ = map(int, input().split())
ValueError: invalid literal for int() with base 10: 'a'


C = open(0)
for i in C[1:]:
    print(i)
    print(i)

import sys

H, W = sys.stdin.readline().split()
C = map(str, sys.stdin)
for i in C:
    print(i)
    print(i)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03853/Python/s894840056.py", line 2, in <module>
    for i in C[1:]:
TypeError: '_io.TextIOWrapper' object is not subscriptable


H, W = map(int, input().split())
px = []
ans = []
for x in range(H):
    px.append(input())
    ans.append(px[x])
    ans.append(px[x])

for x in range(ans):
    print(ans[x])

H, W = map(int, input().split())
px = []
ans = []
for x in range(H):
    px.append(input())
    ans.append(px[x])
    ans.append(px[x])

for x in range(len(ans)):
    print(ans[x])

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03853/Python/s440756858.py", line 9, in <module>
    for x in range(ans):
TypeError: 'list' object cannot be interpreted as an integer


import re

def main():
    S = input()
    lens = len(S)
    while len(S):
        S = re.sub("dreamer$", "", S)
        S = re.sub("eraser$", "", S)
        S = re.sub("dream$", "", S)
        S = re.sub("erase$", "", S)
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return

main()

dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"

def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[lens - len(dreamer) :] == dreamer:
            S = S[: lens - len(dreamer)]
        elif S[lens - len(eraser) :] == eraser:
            S = S[: lens - len(eraser)]
        elif S[lens - len(dream) :] == dream:
            S = S[: lens - len(dream)]
        elif S[lens - len(erase) :] == erase:
            S = S[: lens - len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return

main()


S = input()

def is_composable(s):
    if len(s) == 0:
        return True

    if s.startswith("dreamer"):
        dream_s = s[5:]
        dreamer_s = s[7:]
        return is_composable(dream_s) or is_composable(dreamer_s)
    elif s.startswith("dream"):
        dream_s = s[5:]
        return is_composable(dream_s)
    elif s.startswith("eraser"):
        erase_s = s[5:]
        eraser_s = s[6:]
        return is_composable(erase_s) or is_composable(eraser_s)
    elif s.startswith("erase"):
        erase_s = s[5:]
        return is_composable(erase_s)
    else:
        return False

if len(S) > 0 and is_composable(S):
    print("YES")
else:
    print("NO")

S = input()

S = S[::-1]

dream = "maerd"
dreamer = "remaerd"
erase = "esare"
eraser = "resare"

if len(S) > 0:
    while len(S) > 0:
        if S.startswith(dream):
            S = S[len(dream) :]
        elif S.startswith(dreamer):
            S = S[len(dreamer) :]
        elif S.startswith(erase):
            S = S[len(erase) :]
        elif S.startswith(eraser):
            S = S[len(eraser) :]
        else:
            break
    if len(S) > 0:
        print("NO")
    else:
        print("YES")

else:
    print("NO")


s = list(input())

dream = list("dream")
dreamer = list("dreamer")
erase = list("erase")
eraser = list("eraser")

s.reverse()
dream.reverse()
dreamer.reverse()
erase.reverse()
eraser.reverse()

while s != []:
    if s[0:7] == dreamer:
        del s[0:7]
    elif s[0:6] == eraser:
        del s[0:6]
    elif s[0:5] == dream:
        del s[0:5]
    elif s[0:5] == erase:
        del s[0:5]
    else:
        print("NO")
        exit()

print("YES")

s = input()

dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"

while s != "":
    if s.endswith(dreamer):
        s = s[:-7]
    elif s.endswith(eraser):
        s = s[:-6]
    elif s.endswith(dream):
        s = s[:-5]
    elif s.endswith(erase):
        s = s[:-5]
    else:
        print("NO")
        exit()

print("YES")


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

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

ans = 0
new_a = A.copy()
while 1:
    new_a = [a // 2 if a % 2 == 0 else -1 for a in new_a]
    if -1 in new_a:
        print(ans)
        exit()
    ans += 1

print(ans)

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

S = input()
dream_set = {"dream", "dreamer", "erase", "eraser"}
# 感動的計画法やるぞ

while len(S) > 0:
    if S.endswith("dream") or S.endswith("erase"):
        S = S[:-5]
    elif S.endswith("eraser"):
        S = S[:-6]
    elif S.endswith("dreamer"):
        S = S[:-7]
    else:
        print("NO")
        exit()

print("YES")

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


from re import sub

dest = input().rstrip("\\n")

suffixes = ["dream$", "dreamer$", "erase$", "eraser$"]

while True:
    len_before = len(dest)
    for suffix in suffixes:
        dest = sub(suffix, "", dest)
    if len(dest) == len_before:
        break

print("YES" if not dest else "NO")

dest = input().rstrip("\\n")

suffixes = ["dream", "dreamer", "erase", "eraser"]
cut_lens = [-5, -7, -5, -6]

while True:
    for suffix, cut_len in zip(suffixes, cut_lens):
        if dest.endswith(suffix):
            dest = dest[:cut_len]
            break
    else:
        break

print("YES" if not dest else "NO")


#!/usr/bin/env python3
import sys

PARTS = ["eraser", "erase", "dreamer", "dream"]
PARTS2 = []

def main():
    global PARTS2
    sys.setrecursionlimit(100000)
    S = input()

    for i in range(0, 4):
        for j in range(0, 4):
            PARTS2.append(PARTS[i] + PARTS[j])

    PARTS2 = PARTS2 + PARTS

    if judgeStr(S):
        print("YES")
    else:
        print("NO")

def judgeStr(target: str) -> bool:
    for item in PARTS2:
        if target.startswith(item):
            tempStr = target.replace(item, "", 1)
            if tempStr == "" or judgeStr(tempStr):
                return True

    return False

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
import sys

PARTS = ["eraser", "erase", "dreamer", "dream"]
# PARTS2 = []

def main():
    global PARTS2
    sys.setrecursionlimit(100000)
    S = input()

    # for i in range(0, 4):
    #     for j in range(0, 4):
    #         PARTS2.append(PARTS[i] + PARTS[j])

    # PARTS2 = PARTS2 + PARTS

    if judgeStr2(S):
        print("YES")
    else:
        print("NO")

def judgeStr2(target: str) -> bool:
    currentStr = target
    while currentStr != "":
        isNextOK = False
        for item in PARTS:
            if not currentStr.startswith(item):
                continue

            tempStr = currentStr.replace(item, "", 1)
            if tempStr == "":
                return True

            for item2 in PARTS:
                if tempStr.startswith(item2):
                    isNextOK = True
                    break

            if isNextOK:
                currentStr = tempStr
                break
        if isNextOK:
            continue
        else:
            break
    return currentStr == ""

def judgeStr(target: str) -> bool:
    for item in PARTS:
        if target.startswith(item):
            tempStr = target.replace(item, "", 1)
            if tempStr == "" or judgeStr(tempStr):
                return True

    return False

if __name__ == "__main__":
    main()


import sys
import numpy as np

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

class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parent = [i for i in range(n_nodes)]
        self.rank = [1] * n_nodes
        self.size = [1] * n_nodes

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def check(self, x, y):
        return self.find(x) == self.find(y)

    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()}

def main():
    N, K, L = map(int, input().split())
    Tree_road = UnionFind(N)
    Tree_train = UnionFind(N)
    for _ in range(K):
        p, q = map(int, input().split())
        Tree_road.unite(p - 1, q - 1)
    for _ in range(L):
        p, q = map(int, input().split())
        Tree_train.unite(p - 1, q - 1)
    road = Tree_road.get_members_dict()
    train = Tree_train.get_members_dict()
    answer = []
    for i in range(N):
        R = np.array(road[Tree_road.find(i)])
        T = np.array(train[Tree_train.find(i)])
        answer.append(len(np.intersect1d(R, T)))
    print(*answer, sep=" ")

if __name__ == "__main__":
    main()

import sys
from collections import defaultdict

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

class UnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parent = [i for i in range(n_nodes)]
        self.rank = [1] * n_nodes
        self.size = [1] * n_nodes

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.size[x] += self.size[y]
        else:
            self.parent[x] = y
            self.size[y] += self.size[x]
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def check(self, x, y):
        return self.find(x) == self.find(y)

    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()}

def main():
    N, K, L = map(int, input().split())
    Tree_road = UnionFind(N)
    Tree_train = UnionFind(N)
    for _ in range(K):
        p, q = map(int, input().split())
        Tree_road.unite(p - 1, q - 1)
    for _ in range(L):
        p, q = map(int, input().split())
        Tree_train.unite(p - 1, q - 1)
    DD = defaultdict(int)
    for i in range(N):
        DD[(Tree_road.find(i), Tree_train.find(i))] += 1
    answer = []
    for i in range(N):
        answer.append(DD[(Tree_road.find(i), Tree_train.find(i))])

    print(*answer, sep=" ")

if __name__ == "__main__":
    main()


from collections import defaultdict
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def root(par, x):
    if par[x] == x:
        return x
    else:
        return root(par, par[x])

def unite(rank, par, x, y):
    x = root(par, x)
    y = root(par, y)

    if x == y:
        return

    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

def main():
    N, K, L = map(int, readline().split())
    m = map(int, read().split())
    pq = list(zip(m, m))
    pq, rs = pq[:K], pq[K:]

    d_c = defaultdict(list)
    d_t = defaultdict(list)

    par = list(range(N))
    rank = [0] * N
    for p, q in pq:
        p -= 1
        q -= 1
        unite(rank, par, p, q)

    par_t = list(range(N))
    rank_t = [0] * N
    for r, s in rs:
        r -= 1
        s -= 1
        unite(rank_t, par_t, r, s)

    for i in range(N):
        par[i] = root(par, i)
        par_t[i] = root(par_t, i)
        d_c[par[i]].append(i)
        d_t[par_t[i]].append(i)

    for i in range(N):
        d_c[i] = d_c[par[i]]
        d_t[i] = d_t[par_t[i]]

    cnt = [0] * N
    for i in range(N):
        cnt[i] = len(list(set(d_c[i]) & set(d_t[i])))

    print(*cnt)

main()

from collections import defaultdict
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def root(par, x):
    if par[x] == x:
        return x
    else:
        return root(par, par[x])

def unite(rank, par, x, y):
    x = root(par, x)
    y = root(par, y)

    if x == y:
        return

    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1

def main():
    N, K, L = map(int, readline().split())
    m = map(int, read().split())
    pq = list(zip(m, m))
    pq, rs = pq[:K], pq[K:]

    par = list(range(N))
    rank = [0] * N
    for p, q in pq:
        p -= 1
        q -= 1
        unite(rank, par, p, q)

    par_t = list(range(N))
    rank_t = [0] * N
    for r, s in rs:
        r -= 1
        s -= 1
        unite(rank_t, par_t, r, s)

    pp = [(0, 0)] * N
    dd = defaultdict(list)
    for i in range(N):
        par[i] = root(par, i)
        par_t[i] = root(par_t, i)
        pp[i] = (par[i], par_t[i])
        dd[pp[i]].append(i)

    cnt = [0] * N
    for i in range(N):
        cnt[i] = len(dd[pp[i]])

    print(*cnt)

main()


from collections import defaultdict

N, K, L = map(int, input().split())

# union-findを実装
root_road = [-1] * N
root_train = [-1] * N

def find_road(x):
    if root_road[x] < 0:
        return x

    root_road[x] = find_road(root_road[x])
    return root_road[x]

def union_road(x, y):
    x = find_road(x)
    y = find_road(y)
    if x == y:
        return

    root_road[x] += root_road[y]
    root_road[y] = x

def same_road(x, y):
    return find_road(x) == find_road(y)

def find_train(x):
    if root_train[x] < 0:
        return x

    root_train[x] = find_train(root_train[x])
    return root_train[x]

def union_train(x, y):
    x = find_train(x)
    y = find_train(y)
    if x == y:
        return

    root_train[x] += root_train[y]
    root_train[y] = x

def same_train(x, y):
    return find_train(x) == find_train(y)

dc = defaultdict(list)
dt = defaultdict(list)
for _ in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    dc[p].append(q)
    dc[q].append(p)
    union_road(p, q)

for _ in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    dt[r].append(s)
    dt[s].append(r)
    union_train(r, s)

ans = [0] * N
for i in range(N):
    for j in range(i + 1, N):
        if same_road(i, j):
            if same_train(i, j) and ans[i] <= 1 and ans[j] <= 1:
                ans[i] = 2
                ans[j] = 2
            elif not same_train(i, j) and ans[i] != 2 and ans[j] != 2:
                ans[i] = 1
                ans[j] = 1

        if same_train(i, j):
            if same_road(i, j):
                ans[i] = 2
                ans[j] = 2
            elif not same_road(i, j) and ans[i] != 2 and ans[j] != 2:
                ans[i] = 1
                ans[j] = 1
print(*ans)

from collections import defaultdict

N, K, L = map(int, input().split())

# union-findを実装
root_road = [-1] * N
root_train = [-1] * N

def find_road(x):
    if root_road[x] < 0:
        return x

    root_road[x] = find_road(root_road[x])
    return root_road[x]

def union_road(x, y):
    x = find_road(x)
    y = find_road(y)
    if x == y:
        return

    root_road[x] += root_road[y]
    root_road[y] = x

def same_road(x, y):
    return find_road(x) == find_road(y)

def find_train(x):
    if root_train[x] < 0:
        return x

    root_train[x] = find_train(root_train[x])
    return root_train[x]

def union_train(x, y):
    x = find_train(x)
    y = find_train(y)
    if x == y:
        return

    root_train[x] += root_train[y]
    root_train[y] = x

def same_train(x, y):
    return find_train(x) == find_train(y)

dc = defaultdict(list)
dt = defaultdict(list)
for _ in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    dc[p].append(q)
    dc[q].append(p)
    union_road(p, q)

for _ in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    dt[r].append(s)
    dt[s].append(r)
    union_train(r, s)

# print(root_road, root_train)
dic = {}
for i in range(N):
    if (find_road(i), find_train(i)) not in dic:
        dic[(find_road(i), find_train(i))] = 1
        continue
    else:
        dic[(find_road(i), find_train(i))] += 1

ans = []
for i in range(N):
    ans.append(dic[(find_road(i), find_train(i))])
print(*ans)


class UnionFind3:
    def __init__(self, size):
        # 負の値はルート (集合の代表) で集合の個数
        # 正の値は次の要素を表す
        self.table = [-1 for _ in range(size)]

    # 集合の代表を求める
    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    # 併合
    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                # 小さいほうが個数が多い
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

n, k, l = map(int, input().split())
ufd, ufr = UnionFind3(n), UnionFind3(n)
for _ in range(k):
    p, q = map(int, input().split())
    ufd.union(p - 1, q - 1)
for _ in range(l):
    r, s = map(int, input().split())
    ufr.union(r - 1, s - 1)
result = [1] * n
for i in range(n):
    for j in range(i + 1, n):
        if ufd.find(i) == ufd.find(j) and ufr.find(i) == ufr.find(j):
            result[i] += 1
            result[j] += 1
print(*result)

from collections import defaultdict

class UnionFind3:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.root(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2

n, k, l = map(int, input().split())
ufd, ufr = UnionFind3(n), UnionFind3(n)
for _ in range(k):
    p, q = map(int, input().split())
    ufd.union(p - 1, q - 1)
for _ in range(l):
    r, s = map(int, input().split())
    ufr.union(r - 1, s - 1)
d = defaultdict(int)
for i in range(n):
    d[ufd.root(i), ufr.root(i)] += 1
print(*(d[ufd.root(i), ufr.root(i)] for i in range(n)))


a, b, c = str(input().split())
print(a[0], b[0], c[0])

[print(i[0], end="") for i in input().split()]
print()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03860/Python/s197123700.py", line 1, in <module>
    a, b, c = str(input().split())
ValueError: too many values to unpack (expected 3)


a, s, c = map(int, input().split())
print(a[0] + s[0] + c[0])

a, s, c = map(str, input().split())
print(a[0] + s[0] + c[0])

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03860/Python/s937750481.py", line 1, in <module>
    a, s, c = map(int, input().split())
ValueError: invalid literal for int() with base 10: 'AtCoder'


a, b, c = map(int, input().split())
print(a[0] + b[0] + c[0])

a, b, c = map(str, input().split())
print(a[0] + b[0] + c[0])

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03860/Python/s356083073.py", line 1, in <module>
    a, b, c = map(int, input().split())
ValueError: invalid literal for int() with base 10: 'AtCoder'


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

if len(A) % 2 == 0:
    A = A + [0]
# print('A', A)

ans = 0
for i in range(1, N, 2):
    total = A[i - 1] + A[i]
    diff = total - x
    if diff <= 0:
        continue
    v1 = min(A[i], diff)
    v2 = diff - v1
    A[i] -= v1
    A[i - 1] -= v2
    ans += v1 + v2
    # print('A', A)
print(ans)

S = input().split()
ans = f"A{S[1][0]}C"
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03860/Python/s510991095.py", line 1, in <module>
    N, x = map(int, input().split())
ValueError: invalid literal for int() with base 10: 'AtCoder'


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

res = 0
for n in range(a, b + 1):
    if n % x == 0:
        res += 1
print(res)

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

qa = a // x
qb = b // x
ra = a % x
rb = b % x
res = qb - qa
if ra == 0:
    res += 1

print(res)


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

ans = 0
for i in range(a, b + 1):
    if i % x == 0:
        ans += 1

print(ans)

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

ans = b // x - (a - 1) // x

print(ans)


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

if x % a == 0:
    print((b - a + 1) // x + 1)
else:
    print((b - a + 1) // x)

a, b, x = map(int, input().split())
print(b // x - (a - 1) // x)


a, b, x = tuple(int(x) for x in input().split())

y = -1
for i in range(a, b + 1):
    if i % x == 0:
        y = i
        break

if y == -1:
    ans = 0
else:
    ans = (b - y) // x + 1

print(ans)

a, b, x = tuple(int(x) for x in input().split())

if a == 0:
    y = 0
else:
    y = x * ((a - 1) // x + 1)

if y == -1:
    ans = 0
else:
    ans = (b - y) // x + 1

print(ans)


a, b, x = map(int, input().split())
while b % x:
    b -= 1
if a == 0:
    print(b // x + 1)
else:
    print((b // x) - ((a - 1) // x))

a, b, x = map(int, input().split())
if a == 0:
    print(b // x + 1)
else:
    print((b // x) - ((a - 1) // x))


a, b, x = map(int, input().split())
int_list = [i for i in range(a, b + 1)]
counter = 0
for i in range(len(int_list)):
    if int_list[i] % x == 0:
        counter += 1

print(counter)


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

start = a if a >= x else x
end = b
while start <= end:
    if start % x == 0:
        break
    if start == end:
        print(0)
        exit()
    start += 1

result = (end - start) // x + 1
if a == 0:
    result += 1
print(result)

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

start = 0
end = b
if a > x:
    if a % x == 0:
        start = a
    else:
        start = x * (a // x + 1)
else:
    start = x

if start > end:
    result = 0
else:
    result = (end - start) // x + 1
if a == 0:
    result += 1
print(result)


# coding: utf-8

a, b, x = map(int, input().split(" "))

n = b - a - 1
# coding: utf-8

a, b, x = map(int, input().split(" "))

n = b - a
if a % x == 0 or b % x == 0:
    print(n // x + 1)
else:
    print(n // x)

# coding: utf-8

a, b, x = map(int, input().split(" "))

def f(n):
    if n == -1:
        return 0
    else:
        return n // x + 1

print(f(b) - f(a - 1))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03861/Python/s822708116.py", line 8, in <module>
    a, b, x = map(int, input().split(" "))
EOFError: EOF when reading a line


# 非負の整数a, b(a ≤ b)と 、 正の整数xが与えられます 。
# a以上b以下の整数のうち 、 xで割り切れるものの個数を求めてください 。
a, b, x = [int(i) for i in input().split()]

cou = 0
for i in range(a, b + 1):
    if i % x == 0:
        cou += 1

print(cou)

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

def ret(n):
    if n >= 0:
        return n // x + 1
    else:
        return 0

print(ret(b) - ret(a - 1))


def resolve():
    a, b, x = map(int, input().split())

    cnt = 0
    for i in range(a, b + 1):
        if i % x == 0:
            cnt += 1

    print(cnt)

resolve()

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    a, b, x = map(int, input().split())

    print(b // x - (a - 1) // x)

resolve()


a, b, x = map(int, input().split())
cnt = 0
for i in range(a, b + 1):
    if i % x == 0:
        cnt += 1
print(cnt)

a, b, x = map(int, input().split())
zenbu = b // x + 1
tmp = 0
if a % x == 0:
    tmp += 1
bubun = a // x + 1
ans = zenbu - bubun + tmp
print(ans)


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

for i in range(a, b + 1):
    if i % x == 0:
        ans += 1
print(ans)


# input
a, b, x = map(int, input().split())

ans = 0

for i in range(a, b + 1):
    if i % x == 0:
        ans += 1

print(ans)

# input
import math

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

# 0,...,nの中でxで割り切れるのは
# 0, x, 2x,..., (n // x)* x の(n //x) + 1個

if a % x == 0:
    ans = ((b // x) + 1) - ((a // x) + 1) + 1
    print(ans)
else:
    ans = ((b // x) + 1) - ((a // x) + 1)
    print(ans)


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

cnt = 0
for i in range(a, b + 1):
    if i % x == 0:
        cnt += 1

print(cnt)

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

if a % x == 0:
    ans = (b // x) - (a // x) + 1
else:
    ans = (b // x) - (a // x)

print(ans)


n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    while a[i] + a[i + 1] > x:
        if a[i + 1] != 0:
            ans += 1
            a[i + 1] -= 1
        else:
            ans += 1
            a[i] -= 1
print(ans)

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


# -*- coding: utf-8

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

if a[0] > x:
    count += a[0] - x
    a[0] = x

for i in range(len(a) - 1):

    while a[i] + a[i + 1] > x:
        a[i + 1] -= 1
        count += 1
print(count)

# -*- coding: utf-8

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

count = max(0, a[0] - x)
a[0] = min(a[0], x)

for i in range(len(a) - 1):
    if a[i] + a[i + 1] > x:
        tmp_num = max(0, a[i] + a[i + 1] - x)
        count += tmp_num
        a[i + 1] -= tmp_num
print(count)


n, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(n - 2):
    if a[i] + a[i + 1] > x:
        count += a[i] + a[i + 1] - x
        a[i + 1] = x - a[i]
if a[n - 1] + a[n] > x:
    count += a[n - 1] + a[n] - x
print(int(count))

n, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(n - 1):
    if a[i] + a[i + 1] > x:
        count += a[i] + a[i + 1] - x
        if a[i + 1] >= a[i] + a[i + 1] - x:
            a[i + 1] = x - a[i]
        else:
            a[i + 1] = 0
            a[i] = x
print(int(count))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03862/Python/s859205699.py", line 8, in <module>
    if a[n - 1] + a[n] > x:
IndexError: list index out of range


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

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

ans = 0

for i in range(n - 1):
    while a[i] + a[i + 1] > x:
        a[i + 1] -= 1
        ans += 1

print(ans)

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

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


#!/usr/bin/env python
# -*- coding:utf-8 -*-

s = input()
if len(s) % 2 == 0 ^ s[0] == s[-1]:
    print("Second")
else:
    print("First")

#!/usr/bin/env python
# -*- coding:utf-8 -*-

s = input()
if (len(s) % 2 == 0) and (s[0] == s[-1]):
    print("First")
elif (len(s) % 2 == 0) or (s[0] == s[-1]):
    print("Second")
else:
    print("First")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03865/Python/s528270335.py", line 5, in <module>
    if len(s) % 2 == 0 ^ s[0] == s[-1]:
TypeError: unsupported operand type(s) for ^: 'int' and 'str'


a, b, c = map(int, input().split())
print((a * b / (a + b)))

a, b = map(int, input().split())
print((a * b / (a + b)))

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


from itertools import accumulate
import bisect

N = int(input())
li = [i for i in range(1, N + 1)]
acc_list = list(accumulate(li))
index = bisect.bisect_left(acc_list, N)
garbage = acc_list[index] - N
for i in range(index + 1):
    if li[i] != garbage:
        print(li[i])

N = int(input())
li = [i for i in range(1, N + 1)]
acc = 0
index = 0
for i in range(N):
    acc += li[i]
    if acc >= N:
        index = i
        break
garbage = acc - N
for i in range(index + 1):
    if li[i] != garbage:
        print(li[i])


# 最大値の最小値、ちょうどn/2臭い
# あとは帳尻合わせが効きそう
# 14とかだと7+4+2+1 （7+5+2でも7+4+3でもいい
# かと思いきや 1+2+3+4+5で15いくので, 5+4+3+2でよかった
# 10^7なので毎回足してもどうせ間に合う。これで答えの集合のうち最大値は確定
# あとはそれでnを引いて0になるまで

n = int(input())
ans = []
cur = 0

while cur != n:
    tmp = 0
    for i in range(1, n + 1 - cur):
        if i + tmp >= n - cur:
            tmp = i
            break
        tmp += i
    ans.append(tmp)
    cur += tmp
    # print("tmp = {}, cur = {}".format(tmp, cur))
# print(ans)
for a in ans:
    print(a)

# 最大値の最小値、ちょうどn/2臭い
# あとは帳尻合わせが効きそう
# 14とかだと7+4+2+1 （7+5+2でも7+4+3でもいい
# かと思いきや 1+2+3+4+5で15いくので, 5+4+3+2でよかった
# 10^7なので毎回足してもどうせ間に合う。これで答えの集合のうち最大値は確定
# あとはそれでnを引いて0になるまで -> これだと間に合わない

n = int(input())
ans = []
cur = 0

while cur != n:
    tmp = 0
    for i in range(1, n + 1 - cur):
        if i + tmp >= n - cur:
            tmp = i
            break
        tmp += i
    ans.append(tmp)
    cur += tmp
    # print("tmp = {}, cur = {}".format(tmp, cur))
# print(ans)
for a in ans:
    print(a)


#!/usr/bin/env python3
N = int(input())

sum = 0
m = 0
for i in range(1, 10**3 + 1):
    sum += i
    if sum >= N:
        m = i
        break

sum = N
for i in range(1, m + 1)[::-1]:
    if sum - i >= 0:
        sum -= i
        print(i)

#!/usr/bin/env python3
class UnionFind:
    def __init__(self, size):
        self.table = [-1] * size

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s2] < self.table[s1]:
                s1, s2 = s2, s1
            self.table[s1] += self.table[s2]
            self.table[s2] = s1
        return s1 != s2

N, M = map(int, input().split())
uf = UnionFind(N + M)
for i in range(N):
    L = [int(x) - 1 for x in input().split()]
    L[0] += 1
    for j in range(L[0]):
        uf.union(L[j + 1], M + i)

ans = True
for i in range(N):
    if uf.find(M + i) != uf.find(M):
        ans = False
print(("NO", "YES")[ans])

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


# 右と下の両方に#があったら終了だしどちらにもなくても終了
# なんやこのクソみたいな実装は

h, w = map(int, input().split())
table = []
for _ in range(h):
    table.append(input())

flag = False
pos = [0, 0]
while True:
    if pos == [h - 1, w - 1]:
        flag = True
        break
    if h <= pos[0] or w <= pos[1]:
        break
    if (
        pos[0] < h - 1
        and pos[1] < w - 1
        and table[pos[0] + 1][pos[1]] == "#"
        and table[pos[0]][pos[1] + 1] == "#"
    ):
        break
    if pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0] + 1][pos[1]] == "#":
        pos[0] += 1
        continue
    elif pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#":
        pos[1] += 1
        continue
    if pos[0] == h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#":
        pos[1] += 1
        continue
    elif pos[0] < h - 1 and pos[1] == w - 1 and table[pos[0] + 1][pos[0]] == "#":
        pos[0] += 1
        continue
    else:
        break

print("Possible" if flag else "Impossible")

# 右と下の両方に#があったら終了だしどちらにもなくても終了
# なんやこのクソみたいな実装は

h, w = map(int, input().split())
table = []
sharp = 0
for _ in range(h):
    get = input()
    table.append(get)
    sharp += get.count("#")

flag = False
pos = [0, 0]
path = 0
while True:
    if pos == [h - 1, w - 1]:
        path += 1
        flag = True
        break
    if h <= pos[0] or w <= pos[1]:
        break
    if (
        pos[0] < h - 1
        and pos[1] < w - 1
        and table[pos[0] + 1][pos[1]] == "#"
        and table[pos[0]][pos[1] + 1] == "#"
    ):
        break
    if pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0] + 1][pos[1]] == "#":
        pos[0] += 1
        path += 1
        continue
    elif pos[0] < h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#":
        pos[1] += 1
        path += 1
        continue
    if pos[0] == h - 1 and pos[1] < w - 1 and table[pos[0]][pos[1] + 1] == "#":
        pos[1] += 1
        path += 1
        continue
    elif pos[0] < h - 1 and pos[1] == w - 1 and table[pos[0] + 1][pos[1]] == "#":
        pos[0] += 1
        path += 1
        continue
    else:
        break

print("Possible" if flag and path == sharp else "Impossible")


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

r = {}
for i in range(N):
    r[p_list[i]] = i + 1

a_list = []
b_list = []

for i in range(1, N + 1):
    a_list.append(30000 * i)
    b_list.append(30000 * (N - i) + r[i - 1])

print(*a_list)
print(*b_list)

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

r = {}
for i in range(N):
    r[p_list[i]] = i + 1

a_list = []
b_list = []
for i in range(1, N + 1):
    a_list.append(30000 * i)
    b_list.append(30000 * (N - i) + r[i])

print(*a_list)
print(*b_list)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03938/Python/s221768182.py", line 13, in <module>
    b_list.append(30000 * (N - i) + r[i - 1])
KeyError: 0


from decimal import Decimal

n, d, x = map(Decimal, input().split())
print((d + (2 * n - 1) * x / 2) * sum((n - i) / (i + 1) for i in range(int(n))))

def solve(n, d, x):
    ans = 0
    while n:
        ans += d + (2 * n - 1) * x / 2
        d = ((n + 1) * d + 5 * x / 2) / n
        x *= (n + 2) / n
        n -= 1
    return ans

print("{:.10f}".format(solve(*map(float, input().split()))))


packs = list(map(int, input().split())).sort()
if packs[2] - packs[1] == packs[0]:
    print("Yes")
else:
    print("No")

packs = sorted(list(map(int, input().split())))
if packs[2] - packs[1] == packs[0]:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03943/Python/s546754965.py", line 2, in <module>
    if packs[2] - packs[1] == packs[0]:
TypeError: 'NoneType' object is not subscriptable


# 3個のパックにそれぞれ、a,b,c個のキャンディーが入っている
# キャンディーを2人に分ける際、個数が等しくなるか判定

# 入力
a = int(input())
b = int(input())
c = int(input())

# 処理
if a == b + c or b == a + c or c == a + b:
    print("Yes")
else:
    print("No")

# 3個のパックにそれぞれ、a,b,c個のキャンディーが入っている
# キャンディーを2人に分ける際、個数が等しくなるか判定

# 入力
a, b, c = map(int, input().split())

# 処理
if a == b + c or b == a + c or c == a + b:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03943/Python/s124699189.py", line 5, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '10 30 20'


from functools import reduce
from operator import add

A = list(map(int, input().split()))
print("Yes" if max(A) == reduce(add, [i for i in A if i != max(A)]) else "No")

from functools import reduce
from operator import add

A = list(map(int, input().split()))
M = max(A)
T = [i for i in A if i != M]
if len(T) == 0:
    print("No")
else:
    print("Yes" if M == reduce(add, T) else "No")


w, h, n = [int(i) for i in input().split()]
w2, h2 = w, h
wb, hb = [False] * w, [False] * h
for i in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1 and not wb[x]:
        w2 -= x
        wb[x] = True
    elif a == 2 and not wb[x]:
        w2 -= w - x
        wb[x] = True
    elif a == 3 and not hb[y]:
        h2 -= y
        hb[y] = True
    elif a == 4 and not hb[y]:
        h2 -= h - y
        hb[y] = True
ans = w2 * h2
print(ans if ans > 0 else 0)

w, h, n = [int(i) for i in input().split()]
W = set(range(w))
H = set(range(h))
for i in range(n):
    x, y, a = [int(i) for i in input().split()]
    if a == 1:
        W &= set(range(x, w))
    elif a == 2:
        W &= set(range(0, x))
    elif a == 3:
        H &= set(range(y, h))
    elif a == 4:
        H &= set(range(0, y))
print(len(W) * len(H))


def solve(n):
    if n == 1:
        return 0
    else:
        if S[n - 2] == S[n - 1]:
            return solve(n - 1)
        else:
            return solve(n - 1) + 1

if __name__ == "__main__":
    S = input()
    first_s = S[0]
    S = [1 if first_s == s else 0 for s in S]

    print(solve(len(S)))

import threading
import sys

def main():
    def solve(n):
        if n == 1:
            return 0
        else:
            if S[n - 2] == S[n - 1]:
                return solve(n - 1)
            else:
                return solve(n - 1) + 1

    S = input()
    first_s = S[0]
    S = [1 if first_s == s else 0 for s in S]

    print(solve(len(S)))

if __name__ == "__main__":

    sys.setrecursionlimit(1024 * 1024 * 2)
    threading.stack_size(128 * 1024 * 1024 * 2)
    threading.Thread(target=main).start()


s = input()
ans = 0
while len(set(s)) == 2:
    c = s[0]
    for i in range(len(s)):
        if s[i] != c:
            idx = i
            break
    s = s[i:]
    ans += 1
print(ans)

s = input()
ans = 0
while len(s):
    c = s[0]
    for i in range(len(s)):
        if s[i] != c:
            idx = i
            break
        idx2 = i
    if idx2 == len(s) - 1:
        break
    s = s[idx:]
    ans += 1

print(ans)


S = input()

# 1以上の同じ色の石の列は1つに集約できる
T = S[0]
prev = T
for s in S[1:]:
    if prev != s:
        T += s
        prev = s

print(len(T) - 1)

S = input()

# 1以上の同じ色の石の列は1つに集約できる
cnt = 1
prev = S[0]
for s in S[1:]:
    if prev != s:
        cnt += 1
        prev = s

print(cnt - 1)


N, T = map(int, input().split())
A = [int(Ai) for Ai in input().split()]
B = [0] * len(A)
for i in range(1, len(A)):
    B[i] = A[i] - min(A[:i])
print(sum([Bi == max(B) for Bi in B]))

N, T = map(int, input().split())
A = [int(Ai) for Ai in input().split()]
Amin = A[0]
Bmax = 0
count = 0
for i in range(1, len(A)):
    Amin = min(A[i - 1], Amin)
    Bi = A[i] - Amin
    if Bmax == Bi:
        count += 1
    elif Bmax < Bi:
        Bmax = Bi
        count = 1
print(count)


n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
min = 1000000000
min_c = 0
max_dif = 0
max_dif_c = 0
for i in range(n):
    if a[i] < min:
        min = a[i]
        min_c = 1
        continue
    elif a[i] == min:
        min_c += 1
        continue
    if a[i] - min > max_dif:
        max_dif = a[i] - min
        max_dif_c = 1
    elif a[i] - min == max_dif:
        max_dif_c += 1
c = min([min_c, max_dif_c])
print(str(c))

n, t = list(map(int, input().split()))
a = list(map(int, input().split()))
min_a = 1000000000
max_dif = 0
max_dif_c = 0
for i in range(n):
    if a[i] < min_a:
        min_a = a[i]
    elif a[i] - min_a > max_dif:
        max_dif = a[i] - min_a
        max_dif_c = 1
    elif a[i] - min_a == max_dif:
        max_dif_c += 1
print(str(max_dif_c))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03946/Python/s626493298.py", line 20, in <module>
    c = min([min_c, max_dif_c])
TypeError: 'int' object is not callable


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

n = int(input())
s = list(input())
t = list(input())

for i in range(n):
    match = True
    for j in range(n):
        if i + j < n:
            if s[i + j] != t[j]:
                match = False
    if match:
        if i == 0:
            print(n)
        else:
            print(n + i)
        break
else:
    print(len(n * 2))

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

n = int(input())
s = list(input())
t = list(input())

for i in range(n):
    match = True
    for j in range(n):
        if i + j < n:
            if s[i + j] != t[j]:
                match = False
    if match:
        if i == 0:
            print(n)
        else:
            print(n + i)
        break
else:
    print(n * 2)


s = input()
print("Yes" if 0 <= s.index("C") < s.rindex("F") else "No")

s = input()
print("Yes" if 0 <= s.find("C") < s.rfind("F") else "No")


k, t = list(map(int, input().split()))
nums = list(map(int, input().split()))

m = max(nums)
rest = k - m
if max - rest - 1 > 0:
    print(max - rest - 1)
else:
    print(0)

k, t = list(map(int, input().split()))
nums = list(map(int, input().split()))

m = max(nums)
rest = k - m
if m - rest - 1 > 0:
    print(m - rest - 1)
else:
    print(0)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03958/Python/s472647627.py", line 6, in <module>
    if max - rest - 1 > 0:
TypeError: unsupported operand type(s) for -: 'builtin_function_or_method' and 'int'


a, b, c = map(int, (input()))

if a == b and a == c:
    print(1)
elif a == b or a == c or b == c:
    print(2)
else:
    print(3)

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

if a == b and a == c:
    print(1)
elif a == b or a == c or b == c:
    print(2)
else:
    print(3)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03962/Python/s879938212.py", line 1, in <module>
    a, b, c = map(int, (input()))
ValueError: invalid literal for int() with base 10: ' '


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03962/Python/s122319226.py", line 1, in <module>
    print(len(set([input().split()])))
TypeError: unhashable type: 'list'


from collections import Counter

print(len(Counter([int(input()) for i in range(3)])))

# A
from collections import Counter

print(len(Counter([int(i) for i in input().split()])))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03962/Python/s782636979.py", line 3, in <module>
    print(len(Counter([int(input()) for i in range(3)])))
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03962/Python/s782636979.py", line 3, in <listcomp>
    print(len(Counter([int(input()) for i in range(3)])))
ValueError: invalid literal for int() with base 10: '3 1 4'


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03962/Python/s798226179.py", line 1, in <module>
    print(len({input().split()}))
TypeError: unhashable type: 'list'


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

ans = set(n)
print(ans.count)

n = list(int(x) for x in input().split(" "))

ans = set(n)
print(len(ans))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03962/Python/s857335382.py", line 4, in <module>
    print(ans.count)
AttributeError: 'set' object has no attribute 'count'


a, b, c = map(int, input().split())
print(len(set(a, b, c)))

a, b, c = map(int, input().split())
print(len(set([a, b, c])))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03962/Python/s707893021.py", line 2, in <module>
    print(len(set(a, b, c)))
TypeError: set expected at most 1 argument, got 3


from sys import stdin

a = map((int(x) for x in stdin.readline().split()))

print(len(a))

from sys import stdin

a = set((int(x) for x in stdin.readline().split()))

print(len(a))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03962/Python/s114624251.py", line 3, in <module>
    a = map((int(x) for x in stdin.readline().split()))
TypeError: map() must have at least two arguments.


n = int(input())
votes = [list(map(int, input().split())) for _ in range(n)]

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = min(curr_a // v1, curr_b // v2)

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print(curr_a + curr_b)

n = int(input())
votes = [list(map(int, input().split())) for _ in range(n)]

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = max(curr_a // v1, curr_b // v2)

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print(curr_a + curr_b)


n = int(input())
ratio = [list(map(int, input().split())) for _ in range(n)]

t_voted, a_voted = ratio[0][0], ratio[0][1]
for t, a in ratio[1:]:
    tt, aa = t, a
    while tt < t_voted or aa < a_voted:
        tt += t
        aa += a
    t_voted, a_voted = tt, aa

print(t_voted + a_voted)

from decimal import Decimal
from math import ceil

n = int(input())
ratio = [list(map(int, input().split())) for _ in range(n)]

t_voted = a_voted = 1
for t, a in ratio:
    val = max(ceil(Decimal(t_voted) / Decimal(t)), ceil(Decimal(a_voted) / Decimal(a)))
    t_voted = t * val
    a_voted = a * val

print(t_voted + a_voted)


import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
vote = [1, 1]
for i in range(n):
    t, a = [int(i) for i in input().split()]
    k = max(math.ceil(vote[0] / t), math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    if sum(vote) > 10**10:
        t[1000000000] = 1
    # print("i:{} vote:{}".format(i, vote))
print(vote[0] + vote[1])

import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
vote = [1, 1]
for i in range(n):
    t, a = [int(i) for i in input().split()]
    if vote[0] % t == 0:
        k = vote[0] // t
    else:
        k = vote[0] // t + 1
    if vote[1] % a == 0:
        k = max(k, vote[1] // a)
    else:
        k = max(k, vote[1] // a + 1)
    # k = max(math.ceil(vote[0] / t), math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    # a / b + (a % b == 0 ? 0: 1)
    # print("i:{} vote:{}".format(i, vote))
print(vote[0] + vote[1])


n = int(input())
ta = [tuple(int(x) for x in input().split()) for _ in range(n)]

a = 0
b = 0
for x, y in ta:
    if x >= a and y >= b:
        a = x
        b = y
    else:
        temp = 2
        while x * temp < a or y * temp < b:
            temp += 1
        a = x * temp
        b = y * temp

print(a + b)

n = int(input())
ta = [tuple(int(x) for x in input().split()) for _ in range(n)]

a = 0
b = 0
for x, y in ta:
    if x >= a and y >= b:
        a = x
        b = y
    else:
        temp = max(a // x, b // y)
        while x * temp < a or y * temp < b:
            temp += 1
        a = x * temp
        b = y * temp

print(a + b)


N = int(input())
T = []
A = []

for _ in range(N):
    t, a = list(map(int, input().split()))
    T.append(t)
    A.append(a)

t_num = 1
a_num = 1
for i in range(N):
    # TAは常にn倍ずつ増加していく
    n = 1
    while T[i] * n < t_num or A[i] * n < a_num:
        n += 1
    t_num = T[i] * n
    a_num = A[i] * n

print(t_num + a_num)

from math import ceil

N = int(input())
T = []
A = []

for _ in range(N):
    t, a = list(map(int, input().split()))
    T.append(t)
    A.append(a)

t_num = T[0]
a_num = A[0]
for i in range(1, N):
    tn = (t_num + T[i] - 1) // T[i]
    an = (a_num + A[i] - 1) // A[i]
    n = max(tn, an)
    t_num = T[i] * n
    a_num = A[i] * n

print(t_num + a_num)


a = int(input())
d = e = 0
for i in range(a):
    b, c = map(int, input().split())
    if i == 0:
        d = b
        e = c
    else:
        f = b
        g = c
        while True:
            if d <= f and e <= g:
                d = f
                e = g
                break
            else:
                f += b
                g += c
print(d + e)

a = int(input())
d = e = 0
for i in range(a):
    b, c = map(int, input().split())
    if i == 0:
        d = b
        e = c
    else:
        if d <= b and e <= c:
            d = b
            e = c
        else:
            h = max((b + d - 1) // b, (c + e - 1) // c)
            d = b * h
            e = c * h
print(d + e)


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

# a: 国内の学生
# b: 海外の学生
# c: その他
# i番idxはi位

# # 海外の学生
# foregin_list = []
# for i, c in enumerate(s):
#     if c == "b":
#         foregin_list.append(i)

passes_num = 0
foregin_list = []
thredshould = a + b
for i, c in enumerate(s):
    if c == "c":
        print("No")
    elif c == "a":
        if passes_num < thredshould:
            passes_num += 1
            print("Yes")
        else:
            print("No")
    else:
        foregin_list.append(i)
        if passes_num < thredshould and foregin_list.index(i) + 1 <= b:
            passes_num += 1
            print("Yes")
        else:
            print("No")

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

# a: 国内の学生
# b: 海外の学生
# c: その他
# i番idxはi位

passes_num = 0  # 通過した人の数
foregin_rank = 1  # 海外の学生の中での順位
thredshould = a + b
for c in s:
    if c == "c":
        print("No")
    elif c == "a":
        if passes_num < thredshould:
            passes_num += 1
            print("Yes")
        else:
            print("No")
    else:
        if passes_num < thredshould and foregin_rank <= b:
            passes_num += 1
            foregin_rank += 1
            print("Yes")
        else:
            print("No")


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

HP = []
for p in range(1, 101, 1):
    P = [p] * len(X)
    delta = sum([(i - j) ** 2 for (i, j) in zip(X, P)])
    HP.append(delta)

print(min(HP))

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

AB = A + B

count_all = 0
count_abroad = 0
for i in range(N):
    if S[i] == "a" and count_all < AB:
        count_all += 1
        print("Yes")

    elif S[i] == "b" and count_abroad < B and count_all < AB:
        count_all += 1
        count_abroad += 1
        print("Yes")

    else:
        print("No")

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


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

answer = [0] * len(S)
b_list = []
for idx, moji in enumerate(S):
    if moji == "a" and sum(answer) < A + B:
        answer[idx] = 1
        print("Yes")
        continue
    elif moji == "b":
        b_list.append(1)
        if sum(answer) < A + B and sum(b_list) <= B:
            answer[idx] = 1
            print("Yes")
            continue
    print("No")

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

answer = 0
b_list = 0
for idx, moji in enumerate(S):
    if moji == "a" and answer < A + B:
        answer += 1
        print("Yes")
        continue
    elif moji == "b":
        b_list += 1
        if answer < A + B and b_list <= B:
            answer += 1
            print("Yes")
            continue
    print("No")


X = input()

while X.count("ST"):
    X = X.replace("ST", "")

print(len(X))

X = input()

ans = ["foo"]
for i in range(len(X)):
    ans.append(X[i])
    if ans[-2] == "S" and ans[-1] == "T":
        ans.pop()
        ans.pop()

print(len(ans) - 1)


X = input()
X_length = len(X)
change = True
while change:
    X = X.replace("ST", "", 1)
    change = len(X) != X_length
    X_length = len(X)
print(X_length)

X = input()
stack = []
for s in X:
    if s == "S":
        stack.append(s)
    elif s == "T":
        if len(stack) == 0 or stack[-1] == "T":
            stack.append(s)
        else:
            stack.pop(-1)
print(len(stack))


# coding: utf-8
# Your code here!

X = list(input())
num = len(X)
stack = []

for i in X:
    if i == "S":
        stack.append(i)
    else:
        if stack[-1] == "T" or stack[0] == "":
            stack.append(i)
        else:
            stack.pop()
print(len(stack))

# coding: utf-8
# Your code here!

X = list(input())
num = len(X)
stack = []

for i in X:
    if i == "S":
        stack.append(i)
    else:
        if stack == [] or stack[-1] == "T":
            stack.append(i)
        else:
            stack.pop()
print(len(stack))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03986/Python/s803491766.py", line 12, in <module>
    if stack[-1] == "T" or stack[0] == "":
IndexError: list index out of range


_x = input()
x = []
for i in _x:
    x.append(i)
count = 0
i = 0
while i < len(x):
    # print("i:{} x:{}".format(i, x))
    if i < len(x) - 1 and x[i] == "S" and x[i + 1] == "T":
        del x[i]
        del x[i]
        if i > 0:
            i -= 1
        continue
    else:
        count += 1
        i += 1
print(len(x))

_x = input()
x = []
for i in _x:
    x.append(i)
count = 0

# 今まで確認してきたものはスタックに入れる
# スタックの頂上がSで次の入力がTならスタックをポップ
stack = []
i = 0
while i < len(x):
    if len(stack) > 0 and stack[-1] == "S" and x[i] == "T":
        del stack[-1]
    else:
        stack.append(x[i])
    i += 1
print(len(stack))
# print(stack)


import sys
from operator import itemgetter

class BinaryIndexedTreeCustom:
    def __init__(self, n, init, func):
        self.size = n
        self.tree = [init] * (n + 1)
        self.depth = n.bit_length()
        self.init = init
        self.func = func

    def get(self, i):
        s = self.init
        tr = self.tree
        f = self.func
        while i > 0:
            s = f(s, tr[i])
            i -= i & -i
        return s

    def put(self, i, x):
        n = self.size
        tr = self.tree
        f = self.func
        while i <= n:
            y = tr[i]
            tr[i] = f(tr[i], x)
            if y == tr[i]:
                break
            i += i & -i

n, *aaa = map(int, sys.stdin.buffer.read().split())
bit1 = BinaryIndexedTreeCustom(n, 0, max)
bit2 = BinaryIndexedTreeCustom(n, n + 1, min)
aaa_with_index = list(enumerate(aaa, start=1))
aaa_with_index.sort(key=itemgetter(1))
ans = 0
for i, a in aaa_with_index:
    li = bit1.get(i)
    ri = bit2.get(n - i)
    ans += a * (i - li) * (ri - i)
    bit1.put(i, i)
    bit2.put(n + 1 - i, i)
print(ans)

import sys
from operator import itemgetter

n, *aaa = map(int, sys.stdin.buffer.read().split())
aaa_with_index = list(enumerate(aaa, start=1))
aaa_with_index.sort(key=itemgetter(1), reverse=True)
left = list(range(-1, n + 1))
right = list(range(1, n + 3))
ans = 0
for i, a in aaa_with_index:
    li = left[i]
    ri = right[i]
    ans += a * (i - li) * (ri - i)
    left[ri] = li
    right[li] = ri

print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
opp_list = []
for i in range(1, n + 1):
    opp = a[a[i - 1] - 1]
    if i == opp and i not in opp_list:
        opp_list.append(a[i - 1])
        ans += 1
print(ans)

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


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

like = {}
ans = 0

for i, r in enumerate(a):
    like[i] = r
    if like.get(r, default=0) == i:
        ans += 1

print(ans)

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

like = {}
ans = 0

for i, r in enumerate(a):
    like[i + 1] = r
    if r in like and like[r] == i + 1:
        ans += 1

print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03993/Python/s578229972.py", line 9, in <module>
    if like.get(r, default=0) == i:
TypeError: dict.get() takes no keyword arguments


size = int(input())

r_str = input().split()

rabs = []
for r in r_str:
    rabs.append(int(r) - 1)

visited = []
t = 0

for i in range(0, size):
    if rabs[rabs[i]] == i and (i not in visited):
        visited.append(i)
        visited.append(rabs[i])
        t += 1

print(t)

size = int(input())

r_str = input().split()

rabs = []
for r in r_str:
    rabs.append(int(r) - 1)

# visited = []
t = 0

for i in range(0, size):
    if rabs[rabs[i]] == i and (not rabs[i] < i):
        # visited.append(i)
        # visited.append(rabs[i])
        t += 1

print(t)


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

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

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03993/Python/s832397420.py", line 4, in <module>
    for i in range(N):
TypeError: 'map' object cannot be interpreted as an integer


# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

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

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

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


from collections import Counter

n = int(input())
a = list(map(int, input().split()))
pair = []
cp = [None]
for i, tgt in enumerate(a):
    cp.clear()
    if a.index(tgt) == i:
        cp = [str(a[i]), str(i + 1)]
        cp.sort()
        cpj = "".join(cp)
        pair.append(cpj)

pcnt = Counter(pair)
pcv = list(pcnt.values())
print(pcv.count(2))

n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i, tgt in enumerate(a, 1):
    if a[tgt - 1] == i:
        cnt += 1
print(cnt // 2)


def main():
    s = input()
    K = int(input())
    a = ord("a")
    code = [ord(c) - a for c in s]
    for i in range(len(s)):
        x = 26 - code[i] % 26
        if x <= K:
            code[i] = 0
            K -= x
    code[-1] = code[-1] + K % 26
    ans = ""
    for x in code:
        ans += chr(a + x)
    print(ans)

if __name__ == "__main__":
    main()

def main():
    s = input()
    K = int(input())
    a = ord("a")
    code = [ord(c) - a for c in s]
    for i in range(len(s)):
        x = (26 - code[i]) % 26
        if x <= K:
            code[i] = 0
            K -= x
    code[-1] = code[-1] + K % 26
    ans = "".join([chr(a + x) for x in code])
    print(ans)

if __name__ == "__main__":
    main()


alphabet = "abcdefghijklmnopqrstuvwxyz"
a_len = len(alphabet)
table = {c: idx for idx, c in enumerate(alphabet)}

s = input()
k = int(input())

ans = ""
for i in range(len(s[:-1])):
    gap = a_len - table[s[i]]
    if gap <= k:
        ans += "a"
        k -= gap
    elif k == 0:
        ans += s[i:-1]
    else:
        ans += s[i]

ans += alphabet[(table[s[-1]] + k) % a_len]
print(ans)

import sys

sys.setrecursionlimit(10**7)
rl = sys.stdin.readline

def solve():
    s = rl().rstrip()
    K = int(rl())

    ans = []
    for si in s:
        if si == "a":
            ans.append("a")
            continue
        cnt = ord("z") - ord(si) + 1
        if cnt <= K:
            ans.append("a")
            K -= cnt
        else:
            ans.append(si)

    ans[-1] = chr(ord("a") + (ord(ans[-1]) - ord("a") + K % 26) % 26)
    print("".join(ans))

if __name__ == "__main__":
    solve()


a, b, h = [input() for _ in range(3)]
print(int((a + b) * h / 2))

a, b, h = [int(input()) for _ in range(3)]
print(int((a + b) * h / 2))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03997/Python/s114340775.py", line 2, in <module>
    print(int((a + b) * h / 2))
TypeError: can't multiply sequence by non-int of type 'str'


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

print((a + b) * h / 2)

a = int(input())
b = int(input())
h = int(input())
print((a + b) * h // 2)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03997/Python/s538426615.py", line 1, in <module>
    a, b, h = map(int, input().split())
ValueError: not enough values to unpack (expected 3, got 1)


a = int(input())
b = int(input())
h = int(input())

area = int((a + b) * h / 2)
print(area)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03997/Python/s214643900.py", line 1, in <module>
    a, b, h = map(int, input().split())
ValueError: not enough values to unpack (expected 3, got 1)


""" AtCoder """

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

print((a + b) * h / 2)

""" AtCoder """

a = int(input())
b = int(input())
h = int(input())

print(int((a + b) * h / 2))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03997/Python/s944882816.py", line 3, in <module>
    a, b, h = map(int, input().split())
ValueError: not enough values to unpack (expected 3, got 1)


def resolve():
    a, b, h = map(int, input().split())
    print((a + b) * h // 2)

if __name__ == "__main__":
    resolve()

def resolve():
    a = int(input())
    b = int(input())
    h = int(input())
    print((a + b) * h // 2)

if __name__ == "__main__":
    resolve()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03997/Python/s259788820.py", line 7, in <module>
    resolve()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03997/Python/s259788820.py", line 2, in resolve
    a, b, h = map(int, input().split())
ValueError: not enough values to unpack (expected 3, got 1)


SA = list(input())
SB = list(input())
SC = list(input())

turn = SA.pop(0)
while True:
    if turn == "a":
        turn = SA.pop(0)
    elif turn == "b":
        turn = SB.pop(0)
    elif turn == "c":
        turn = SC.pop(0)

    if turn == "a":
        if not SA:
            print("A")
            break
    elif turn == "b":
        if not SB:
            print("B")
            break
    elif turn == "c":
        if not SC:
            print("C")
            break

SA = list(input())
SB = list(input())
SC = list(input())

turn = SA.pop(0)
while True:
    if turn == "a":
        try:
            turn = SA.pop(0)
        except:
            print("A")
            break
    elif turn == "b":
        try:
            turn = SB.pop(0)
        except:
            print("B")
            break
    elif turn == "c":
        try:
            turn = SC.pop(0)
        except:
            print("C")
            break


Sa = list(input())
Sb = list(input())
Sc = list(input())
for _ in range(10**8):
    if _ == 0:
        s = Sa[0]
        if s == "a":
            s = Sa[1]
            del Sa[0]
        elif s == "b":
            s = Sb[1]
            del Sb[0]
        else:
            s = Sc[1]
            del Sc[0]
    elif len(Sa) == 1 and s == "a":
        print("A")
        break
    elif len(Sb) == 1 and s == "b":
        print("B")
        break
    elif len(Sc) == 1 and s == "c":
        print("C")
        break
    else:
        if s == "a":
            s = Sa[1]
            del Sa[0]
        elif s == "b":
            s = Sb[1]
            del Sb[0]
        else:
            s = Sc[1]
            del Sc[0]

Sa = list(input())
Sb = list(input())
Sc = list(input())
c = 0
for _ in range(10**9):
    if c == "a" and not Sa:
        print("A")
        break
    if c == "b" and not Sb:
        print("B")
        break
    if c == "c" and not Sc:
        print("C")
        break
    if _ == 0:
        c = Sa[0]
        del Sa[0]
    elif c == "a":
        c = Sa[0]
        del Sa[0]
    elif c == "b":
        c = Sb[0]
        del Sb[0]
    else:
        c = Sc[0]
        del Sc[0]


def resolve():
    a = input()
    b = input()
    c = input()
    d = {"a": a, "b": b, "c": c}
    now = d["a"][0]
    d["a"] = d["a"][1:]
    next = d[now][0]
    while True:
        if len(d[next]) == 0:
            print(next.upper())
            return 0
        next = d[next][0]
        d[next] = d[next][1:]

if __name__ == "__main__":
    resolve()

def resolve():
    a = list(input())
    b = list(input())
    c = list(input())
    d = {"a": a, "b": b, "c": c}
    now = "a"
    while d[now]:
        now = d[now].pop(0)
    print(now.upper())

if __name__ == "__main__":
    resolve()