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

degs = [0] * N
clusters = [[] for _ in range(N)]

def go(curr, fro):
    col = Cs[curr] - 1
    deg = 1
    clust = {}
    for n in adj[curr]:
        if n == fro:
            continue
        ch_deg, ch_clust = yield n, curr
        clusters[col].append(ch_deg - ch_clust.get(col, 0))
        if len(ch_clust) > len(clust):
            clust, ch_clust = ch_clust, clust
        for k, v in ch_clust.items():
            clust[k] = clust.get(k, 0) + v
        deg += ch_deg
    clust[col] = deg
    return deg, clust

stack = [[None, None], [go(0, -1), None]]
while len(stack) > 1:
    gen, val = stack[-1]
    try:
        params = gen.send(val)
    except StopIteration as e:
        stack[-2][1] = e.value
        stack.pop()
    else:
        stack.append([go(*params), None])

_, root_clust = stack[0][1]
for i in range(N):
    clusters[i].append(N - root_clust.get(i, 0))

for clust in clusters:
    tot = (N * N + N) // 2
    for cnt in clust:
        tot -= (cnt * cnt + cnt) // 2
    print(tot)

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

degs = [0] * N
clusters = [[] for _ in range(N)]

def go(curr, fro):
    col = Cs[curr] - 1
    deg = 1
    clust = {}
    for n in adj[curr]:
        if n == fro:
            continue
        ch_deg, ch_clust = yield n, curr
        clusters[col].append(ch_deg - ch_clust.get(col, 0))
        if len(ch_clust) > len(clust):
            clust, ch_clust = ch_clust, clust
        for k, v in ch_clust.items():
            clust[k] = clust.get(k, 0) + v
        deg += ch_deg
    clust[col] = deg
    return deg, clust

def tramp(gen_fn, *args):
    stack = [gen_fn(*args)]
    val = None
    while stack:
        gen = stack[-1]
        try:
            params = gen.send(val)
        except StopIteration as e:
            stack.pop()
            val = e.value
        else:
            stack.append(go(*params))
            val = None
    return val

_, root_clust = tramp(go, 0, -1)
for i in range(N):
    clusters[i].append(N - root_clust.get(i, 0))

for clust in clusters:
    tot = (N * N + N) // 2
    for cnt in clust:
        tot -= (cnt * cnt + cnt) // 2
    print(tot)


import asyncio

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

degs = [0] * N
clusters = [[] for _ in range(N)]

async def go(curr, fro):
    col = Cs[curr] - 1
    deg = 1
    clust = {}
    for n in adj[curr]:
        if n == fro:
            continue
        ch_deg, ch_clust = await go(n, curr)
        clusters[col].append(ch_deg - ch_clust.get(col, 0))
        if len(ch_clust) > len(clust):
            clust, ch_clust = ch_clust, clust
        for k, v in ch_clust.items():
            clust[k] = clust.get(k, 0) + v
        deg += ch_deg
    clust[col] = deg
    return deg, clust

_, root_clust = asyncio.get_event_loop().run_until_complete(go(0, -1))
for i in range(N):
    clusters[i].append(N - root_clust.get(i, 0))

for clust in clusters:
    tot = (N * N + N) // 2
    for cnt in clust:
        tot -= (cnt * cnt + cnt) // 2
    print(tot)

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

under_col = [0] * N
ans = [0] * N

def tri(n):
    return n * (n + 1) // 2

def go(curr, fro):
    col = Cs[curr] - 1
    prev_under = under_col[col]
    deg = 1
    for n in adj[curr]:
        if n == fro:
            continue
        curr_under = under_col[col]
        ch_deg = yield go(n, curr)
        diff_under = under_col[col] - curr_under
        ans[col] += tri(ch_deg - diff_under)
        deg += ch_deg
    under_col[col] = prev_under + deg
    return deg

def tramp(gen):
    stack = [gen]
    val = None
    while stack:
        try:
            stack.append(stack[-1].send(val))
            val = None
        except StopIteration as e:
            stack.pop()
            val = e.value
    return val

tramp(go(0, -1))
for i in range(N):
    ans[i] += tri(N - under_col[i])
    print(tri(N) - ans[i])

/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02710/Python/s158459294.py:33: DeprecationWarning: There is no current event loop
  _, root_clust = asyncio.get_event_loop().run_until_complete(go(0, -1))


N = int(input())
str(N)
listN = sorted(N)
if listN.count("7") >= 1:
    print("Yes")
else:
    print("No")

N = int(input())
listN = sorted(str(N))
if listN.count("7") >= 1:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02711/Python/s383379366.py", line 3, in <module>
    listN = sorted(N)
TypeError: 'int' object is not iterable


N = int(input().split())

print(sum([n + 1 for n in range(N) if (n + 1) % 3 != 0 and (n + 1) % 5 != 0]))

N = int(input())

print(sum([n + 1 for n in range(N) if (n + 1) % 3 != 0 and (n + 1) % 5 != 0]))

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


#!/usr/bin/env python3
from functools import reduce
from itertools import product
from math import gcd

k = int(input())
p = list(product(range(1, k + 1), repeat=3))
print(sum(reduce(gcd, i) for i in p))

#!/usr/bin/env python3
from functools import reduce
from itertools import combinations
from math import gcd

K = int(input())

sum = K * (K + 1) // 2

for i in combinations(range(1, K + 1), 2):
    sum += 6 * reduce(gcd, i)

for i in combinations(range(1, K + 1), 3):
    sum += 6 * reduce(gcd, i)

print(sum)


import math

def gcd(a, b, c):

    return math.gcd(math.gcd(a, b), c)

k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        for w_c in range(1, k + 1):
            answer += gcd(w_a, w_b, w_c)

print(answer)

import math

k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        w = math.gcd(w_a, w_b)
        for w_c in range(1, k + 1):
            answer += math.gcd(w, w_c)

print(answer)


import math
from functools import lru_cache

@lru_cache(maxsize=None)
def gcd(a, b):
    return math.gcd(a, b)

K = int(input())

total = 0

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            total += gcd(gcd(a, b), c)

print(total)

import sys
import math
from functools import lru_cache

gcd = [[0] * 201 for _ in range(201)]

for i in range(201):
    for j in range(201):
        gcd[i][j] = math.gcd(i, j)

K = int(input())

total = 0

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            total += gcd[gcd[a][b]][c]

print(total)


import math
from functools import reduce

# from collections import defaultdict

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

def reducef(x, y):
    return gcdd[(x, y)]

def gcd2(*numbers):
    return reduce(reducef, numbers)

K = int(input())
ans = 0
# gcdd=defaultdict()
gcdd = {}
for a in range(1, K + 1):
    for b in range(1, K + 1):
        if (a, b) not in gcdd:
            gcdd[(a, b)] = gcd(a, b)

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd2(a, b, c)
print(ans)

from functools import reduce

# from collections import defaultdict

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

def gcddd(*numbers):
    return reduce(gcd, numbers)

def reducef(x, y):
    return gcdd[(x, y)]

def gcd2(*numbers):
    return reduce(reducef, numbers)

K = int(input())
ans = 0
# gcdd=defaultdict()
gcdd = {}
for a in range(1, K + 1):
    for b in range(1, K + 1):
        if (a, b) not in gcdd:
            gcdd[(a, b)] = gcddd(a, b)

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd2(a, b, c)
print(ans)


import math as f

K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            total += f.gcd(f.gcd(i, j), k)

print(total)

import math as f

K = int(input())
total = 0

for i in range(1, K + 1):
    for j in range(1, K + 1):
        ij = f.gcd(i, j)
        if ij == 1:
            total += K
            continue
        for k in range(1, K + 1):
            total += f.gcd(ij, k)

print(total)


N = int(input())
A = list(map(int, input().split()))
worker_list = [0] * N

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

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

from math import gcd

def gcd_3(a, b, c):
    return gcd(gcd(a, b), c)

sum_gcd = 0
K = int(input())
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for l in range(1, K + 1):
            sum_gcd += gcd_3(i, j, l)

print(sum_gcd)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02713/Python/s110715782.py", line 2, in <module>
    A = list(map(int, input().split()))
EOFError: EOF when reading a line


import math

K = int(input())

sum = 0

for a in range(K):
    for b in range(K):
        for c in range(K):
            sum += math.gcd(math.gcd(a + 1, b + 1), c + 1)

print(sum)

import math

K = int(input())

sum = 0

for a in range(K):
    sum += a + 1
    # print(a + 1, a + 1)
    for b in range(K):
        if a < b:
            gcd2_sum = math.gcd(a + 1, b + 1) * 3 * 2
            sum += gcd2_sum
            # print(a + 1, b + 1, gcd2_sum)
            for c in range(K):
                if b < c:
                    gcd3_sum = math.gcd(math.gcd(a + 1, b + 1), c + 1) * 6
                    sum += gcd3_sum
                    # print(a + 1, b + 1, c + 1, gcd3_sum)
print(sum)


#!/usr/bin/env python3
n = int(input())
ans = 0

def gcd(n, m):
    a, b = n, m
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    return b

for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            ans += gcd(k, gcd(i, j))
print(ans)

#!/usr/bin/env python3
n = int(input())
ans = 0
# gcd_grid = [[0] * 201 for _ in range(201)]

def gcd(n, m):
    """if n <= 200 and m <= 200:
    if gcd_grid[n][m] != 0:
        return gcd_grid[n][m]"""
    a, b = n, m
    if a > b:
        a, b = b, a
    while a != 0:
        a, b = b % a, a
    # gcd_grid[n][m] = b
    # gcd_grid[m][n] = b
    return b

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        for k in range(j + 1, n + 1):
            ans += 6 * gcd(k, gcd(i, j))
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        ans += 6 * gcd(i, j)
for i in range(n + 1):
    ans += i
print(ans)


import itertools
import math

def gcd(a: int, b: int, c: int) -> int:
    return math.gcd(math.gcd(a, b), c)

def main() -> None:
    k = int(input())

    s = sum(gcd(a, b, c) for a, b, c in itertools.product(range(1, k + 1), repeat=3))
    print(s)

if __name__ == "__main__":
    main()

import itertools
import math

def gcd(a: int, b: int, c: int) -> int:
    return math.gcd(math.gcd(a, b), c)

def main() -> None:
    k = int(input())

    one_to_k = range(1, k + 1)
    s1 = sum(one_to_k)
    s2 = sum(math.gcd(a, b) for a, b in itertools.combinations(one_to_k, 2))
    s3 = sum(gcd(a, b, c) for a, b, c in itertools.combinations(one_to_k, 3))
    print(s1 + 6 * s2 + 6 * s3)

if __name__ == "__main__":
    main()


import math
from functools import reduce

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

K = int(input())
sumGCD = K * K * K
for a in range(2, K + 1, 1):
    for b in range(2, K + 1, 1):
        for c in range(2, K + 1, 1):
            arr = [a, b, c]
            gcdNum = gcd(*arr)
            # if gcdNum != 1:
            # print(arr)
            # print(gcdNum)
            sumGCD += gcdNum - 1
print(sumGCD)

import math

K = int(input())
sumGCD = K * K * K
for a in range(2, K + 1, 1):
    for b in range(2, K + 1, 1):
        for c in range(2, K + 1, 1):
            arr = [a, b, c]
            gcdNum = math.gcd(math.gcd(a, b), c)
            # if gcdNum != 1:
            # print(arr)
            # print(gcdNum)
            sumGCD += gcdNum - 1
print(sumGCD)


from math import gcd
from functools import reduce

def gcd_kai(*numbers):
    return reduce(gcd, numbers)

K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans += gcd_kai(i + 1, j + 1, k + 1)
print(ans)

from math import gcd
from functools import reduce

def gcd_kai(*numbers):
    return reduce(gcd, numbers)

K = int(input())
ans = 1
if K == 1:
    next
else:
    ans += (K - 1) * K * 3
    ans_sub = 0
    for i in range(2, K):
        for j in range(i + 1, K + 1):
            for k in range(i, K + 1):
                ans_sub += gcd_kai(i, j, k)
    ans += ans_sub * 3
    for i in range(2, K + 1):
        ans += i
print(ans)


import math

k = int(input())
sum = 0

for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum += math.gcd(c, math.gcd(a, b))
print(sum)

from math import gcd

k = int(input())
sum = 0

for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum += gcd(c, gcd(a, b))
print(sum)


import math
from functools import reduce

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

K = int(input())

hoge = []
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            hoge.append(gcd(i, j, k))

print(sum(hoge))

import math
from functools import reduce

K = int(input())

sum = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            sum += reduce(math.gcd, (i, j, k))

print(sum)


import math

K = int(input())

sum = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            a = math.gcd(math.gcd(i, j), k)
            # print(math.gcd(math.gcd(i, j), k))
            sum += a

print(sum)

import math

K = int(input())

gcds = []

for a in range(1, K + 1):
    for b in range(1, K + 1):
        gcds.append(math.gcd(a, b))

# print(gcds)

ans = 0
for c in range(1, K + 1):
    for g in gcds:
        if c == 1 or g == 1:
            ans += 1
        else:
            ans += math.gcd(c, g)

print(ans)


import math
from functools import reduce

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

n = int(input())

ans = 0

for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            cnt = gcd(i, j, k)
            ans += cnt

print(ans)

import math
from functools import reduce

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

n = int(input())

ans = 0

for i in range(1, n + 1):
    for j in range(i, n + 1):
        for k in range(j, n + 1):
            cnt = gcd(i, j, k)
            if i == j and j == k:
                ans += cnt
            elif (i == j and i != k) or (i == k and i != j) or (j == k and j != i):
                ans += cnt * 3
            else:
                ans += cnt * 6

print(ans)


import math

n = int(input())

ans = 0

for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            ans += math.gcd(math.gcd(i, j), k)

print(ans)

import math

n = int(input())

ans = 0

for i in range(1, n + 1):
    for j in range(1, n + 1):
        a = math.gcd(i, j)
        for k in range(1, n + 1):
            ans += math.gcd(a, k)

print(ans)


import math

k = int(input())

k += 1
ans = 0

for a in range(1, k):
    for b in range(1, k):
        for c in range(1, k):
            ab = math.gcd(a, b)
            bc = math.gcd(b, c)
            abc = math.gcd(ab, bc)

            ans += abc

print(ans)

import math

k = int(input())

k += 1
ans = 0

ab = []

for a in range(1, k):
    for b in range(1, k):
        ab.append(math.gcd(a, b))

for a in ab:
    for c in range(1, k):
        ans += math.gcd(a, c)

print(ans)


import math
from functools import reduce

K = int(input())

# K = 2

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

ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd(a, b, c)

print(ans)

import math
from functools import reduce
import itertools

K = int(input())

# K = 2

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

ans = 0
for i in range(1, K + 1):
    # i = 1
    ans += gcd(i, i, i)

    for j in range(i + 1, K + 1):
        ans += gcd(i, i, j) * 3

    for j, k in itertools.product(range(i + 1, K + 1), range(i + 1, K + 1)):
        ans += gcd(i, j, k) * 3

print(ans)


def gcd(a, b, c):
    minV = min([a, b, c])
    maxV = max([a, b, c])
    start = minV
    diff = maxV - minV
    if diff < start and diff != 0:
        start = diff
    for gcdV in range(start, 1, -1):
        if (a % gcdV == 0) and (b % gcdV == 0) and (c % gcdV == 0):
            return gcdV
    return 1

k = int(input())
sum = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum += gcd(a, b, c)

print(sum)

import unittest
from io import StringIO
import sys
import itertools
import math

def gcd(a, b, c):
    n = 1
    if a == b:
        if b != c:
            n = 3
    else:
        if b != c:
            n = 6
        else:
            n = 3
    return math.gcd(math.gcd(a, b), c) * n

def resolve():
    K = int(input())
    T = [i for i in range(1, K + 1)]
    Tr = itertools.combinations_with_replacement(T, 3)
    sumT = 0
    for a, b, c in Tr:
        sumT += gcd(a, b, c)
    print(sumT)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """200"""
        output = """10813692"""
        self.assertIO(input, output)

    def test_add(self):
        input = """195"""
        output = """9997134"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()


def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

K = int(input())

G = [[0] * (K + 1) for _ in range(K + 1)]

for a in range(1, K + 1):
    for b in range(1, K + 1):
        G[a][b] = gcd(a, b)

ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            if G[a][b] == 1:
                ans += 1
                continue
            ans += gcd(G[a][b], c)
print(ans)

import numpy as np

K = int(input())
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
ans = nums.sum()
print(ans)


import math

K = int(input())
ans = 0
for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans1 = math.gcd(a, b)
            ans2 = math.gcd(ans1, c)
            ans += ans2

print(ans)

from math import gcd

K = int(input())
ans = 0
for i in range(1, K + 1):
    ans += i
for i in range(1, K + 1):
    for j in range(i + 1, K + 1):
        ans += gcd(i, j) * 6

for i in range(1, K - 1):
    for j in range(i + 1, K):
        for k in range(j + 1, K + 1):
            ans += gcd(gcd(i, j), k) * 6

print(ans)


from math import gcd

k = int(input())
d = {}

ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            if (a, b, c) in d:
                ans += d[(a, b, c)]
            else:
                d[(a, b, c)] = gcd(a, gcd(b, c))
                ans += d[(a, b, c)]

print(ans)

def GCD(a, b):
    return a if b == 0 else GCD(b, a % b)

k = int(input())

ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        ab = GCD(a, b)
        if ab == 1:
            ans += k
            continue
        for c in range(1, k + 1):
            ans += GCD(ab, c)

print(ans)


import math

k = int(input())
result = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            p = math.gcd(a, b)
            q = math.gcd(p, c)
            result += q
print(result)

import math

k = int(input())
result = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        p = math.gcd(a, b)
        for c in range(1, k + 1):
            q = math.gcd(p, c)
            result += q
print(result)


# D - RGB Triplets
def main():
    _ = int(input())
    S = input().rstrip()
    cnt = 0
    for j, b in enumerate(S[1:-1], 1):
        for i, a in enumerate(S[:j]):
            for k, c in enumerate(S[j + 1 :], j + 1):
                if a == b or a == c or b == c:
                    continue
                elif j - i == k - j:
                    continue
                cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

# D - RGB Triplets
from collections import defaultdict

def main():
    _ = int(input())
    S = input().rstrip()
    indices = defaultdict(set)
    for i, c in enumerate(S):
        indices[c].add(i)
    cnt = len(indices["R"]) * len(indices["G"]) * len(indices["B"])
    for c1, c2, c3 in ["RGB", "GBR", "BRG"]:
        cnt -= sum(
            (i + j) % 2 == 0 and (i + j) // 2 in indices[c3]
            for i in indices[c1]
            for j in indices[c2]
        )
    print(cnt)

if __name__ == "__main__":
    main()


n = int(input())
s = list(input())
r_pos = []
g_pos = []
b_pos = []

for i in range(n):
    st = s[i]
    if st == "R":
        r_pos.append(i)

    if st == "G":
        g_pos.append(i)

    if st == "B":
        b_pos.append(i)

colors = [r_pos, g_pos, b_pos]
if len(colors[0]) > len(colors[1]):
    colors[0], colors[1] = colors[1], colors[0]
if len(colors[0]) > len(colors[2]):
    colors[0], colors[2] = colors[2], colors[0]
if len(colors[1]) > len(colors[2]):
    colors[1], colors[2] = colors[2], colors[1]

x_num, y_num, z_num = len(colors[0]), len(colors[1]), len(colors[2])

ans = x_num * y_num * z_num
for a in colors[0]:
    for b in colors[1]:
        x, y = min(a, b), max(a, b)

        dif = y - x
        left_pos = x - dif
        right_pos = y + dif
        mid_pos = 4000
        if dif % 2 == 0:
            mid_pos = x + dif // 2

        left = 0
        right = 0
        mid = 0
        if left_pos in colors[2]:
            left = 1
        if right_pos in colors[2]:
            right = 1
        if mid_pos in colors[2]:
            mid = 1

        ans -= left + right + mid

print(ans)

n = int(input())
s = list(input())
r_pos = []
g_pos = []
b_pos = []

for i in range(n):
    st = s[i]
    if st == "R":
        r_pos.append(i)

    if st == "G":
        g_pos.append(i)

    if st == "B":
        b_pos.append(i)

colors = [r_pos, g_pos, b_pos]
if len(colors[0]) > len(colors[1]):
    colors[0], colors[1] = colors[1], colors[0]
if len(colors[0]) > len(colors[2]):
    colors[0], colors[2] = colors[2], colors[0]
if len(colors[1]) > len(colors[2]):
    colors[1], colors[2] = colors[2], colors[1]

x_num, y_num, z_num = len(colors[0]), len(colors[1]), len(colors[2])

ans = x_num * y_num * z_num
c = set(colors[2])
for a in colors[0]:
    for b in colors[1]:
        x, y = min(a, b), max(a, b)

        dif = y - x
        left_pos = x - dif
        right_pos = y + dif
        mid_pos = 4000
        if dif % 2 == 0:
            mid_pos = x + dif // 2

        left = 0
        right = 0
        mid = 0
        if left_pos in c:
            left = 1
        if right_pos in c:
            right = 1
        if mid_pos in c:
            mid = 1

        ans -= left + right + mid

print(ans)


N = int(input())
S = input()

R, G, B = [], [], []
for i, s in enumerate(S):
    if s == "R":
        R.append(i)
    elif s == "G":
        G.append(i)
    else:
        B.append(i)

result = 0
for r in R:
    for g in G:
        for b in B:
            i = min(r, g, b)
            k = max(r, g, b)
            j = (r + g + b) - i - k
            if j - i != k - j:
                result += 1

print(result)

def check_RGB(c1, c2, c3):
    l = [c1, c2, c3]
    return ("R" in l) and ("G" in l) and ("B" in l)

N = int(input())
S = input()

R, G, B = 0, 0, 0
for i, s in enumerate(S):
    if s == "R":
        R += 1
    elif s == "G":
        G += 1
    else:
        B += 1

result = R * G * B

width = 1
while width * 2 < N:
    i = 0
    first = i
    mid = i + width
    last = i + width * 2

    while last < N:
        if check_RGB(S[first], S[mid], S[last]):
            result -= 1

        i += 1
        first = i
        mid = i + width
        last = i + width * 2

    width += 1

print(result)


# https://atcoder.jp/contests/abc162/tasks/abc162_d

N = int(input())
S = input()

ans = 0
for i in range(N):
    for j in range(i, N):
        for k in range(j, N):
            if j - i == k - j:
                continue

            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ans += 1

print(ans)

# https://atcoder.jp/contests/abc162/tasks/abc162_d

N = int(input())
S = input()

def colors(target, a, b):
    for i in range(N):
        for j in range(i + 1, N):
            if S[i] == a and S[j] == b:
                target[i] += 1

rg = [0 for _ in range(N)]
colors(rg, "R", "G")
gr = [0 for _ in range(N)]
colors(gr, "G", "R")

gb = [0 for _ in range(N)]
colors(gb, "G", "B")
bg = [0 for _ in range(N)]
colors(bg, "B", "G")

rb = [0 for _ in range(N)]
colors(rb, "R", "B")
br = [0 for _ in range(N)]
colors(br, "B", "R")

ans = 0
for i in range(N):
    if S[i] == "B":
        for j in range(i + 1, N):
            ans += rg[j]
            ans += gr[j]

            k = j + j - i
            if k >= N:
                continue
            if S[i] == "B" and S[j] == "R" and S[k] == "G":
                ans -= 1
            if S[i] == "B" and S[j] == "G" and S[k] == "R":
                ans -= 1

    if S[i] == "R":
        for j in range(i + 1, N):
            ans += gb[j]
            ans += bg[j]

            k = j + j - i
            if k >= N:
                continue
            if S[i] == "R" and S[j] == "G" and S[k] == "B":
                ans -= 1
            if S[i] == "R" and S[j] == "B" and S[k] == "G":
                ans -= 1

    if S[i] == "G":
        for j in range(i + 1, N):
            ans += rb[j]
            ans += br[j]

            k = j + j - i
            if k >= N:
                continue
            if S[i] == "G" and S[j] == "R" and S[k] == "B":
                ans -= 1
            if S[i] == "G" and S[j] == "B" and S[k] == "R":
                ans -= 1

print(ans)


N = int(input())
S = input()
exc = 0
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = j + (j - i)
        if N - 1 < k:
            continue
        if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]:
            ans -= 1

print(ans)

N = int(input())
S = [s for s in input()]
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k = j + (j - i)
        if N - 1 < k:
            continue
        if S[k] != S[i] and S[k] != S[j] and S[i] != S[j]:
            ans -= 1

print(ans)


N = int(input())
S = input()
c = 0
for i in range(N):
    for j in range(i, N):
        for k in range(j, N):
            if len(set([S[i], S[j], S[k]])) == 3 and j - i != k - j:
                c += 1
print(c)

N = int(input())
S = input()
a = S.count("R") * S.count("G") * S.count("B")
c = 0
for i in range(N):
    for j in range(i + 1, N):
        k = 2 * j - i
        if k >= N:
            continue
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            c += 1
print(a - c)


N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] != S[j]:
            x = 2 * j - i
            if x <= N - 1 and S[i] != S[x] and S[x] != S[j]:
                ans -= 1

print(ans)

N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[i] != S[j]:
            x = 2 * j - i
            if x < N and S[i] != S[x] and S[x] != S[j]:
                ans -= 1

print(ans)


n = int(input())
s = list(input())
ans = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if s[j] == s[i]:
            continue
        for k in range(j + 1, n):
            if s[k] == s[i] or s[k] == s[j] or 2 * j - i == k:
                continue

            ans += 1

print(ans)

n = int(input())
s = list(input())
r = 0
g = 0
b = 0

for i in range(n):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    else:
        b += 1

ans = r * g * b

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        k = 2 * j - i
        if k < n:
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ans -= 1

print(ans)


N = int(input())
S = input()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if S[j] != S[i]:
            for k in range(j + 1, N):
                if j - i != k - j and S[k] != S[i] and S[k] != S[j]:
                    ans += 1
print(ans)

def main():
    N = int(input())
    S = input()
    ans = S.count("R") * S.count("G") * S.count("B")
    for i in range(N):
        for d in range(N - 1):
            j = i + d
            k = j + d
            if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    print(ans)

main()


def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                if j - i == k - j:
                    if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                        cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()

def main():
    N = int(input())
    S = input()
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = 2 * j - i
            if k >= N:
                continue
            if S[j] != S[i] and S[i] != S[k] and S[k] != S[j]:
                cnt += 1
    print(S.count("R") * S.count("B") * S.count("G") - cnt)

if __name__ == "__main__":
    main()


from _collections import defaultdict

N = int(input())
S = input()

counted_dict = defaultdict(list)
for i in range(N):
    char = S[i]
    if char == "R":
        counted_dict["R"].append(i)
    elif char == "G":
        counted_dict["G"].append(i)
    else:
        counted_dict["B"].append(i)

count = 0
for x in range(len(counted_dict["R"])):
    r_pos = counted_dict["R"][x]
    for y in range(len(counted_dict["G"])):
        g_pos = counted_dict["G"][y]
        for z in range(len(counted_dict["B"])):
            b_pos = counted_dict["B"][z]
            colors_pos_list = [r_pos, g_pos, b_pos]
            colors_pos_list.sort()
            if not colors_pos_list[2] + colors_pos_list[0] == 2 * colors_pos_list[1]:
                count += 1

print(count)

N = int(input())
S = input()

total_comb = S.count("R") * S.count("G") * S.count("B")

minus = 0
for i in range(N - 2):
    for j in range(i + 1, N):
        k = 2 * j - i
        if k < N:
            if (S[i] != S[j]) and (S[j] != S[k]) and (S[k] != S[i]):
                minus += 1

print(total_comb - minus)


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

ans = 0
list1 = ["", "", ""]
for i in range(n):
    for j in range(n):
        if i < j:
            for k in range(n):
                if j < k:
                    if s[i] != s[j]:
                        if s[j] != s[k]:
                            if s[i] != s[k]:
                                if j - i != k - j:
                                    ans += 1
print(ans)

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

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n):
    for d in range(n):
        j = i + d
        k = i + 2 * d
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
            ans -= 1

print(ans)


n = int(input())
S = input()

# keyは(色、jの位置)のタプル
dp = {}

ans = 0

for i in range(n - 2):
    c_i = S[i]
    for j in range(i + 1, n - 1):
        if S[j] == c_i:
            continue
        c_j = S[j]
        d_ij = j - i
        if (c_i, c_j, j) in dp:
            ans += dp[(c_i, c_j, j)]
            if j + d_ij < n:
                c_k = S[j + d_ij]
                if c_i != c_j and c_j != c_k and c_k != c_i:
                    ans -= 1
        else:
            tmp = 0
            for k in range(j + 1, n):
                c_k = S[k]
                if c_i != c_j and c_j != c_k and c_k != c_i:
                    tmp += 1
            dp[(c_i, c_j, j)] = tmp
            if j + d_ij < n:
                c_k = S[j + d_ij]
                if c_i != c_j and c_j != c_k and c_k != c_i:
                    tmp -= 1
            ans += tmp
print(ans)

n = int(input())
S = input()

# keyは(色、jの位置)のタプル
dp = {}

ans = 0

for i in range(n - 2):
    c_i = S[i]
    for j in range(i + 1, n - 1):
        if S[j] == c_i:
            continue
        c_j = S[j]
        d_ij = j - i
        if (c_i, j) in dp:
            ans += dp[(c_i, j)]
            if j + d_ij < n:
                c_k = S[j + d_ij]
                if c_i != c_j and c_j != c_k and c_k != c_i:
                    ans -= 1
        else:
            tmp = 0
            for k in range(j + 1, n):
                c_k = S[k]
                if c_i != c_j and c_j != c_k and c_k != c_i:
                    tmp += 1
            dp[(c_i, j)] = tmp
            if j + d_ij < n:
                c_k = S[j + d_ij]
                if c_i != c_j and c_j != c_k and c_k != c_i:
                    tmp -= 1
            ans += tmp
print(ans)


n = int(input())
s = input()

cnt = 0

for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if (s[i] != s[j] and s[i] != s[k] and s[j] != s[k]) and (j - i != k - j):
                cnt += 1

print(cnt)

n = int(input())
s = input()

r = s.count("R")
b = s.count("B")
g = s.count("G")

cnt = 0

for i in range(n):
    for j in range(i + 1, n):
        k = j + j - i
        if k >= n:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            cnt += 1

print(r * b * g - cnt)


n = int(input())
s = input()
rr = 0
gg = 0
bb = 0
for i in range(n):
    if s[i] == "R":
        rr += 1
    if s[i] == "G":
        gg += 1
    if s[i] == "B":
        bb += 1

ans = rr * gg * bb

for i in range(n):
    for j in range(n):
        if j - i >= 0 and j + i < n:
            if s[j - i] != s[j] and s[j] != s[j + i] and s[j + i] != s[j - i]:
                ans -= 1
print(ans)

n = int(input())
s = input()
rr = 0
gg = 0
bb = 0
for i in range(n):
    if s[i] == "R":
        rr += 1
    if s[i] == "G":
        gg += 1
    if s[i] == "B":
        bb += 1

ans = rr * gg * bb

for j in range(n):
    for i in range(min(j + 1, n - j)):
        if s[j - i] != s[j] and s[j] != s[j + i] and s[j + i] != s[j - i]:
            ans -= 1
print(ans)


n = int(input())
s = input()

count = 0

for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if (s[i] != s[j] and s[i] != s[k] and s[j] != s[k]) and (j - i != k - j):
                count += 1
print(count)

n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

cnt = 0

for i in range(n):
    for j in range(i + 1, n):
        if 2 * j - i < n:
            if s[i] != s[j] and s[i] != s[2 * j - i] and s[j] != s[2 * j - i]:
                cnt += 1

print(r * g * b - cnt)


n = int(input())
s = input()
RL = []
GL = []
BL = []
for i in range(1, n + 1):
    word = s[i - 1]
    if word == "R":
        RL.append(i)
    elif word == "G":
        GL.append(i)
    else:
        BL.append(i)
ans = 0
for r in RL:
    for g in GL:
        for b in BL:
            delta1 = abs(r - g)
            delta2 = abs(g - b)
            delta3 = abs(b - r)
            if delta1 == delta2:
                continue
            if delta2 == delta3:
                continue
            if delta3 == delta1:
                continue
            ans += 1
print(ans)

# from bisect import bisect_left

n = int(input())
s = input()
RL = []
GL = []
BL = []
for i in range(1, n + 1):
    word = s[i - 1]
    if word == "R":
        RL.append(i)
    elif word == "G":
        GL.append(i)
    else:
        BL.append(i)
nagasa_r = len(RL)
nagasa_g = len(GL)
nagasa_b = len(BL)
SBL = set(BL)
ans = 0
if nagasa_b == 0 or nagasa_g == 0 or nagasa_r == 0:
    ans = 0
else:
    out_count = 0
    for r in RL:
        for g in GL:
            bigger = max(r, g)
            smaller = min(r, g)
            delta = bigger - smaller
            if (r + g) % 2 == 0:
                outnumber = [bigger + delta, smaller - delta, (r + g) // 2]
            else:
                outnumber = [bigger + delta, smaller - delta]
            for num in outnumber:
                if num in SBL:
                    out_count += 1
            ans += nagasa_b
    ans -= out_count
print(ans)


n = int(input())
s = input()
ans = 0
for i in range(len(s)):
    one = s[i]
    for j in range(i + 1, len(s)):
        if s[j] == one:
            continue
        dis1 = j - i
        two = s[j]
        for k in range(j + 1, len(s)):
            if s[k] == one or s[k] == two:
                continue
            else:
                dis2 = k - j
                if dis1 != dis2:
                    ans += 1

print(ans)

n = int(input())
s = input()

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        # 三個目が範囲内 かつ 三文字違う かつ 距離が同じはダメ
        if k < n and (s[i] != s[j] and s[j] != s[k] and s[i] != s[k]) and j - i == k - j:
            ans -= 1

print(ans)


import sys
from itertools import product

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

def main():
    N = int(input())
    S = input()
    r = []
    g = []
    b = []
    for i in range(N):
        if S[i] == "R":
            r.append(i)
        elif S[i] == "G":
            g.append(i)
        else:
            b.append(i)
    A = product(r, g, b)
    ans = 0
    for a in A:
        a = list(a)
        a.sort()
        if a[2] - a[1] != a[1] - a[0]:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

import sys
from collections import Counter

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

def main():
    N = int(input())
    S = input()
    C = Counter(S)
    R = C.get("R", 0)
    G = C.get("G", 0)
    B = C.get("B", 0)
    ans = R * G * B
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid + mid - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    ans -= 1
    print(ans)

if __name__ == "__main__":
    main()


# YouTube解説
MOD = 1000000007
n, k = [int(x) for x in input().split()]
d = [0] * (k + 1)

for i in range(0, k + 1):
    d[i] = pow(k // i, n, MOD)

for i in range(k, 0, -1):  # 大きいほうから
    for j in range(i * 2, k + 1, i):  # iの倍数
        # d[6] = d'[6] - d[12] - d[18] ...
        d[i] -= d[j]
        d[i] %= MOD
ans = 0
for i, item in enumerate(d):
    ans += i * item
    ans %= MOD
print(ans)

# YouTube解説
MOD = 1000000007
n, k = [int(x) for x in input().split()]
d = [0] * (k + 1)

for i in range(1, k + 1):
    d[i] = pow(k // i, n, MOD)

for i in range(k, 0, -1):  # 大きいほうから
    for j in range(i * 2, k + 1, i):  # iの倍数
        # d[6] = d'[6] - d[12] - d[18] ...
        d[i] -= d[j]
        d[i] %= MOD
ans = 0
for i, item in enumerate(d):
    ans += i * item
    ans %= MOD
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02715/Python/s098159754.py", line 7, in <module>
    d[i] = pow(k // i, n, MOD)
ZeroDivisionError: integer division or modulo by zero


# unfinished
INF = 1 << 64

def find_max(a):
    n = len(a)
    odd_a = [a[i] for i in range(n) if i % 2 == 0]
    even_a = [a[i] for i in range(n) if i % 2 == 1]

    cum_odd_a = [0]
    sum_odd_a = 0
    for odd_a_elem in odd_a:
        cum_odd_a.append(cum_odd_a[-1] + odd_a_elem)
        sum_odd_a += odd_a_elem

    cum_even_a = [0]
    sum_even_a = 0
    for even_a_elem in even_a:
        cum_even_a.append(cum_even_a[-1] + even_a_elem)
        sum_even_a += even_a_elem

    max_sum_half_a = -INF

    if n % 2 == 0:  # nが偶数である場合
        # 奇数と偶数の境目
        for i in range(n // 2 + 1):
            odd_part_sum = cum_odd_a[i]
            even_part_sum = sum_even_a - cum_even_a[i]
            sum_half_a = odd_part_sum + even_part_sum

            if sum_half_a > max_sum_half_a:
                max_sum_half_a = sum_half_a
    else:  # nが奇数である場合
        # 奇数と偶数の境目
        for i in range(n // 2 + 1):
            odd_part_sum_1 = cum_odd_a[i]

            # 偶数と奇数の境目
            for j in range(i, n // 2 + 1):
                even_part_sum = cum_even_a[j] - cum_even_a[i]
                odd_part_sum_2 = sum_odd_a - cum_odd_a[j + 1]

                sum_half_a = odd_part_sum_1 + even_part_sum + odd_part_sum_2

                if sum_half_a > max_sum_half_a:
                    max_sum_half_a = sum_half_a

    return max_sum_half_a

def main():
    _ = int(input())
    a = list(map(int, input().split()))

    print(find_max(a))

main()

def find_max(a):
    n = len(a)

    if n <= 3:
        return max(a)

    dp = [[-(1 << 64)] * (2 + n % 2) for _ in range(n)]

    for i in range(2 + n % 2):
        dp[i][i] = a[i]
        dp[i + 1][i] = a[i]

    for i in range(2, n):
        for j in range(2 + n % 2):
            for extra_space in range(j + 1):
                curr_sum = dp[i - (2 + extra_space)][j - extra_space] + a[i]
                if curr_sum > dp[i][j]:
                    dp[i][j] = curr_sum

    return dp[-1][1 + n % 2]

def main():
    _ = int(input())
    a = list(map(int, input().split()))

    print(find_max(a))

main()


A, B, C = [int(i) for i in input().split()]

A, B, C = B, A, C
A, B, C = C, B, A

print(f"{A} {B} {C}")

A, B, C = [int(i) for i in input().split()]

A, B, C = B, A, C
A, B, C = C, B, A

print("%s %s %s" % (A, B, C))


#!/usr/bin/env python3

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

#!/usr/bin/env python3

a, b, c = map(int, input().split())
print("{} {} {}".format(c, a, b))

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


x, y, z = map(int, input())
print(z, x, y)

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

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


X, Y, Z = map(int, input())
print(Z, X, Y)

X, Y, Z = map(int, input().split())
print(Z, X, Y)

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


x, y, z = map(int, input().split())
print(z + " " + x + " " + y)

x, y, z = map(str, input().split())
print(z + " " + x + " " + y)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s693185745.py", line 2, in <module>
    print(z + " " + x + " " + y)
TypeError: unsupported operand type(s) for +: 'int' and 'str'


# -*- coding: utf-8 -*-
def resolve():
    a, b, c = map(int, list(input()))
    print(a + b + c)

if __name__ == "__main__":
    resolve()

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

    temp_a = a
    temp_b = b
    a = temp_b
    b = temp_a
    temp_c = c
    temp_a = a
    c = temp_a
    a = temp_c
    print(a, b, c)

resolve()

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


XYZ = map(int, input().split())
print(XYZ[2], XYZ[1], XYZ[0])

XYZ = input().split()
print(XYZ[2], XYZ[0], XYZ[1])

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s285964975.py", line 2, in <module>
    print(XYZ[2], XYZ[1], XYZ[0])
TypeError: 'map' object is not subscriptable


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

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

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


data = input().split()

i = [int(n) for n in data]

print(f"{i[2]} {i[0]} {i[1]}")

data = input().split()
i = [int(n) for n in data]
res = "{} {} {}"
print(res.format(i[2], i[0], i[1]))


x, y, z = input().split()
print(f"{z} {x} {y}")

x, y, z = input().split()
print(z, x, y)


X = input()
Y = input()
Z = input()
A = X
B = Y
C = Z
# swap the contents of the boxes A and B
temp = B
B = A
A = temp
print(A + " " + B + " " + C)
# swap the contents of the boxes A and C
swapAC = C
C = A
A = swapAC
print(A + " " + B + " " + C)

X, Y, Z = input().split()
A = X
B = Y
C = Z
# swap the contents of the boxes A and B
temp = B
B = A
A = temp
# swap the contents of the boxes A and C
swapAC = C
C = A
A = swapAC
print(A, B, C)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s970724888.py", line 2, in <module>
    Y = input()
EOFError: EOF when reading a line


X, Y, Z = map(int, input().split())
print(f"{Z} {X} {Y}")


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

real = A[M] / sum(A)
ideal = 1 / (4 * M)

if real >= ideal:
    print("Yes")
else:
    print("No")

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

A.sort(reverse=True)
real = A[M - 1] / sum(A)
ideal = 1 / (4 * M)

if real >= ideal:
    print("Yes")
else:
    print("No")


n, m = set(map(int, input().split()))
a = set(map(int, input().split()))
count = 0
for x in a:
    if x >= sum(a) / (4 * m):
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")

n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for x in a:
    if x >= sum(a) / (4 * m):
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")


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

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

s = sum(a)

a.sort()

if a[m - 1] * a * m >= s:
    print("Yes")
else:
    print("No")

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

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

s = sum(a)

a.sort(reverse=True)

if a[m - 1] >= s / (4 * m):
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02718/Python/s183139755.py", line 9, in <module>
    if a[m - 1] * a * m >= s:
TypeError: '>=' not supported between instances of 'list' and 'int'


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

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

th = sum(A) // (4 * M)

sorted_A = sorted(A, key=lambda x: -x)
if sorted_A[M] < th:
    print("No")
else:
    print("Yes")

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

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

th = 1.0 * sum(A) / (4 * M)

sorted_A = sorted(A, key=lambda x: -x)
if sorted_A[M - 1] < th:
    print("No")
else:
    print("Yes")


#!/usr/bin/env python3

import numpy as np

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

A = np.array(A)

num = np.sum(A >= np.sum(A) / (4 * M))

if num >= M:
    print("Yes")
else:
    print("No")

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


n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
if a[m] >= sum(a) / (4 * m):
    print("Yes")
else:
    print("No")

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
if a[m - 1] >= sum(a) / (4 * m):
    print("Yes")
else:
    print("No")


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

flag = 0
if K == 1:
    print(0)
    quit()
if K == 2:
    if N % 2:
        print(1)
        quit()
    else:
        print(0)
        quit()
while True:
    ab = abs(N - K)
    if N > ab:
        N = ab
    else:
        break

print(N)

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

flag = 0
if K == 1:
    print(0)
    quit()
if K == 2:
    if N % 2:
        print(1)
        quit()
    else:
        print(0)
        quit()

i = N // K
N = N - K * i
while True:
    i = N // K
    ab = abs(N - K)
    if N > ab:
        N = ab
    else:
        break

print(N)


n, k = map(int, input().split())
if n == 0:
    print(0)
else:
    x = abs(n - k)
    a = n % x
    b = abs(a - k)
    print(min(a, b))

n, k = map(int, input().split())
if n == 0 or n == k:
    print(0)
else:
    a = abs(n % k)
    b = abs(a - k)
    print(min(a, b))


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

while abs(N - K) < N:
    N = abs(N - K)

print(N)

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

N %= K

while abs(N - K) < N:
    N = abs(N - K)

print(N)


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

cm = N
if N % K == 0:
    print(0)
    exit()
while True:
    cm = min(cm, abs(N - K))
    if cm >= N:
        break
    N = cm

print(cm)

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

cm = N
k = N % K
if k == 0:
    print(0)
    exit()
print(min(abs(k - K), N))


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

print(min(n % k), (k - (n % k)))

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

print(min((n % k), (k - (n % k))))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02719/Python/s891781735.py", line 3, in <module>
    print(min(n % k), (k - (n % k)))
TypeError: 'int' object is not iterable


n, m = (int(x) for x in input().split())
num_point = [int(x) for x in input().split()]
count = 0

for n in num_point:
    if n > (sum(num_point) / (4 * m)):
        count += 1

if count < m:
    print("No")
else:
    print("Yes")

n, m = (int(x) for x in input().split())

a = n % m
b = n / m
if abs(a - m) > a:
    print(a)
else:
    print(abs(a - m))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02719/Python/s837857825.py", line 2, in <module>
    num_point = [int(x) for x in input().split()]
EOFError: EOF when reading a line


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

N = list_input[0]
K = list_input[1]

while N > abs(N - K):
    N = abs(N - K)

print(N)

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

N = list_input[0]
K = list_input[1]

while N > abs(N - K):
    if N >= K:
        N = N % K
    else:
        N = K - N
print(N)


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

n_prev = n

while True:
    n = abs(n - k)
    if n > n_prev:
        print(n_prev)
        exit()
    else:
        n_prev = n

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

print(min(n % k, abs(k - n % k)))


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

tmp1 = abs(N - K)

while True:
    if K == 1:
        print(0)
        break
    tmp2 = abs(tmp1 - K)
    if tmp1 < tmp2:
        print(tmp1)
        break
    else:
        tmp1 = tmp2

N, K = map(int, input().split())
print(min(N % K, K - (N % K)))


n, k = map(int, input().split())
min = n
fin = 0

while n >= 0:
    n = n - k
    if n >= 0:
        min = n
    else:
        fin = abs(n)

if min < fin:
    print(min)
else:
    print(fin)

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

x = n % k
y = abs(x - k)

if x < y:
    print(x)
else:
    print(y)


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

r = []
if n % k == 0:
    print(0)
    exit()
while True:
    n = abs(n - k)
    r.append(n)
    if r.count(n) >= 2:
        break

print(min(r))

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

r = []
n = n % k
if n == 0:
    print(0)
    exit()
while True:
    n = abs(n - k)
    r.append(n)
    if r.count(n) >= 2:
        break

print(min(r))


N, K = map(int, input().split())
ans = int(N)
k_range = N // K
# print(k_range)

if k_range == 0:
    N = N - K
else:
    N_1 = N - (K * k_range)
    N_2 = N - (K * (k_range + 1))
    print(N_1)
    print(N_2)

if abs(N_1) < abs(N_2):
    if ans > abs(N_1):
        ans = abs(N_1)
    else:
        pass
else:
    if ans > abs(N_2):
        ans = abs(N_2)
    else:
        pass
print(ans)

N, K = map(int, input().split())
ans = int(N)
N_1 = N
N_2 = N
k_range = N // K
# print(k_range)

if k_range == 0:
    N = N - K
    if ans > abs(N):
        ans = abs(N)
else:
    N_1 = N - (K * k_range)
    N_2 = N - (K * (k_range + 1))

if abs(N_1) < abs(N_2):
    if ans > abs(N_1):
        ans = abs(N_1)
    else:
        pass
else:
    if ans > abs(N_2):
        ans = abs(N_2)
    else:
        pass
print(ans)


N, K = map(int, input().split())
Nj = N
while True:
    Ni = Nj
    Nj = abs(Ni - K)
    if Ni > N:
        print(N)
        break
    elif Nj > Ni:
        print(Ni)
        break
    elif K == 1 or Nj == K:
        print(0)
        break
    else:
        continue

n, k = map(int, input().split())
if n % k == 0:
    print(0)
else:
    l = [n]
    p = n // k
    c = n - (p * k)
    half = k // 2
    while c > half:
        c = abs(c - k)
    l.append(c)
    print(min(l))


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

if N >= K:
    print(N % K)
else:
    print(K % N)

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

print(min(N % K, K - (N % K)))


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

prev = None

n = n % k
print(min(n, k % n))

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

min_n = 1000000000000000000000000000
for i in range(1000):
    if n > k:
        n %= k
    n = abs(n - k)
    min_n = min(min_n, n)

print(min_n)


n, k = list(map(int, input().split()))
loop = True
while loop:
    if n > abs(n - k):
        if n > k:
            n = min(n, n % k)
        elif k > n:
            n = min(n, k % n)
    else:
        loop = False

print(n)

n, k = list(map(int, input().split()))
if n == k:
    n = 0
else:
    while n > abs(n - k):
        if n > k:
            n = min(n, n % k)
        elif k > n:
            n = min(n, k % n)

print(n)


N, K = map(int, input().split())
if N % K == 0:
    print(0)
else:
    li = []
    li.append(N)
    aoki = N
    while aoki <= min(li):
        aoki = abs(min(li) - K)
        li.append(aoki)
    print(min(li))

n, k = map(int, input().split())
if n == 0 or k == 1:
    print(0)
    exit()
elif n < k:
    print(min(n, abs(n - k)))
    exit()
elif n % k == 0:
    print(0)
    exit()
else:
    mx = n % k
print(min(abs(mx - k), mx))


#!python3

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

def main():
    x = N
    while True:
        y = max(x - K, K - x)
        if y < x:
            x = y
        else:
            break
    print(x)

if __name__ == "__main__":
    main()

#!python3

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

def main():
    s = N % K
    ans = min(s, K - s)
    print(ans)

if __name__ == "__main__":
    main()


import sys

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

N, K = map(int, read().split())
d = abs(N - K)
N %= d
if abs(N - K) < N:
    print(abs(N - K))
else:
    print(N)

import sys

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

N, K = map(int, read().split())
if N == K:
    print(0)
elif N > K:
    N %= K
    print(min(N, abs(N - K)))
else:
    print(min(N, abs(N - K)))


n, k = map(int, input().split())
# n, k = map(int, "2 6".split())

while True:
    nc = n
    n = n - k
    if n <= 0:
        if abs(n) < nc:
            print(abs(n))
            break
        else:
            print(nc)
            break

n, k = map(int, input().split())
# n, k = map(int, "2 6".split())
q = n // k  # 答え
mod = n % k  # あまり

if q == 0:

    while True:
        nc = n
        n = n - k
        if n <= 0:
            if abs(n) < nc:
                print(abs(n))
                break
            else:
                print(nc)
                break
else:
    n1 = abs(n - (q * k))
    n2 = abs(n - ((q + 1) * k))
    if n1 < n2:
        print(n1)
    else:
        print(n2)


import numpy as np

K = int(input())

top = np.ones(10, dtype=int)
# top[0] = 0
adj = np.eye(10, dtype=int)
adj[1:, :-1] += np.eye(9, dtype=int)
adj[:-1, 1:] += np.eye(9, dtype=int)

counts = [top]
tmp = top
for _ in range(10):
    tmp = tmp.__matmul__(adj)
    counts.append(tmp)

for i in range(10):
    for j in range(1, 10):
        if K > counts[i][j]:
            K -= counts[i][j]
        else:
            break
    else:
        continue
    break

ans = [-1] * (i + 1)
ans[i] = j

for d in range(i, 0, -1):
    for k in range(max(0, j - 1), min(9, j + 1) + 1):
        if K > counts[d - 1][k]:
            K -= counts[d - 1][k]
        else:
            ans[d - 1] = k
            j = k
            break

print("".join(list(map(str, ans))[::-1]))

import numpy as np

K = int(input())

top = np.ones(10, dtype=int)
adj = np.eye(10, dtype=int)
adj[1:, :-1] += np.eye(9, dtype=int)
adj[:-1, 1:] += np.eye(9, dtype=int)

counts = [top]
tmp = top
for _ in range(10):
    tmp = np.dot(tmp, adj)
    counts.append(tmp)

for i in range(10):
    for j in range(1, 10):
        if K > counts[i][j]:
            K -= counts[i][j]
        else:
            break
    else:
        continue
    break

ans = [-1] * (i + 1)
ans[i] = j

for d in range(i, 0, -1):
    for k in range(max(0, j - 1), min(9, j + 1) + 1):
        if K > counts[d - 1][k]:
            K -= counts[d - 1][k]
        else:
            ans[d - 1] = k
            j = k
            break

print("".join(list(map(str, ans))[::-1]))


import math

k = int(input())

a = []

s = str(k)
flg = 0

for i in range(1, 1000000):
    n = math.floor(math.log10(i))
    s = str(i)
    cnt = 0

    if n < 1:
        a.append(i)
    else:
        for j in range(n):
            if abs(int(s[j]) - int(s[j + 1])) <= 1:
                cnt += 1
            if cnt == n:
                a.append(i)

    if len(a) == k:
        print(a[k - 1])
        break

from collections import deque

k = int(input())

q = deque(range(1, 10))

for i in range(k):
    t = q.popleft()

    if t % 10 != 0:
        q.append(10 * t + t % 10 - 1)

    q.append(10 * t + t % 10)

    if t % 10 != 9:
        q.append(10 * t + t % 10 + 1)

print(t)


n = int(input())

arr = []
for i in range(10000):
    si = str(i + 1)
    for i2 in range(len(si) - 1):
        if abs(int(si[i2]) - int(si[i2 + 1])) >= 2:
            break
    else:
        arr.append(si)

print(arr[n - 1])


k = int(input())
border = 10000
if k < border:
    candidate = 1
    count = 1
    while True:
        if count == k:
            print(candidate)
            break

        candidate += 1
        digits = tuple(int(c) for c in str(candidate))
        for i, d in enumerate(digits[:-1]):
            if abs(d - digits[i + 1]) > 1:
                break
        else:
            count += 1

else:
    candidate = 3234566667
    count = 100000
    while True:
        if count == k:
            print(candidate)
            break

        digits = tuple(int(c) for c in str(candidate))
        for i, d in enumerate(digits[:-1]):
            if abs(d - digits[i + 1]) > 1:
                break
        else:
            count -= 1

        candidate -= 1

# Candidate 100000 -> 3234566667

def main():
    k = int(input())
    lunluns = [i for i in range(1, 10)]
    if k <= len(lunluns):
        print(lunluns[k - 1])
        return

    while True:
        if k <= len(lunluns):
            print(lunluns[k - 1])
            return
        k -= len(lunluns)
        olds = lunluns
        lunluns = []
        for old in olds:
            for i in (-1, 0, 1):
                digit_next = old % 10 + i
                if digit_next < 0 or digit_next > 9:
                    continue
                new = old * 10 + digit_next
                lunluns.append(new)

if __name__ == "__main__":
    main()


from sys import stdin

K = int(stdin.readline())

if K < 50000:
    count = 0
    for _ in range(1, 3234566667):
        i = str(_)
        L = len(i)
        for j in range(1, L):
            if abs(ord(i[j]) - ord(i[j - 1])) > 1:
                break
        else:
            count += 1
            if count == K:
                print(_)
                quit()
else:
    count = 100001
    for _ in range(1, 3234566668)[::-1]:
        i = str(_)
        L = len(i)
        for j in range(1, L):
            if abs(ord(i[j]) - ord(i[j - 1])) > 1:
                break
        else:
            count -= 1
            if count == K:
                print(_)
                quit()

from sys import stdin
from collections import deque

K = int(stdin.readline())

deque = deque()
for i in range(1, 10):
    deque.append(i)

for i in range(K - 1):
    s = deque.popleft()
    for j in range(-1, 2):
        add = (s % 10) + j
        if 0 <= add <= 9:
            deque.append(s * 10 + add)

print(deque.popleft())


#!/usr/bin/env python3
n, k, c = map(int, input().split())
s = input()

if c == 0:
    if s.cnt("o") == k:
        print(*range(1, n + 1), sep="\\n")
    exit()

left = []
i = 0
while i < n:
    if s[i] == "o":
        left.append(i)
        i += c
    i += 1

right = []
i = n - 1
while i >= 0:
    if s[i] == "o":
        right.append(i)
        i -= c
    i -= 1
right.reverse()
for i in range(len(left)):
    if left[i] == right[i]:
        print(left[i] + 1)

#!/usr/bin/env python3
n, k, c = map(int, input().split())
s = input()

if c == 0:
    if s.count("o") == k:
        for i in range(n):
            if s[i] == "o":
                print(i + 1)
    exit()

left = []
i = 0
while i < n:
    if s[i] == "o":
        left.append(i)
        i += c
    i += 1

right = []
i = n - 1
while i >= 0:
    if s[i] == "o":
        right.append(i)
        i -= c
    i -= 1
right.reverse()
for i in range(len(left)):
    if left[i] == right[i]:
        print(left[i] + 1)


import sympy

n = int(input())

tmp = n - 1
ret = len(sympy.divisors(tmp)) - 1

tmplen = sympy.divisors(n)

for item in tmplen:
    if item == 1:
        continue
    val = n
    while True:
        if val % item == 0:
            val = val // item
        else:
            if val % item == 1:
                ret += 1
            break

print(ret)

def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())

tmp = n - 1
ret = len(make_divisors(tmp)) - 1

tmplen = make_divisors(n)

for item in tmplen:
    if item == 1:
        continue
    val = n
    while True:
        if val % item == 0:
            val = val // item
        else:
            if val % item == 1:
                ret += 1
            break

print(ret)


s = input().split()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")

s = input()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02723/Python/s530567045.py", line 2, in <module>
    if s[2] == s[3] and s[4] == s[5]:
IndexError: list index out of range


s = input()
if s[3] == s[4] and s[5] == s[6]:
    print("Yes")
else:
    print("No")


s = str(input())

if s[2] == s[3]:
    if s[4] == s[5]:
        print("Yes")

else:
    print("No")

s = str(input())

if s[2] == s[3]:
    if s[4] == s[5]:
        print("Yes")
        quit()

print("No")


S = input()
print("Yes" if S[3] == S[4] and S[5] == S[6] else "No")

S = input()
print("Yes" if S[2] == S[3] and S[4] == S[5] else "No")


from collections import deque
import copy

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

p1 = deque(p)
q1 = deque(q)
r1 = deque(r)
p2 = copy.deepcopy(p1)
q2 = copy.deepcopy(q1)
r2 = copy.deepcopy(r1)

ans = 0

ans1 = 0
for _ in range(X):
    if len(r1) > 0:
        if p1[0] > r1[0]:
            ans1 += p1.popleft()
        else:
            ans1 += r1.popleft()
    else:
        ans1 += p1.popleft()

for _ in range(Y):
    if len(r1) > 0:
        if q1[0] > r1[0]:
            ans1 += q1.popleft()
        else:
            ans1 += r1.popleft()
    else:
        ans1 += q1.popleft()

ans2 = 0
for _ in range(Y):
    if len(r2) > 0:
        if q2[0] > r2[0]:
            ans2 += q2.popleft()
        else:
            ans2 += r2.popleft()
    else:
        ans2 += q2.popleft()

for _ in range(X):
    if len(r2) > 0:
        if p2[0] > r2[0]:
            ans2 += p2.popleft()
        else:
            ans2 += r2.popleft()
    else:
        ans2 += p2.popleft()

ans = max(ans1, ans2)
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02724/Python/s107835112.py", line 4, in <module>
    X, Y, A, B, C = map(int, input().split())
ValueError: not enough values to unpack (expected 5, got 1)


K, N = map(int, input().split())
houses = list(map(int, input().split()))
# syaku_houses = []
# for i, num in enumerate(houses):
#     if i == 0:
#         syaku_houses.append(num)
#     else:
#         syaku_houses.append(num - houses[i - 1])
# print(syaku_houses)

# min_costs = []
# for house in syaku_houses:

# 右回りか左回りか？
reverse_houses = []
for i in range(N - 1):
    reverse_houses.insert(0, -1 * (K - houses[N - 1 - i]))
reverse_houses.reverse()
for house in reverse_houses:
    houses.insert(0, house)

min_costs = []
for i in range(N):
    min_costs.append(houses[N - 1 + i] - houses[i])
print(min(min_costs))

K, N = map(int, input().split())
houses = list(map(int, input().split()))
# syaku_houses = []
# for i, num in enumerate(houses):
#     if i == 0:
#         syaku_houses.append(num)
#     else:
#         syaku_houses.append(num - houses[i - 1])
# print(syaku_houses)

# min_costs = []
# for house in syaku_houses:

# 右回りか左回りか？
for i in range(N - 1):
    houses.append(K + houses[i])

min_costs = []
for i in range(N):
    min_costs.append(houses[N - 1 + i] - houses[i])
print(min(min_costs))


K, N = [int(x) for x in input().split()]
A = list([int(x) for x in input().split()])

result = []

for i in range(N):
    if i == N - 1:
        result.append(K - A[i] + A[0])
    else:
        result.appnd(A[i + 1] - A[i])

result.sort()

print(sum(result[:-1]))

K, N = [int(x) for x in input().split()]
A = list([int(x) for x in input().split()])

result = []

for i in range(N):
    if i == N - 1:
        result.append(K - A[i] + A[0])
    else:
        result.append(A[i + 1] - A[i])

result.sort()

print(sum(result[:-1]))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02725/Python/s465874099.py", line 10, in <module>
    result.appnd(A[i + 1] - A[i])
AttributeError: 'list' object has no attribute 'appnd'. Did you mean: 'append'?


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

ans = 0
for i in range(N - 1):
    S = [A[i + 1] - A[i]]
    S.append((K - A[N - 1]) + A[0])
    m = sorted(S)
    for n in range(N - 1):
        ans += m[n]
print(ans)

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

ans = 0
S = [(A[i + 1] - A[i]) for i in range(N - 1)]
S.append((K - A[N - 1]) + A[0])
S.sort
m = sorted(S)
for n in range(N - 1):
    ans += m[n]
print(ans)


K, N = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = []
for i in range(len(A)):
    ans.append(max(A) - min(A))
    A[i] += K

print(min(ans))

import sys
import random

def test(K, N, A):
    ans = []
    maxp = N - 1
    minp = 0
    for i in range(len(A)):
        ans.append(A[maxp] - A[minp])
        A[i] += K
        maxp = (maxp + 1) % (N)
        minp = (minp + 1) % (N)
    print(min(ans))

if __name__ == "__main__":
    if "random" in sys.argv:
        K = int(random.random() * 20000)
        N = int(random.random() * 65536)
        A = sorted([int(random.random() * K) for _ in range(N)])
    else:
        K, N = [int(x) for x in input().split()]
        A = [int(x) for x in input().split()]
    test(K, N, A)
    pass


import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import lil_matrix

N, X, Y = [int(_) for _ in input().split()]
G = lil_matrix((N, N))
G[X - 1, Y - 1] = 1
for i in range(N - 1):
    G[i, i + 1] = 1
D = floyd_warshall(G, directed=False)
for i in range(1, N):
    print(np.sum(D == i) // 2)

import numpy as np

N, X, Y = [int(_) for _ in input().split()]
X -= 1
Y -= 1
cnt = np.zeros(N, dtype=int)
for i in range(0, (X + Y) // 2):
    # t-i<=abs(i-X)+1+Y-t
    # 2*t<=abs(i-X)+1+Y+i
    # t<= tmax = 0 - - (abs(i-X)+1+Y+i)//2
    # tmin=i-X+1
    # range(tmin,tmin+Y-tmax) + range(1,tmax-i+1) + range(tmin+1,tmin+N-Y)
    tmin = abs(i - X) + 1
    tmax = 0 - -(abs(i - X) + 1 + Y + i) // 2
    cnt[1 : tmax - i] += 1
    cnt[tmin : tmin + Y - tmax + 1] += 1
    cnt[tmin + 1 : tmin + N - Y] += 1
for i in range((X + Y) // 2, N):
    cnt[1 : N - i] += 1
print(*cnt[1:], sep="\\n")


from collections import deque

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

inf = 100100100

x -= 1
y -= 1

ans = [0] * n

for i in range(n):
    dist = [inf] * n
    queue = deque()
    queue.append(i)
    dist[i] = 0
    while queue:
        current = queue.popleft()
        d = dist[current]

        if current - 1 >= 0 and dist[current - 1] == inf:
            queue.append(current - 1)
            dist[current - 1] = d + 1
        if current + 1 < n and dist[current + 1] == inf:
            queue.append(current + 1)
            dist[current + 1] = d + 1
        if current == x and dist[y] == inf:
            queue.append(y)
            dist[y] = d + 1
        if current == y and dist[x] == inf:
            queue.append(x)
            dist[x] = d + 1

    for j in range(n):
        ans[dist[j]] += 1

for k in range(1, n):
    print(ans[k] // 2)

from collections import deque, Counter

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

inf = 100100100
x -= 1
y -= 1

ans = [0] * n

for i in range(n):
    dist = [inf] * n
    queue = deque()
    queue.append(i)
    dist[i] = 0
    while queue:
        current = queue.popleft()
        d = dist[current]

        if current - 1 >= 0 and dist[current - 1] == inf:
            queue.append(current - 1)
            dist[current - 1] = d + 1
        if current + 1 < n and dist[current + 1] == inf:
            queue.append(current + 1)
            dist[current + 1] = d + 1
        if current == x and dist[y] == inf:
            queue.append(y)
            dist[y] = d + 1
        if current == y and dist[x] == inf:
            queue.append(x)
            dist[x] = d + 1

    for j in range(n):
        ans[dist[j]] += 1

for k in range(1, n):
    print(ans[k] // 2)


n, x, y = list(map(int, input().split()))
x -= 1
y -= 1

cnt = [0] * n
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        dist = min(j - i, abs(j - y) + 1 + abs(i - x), abs(j - x) + 1 + abs(i - y))
        cnt[dist] += 1
for i in range(1, n):
    print(cnt[i])

n, x, y = list(map(int, input().split()))
x -= 1
y -= 1

cnt = [0] * n

dist = []
for i in range(n):
    dist.append([-1] * n)
for i in range(n):
    dist[i][x] = abs(i - x)
    dist[i][y] = abs(i - y)
    dist[x][i] = abs(i - x)
    dist[y][i] = abs(i - y)

for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        dis = min(j - i, dist[j][y] + 1 + dist[i][x], dist[j][x] + 1 + dist[i][y])
        cnt[dis] += 1
for i in range(1, n):
    print(cnt[i])


import numpy as np
from collections import defaultdict

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

x -= 1
y -= 1

inf = 1000000000
dist = np.full((n, n), inf, dtype=np.int)

for i in range(n):
    for j in range(n):
        if i == j:
            dist[i][j] = 0
        else:
            path1 = abs(j - i)
            path2 = abs(x - i) + 1 + abs(y - j)
            dist[i][j] = min(abs(j - i), path2)

dist_counts = defaultdict(int)
for i in range(n):
    for j in range(i + 1, n):
        d = dist[i][j]
        dist_counts[d] += 1

for k in range(1, n):
    print(dist_counts[k])

from collections import defaultdict

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

x -= 1
y -= 1

dist_counts = defaultdict(int)
for i in range(n):
    for j in range(i + 1, n):
        path1 = abs(j - i)
        path2 = abs(x - i) + 1 + abs(y - j)
        dist = min(abs(j - i), path2)
        dist_counts[dist] += 1

for k in range(1, n):
    print(dist_counts[k])


n, x, y = map(int, input().split())
ans = [0] * n
a = [n] * n
x -= 1
y -= 1
for i in range(0, n):
    a = [n] * n
    a[i] = 0
    b = [i, x, y, x, y]
    for k in b:
        for j in range(k, 0, -1):
            if j == x:
                a[y] = min(a[y], a[j] + 1)
            if j == y:
                a[x] = min(a[x], a[j] + 1)
            a[j - 1] = min(a[j - 1], a[j] + 1)
        for j in range(k, n - 1):
            if j == x:
                a[y] = min(a[y], a[j] + 1)
            if j == y:
                a[x] = min(a[x], a[j] + 1)
            a[j + 1] = min(a[j + 1], a[j] + 1)
    for k in range(0, n):
        ans[a[k]] += 1
for i in range(1, n):
    print(ans[i] // 2)


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

inf = 1000000000
edges = [[inf] * n for _ in range(n)]
for i in range(n - 1):
    edges[i][i + 1] = 1
    edges[i + 1][i] = 1

edges[x - 1][y - 1] = 1

for k in range(n):
    for i in range(n):
        for j in range(n):
            edges[i][j] = min(edges[i][j], edges[i][k] + edges[k][j])

cnts = [0] * (n - 1)
for i in range(n - 1):
    for j in range(i + 1, n):
        cnts[edges[i][j] - 1] += 1

for x in cnts:
    print(x)

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

ans = [0] * n
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        ans[
            min(j - i, min(abs(i - x) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j)))
        ] += 1

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


# D - Line++

import queue

N, X, Y = map(int, input().split())
X, Y = X - 1, Y - 1
M = [(i, []) for i in range(N)]
for i in range(N):
    if i != 0:
        M[i][1].append(i - 1)
    if i != N - 1:
        M[i][1].append(i + 1)
    if i == X:
        M[X][1].append(Y)
    if i == Y:
        M[Y][1].append(X)

cost = [[-1] * N for _ in range(N)]
p = [[None] * N for _ in range(N)]
Q = queue.Queue()

for i in range(N):
    Q.put(M[i])
    key = M[i][0]
    cost[key][key] = 0
    p[key][key] = key
    while not Q.empty():
        q = Q.get()
        for j in q[1]:
            if cost[i][j] == -1:
                p[i][j] = q[0]
                cost[i][j] = cost[i][p[i][j]] + 1
                Q.put(M[j])

ans = [0] * N
for i in range(N):
    for j in range(N):
        ans[cost[i][j]] += 1

for i in range(1, N):
    print(int(ans[i] / 2))

# D - Line++

n, x, y = map(int, input().split())
x, y = x - 1, y - 1

cnt = [0] * n
for i in range(n):
    for j in range(i + 1, n):
        dist = min(j - i, abs(x - i) + abs(y - j) + 1)
        cnt[dist] += 1

for i in range(1, len(cnt)):
    print(cnt[i])


n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
    for j in range(i + 1, n):
        if i <= x - 1:
            if j <= x - 1:  # 1 idx
                cnt[j - i] += 1
            elif j <= y - 1:
                cnt[min(j - i, x + y - i - j - 1)] += 1
            else:
                cnt[x - y - i + j + 1] += 1
        elif x - 1 < x <= y - 1:
            if j <= y - 1:
                cnt[min(j - i, 1 + (i - x + 1) + (y - 1 - j))] += 1
            else:
                cnt[min(j - i), 1 + (i - x + 1) + (j - y + 1)] += 1
        else:
            cnt[j - i] += 1

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

n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
    for j in range(i + 1, n):
        if i <= x - 1:
            if j <= x - 1:  # 1 idx
                cnt[j - i] += 1
            elif j <= y - 1:
                cnt[min(j - i, x + y - i - j - 1)] += 1
            else:
                cnt[x - y - i + j + 1] += 1
        elif x - 1 < x <= y - 1:
            if j <= y - 1:
                cnt[min(j - i, 1 + (i - x + 1) + (y - 1 - j))] += 1
            else:
                cnt[min((j - i), 1 + (i - x + 1) + (j - y + 1))] += 1
        else:
            cnt[j - i] += 1

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

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02726/Python/s903600229.py", line 18, in <module>
    cnt[min(j - i), 1 + (i - x + 1) + (j - y + 1)] += 1
TypeError: 'int' object is not iterable


#!/usr/bin/python3

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

cs = [0 for i in range(n)]

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        d = min(abs(j - i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))
        if d == (abs(y - i) + 1 + abs(j - x)):
            print(i, j, d)
        cs[d] += 1

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

#!/usr/bin/python3

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

cs = [0 for i in range(n)]

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        d = min(abs(j - i), abs(x - i) + 1 + abs(j - y))
        cs[d] += 1

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


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

dist_from_X = list(abs(i - (X - 1)) for i in range(N))
dist_from_Y = list(abs(i - (Y - 1)) for i in range(N))

ans_list = [0] * N

for i in range(N):
    for j in range(N):
        i_X_Y_j = dist_from_X[i] + 1 + dist_from_Y[j]
        i_Y_X_j = dist_from_Y[i] + 1 + dist_from_X[j]
        i_j = abs(i - j)
        min_dist_i_j = min(i_X_Y_j, i_Y_X_j, i_j)
        ans_list[min_dist_i_j] += 1

for num in ans_list[1:]:
    print(num // 2)

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

dist_from_X = list(abs(i - (X - 1)) for i in range(N))
dist_from_Y = list(abs(i - (Y - 1)) for i in range(N))

ans_list = [0] * N

for i in range(N):
    for j in range(i, N):
        i_X_Y_j = dist_from_X[i] + 1 + dist_from_Y[j]
        i_Y_X_j = dist_from_Y[i] + 1 + dist_from_X[j]
        i_j = abs(i - j)
        min_dist_i_j = min(i_X_Y_j, i_Y_X_j, i_j)
        ans_list[min_dist_i_j] += 1

for num in ans_list[1:]:
    print(num)


from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
import numpy as np

N, X, Y = map(int, input().split())
F = [[0 for i in range(N)] for j in range(N)]

for i in range(N - 1):
    F[i][i + 1] = 1
    F[i + 1][i] = 1
F[X - 1][Y - 1] = 1
F[Y - 1][X - 1] = 1

G = csgraph_from_dense(F, null_value=0)
d = dijkstra(G)

# print(F)
# print(d)

# print(np.count_nonzero(d == 1))
for i in range(1, N):
    print(np.count_nonzero(d == i) // 2)

from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
import numpy as np
from collections import Counter

N, X, Y = map(int, input().split())
F = [[0 for i in range(N)] for j in range(N)]

for i in range(N - 1):
    F[i][i + 1] = 1
    F[i + 1][i] = 1
F[X - 1][Y - 1] = 1
F[Y - 1][X - 1] = 1

G = csgraph_from_dense(F, null_value=0)
d = dijkstra(G)

# print(F)
# print(d)

# print(np.count_nonzero(d == 1))
s = Counter(d.flatten().astype(np.int64))
# print(s)
for i in range(1, N):
    if i in s:
        print(s[i] // 2)
    else:
        print(0)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02726/Python/s587734199.py", line 1, in <module>
    from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
ModuleNotFoundError: No module named 'scipy'


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

dic = {}

X = X - 1
Y = Y - 1

for i in range(N):
    for j in range(i + 1, N):
        if i <= X and Y <= j:
            v = X - i + 1 + j - Y
        elif (i <= X) and (X <= j and j <= Y):
            v = min(j - i, X - i + 1 + Y - j)
        elif (X <= i and i <= Y) and Y <= j:
            v = min(j - i, i - X + 1 + j - Y)
        elif (X <= i and i <= Y) and (X <= j and j <= Y):
            v = min(j - i, i - X + 1 + Y - j)
        else:
            v = j - i

        if v in dic:
            dic[v] += 1
        else:
            dic[v] = 1

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

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

dic = {}

X = X - 1
Y = Y - 1

for i in range(N):
    for j in range(i + 1, N):
        if i <= X and Y <= j:
            v = X - i + 1 + j - Y
        elif (i <= X) and (X <= j and j <= Y):
            v = min(j - i, X - i + 1 + Y - j)
        elif (X <= i and i <= Y) and Y <= j:
            v = min(j - i, i - X + 1 + j - Y)
        elif (X <= i and i <= Y) and (X <= j and j <= Y):
            v = min(j - i, i - X + 1 + Y - j)
        else:
            v = j - i

        if v in dic:
            dic[v] += 1
        else:
            dic[v] = 1

for i in range(1, N):
    if i in dic:
        print(dic[i])
    else:
        print(0)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02726/Python/s708368036.py", line 29, in <module>
    print(dic[i])
KeyError: 4


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

N, X, Y = inpl()
X -= 1
Y -= 1
ans = {}
for i in range(N):
    for j in range(i + 1, N):
        c = min(j - i, abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X))
        ans[c] = ans.get(c, 0) + 1

for i in range(1, N):
    print(ans.get(i, 0))

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

N, X, Y = inpl()
X -= 1
Y -= 1
ans = {i: 0 for i in range(N)}
for i in range(N):
    for j in range(i + 1, N):
        c = min(j - i, abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X))
        ans[c] += 1

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


# https://atcoder.jp/contests/abc160/tasks/abc160_d
N, X, Y = map(int, input().split())

visited = set()

# special case: first advance
for i in range(N - 1):
    visited.add((i, i + 1))
visited.add((X - 1, Y - 1))

print(len(visited))

for _ in range(N - 2):
    total = 0

    for point in visited.copy():
        x, y = point

        if (x - 1, y) not in visited and x - 1 >= 0:
            visited.add((x - 1, y))
            total += 1

        if (x + 1, y) not in visited and x + 1 != y:
            visited.add((x + 1, y))
            total += 1

        if (x, y - 1) not in visited and x != y - 1:
            visited.add((x, y - 1))
            total += 1

        if (x, y + 1) not in visited and y + 1 < N:
            visited.add((x, y + 1))
            total += 1

    print(total)

# https://atcoder.jp/contests/abc160/tasks/abc160_d
N, X, Y = map(int, input().split())

visited = set()

# special case: first advance
for i in range(N - 1):
    visited.add((i, i + 1))
visited.add((X - 1, Y - 1))

print(len(visited))

next_items = visited.copy()
for _ in range(N - 2):
    candidates = []

    for point in next_items:
        x, y = point

        if (x - 1, y) not in visited and x - 1 >= 0:
            visited.add((x - 1, y))
            candidates.append((x - 1, y))

        if (x + 1, y) not in visited and x + 1 != y:
            visited.add((x + 1, y))
            candidates.append((x + 1, y))

        if (x, y - 1) not in visited and x != y - 1:
            visited.add((x, y - 1))
            candidates.append((x, y - 1))

        if (x, y + 1) not in visited and y + 1 < N:
            visited.add((x, y + 1))
            candidates.append((x, y + 1))

    print(len(candidates))
    next_items = candidates


from collections import deque

def bfs(start, end):
    Q = deque()
    Q.append(start)
    dist[start] = 0

    while Q:
        v = Q.popleft()

        for nv in G[v]:
            if dist[nv] != -1:
                continue
            Q.append(nv)
            dist[nv] = dist[v] + 1

            if nv == end:
                return dist[nv]

N, X, Y = map(int, input().split())
G = [[] for _ in range(N)]
res = [0] * N

for i in range(N - 1):
    G[i].append(i + 1)
    G[i + 1].append(i)

if abs(X - Y) != 1:
    G[X - 1].append(Y - 1)
    G[Y - 1].append(X - 1)

for i in range(N - 1):
    for j in range(i + 1, N):
        dist = [-1] * N
        res[bfs(i, j)] += 1

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

N, X, Y = map(int, input().split())
ans = [0 for i in range(1, N)]

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

for i in ans:
    print(i)


import sys
import numpy as np

X, Y, A, B, C = map(int, sys.stdin.readline().rstrip().split())
P = list(map(int, sys.stdin.readline().rstrip().split()))
Q = list(map(int, sys.stdin.readline().rstrip().split()))
R = list(map(int, sys.stdin.readline().rstrip().split()))

if A == 1 and B == 1 and C == 1:
    ans = sum(sorted([P[0], Q[0], R[0]], reverse=True)[:2])
    print(ans)
    sys.exit()

Pmin = np.min(P)
Qmin = np.min(Q)
Rmax = np.max(R)

# 着色する必要がない場合
if Pmin > Rmax and Qmin > Rmax:
    sP = np.sort(P)[::-1] if len(set(P)) > 1 else P
    sQ = np.sort(Q)[::-1] if len(set(Q)) > 1 else Q
    ans = np.sum(sP[:X]) + np.sum(sQ[:Y])
    print(ans)
    sys.exit()

gS = P + Q + R
p = A + B
iX = 0
iY = 0
iR = []
aX = [0] * X
aY = [0] * Y
aR = []
ans = 0
for index in np.argsort(gS)[::-1]:
    if iX == X and iY == Y:
        break
    if index < A:
        if iX == X:
            continue
        else:
            aX[iX] = gS[index]
            iX += 1
    elif index < p:
        if iY == Y:
            continue
        else:
            aY[iY] = gS[index]
            iY += 1
    else:
        iR.append((iX, iY))
        aR.append(gS[index])

sumX = sum(aX)
sumY = sum(aY)
for (iX, iY), s in zip(iR, aR):
    print(aX, aY)
    if len(aX) == 0:
        sumY = sumY + s - aY.pop()
        if len(aY) == 0:
            break
    elif len(aY) == 0:
        sumX = sumX + s - aX.pop()
        if len(aX) == 0:
            break
    else:
        if s <= aX[-1] and s <= aY[-1]:
            break
        if iX == X:
            sumY = sumY + s - aY.pop()
        elif iY == Y:
            sumX = sumX + s - aX.pop()
        else:
            if aX[-1] < aY[-1]:
                sumX = sumX + s - aX.pop()
            else:
                sumY = sumY + s - aY.pop()

print(sumX + sumY)

import sys
import numpy as np

X, Y, A, B, C = map(int, sys.stdin.readline().rstrip().split())
P = list(map(int, sys.stdin.readline().rstrip().split()))
Q = list(map(int, sys.stdin.readline().rstrip().split()))
R = list(map(int, sys.stdin.readline().rstrip().split()))

if A == 1 and B == 1 and C == 1:
    ans = sum(sorted([P[0], Q[0], R[0]], reverse=True)[:2])
    print(ans)
    sys.exit()

Pmin = np.min(P)
Qmin = np.min(Q)
Rmax = np.max(R)

# 着色する必要がない場合
if Pmin > Rmax and Qmin > Rmax:
    sP = np.sort(P)[::-1] if len(set(P)) > 1 else P
    sQ = np.sort(Q)[::-1] if len(set(Q)) > 1 else Q
    ans = np.sum(sP[:X]) + np.sum(sQ[:Y])
    print(ans)
    sys.exit()

gS = P + Q + R
p = A + B
iX = 0
iY = 0
iR = []
aX = [0] * X
aY = [0] * Y
aR = []
for index in np.argsort(gS)[::-1]:
    if iX == X and iY == Y:
        break
    if index < A:
        if iX == X:
            continue
        else:
            aX[iX] = gS[index]
            iX += 1
    elif index < p:
        if iY == Y:
            continue
        else:
            aY[iY] = gS[index]
            iY += 1
    else:
        iR.append((iX, iY))
        aR.append(gS[index])

sumX = sum(aX)
sumY = sum(aY)
for (iX, iY), s in zip(iR, aR):
    if len(aX) == 0 and len(aY) == 0:
        break
    if len(aX) == 0:
        if s <= aY[-1]:
            break
        sumY = sumY + s - aY.pop()
        if len(aY) == 0:
            break
    elif len(aY) == 0:
        if s <= aX[-1]:
            break
        sumX = sumX + s - aX.pop()
        if len(aX) == 0:
            break
    else:
        if s <= aX[-1] and s <= aY[-1]:
            break
        if iX == X:
            sumY = sumY + s - aY.pop()
        elif iY == Y:
            sumX = sumX + s - aX.pop()
        else:
            if aX[-1] < aY[-1]:
                sumX = sumX + s - aX.pop()
            else:
                sumY = sumY + s - aY.pop()

print(sumX + sumY)


X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
eat_p = p[:X]
eat_q = q[:Y]

ans = sum(eat_p) + sum(eat_q)
if A == 1:
    i = 0
else:
    i = -1
if B == 1:
    j = 0
else:
    j = -1
k = 0

while True:
    if k == C or (eat_p[i] >= r[k] and eat_q[j] >= r[k]):
        break
    if eat_p[i] < eat_q[j] and eat_p[i] < r[k]:
        ans += r[k] - eat_p[i]
        k += 1
        i -= 1
    elif eat_p[i] >= eat_q[j] and eat_q[j] < r[k]:
        ans += r[k] - eat_q[j]
        k += 1
        j -= 1
    if i == -A:
        i = 0
    if j == -B:
        j = 0

print(ans)

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
eat_p = p[:X]
eat_q = q[:Y]

all_apple = eat_p + eat_q + r
all_apple.sort(reverse=True)

print(sum(all_apple[: X + Y]))


#!/usr/bin/env python3

X, Y, A, B, C = list(map(int, input().split()))
p_list = list(map(int, input().split()))  # 10 ** 5
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

p_list = sorted(p_list, reverse=True)
q_list = sorted(q_list, reverse=True)
r_list = sorted(r_list, reverse=True)

total = 0
for _ in range(X):
    if r_list and p_list:
        r = r_list[0]
        p = p_list[0]

        if p >= r:
            total += p_list.pop(0)
        else:
            total += r_list.pop(0)
    elif r_list:
        total += r_list.pop()
    elif p_list:
        total += p_list.pop()
    else:
        break

for _ in range(Y):
    if r_list and q_list:
        r = r_list[0]
        q = q_list[0]

        if q >= r:
            total += q_list.pop(0)
        else:
            total += r_list.pop(0)
    elif r_list:
        total += r_list.pop(0)
    elif q_list:
        total += q_list.pop(0)
    else:
        break
ans = total
print(ans)

#!/usr/bin/env python3

X, Y, A, B, C = list(map(int, input().split()))
p_list = list(map(int, input().split()))  # 10 ** 5
q_list = list(map(int, input().split()))
r_list = list(map(int, input().split()))

p_list = list(sorted(p_list, reverse=True))
q_list = list(sorted(q_list, reverse=True))
# r_list = sorted(r_list, reverse=True)

p_list = p_list[:X]
q_list = q_list[:Y]

all_list = p_list + q_list + r_list
all_list = list(sorted(all_list, reverse=True))
total = sum(all_list[: X + Y])

ans = total
print(ans)


x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))[::-1]
q = sorted(map(int, input().split()))[::-1]
r = sorted(map(int, input().split()))[::-1]

z = 0
red, green = 0, 0
ans = 0
while True:
    finish = True
    if p[x] <= q[y]:
        if z < c and p[x] < r[z]:
            x -= 1
            z += 1
            finish = False
    else:
        if z < c and q[y] < r[z]:
            y -= 1
            z += 1
            finish = False
    if finish:
        break
print(sum(p[:x]) + sum(q[:y]) + sum(q[:z]))

x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))[::-1]
q = sorted(map(int, input().split()))[::-1]
r = sorted(map(int, input().split()))[::-1]

x, y = x - 1, y - 1
z = 0
red, green = 0, 0
ans = 0
while True:
    finish = True
    if p[x] <= q[y] or y < 0:
        if z < c and p[x] < r[z]:
            x -= 1
            z += 1
            finish = False
    elif p[x] >= q[y] or x < 0:
        if z < c and q[y] < r[z]:
            y -= 1
            z += 1
            finish = False
    if finish:
        break
print(sum(p[: x + 1]) + sum(q[: y + 1]) + sum(r[:z]))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02727/Python/s242480686.py", line 11, in <module>
    if p[x] <= q[y]:
IndexError: list index out of range


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

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

# step1: sort red/green apples in descending order
p.sort(reverse=True)
q.sort(reverse=True)

# step2:clip necessary apples
p = p[:x]
q = q[:y]

# step3: sort red/green apples in ascending order
p.sort()
q.sort()

# step4: sort non-color apples in descending order
r.sort(reverse=True)

# step5:swap apples to eliminate the least delicious apple
r_idx = g_idx = 0
for idx in range(c):

    if r_idx >= x or g_idx >= y:
        break

    if r[idx] < p[r_idx] and r[idx] < q[g_idx]:
        break

    if r[idx] > p[r_idx] and r[idx] > q[g_idx]:
        if p[r_idx] < q[g_idx]:
            p[r_idx], r[idx] = r[idx], p[r_idx]
            r_idx += 1
        else:
            q[g_idx], r[idx] = r[idx], q[g_idx]
            g_idx += 1

    if r[idx] > p[r_idx]:
        p[r_idx], r[idx] = r[idx], p[r_idx]
        r_idx += 1

    if r[idx] > q[g_idx]:
        q[g_idx], r[idx] = r[idx], q[g_idx]
        g_idx += 1

print(sum(p) + sum(q))

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

p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

# step1: sort red/green apples in descending order
p.sort(reverse=True)
q.sort(reverse=True)

# step2:clip necessary apples
p = p[:x]
q = q[:y]

# step3: sort red/green apples in ascending order
p.sort()
q.sort()

# step4: sort non-color apples in descending order
r.sort(reverse=True)

# step5:swap apples to eliminate the least delicious apple
d = []

d.extend(p)
d.extend(q)
d.extend(r)
d.sort(reverse=True)

print(sum(d[: x + y]))


x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()))
q = sorted(map(int, input().split()))
r = sorted(map(int, input().split()))
v = 0

for _ in range(x):
    if len(r):
        if p[-1] > r[-1]:
            v += p.pop()
        else:
            v += r.pop()
    else:
        v += p.pop()

for _ in range(y):
    if len(r):
        if q[-1] > r[-1]:
            v += q.pop()
        else:
            v += r.pop()
    else:
        v += r.pop()

print(v)

x, y, a, b, c = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)
q = sorted(map(int, input().split()), reverse=True)
r = sorted(map(int, input().split()))
v = 0
c = sorted(p[0:x] + q[0:y])
for i in range(x + y):
    if len(r):
        if c[i] < r[-1]:
            c[i] = r.pop()
    else:
        break
print(sum(c))


X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

p = p[:X]
q = q[:Y]
plus_r = []

while r != [] and (p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1]):
    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

print(sum(p) + sum(q) + sum(plus_r))

X, Y, A, B, C = map(int, input().split())
p = sorted([int(i) for i in input().split()], reverse=True)
q = sorted([int(i) for i in input().split()], reverse=True)
r = sorted([int(i) for i in input().split()])

p = p[:X]
q = q[:Y]
plus_r = []

while r != [] and ((p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1])):
    if p == []:
        q.pop()
        plus_r.append(r.pop())
        continue
    elif q == []:
        p.pop()
        plus_r.append(r.pop())
        continue

    if p[-1] < q[-1]:
        p.pop()
    else:
        q.pop()
    plus_r.append(r.pop())

print(sum(p) + sum(q) + sum(plus_r))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02727/Python/s816996261.py", line 10, in <module>
    while r != [] and (p != [] and r[-1] > p[-1]) or (q != [] and r[-1] > q[-1]):
IndexError: list index out of range


X, Y, A, B, C = map(int, input().split())
p, pi = sorted(list(map(int, input().split())), reverse=True)[:X] + [-1], 0
q, qi = sorted(list(map(int, input().split())), reverse=True)[:Y] + [-1], 0
r, ri = sorted(list(map(int, input().split())), reverse=True) + [-1], 0
ans, nX, nY = 0, 0, 0
while nX < X or nY < Y:
    if r[ri] >= p[pi] and r[ri] >= q[qi]:
        if nX < X and nY < Y:
            if p[pi] >= q[qi]:
                nX += 1
            else:
                nY += 1
        elif nX < X:
            nX += 1
        elif nY < Y:
            nY += 1
        ans += r[ri]
        ri += 1
    elif p[pi] >= q[qi] and p[pi] >= r[ri]:
        if nX < X:
            nX += 1
            ans += p[pi]
            pi += 1
    elif q[qi] >= r[ri] and q[qi] >= p[pi]:
        if nY < Y:
            nY += 1
            ans += q[qi]
            qi += 1

print(ans)

X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())))[-X:]
q = sorted(list(map(int, input().split())))[-Y:]
r = list(map(int, input().split()))
print(sum(sorted(p + q + r)[-(X + Y) :]))


x, y, a, b, c = map(int, input().split())
La = sorted(list(map(int, input().split())), reverse=True)
Lb = sorted(list(map(int, input().split())), reverse=True)
Lc = sorted(list(map(int, input().split())), reverse=True)

L = La[:x]
L.extend(Lb[:y])
L.sort(reverse=False)

for i in range(c):
    if L[i] < Lc[i]:
        L[i] = Lc[i]

print(sum(L))

x, y, a, b, c = map(int, input().split())
La = sorted(list(map(int, input().split())), reverse=True)
Lb = sorted(list(map(int, input().split())), reverse=True)
Lc = sorted(list(map(int, input().split())), reverse=True)

L = La[:x]
L.extend(Lb[:y])
L.sort(reverse=False)
min = min(c, len(L))

for i in range(min):
    if L[i] < Lc[i]:
        L[i] = Lc[i]

print(sum(L))