import sys
from io import StringIO
import unittest
import os

sys.setrecursionlimit(9999999999)

def dfs(now, edge, colors):
    # 枝を全て調査
    for i in edge[now]:
        # 色を設定済みなら何もしない
        if not colors[i[0]] == -1:
            continue

        # 色の設定
        # 親子の距離%2(偶数0:奇数:1) + 親(偶数0:奇数:1) の余りを子に設定(偶数なら0 奇数なら1を設定できるロジック)
        colors[i[0]] = (i[1] % 2 + colors[now]) % 2

        # 再帰処理
        dfs(i[0], edge, colors)

# 実装を行う関数
def resolve():
    n = int(input())
    uvw = [list(map(int, input().split())) for i in range(n - 1)]

    edge = [[] for i in range(n + 1)]

    # 例：edge[0] = [[1, 100][2, 300]]
    # 点0は点1と距離100、点2と距離300でつながっている。
    for i in uvw:
        edge[i[0]].append([i[1], i[2]])
        edge[i[1]].append([i[0], i[2]])

    # -1は「未設定」の意味
    colors = [-1 for i in range(n + 1)]

    # 初期(適当な点を黒に塗る)
    colors[1] = 1

    dfs(1, edge, colors)

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

# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
1 2 2
2 3 1"""
        output = """0
0
1"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """5
2 5 2
2 3 10
1 3 8
3 4 2"""
        output = """1
0
1
0
1"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)

# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

import sys
from io import StringIO
import unittest
import os

sys.setrecursionlimit(999999999)

def dfs(now, edge, colors):
    # 枝を全て調査
    for i in edge[now]:
        # 色を設定済みなら何もしない
        if not colors[i[0]] == -1:
            continue

        # 色の設定
        # 親子の距離%2(偶数0:奇数:1) + 親(偶数0:奇数:1) の余りを子に設定(偶数なら0 奇数なら1を設定できるロジック)
        colors[i[0]] = (i[1] % 2 + colors[now]) % 2

        # 再帰処理
        dfs(i[0], edge, colors)

# 実装を行う関数
def resolve():
    n = int(input())
    uvw = [list(map(int, input().split())) for i in range(n - 1)]

    edge = [[] for i in range(n + 1)]

    # 例：edge[0] = [[1, 100][2, 300]]
    # 点0は点1と距離100、点2と距離300でつながっている。
    for i in uvw:
        edge[i[0]].append([i[1], i[2]])
        edge[i[1]].append([i[0], i[2]])

    # -1は「未設定」の意味
    colors = [-1 for i in range(n + 1)]

    # 初期(適当な点を黒に塗る)
    colors[1] = 1

    dfs(1, edge, colors)

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

# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
1 2 2
2 3 1"""
        output = """0
0
1"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """5
2 5 2
2 3 10
1 3 8
3 4 2"""
        output = """1
0
1
0
1"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)

# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03044/Python/s708960220.py", line 6, in <module>
    sys.setrecursionlimit(9999999999)
OverflowError: Python int too large to convert to C int


import sys

sys.setrecursionlimit(10**6)

class Tree:
    WHITE = 0
    GRAY = 1
    BLACK = 2

    def __init__(self, adj):
        n = len(adj)
        self.adj = adj
        self.colors = [self.WHITE] * n
        self.depths = [-1] * n
        self.depth = 0

    def dfs(self, u):
        if self.colors[u] == self.BLACK:
            return

        self.colors[u] = self.GRAY
        self.depths[u] = self.depth

        for v, w in self.adj[u]:
            if self.colors[v] == self.WHITE:
                self.depth += w
                self.dfs(v)
                self.depth -= w

        self.colors[u] = self.BLACK

if __name__ == "__main__":
    n = int(input())
    uvw = [list(map(int, input().split())) for _ in range(n - 1)]

    g = [[] for _ in range(n)]

    for u, v, w in uvw:
        u -= 1
        v -= 1
        g[u].append((v, w))
        g[v].append((u, w))

    tree = Tree(g)
    tree.dfs(0)
    ans = [x % 2 for x in tree.depths]
    print(*ans, sep="\\n")


N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append((v, w))
    G[v].append((u, w))

C = [-1 for _ in range(N)]

def dfs(pos, color):
    for e in G[pos]:
        if C[e[0]] != -1:
            continue
        # odd
        if e[1] & 1:
            c = 1 - color
            C[e[0]] = c
            dfs(e[0], c)
        # even
        else:
            c = color
            C[e[0]] = c
            dfs(e[0], c)

C[0] = 0
dfs(0, 0)
for i in range(N):
    print(C[i])

import sys

sys.setrecursionlimit(100000)

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append((v, w))
    G[v].append((u, w))

C = [-1 for _ in range(N)]

def dfs(pos, color):
    C[pos] = color
    for e in G[pos]:
        if C[e[0]] != -1:
            continue
        # odd
        if e[1] & 1:
            c = 1 - color
            dfs(e[0], c)
        # even
        else:
            c = color
            dfs(e[0], c)

dfs(0, 0)
for i in range(N):
    print(C[i])


import sys
from io import StringIO
import unittest
import os

def dfs(now, edge, colors):
    # 枝を全て調査
    for i in edge[now]:
        # 色を設定済みなら何もしない
        if not colors[i[0]] == -1:
            continue

        # 色の設定
        # 親子の距離%2(偶数0:奇数:1) + 親(偶数0:奇数:1) の余りを子に設定(偶数なら0 奇数なら1を設定できるロジック)
        colors[i[0]] = (i[1] % 2 + colors[now]) % 2

        # 再帰処理
        dfs(i[0], edge, colors)

# 実装を行う関数
def resolve():
    n = int(input())
    uvw = [list(map(int, input().split())) for i in range(n - 1)]

    edge = [[] for i in range(n + 1)]

    # 例：edge[0] = [[1, 100][2, 300]]
    # 点0は点1と距離100、点2と距離300でつながっている。
    for i in uvw:
        edge[i[0]].append([i[1], i[2]])
        edge[i[1]].append([i[0], i[2]])

    # -1は「未設定」の意味
    colors = [-1 for i in range(n + 1)]

    # 初期(適当な点を黒に塗る)
    colors[1] = 1

    dfs(1, edge, colors)

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

# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
1 2 2
2 3 1"""
        output = """0
0
1"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """5
2 5 2
2 3 11
1 3 8
3 4 2"""
        output = """1
0
1
0
1"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)

# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

import sys
from io import StringIO
import unittest
import os

sys.setrecursionlimit(1000000)

def dfs(now, edge, colors):
    # 枝を全て調査
    for i in edge[now]:
        # 色を設定済みなら何もしない
        if not colors[i[0]] == -1:
            continue

        # 色の設定
        # 親子の距離%2(偶数0:奇数:1) + 親(偶数0:奇数:1) の余りを子に設定(偶数なら0 奇数なら1を設定できるロジック)
        colors[i[0]] = (i[1] % 2 + colors[now]) % 2

        # 再帰処理
        dfs(i[0], edge, colors)

# 実装を行う関数
def resolve():
    n = int(input())
    uvw = [list(map(int, input().split())) for i in range(n - 1)]

    edge = [[] for i in range(n + 1)]

    # 例：edge[0] = [[1, 100][2, 300]]
    # 点0は点1と距離100、点2と距離300でつながっている。
    for i in uvw:
        edge[i[0]].append([i[1], i[2]])
        edge[i[1]].append([i[0], i[2]])

    # -1は「未設定」の意味
    colors = [-1 for i in range(n + 1)]

    # 初期(適当な点を黒に塗る)
    colors[1] = 1

    dfs(1, edge, colors)

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

# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
1 2 2
2 3 1"""
        output = """0
0
1"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """5
2 5 2
2 3 10
1 3 8
3 4 2"""
        output = """1
0
1
0
1"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)

# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


def dfs(v, p, c):
    for u, w in tree[v]:
        res[v] = c
        if u == p:
            continue
        else:
            if w % 2 == 0:
                dfs(u, v, c)
            else:
                dfs(u, v, c + 1)

n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append([v - 1, w])
    tree[v - 1].append([u - 1, w])

res = [0 for _ in range(n)]
dfs(0, -1, 0)

for i in res:
    print(i)

import sys

sys.setrecursionlimit(10**9)

def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)

n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))

dist = [0 for _ in range(n)]
dfs(0, -1, dist)

for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)


import sys
from collections import defaultdict

input = sys.stdin.readline

N = int(input())
G = defaultdict(list)
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    G[u - 1].append((v - 1, w))
    G[v - 1].append((u - 1, w))
res = [None] * N

def dfs(v, c):
    res[v] = c
    for u, w in G[v]:
        if res[u] is not None:
            continue
        if w % 2 == 0:
            dfs(u, c)
        else:
            dfs(u, 1 - c)

dfs(0, 0)
for x in res:
    print(x)

import sys
from collections import defaultdict

sys.setrecursionlimit(100000)
input = sys.stdin.readline

N = int(input())
G = defaultdict(list)
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    G[u - 1].append((v - 1, w))
    G[v - 1].append((u - 1, w))
res = [None] * N

def dfs(v, c):
    res[v] = c
    for u, w in G[v]:
        if res[u] is not None:
            continue
        if w % 2 == 0:
            dfs(u, c)
        else:
            dfs(u, 1 - c)

dfs(0, 0)
for x in res:
    print(x)


import sys

sys.setrecursionlimit(200000)

N = int(input())

neighbors = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    neighbors[u].append((v, w))
    neighbors[v].append((u, w))

ans = [None for _ in range(N)]

def dfs(v, p, c):
    ans[v - 1] = c
    for next_v, distance in neighbors[v]:
        if next_v == p:
            continue
        next_c = c if distance % 2 == 0 else 1 - c
        dfs(next_v, v, next_c)

dfs(1, -1, 0)
for e in ans:
    print(e)


import networkx as nx

N = int(input())

UVW = [list(map(int, input().split())) for _ in range(N - 1)]

G = nx.Graph()

color = [0 for _ in range(N)]  # 0: tbd，1: white, 2: black

for u, v, w in UVW:
    G.add_edge(u - 1, v - 1, weight=w)

color[0] = -1

for i in range(N - 1):
    if color[i] == 0 or i == 0:
        for j in range(i + 1, N):
            if color[j] == 0:
                d = nx.shortest_path_length(G, source=i, target=j, weight="weight")
                if int(d + 0.5) % 2 == 0:
                    color[j] = color[i]
                else:
                    color[j] = color[i] * -1

ans = [1 if i == -1 else 0 for i in color]
print(*ans)

import networkx as nx

N = int(input())
UVW = [list(map(int, input().split())) for _ in range(N - 1)]

G = nx.Graph()

color = [0 for _ in range(N)]

for u, v, w in UVW:
    G.add_edge(u - 1, v - 1, weight=w)

color[0] = -1

pred, dist = nx.dijkstra_predecessor_and_distance(G, 0)

c = [dist[i] for i in range(N)]
ans = [1 if i % 2 == 0 else 0 for i in c]
print(*ans)


from sys import setrecursionlimit

setrecursionlimit(10**8)

def dfs(i, d):
    # print(i, d)
    for j, w in node_array[i]:
        if color_array[j] == -1:
            color_array[j] = (d + w) % 2
            dfs(j, d + w)

N = int(input())
node_array = [[] for i in range(N)]
color_array = [-1] * N

for _ in range(N - 1):
    i, j, w = map(int, input().split())
    node_array[i - 1].append((j - 1, w))
    node_array[j - 1].append((i - 1, w))

color_array[0] = 0
dfs(0, 0)

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


from collections import deque

N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u, v, w = u - 1, v - 1, w % 2
    graph[u].append([v, w])
    graph[v].append([u, w])

colors = [-1 for _ in range(N)]
stack = deque()
stack.append(0)
colors[0] = 0

while stack:
    n = stack.pop()
    for _next, w in graph[n]:
        if colors[_next] != -1:
            continue
        colors[_next] = (colors[n] + w) % 2
        stack.append([_next])

for c in colors:
    print(c)

from collections import deque

N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u, v = u - 1, v - 1
    graph[u].append([v, w])
    graph[v].append([u, w])

colors = [-1 for _ in range(N)]
stack = deque()
stack.append(0)
colors[0] = 0

while stack:
    n = stack.popleft()
    for _next, w in graph[n]:
        if colors[_next] != -1:
            continue
        colors[_next] = (colors[n] + w) % 2
        stack.append(_next)

for c in colors:
    print(c)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03044/Python/s113709906.py", line 18, in <module>
    for _next, w in graph[n]:
TypeError: list indices must be integers or slices, not list


from scipy.sparse import lil_matrix
from scipy.sparse.csgraph import connected_components

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

for _ in range(M):
    x, y, z = map(int, input().split())
    matr[x - 1, y - 1] = matr[y - 1, x - 1] = 1

matr = matr.tocsr()
print(connected_components(matr, return_labels=False))

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components

N, M = map(int, input().split())
edge = np.array([input().split() for _ in range(M)], dtype=np.int64).T

matr = csr_matrix(([1 for _ in range(M)], (edge[:2] - 1)), (N, N))
print(connected_components(matr, return_labels=False))


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

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

def root(x):
    i = x
    while xy[i] != 0:
        i = xy[i]
    return i

for _ in range(m):
    x, y, z = map(int, input().split())
    rx = root(x)
    ry = root(y)
    if rx != ry:
        xy[ry] = rx

ans = 0
for i in xy[1:]:
    if i == 0:
        ans += 1

print(ans)

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

xy = [i for i in range(n + 1)]

def root(x):
    i = x
    while i != xy[i]:
        i = xy[i]
    xy[x] = i
    return i

for _ in range(m):
    x, y, z = map(int, input().split())
    rx = root(x)
    ry = root(y)
    if rx != ry:
        xy[ry] = rx

ans = -1
for i, v in enumerate(xy):
    if i == v:
        ans += 1

print(ans)


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

p = list(range(n))

def find(x):
    if p[x] != x:
        p[x] = find(p[x])
    return p[x]

def union(x, y):
    x, y = find(x), find(y)
    p[y] = x

for _ in range(m):
    x, y, z = [int(i) - 1 for i in input().split()]
    if find(x) != find(y):
        union(x, y)

ans = set()
for i in range(n):
    find(i)
print(len(set(p)))

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

p = list(range(n))

def find(x):
    if p[x] != x:
        p[x] = find(p[x])
    return p[x]

def union(x, y):
    x, y = find(x), find(y)
    p[x] = p[y] = min(x, y)

for _ in range(m):
    x, y, z = [int(i) - 1 for i in input().split()]
    if find(x) != find(y):
        union(x, y)

ans = set()
for i in range(n):
    find(i)
print(len(set(p)))


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

print(N - K + 1)

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

print(N - K + 1)

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


N, K = map(int, input())
print(N - (K - 1))

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

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


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

print(n - k + 1)

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

print(nk[0] - nk[1] + 1)

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


#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
# input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
a, b, c, n = map(int, input().split())
ans = 0
for i in range(3001):
    for j in range(3001):
        if n <= i * a + j * b and (n - i * a - j * b) % c == 0:
            ans += 1
print(ans)

#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
# input = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
a, b, c, n = map(int, input().split())
ans = 0
for i in range(3001):
    for j in range(3001):
        if n >= i * a + j * b and (n - i * a - j * b) % c == 0:
            ans += 1
print(ans)


r, g, b, n = map(int, input().split())

cnt = 0
for i in range(3001):
    for j in range(3001):
        x = n - (r * i + g * j)
        if x < 0:
            continue
        if x % b == 0:
            cnt += 1

print(cnt)

r, g, b, n = map(int, input().split())

cnt = 0
for i in range(int(n // r) + 1):
    r_num = r * i
    for j in range(int((n - r_num) // g) + 1):
        g_num = g * j
        b_num = n - r_num - g_num
        if b_num >= 0 and b_num % b == 0:
            cnt += 1

print(cnt)


r, g, b, n = map(int, input().split())
arr = [r, g, b]
arr.sort()
ans = 0
for i in range(n // arr[2] + 1):
    if arr[2] * i > n:
        break
    for j in range(n // arr[1] + 1):
        tmp = arr[2] * i + arr[1] * j
        if tmp > n:
            break
        else:
            if tmp == n:
                ans += 1
                break
            elif n - tmp > 0 and (n - tmp) % arr[0] == 0:
                ans += 1

print(ans)

R, G, B, n = map(int, input().split())
ans = 0
for r in range(n // R + 1):
    Rr = R * r
    for g in range((n - Rr) // G + 1):
        tmp = Rr + G * g
        if (n - tmp) % B == 0:
            ans += 1
print(ans)


r, g, b, n = map(int, input().split())
c = sorted([r, g, b])[::-1]
ans = 0
for i in range(n // c[0] + 1):
    for j in range((n - i * r) // c[1] + 1):
        x = n - i * c[0] - j * c[1]
        if x >= 0 and x % c[2] == 0:
            ans += 1
print(ans)

r, g, b, n = map(int, input().split())
c = sorted([r, g, b])[::-1]
ans = 0
for i in range(n // c[0] + 1):
    x = n - i * c[0]
    for j in range(x // c[1] + 1):
        y = x - j * c[1]
        if y < 0:
            break
        elif y % c[2] == 0:
            ans += 1
print(ans)


r, g, b, n = map(int, input().split())

if r >= g and g >= b:
    pass
elif r >= b and b >= g:
    temp = g
    g = b
    b = temp
else:
    temp = r
    r = g
    g = temp

rg = {}
ri = 0
while ri <= n:
    gi = 0
    while gi <= n - ri:
        if (n - ri - gi) % b == 0:
            total = rg.get(ri + gi, 0)
            rg[ri + gi] = total + 1
        else:
            pass
        gi += g
    ri += r

bi = 0
result = 0

while bi <= n:
    total = rg.get(n - bi, 0)
    result += total
    bi += b

print(result)

r, g, b, n = map(int, input().split())

if r >= g and g >= b:
    pass
elif r >= b and b >= g:
    temp = g
    g = b
    b = temp
else:
    temp = r
    r = g
    g = temp

if (r == 1 and g == 1) or (r == 1 and b == 1) or (g == 1 and b == 1):
    rg = [i + 1 for i in range(n + 1)]
elif (
    (r == 1 and g == 2)
    or (r == 1 and b == 2)
    or (g == 1 and b == 2)
    or (r == 2 and g == 1)
    or (r == 2 and b == 1)
    or (g == 2 and b == 1)
):
    rg = [1 + i // 2 for i in range(n + 1)]
else:
    rg = [0 for _ in range(n + 1)]
    ri = 0
    while ri <= n:
        gi = 0
        while gi <= n - ri:
            rg[ri + gi] += 1
            gi += g
        ri += r

bi = 0
result = 0

while bi <= n:
    total = rg[n - bi]
    result += total
    bi += b

print(result)


R, G, B, N = map(int, input().split())
ans = 0
for r in range(N + 1):
    for g in range(N + 1):
        b = (N - R * r - G * g) / B
        if b >= 0 and int(b) == b:
            ans += 1
print(ans)

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range(N // G + 1):
        b = (N - R * r - G * g) / B
        if b == int(b) and b >= 0:
            ans += 1
print(ans)


R, G, B, N = map(int, input().split())

res = 0

for i in range(N // R + 1):
    for j in range(N // G + 1):
        b = N - R * i - G * j
        if b >= 0 and b % B == 0:
            res += 1

print(res)

R, G, B, N = map(int, input().split())

res = 0

for i in range(N // R + 1):
    for j in range((N - R * i) // G + 1):
        b = N - R * i - G * j
        if b >= 0 and b % B == 0:
            res += 1

print(res)


R, G, B, N = map(int, input().split())

ans = 0
for r in range(N // R + 1):
    if N - r * R < 0:
        break
    for g in range((N - R * r) // G + 1):
        tmp = N - r * R - g * G
        if tmp < 0:
            break
        if tmp % B == 0 and tmp // B >= 0:
            ans += 1

print(ans)

R, G, B, N = map(int, input().split())

ans = 0
for r in range(N // R + 1):
    for g in range((N - R * r) // G + 1):
        tmp = N - r * R - g * G
        if tmp % B == 0:
            ans += 1

print(ans)


r, g, b, n = map(int, input().split())
ans = 0
nr = n // r
ng = n // g
for i in range(nr + 1):
    for j in range(ng + 1):
        tmp = n - i * r - j * g
        if tmp % b == 0 and tmp >= 0:
            ans += 1
print(ans)

r, g, b, n = map(int, input().split())
ans = 0
nr = n // r
ng = n // g
for i in range(nr + 1):
    for j in range(ng + 1):
        tmp = n - i * r - j * g
        if tmp >= 0 and tmp % b == 0:
            ans += 1
print(ans)


R, G, B, N = map(int, input().split())
LIM = 3003
ans = 0
for r in range(LIM):
    for g in range(LIM):
        if R * r + G * g > N:
            break
        Bb = N - R * r - G * g
        if Bb % B == 0:
            ans += 1
print(ans)

def solve():
    R, G, B, N = map(int, input().split())
    LIM = 3001
    ans = 0
    for r in range(LIM):
        for g in range(LIM):
            if R * r + G * g > N:
                break
            Bb = N - R * r - G * g
            if Bb % B == 0:
                ans += 1
    return ans

print(solve())


# import time
R, G, B, N = map(int, input().split())
# print(R, G, B)
i = 0
# r, g = 0, 0
# s = time.time()
for r in range(N // R + 1):
    for g in range(N // G + 1):
        if (N - r * R - g * G) >= 0:
            b = int((N - r * R - g * G) / B)
            if N - (r * R + g * G + b * B) == 0:
                # print(r, g, b)
                i += 1
print(i)
# print(time.time()-s)

R, G, B, N = map(int, input().split())
i = 0
for r in range(N // R + 1):
    Rr = r * R
    for g in range(N // G + 1):
        Gg = g * G
        Bb = N - Rr - Gg
        if Bb < 0:
            break
        if Bb % B == 0:
            i += 1
print(i)


r, g, b, n = map(int, input().split())

count = 0
r, g, b = sorted([r, g, b])

for i in range(n // r + 1):
    total = r * i
    if total > n:
        continue
    for j in range((n - total) // g + 1):
        total = r * i + g * j
        if total > n:
            continue
        for k in range((n - total) // b + 1):
            total = r * i + g * j + b * k
            if total == n:
                count += 1

print(count)

r, g, b, n = map(int, input().split())

count = 0
r, g, b = sorted([r, g, b], reverse=True)

for i in range(n // r + 1):
    rc = r * i
    for j in range((n - rc) // g + 1):
        gc = g * j
        if (n - rc - gc) % b == 0:
            count += 1
print(count)


R, G, B, N = map(int, input().split())

ans = 0
for i in range(N // R + 1):
    N_R = N - i * R
    for j in range(N_R // G + 1):
        N_RG = N_R - j * G
        for k in range(N_RG // B + 1):
            N_RGB = N_RG - k * B
            if N_RGB == 0:
                ans += 1
print(ans)

R, G, B, N = map(int, input().split())

ans = 0
for i in range(N // R + 1):
    for j in range((N - i * R) // G + 1):
        if (N - i * R - j * G) % B == 0:
            ans += 1
print(ans)


R, G, B, N = map(int, input().split())

res = 0
for i in range(N // R + 1):
    for j in range(N // G + 1):
        b = N - (i * R + j * G)
        if b >= 0 and b % B == 0:
            res += 1
print(res)

R, G, B, N = map(int, input().split())

res = 0
for i in range(N // R + 1):
    for j in range((N - i * R) // G + 1):
        if (N - (i * R + j * G)) % B == 0:
            res += 1

print(res)


R, G, B, N = map(int, input().split())
ans = 0

for r in range(min(3000, 3000 // R) + 1):
    for g in range(min(3000, 3000 // G) + 1):
        v = R * r + G * g
        if N >= v and (N - v) % B == 0:
            ans += 1

print(ans)

R, G, B, N = map(int, input().split())
ans = 0

for r in range(min(3000, 3000 // R) + 1):
    if R * r <= N:
        for g in range(min(3000, 3000 // G) + 1):
            v = R * r + G * g
            if N >= v and (N - v) % B == 0:
                ans += 1

print(ans)


R, G, B, N = map(int, input().split())
ans = 0
for r in range(3001):
    if R * r > N:
        break
    for g in range(3001):
        if R * r + G * g > N:
            break
        elif (N - (R * r + G * g)) % B == 0:
            ans += 1
print(ans)

R, G, B, N = map(int, input().split())
ans = 0
for r in range(N // R + 1):
    for g in range((N - R * r) // G + 1):
        if (N - (R * r + G * g)) % B == 0:
            ans += 1
print(ans)


r, g, b, n = map(int, input().split())
s_rgb = sorted([r, g, b], reverse=True)
result = 0
for i in range(int(n / s_rgb[0]) + 1)[::-1]:
    for j in range(int((n - s_rgb[0] * i) / s_rgb[1]) + 1)[::-1]:
        if s_rgb[0] * i + s_rgb[1] * j > n:
            break
        for k in range(int((n - s_rgb[0] * i - s_rgb[1] * j) / s_rgb[2]) + 1)[::-1]:
            if s_rgb[0] * i + s_rgb[1] * j + s_rgb[2] * k > n:
                break
            if s_rgb[0] * i + s_rgb[1] * j + s_rgb[2] * k == n:
                result += 1
                break
print(result)

r, g, b, n = map(int, input().split())
s_rgb = sorted([r, g, b], reverse=True)
count = 0
for i in range(int(n / s_rgb[0]) + 1)[::-1]:
    for j in range(int((n - s_rgb[0] * i) / s_rgb[1]) + 1)[::-1]:
        tmp = n - s_rgb[0] * i - s_rgb[1] * j
        if tmp >= 0 and tmp % s_rgb[2] == 0:
            count += 1
print(count)


R, G, B, N = map(int, input().split())

counter = 0
for r in range((N // R) + 1):
    for g in range(((N - (r * R)) // G) + 1):
        w_b_sum = N - ((R * r) + (G * g))

        if w_b_sum % B == 0 and w_b_sum >= 0 and w_b_sum == N - ((R * r) + (G * g)):
            # print(r, g, (w_b_sum // B))
            counter += 1
print(counter)

R, G, B, N = map(int, input().split())

counter = 0
for r in range((N // R) + 1):
    for g in range(((N - (r * R)) // G) + 1):
        w_b_sum = N - ((R * r) + (G * g))

        if w_b_sum % B == 0 and w_b_sum >= 0:
            # print(r, g, (w_b_sum // B))
            counter += 1
print(counter)


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

def gcd(a, b):
    # greatest common divisor
    la = max(a, b)
    sm = min(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la - sm)

def lcm(a, b):
    # least common multiple
    return a * b // gcd(a, b)

R, G, B, N = inpl()
ans = 0
for r in range(N // R + 1):
    rest = N - r * R
    for i in range(B):
        if (G * i) % B == rest % B:
            x = i
            break
    else:
        # print(r)
        continue
    if rest - G * x < 0:
        continue
    ans += (rest - G * x) // lcm(B, G) + 1
    # print(r, rest, x, ans)

print(ans)

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

def gcd(a, b):
    # greatest common divisor
    la = max(a, b)
    sm = min(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la - sm)

def lcm(a, b):
    # least common multiple
    return a * b // gcd(a, b)

import sys

sys.setrecursionlimit(5000)

R, G, B, N = inpl()
ans = 0
for r in range(N // R + 1):
    rest = N - r * R
    for i in range(B):
        if (G * i) % B == rest % B:
            x = i
            break
    else:
        # print(r)
        continue
    if rest - G * x < 0:
        continue
    ans += (rest - G * x) // lcm(B, G) + 1
    # print(r, rest, x, ans)

print(ans)


R, G, B, N = map(int, input().split())

ans = 0
for i in range(int(N / R) + 1):
    for j in range(int((N - i * R) / G) + 1):
        if (N - (i * R + j * G)) % B == 0 and (N - (i * R + j * G)) >= 0:
            ans += 1
print(ans)

R, G, B, N = map(int, input().split())

ans = 0
for i in range(int(N / R) + 1):
    for j in range(int((N - i * R) / G) + 1):
        if (N - (i * R + j * G)) % B == 0:
            ans += 1
print(ans)


r, g, b, n = map(int, input().split())

ans = 0
for i in range(n // r + 1):
    for j in range(n // g + 1):
        m = r * i + g * j
        if m <= n and (n - m) % b == 0:
            ans += 1

print(ans)

r, g, b, n = map(int, input().split())

ans = 0
for i in range(n // r + 1):
    for j in range(n // g + 1):
        m = r * i + g * j
        if m <= n and (n - m) % b == 0:
            ans += 1
        elif m > n:
            break

print(ans)


import math

def main():
    n = int(input())
    a = []
    for i in range(1, (int)(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                a.append(i - 1)
            a.append((n // i) - 1)
    a.sort()
    ans = 0
    if len(a) == 0:
        ans = 0
    else:
        for i in a:
            if i != 1 and (n // i == n % i):
                ans += i
    print(ans)

main()

import math

def main():
    n = int(input())
    a = []
    for i in range(1, (int)(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                a.append(i - 1)
            if n // i - 1 != 0:
                a.append((n // i) - 1)
    ans = 0
    for i in range(len(a)):
        if a[i] != 1 and (n // a[i] == n % a[i]):
            ans += a[i]
    print(ans)

main()


import math

N = int(input())
ans = 0
for i in range(1, int(math.sqrt(N)) + 2):
    if N % i:
        continue
    m = N // i - 1
    if N // m == N % m:
        ans += m
print(ans)

import math

N = int(input())
ans = 0
for i in range(1, int(math.sqrt(N)) + 2):
    if N % i:
        continue
    m = N // i - 1
    if m <= 0:
        continue
    if N // m == N % m:
        ans += m
print(ans)


n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if n // m == n % m:
            ans += m

print(ans)

n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if m != 0 and n // m == n % m:
            ans += m

print(ans)


import math

N = int(input())
ans = 0
for i in range(1, math.ceil(math.sqrt(N)) + 1):
    if N % i:
        continue
    n = N // i - 1
    if N % n == N // n:
        ans += n
print(ans)

import math

N = int(input())
ans = 0
for i in range(1, math.ceil(math.sqrt(N)) + 1):
    if N % i:
        continue
    n = N // i - 1
    if n and N % n == N // n:
        ans += n
print(ans)


n = int(input())
i = 1
ans = 0
while True:
    d, m = divmod(n, i)
    if m != 0:
        i += 1
        continue
    d -= 1
    if i >= d:
        break
    ans += d
    i += 1
print(ans)

n = int(input())
i = 1
ans = 0
while True:
    d, m = divmod(n, i)
    d -= 1
    if i >= d:
        break
    if m != 0:
        i += 1
        continue
    ans += d
    i += 1
print(ans)


H, W = map(int, input().split())
items = []
black = []
for i in range(H):
    tmp = input()
    for j in range(W):
        if tmp[j] == "#":
            black.append((i, j))
    items.append(list(tmp))

que = []

for b in black:
    que.append(b)

ans = 0
d4 = [(1, 0), (0, -1), (-1, 0), (0, 1)]
next_que = que.copy()
while len(que) != H * W:
    tmp = next_que.copy()
    next_que = []
    for b in list(tmp):
        x, y = b[0], b[1]
        for d in d4:
            dx = d[0]
            dy = d[1]
            if 0 <= x + dx <= H - 1 and 0 <= y + dy <= W - 1:
                tar = items[x + dx][y + dy]
                if tar == ".":
                    next_que.append((x + dx, y + dy))
                    que.append((x + dx, y + dy))
                    items[x + dx][y + dy] = "#"
    ans += 1
print(ans)

H, W = map(int, input().split())
items = []
black = []
for i in range(H):
    tmp = list(input())
    for j in range(W):
        if tmp[j] == "#":
            black.append((i, j))
    items.append(tmp)

que = []
for b in black:
    que.append(b)

ans = 0
d4 = [(1, 0), (0, -1), (-1, 0), (0, 1)]
next_que = que
while len(que) != H * W:
    tmp = next_que
    next_que = []
    for b in list(tmp):
        x, y = b[0], b[1]
        for d in d4:
            dx = d[0]
            dy = d[1]
            if 0 <= x + dx <= H - 1 and 0 <= y + dy <= W - 1:
                tar = items[x + dx][y + dy]
                if tar == ".":
                    next_que.append((x + dx, y + dy))
                    que.append((x + dx, y + dy))
                    items[x + dx][y + dy] = "#"
    ans += 1
print(ans)


H, W = map(int, input("").split(" "))

grid = []
blacks = set()
for i in range(H):
    row = list(input(""))
    grid.append(row)

    for idx, r in enumerate(row):
        if r == "#":
            blacks.add((i, idx))

c = 0
while len(blacks) > 0:
    c += 1

    new_blacks = set()
    for b in blacks:
        top = b[0] - 1
        bottom = b[0] + 1
        left = b[1] - 1
        right = b[1] + 1

        if top >= 0:
            if grid[top][b[1]] == ".":
                grid[top][b[1]] = "#"
                new_blacks.add((top, b[1]))
        if bottom < H:
            if grid[bottom][b[1]] == ".":
                grid[bottom][b[1]] = "#"
                new_blacks.add((bottom, b[1]))
        if left >= 0:
            if grid[b[0]][left] == ".":
                grid[b[0]][left] = "#"
                new_blacks.add((b[0], left))
        if right < W:
            if grid[b[0]][right] == ".":
                grid[b[0]][right] = "#"
                new_blacks.add((b[0], right))

    blacks = new_blacks

print(c - 1)

H, W = map(int, input("").split(" "))

grid = []
blacks = []
for i in range(H):
    row = list(input(""))
    grid.append(row)

    for idx, r in enumerate(row):
        if r == "#":
            blacks.append((i, idx))

c = 0
while len(blacks) > 0:
    c += 1

    new_blacks = []
    for b in blacks:
        top = b[0] - 1
        bottom = b[0] + 1
        left = b[1] - 1
        right = b[1] + 1

        if top >= 0:
            if grid[top][b[1]] == ".":
                grid[top][b[1]] = "#"
                new_blacks.append((top, b[1]))
        if bottom < H:
            if grid[bottom][b[1]] == ".":
                grid[bottom][b[1]] = "#"
                new_blacks.append((bottom, b[1]))
        if left >= 0:
            if grid[b[0]][left] == ".":
                grid[b[0]][left] = "#"
                new_blacks.append((b[0], left))
        if right < W:
            if grid[b[0]][right] == ".":
                grid[b[0]][right] = "#"
                new_blacks.append((b[0], right))

    blacks = new_blacks

print(c - 1)


from collections import deque
import sys

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

h, w = map(int, input().split())
grid = [input() for _ in range(h)]
cost = [[float("inf")] * w for _ in range(h)]
nb = [(-1, 0), (0, -1), (1, 0), (0, 1)]

q = deque()
for i in range(h):
    for j in range(w):
        if grid[i][j] == "#":
            q.append((i, j))
            cost[i][j] = 0

while q:
    x, y = q.popleft()
    for dx, dy in nb:
        nx = x + dx
        ny = y + dy
        if 0 <= nx and nx < h and 0 <= ny and ny < w and cost[nx][ny] == float("inf"):
            cost[nx][ny] = cost[x][y] + 1
            q.append((nx, ny))

print(max([max(c) for c in cost]))

from collections import deque

H, W = map(int, input().split())
A = [input() for i in range(H)]
q = deque()
c = [[-1] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i, j))
            c[i][j] = 0
D = [[0, 1], [1, 0], [0, -1], [-1, 0]]
while q:
    y, x = q.popleft()
    for dy, dx in D:
        ny, nx = y + dy, x + dx
        if 0 <= ny < H and 0 <= nx < W and c[ny][nx] == -1:
            q.append((ny, nx))
            c[ny][nx] = c[y][x] + 1
print(max([max(l) for l in c]))


import sys
from collections import deque

import numpy as np

input = sys.stdin.readline

def bfs(H, W, A, dist):
    queue = deque([])
    for h, w in zip(*np.where(A == "#")):
        dist[h, w] = 0
        queue.append((h, w))
    while queue:
        h, w = queue.popleft()
        for y, x in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            next_h, next_w = h + y, w + x
            if not (0 <= next_h < H and 0 <= next_w < W):
                continue
            if dist[next_h][next_w] == -1:
                dist[next_h][next_w] = dist[h][w] + 1
                queue.append((next_h, next_w))

    return dist.max()

def main():
    H, W = map(int, input().split())
    A = np.zeros(shape=(H, W), dtype=str)
    for i in range(H):
        A[i] = list(input().rstrip())

    dist = np.full(shape=(H, W), fill_value=-1, dtype=np.int32)
    ans = bfs(H, W, A, dist)
    print(ans)

if __name__ == "__main__":
    main()

import sys
from collections import deque

input = sys.stdin.readline

def bfs(H, W, A, dist):
    queue = deque([])
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#":
                dist[h][w] = 0
                queue.append((h, w))
    while queue:
        h, w = queue.popleft()
        for y, x in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            next_h, next_w = h + y, w + x
            if dist[next_h][next_w] == -1:
                dist[next_h][next_w] = dist[h][w] + 1
                queue.append((next_h, next_w))

def main():
    H, W = map(int, input().split())
    A = [None] * (H + 2)
    A[0] = A[-1] = "." * (W + 2)
    for i in range(1, H + 1):
        A[i] = "".join([".", input().rstrip(), "."])

    dist = [[0] + [-1] * W + [0] for _ in range(H + 2)]
    dist[0] = dist[-1] = [0] * (W + 2)
    bfs(H + 2, W + 2, A, dist)

    ans = max(map(max, dist))
    print(ans)

if __name__ == "__main__":
    main()


from collections import deque

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

q = deque()
done = set()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            q.append((i, j, 0))
            done.add((i, j))

while q:
    # print(q)
    i, j, k = q.popleft()
    if i > 0 and (i - 1, j) not in done:
        q.append((i - 1, j, k + 1))
        done.add((i - 1, j))
    if i < h - 1 and (i + 1, j) not in done:
        q.append((i + 1, j, k + 1))
        done.add((i + 1, j))
    if j > 0 and (i, j - 1) not in done:
        q.append((i, j - 1, k + 1))
        done.add((i, j - 1))
    if j < w - 1 and (i, j + 1) not in done:
        q.append((i, j + 1, k + 1))
        done.add((i, j + 1))

print(k)

import numpy as np
from scipy.ndimage.morphology import distance_transform_cdt

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

a = np.array([[(ai[j] != "#") for j in range(w)] for ai in a])
d = distance_transform_cdt(a, metric="taxicab").max()
print(d)


H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input()
T = input()

left = 1
right = W
up = 1
down = H

for i in reversed(range(N)):
    if i != N - 1:
        if T[i] == "U":
            if down != H:
                down -= 1
        elif T[i] == "D":
            if up != 1:
                up += 1
        elif T[i] == "L":
            if right != W:
                right += 1
        else:
            if left != 1:
                left -= 1
    if S[i] == "U":
        up -= 1
    elif S[i] == "D":
        down += 1
    elif S[i] == "L":
        left += 1
    else:
        right -= 1
    if left == right or up == down:
        print("NO")
        exit()
if left <= sr <= right and up <= sc <= down:
    print("YES")
else:
    print("NO")

from collections import deque

H, W = map(int, input().split())
grid = (
    [["#"] * (W + 2)] + [list("#" + input() + "#") for i in range(H)] + [["#"] * (W + 2)]
)
# print(grid)
stack = deque()
for h in range(1, H + 1):
    for w in range(1, W + 1):
        # 黒ならスタックにpush
        if grid[h][w] == "#":
            stack.append([h, w])

for i in range(h + w + 3):
    tmp = deque()
    while stack:
        h, w = stack.pop()
        for dh, dw in ([0, 1], [0, -1], [1, 0], [-1, 0]):
            if grid[h + dh][w + dw] == ".":
                grid[h + dh][w + dw] = "#"
                tmp.append([h + dh, w + dw])
    stack = tmp
    if not stack:
        print(i)
        break

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


a, b, t = (int(i) for i in input())

times = int(t / a)

num = times * b

print(num)

a, b, t = (int(i) for i in input().split())

times = int(t / a)

num = times * b

print(num)

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


N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

# 価値 - コスト > 0 のフィルタ
for i in range(N):
    s = V[i] - C[i]
    if s > 0:
        ans += s

print(ans)

nums = [int(e) for e in input().split()]

a = nums[0]
b = nums[1]
t = nums[2]

ans = 0

ans = ((t + 0.5) // a) * b
print(int(ans))

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


def resolve():
    N = int(input())
    V = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    maxA = 0
    for i in range(2**N):
        X = 0
        Y = 0
        for j in range(N):
            if (i >> j) & 1:
                X += V[j]
                Y += C[j]
        maxA = max(maxA, X - Y)
    print(maxA)

resolve()

def resolve():
    N = int(input())
    V = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if V[i] > C[i]:
            ans += V[i] - C[i]
    print(ans)

resolve()


def sub():
    N, Vs, Cs = [e for e in input().split(" ")]
    N = int(N)
    Vs = [int(e) for e in Vs.split(" ")]
    Cs = [int(e) for e in Cs.split(" ")]
    ds = [v - c for v, c in zip(Vs, Cs)]
    ds = [d for d in ds if d > 0]
    print(sum(ds))

sub()

def sub():
    N, Vs, Cs = [input() for _ in range(3)]
    N = int(N)
    Vs = [int(e) for e in Vs.split(" ")]
    Cs = [int(e) for e in Cs.split(" ")]
    ds = [v - c for v, c in zip(Vs, Cs)]
    ds = [d for d in ds if d > 0]
    print(sum(ds))

sub()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03060/Python/s308117687.py", line 11, in <module>
    sub()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03060/Python/s308117687.py", line 2, in sub
    N, Vs, Cs = [e for e in input().split(" ")]
ValueError: not enough values to unpack (expected 3, got 1)


n = int(input())
v = [int(item) for item in input().split()]
c = [int(item) for item in input().split()]

d = [[v[i], c[i]] for i in range(n)]
d.sort(key=lambda x: x[0] - x[1], reverse=True)

ans = 0
i = 0
while d[i][0] - d[i][1] > 0:
    ans += d[i][0] - d[i][1]
    i += 1

print(ans)

n = int(input())
v = [int(item) for item in input().split()]
c = [int(item) for item in input().split()]

d = [[v[i], c[i]] for i in range(n)]
d.sort(key=lambda x: x[0] - x[1], reverse=True)

ans = 0
i = 0
while i < n and d[i][0] - d[i][1] > 0:
    ans += d[i][0] - d[i][1]
    i += 1

print(ans)


import itertools as it

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

ans = 0
for ith_conf in it.product(range(2), repeat=N):
    dif = 0
    for j_jewel in range(N):
        if ith_conf[j_jewel] == 1:
            dif += V[j_jewel] - C[j_jewel]
    ans = max(ans, dif)
print(ans)

N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    if V[i] > C[i]:
        ans += V[i] - C[i]
print(ans)


import math as mt

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

def solve(n: int, a: list):
    lgcd = [0] * (n - 1)
    lgcd[0] = a[0]
    for i in range(1, n - 1):
        lgcd[i] = mt.gcd(a[i], lgcd[i - 1])
    a.reverse()

    rgcd = [0] * (n - 1)
    rgcd[0] = a[0]
    for i in range(1, n - 1):
        rgcd[i] = mt.gcd(a[i], rgcd[i - 1])
    a.reverse()

    ans = [0] * n
    ans[0] = rgcd[n - 2]
    ans[n - 1] = lgcd[n - 2]
    for i in range(1, n):
        ans[i] = mt.gcd(lgcd[i - 1], rgcd[n - 2 - i])

    return max(ans)

print(solve(N, A))

from fractions import *

n, *a = map(int, open(0).read().split())
b = [0]
for i in a:
    b += (gcd(b[-1], i),)
w = m = 0
for i in range(n):
    m = max(m, gcd(w, b[-i - 2]))
    w = gcd(w, a[~i])
print(m)


from math import gcd

n = int(input())
a = list(map(int, input().split()))
p = list(a)
s = list(a)
for i in range(1, n):
    p[i] = gcd(p[i - 1], p[i])
for i in range(n - 2, -1, -1):
    s[i] = gcd(s[i], s[i + 1])

ans = max(p[-2], s[1])
if n > 2:
    ans = max(ans, max(gcd(p[i - 1], s[i + 1]) for i in range(1, n - 1)))

print(ans)

from fractions import gcd

n = int(raw_input())
a = list(map(int, raw_input().split()))
p = list(a)
s = list(a)
for i in range(1, n):
    p[i] = gcd(p[i - 1], p[i])
for i in range(n - 2, -1, -1):
    s[i] = gcd(s[i], s[i + 1])

ans = max(p[-2], s[1])
if n > 2:
    ans = max(ans, max(gcd(p[i - 1], s[i + 1]) for i in range(1, n - 1)))

print(ans)


from functools import lru_cache, reduce
from sys import stdin

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

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

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

if __name__ == "__main__":
    main()

from functools import lru_cache
from sys import stdin

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

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

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

if __name__ == "__main__":
    main()


import fractions
from functools import reduce

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

gcds = []

for i in range(n):
    as2 = as_[:]
    del as2[i]
    gcds.append(reduce(fractions.gcd, as2))

print(max(gcds))

from fractions import gcd

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

gcd_all = as_.pop()
set_ = {as_[0]}
for a in as_:
    set_ = set(gcd(s, a) for s in set_)
    set_.add(gcd_all)
    gcd_all = gcd(gcd_all, a)

print(max(set_))


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

if len(A) > 1:
    result = sorted(A)[1]
else:
    result = min(A)

while True:
    counter = 0
    should_continue = False
    for e in A:
        if e % result != 0:
            counter += 1
            if counter > 1:
                should_continue = True
                break
    if should_continue:
        continue
    if counter <= 1:  # 1つは書き換えられる
        break
    else:
        result -= 1

print(result)

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

if len(A) > 1:
    result = sorted(A)[1]
else:
    result = min(A)

while True:
    counter = 0
    should_continue = False
    for e in A:
        if e % result != 0:
            counter += 1
            if counter > 1:
                should_continue = True
                break
    if should_continue:
        result -= 1
        continue
    if counter <= 1:  # 1つは書き換えられる
        break
    else:
        result -= 1

print(result)


from math import gcd
from itertools import accumulate

input()
a = list(map(int, input().split()))
b = list(accumulate(a, gcd))
c = list(accumulate(reversed(a), gcd))
b = [c[-2]] + b
c = [b[-2]] + c
print(max(map(gcd, b, c[-2::-1])))

from fractions import gcd
from itertools import accumulate

input()
a = list(map(int, input().split()))
b = list(accumulate(a, gcd))
c = list(accumulate(reversed(a), gcd))
print(max(b[-2], c[-2], *map(gcd, b[:-2], c[-3::-1])))


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

v.sort()
c.sort()

maximum = 0
profit = []
for i in range(len(v)):
    tmp = v[i] - c[i]
    if tmp > 0:
        maximum += tmp
    tmp = 0

print(maximum)

from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
tA = list(reversed(A))
l = [0]
r = [0]
m = []
for i in range(N):
    tmpl = l[i]
    tmpa = A[i]
    tmpta = tA[i]
    l.append(gcd(l[i], A[i]))
    r.append(gcd(r[i], tA[i]))
r = list(reversed(r))
for i in range(N):
    m.append(gcd(l[i], r[i + 1]))
print(max(m))

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


from math import gcd

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

cum_left = [A[0]]
cum_right = [A[N - 1]]
for i in range(1, N - 1):
    cum_left.append(gcd(cum_left[-1], A[i]))
    cum_right.append(gcd(cum_right[-1], A[N - 1 - i]))

ans = max(cum_left[N - 2], cum_right[N - 2])
for i in range(1, N - 1):
    ans = max(ans, gcd(cum_left[i - 1], cum_right[N - 2 - i]))
print(ans)

from fractions import gcd

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

cum_left = [A[0]]
cum_right = [A[N - 1]]
for i in range(1, N - 1):
    cum_left.append(gcd(cum_left[-1], A[i]))
    cum_right.append(gcd(cum_right[-1], A[N - 1 - i]))

ans = max(cum_left[N - 2], cum_right[N - 2])
for i in range(1, N - 1):
    ans = max(ans, gcd(cum_left[i - 1], cum_right[N - 2 - i]))
print(ans)


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

def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    for i in range(N):
        tmp = As[:i] + As[i + 1 :]
        gI = gcd(tmp[0], tmp[1])
        tmp = tmp[2:]
        for t in tmp:
            gI = gcd(t, gI)
            if gI < memG:
                break
        if gI > memG:
            memG = gI
    print("{}".format(memG))

sub()

from functools import lru_cache, reduce

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

def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    # if N == 2:
    # memG = gcd(As[0], As[1])
    if N < 10:
        for i in range(N):
            tmp = As[:i] + As[i + 1 :]
            g = reduce(gcd, tmp)
            if g > memG:
                memG = g
    else:
        gLeft = {0: As[0], 1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI
        gRight = {N - 1: As[N - 1], N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        buf = []
        for i in range(N):
            leftG = None
            if (i - 1) in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if (i + 1) in gRight:
                rightG = gRight[i + 1]
            # tmpG = None
            if leftG is None:
                leftG = rightG
            elif rightG is None:
                rightG = leftG
            buf.append(gcd(leftG, rightG))
            # tmpG = gcd(leftG, rightG)
            # if tmpG > memG:
            #     memG = tmpG
        memG = max(buf)

    print("{}".format(memG))

sub()


from functools import reduce
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
A = list(set(a))
ans = [reduce(gcd, A)]

if len(A) == 1:
    print(A[0])
    exit()
for i in a:
    b = sorted(A)
    b.remove(i)
    if a.count(i) == 1:
        ans.append(reduce(gcd, b))

print(max(ans))

from functools import reduce
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
A = list(set(a))
ans = [reduce(gcd, A)]

if len(A) == 1:
    print(A[0])
    exit()
for i in A:
    b = sorted(A)
    b.remove(i)
    if a.count(i) == 1:
        ans.append(reduce(gcd, b))

print(max(ans))


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

def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a

gcds = []
for i in range(N):
    m = A[0] if i != 0 else A[1]
    for j in range(N):
        if i == j:
            continue
        m = gcd(m, A[j])
    gcds.append(m)

max_gcd = 1
for i in range(N):
    max_gcd = max(max_gcd, max(gcd(A[i], gcds[i]), gcds[i]))

print(max_gcd)

from itertools import *
import fractions

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

L = list(accumulate([0] + A, fractions.gcd))
R = list(accumulate([0] + A[::-1], fractions.gcd))

print(max(fractions.gcd(s, t) for s, t in zip(L, R[::-1][1:])))


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

def gcd_list(lst):
    a = lst[0]
    for i in lst[1:]:
        a = gcd(a, i)
    return a

n = int(input())
a = list(map(int, input().split()))
max_value = max(a)
ans = 0
for i in range(n):
    target = [a[j] for j in range(n)]
    target.pop(i)
    ans = max(ans, gcd_list(target))
print(ans)

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

def gcd_list(lst):
    a = lst[0]
    for i in lst[1:]:
        a = gcd(a, i)
    return a

n = int(input())
a = list(map(int, input().split()))
l = [0 for _ in range(n)]
r = [0 for _ in range(n)]
for i in range(n - 1):
    l_i = 0 if 0 == i else l[i]
    l[i + 1] = gcd(l_i, a[i])
for i in range(n)[::-1]:
    r_i1 = 0 if i == n - 1 else r[i + 1]
    r[i] = gcd(r_i1, a[i])
m = []
for i in range(n):
    r_i1 = 0 if i == n - 1 else r[i + 1]
    m.append(gcd(l[i], r_i1))
print(max(m))


import math

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

gcd_l = [0] * N

gcd_l[0] = A[0]
for i in range(1, N):
    gcd_l[i] = math.gcd(gcd_l[i - 1], A[i])

gcd_r = [0] * N

gcd_r[N - 1] = A[N - 1]
for i in reversed(range(0, N - 1)):
    gcd_l[i] = math.gcd(gcd_r[i + 1], A[i])

gcd_lr = [0] * N

for i in range(N):
    if i == 0:
        gcd_lr[i] = gcd_r[i + 1]
    elif 1 <= i <= N - 2:
        gcd_lr[i] = math.gcd(gcd_l[i - 1], gcd_r[i + 1])
    elif i == N - 1:
        gcd_lr[i] = gcd_l[i - 1]

print(max(gcd_lr))

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

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

gcd_l = [0] * N

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

gcd_r = [0] * N

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

gcd_lr = [0] * N

for i in range(N):
    if i == 0:
        gcd_lr[i] = gcd_r[i + 1]
    elif 1 <= i <= N - 2:
        gcd_lr[i] = gcd(gcd_l[i - 1], gcd_r[i + 1])
    elif i == N - 1:
        gcd_lr[i] = gcd_l[i - 1]

print(max(gcd_lr))


from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
ans = 1
for i in range(0, N):
    if i == 0:
        tmp = A[1]
    else:
        tmp = A[0]
    for j in range(0, N):
        if i != j:
            tmp = gcd(A[j], tmp)
        if tmp < ans:
            break
    ans = max(ans, tmp)
print(ans)

from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
L = [0]
for i in range(1, N):
    L.append(gcd(A[i - 1], L[i - 1]))
R = [0]
for i in range(1, N):
    R.append(gcd(R[i - 1], A[N - i]))
R.reverse()
ans = []
for i in range(0, N):
    ans.append(gcd(L[i], R[i]))
print(max(ans))


from math import gcd

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

# check
A.sort(reverse=True)
max_gcd = A[0]
change = False
for a in A:
    ans = gcd(max_gcd, a)
    if ans < max_gcd and change is False:
        change = True
        continue
    max_gcd = ans

print(max_gcd)

from fractions import gcd

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

# 累積GCD
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    left[i + 1] = gcd(left[i], a[i])
    right[n - i - 1] = gcd(right[n - i], a[n - 1 - i])

ans = 0
for i in range(n):
    ans = max(ans, gcd(left[i], right[i + 1]))
print(ans)


from math import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))

for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])

ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)

from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))

for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])

ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)


def make_divisors(n):
    divisors = []

    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort(reverse=True)
    return divisors

N = int(input())
A = sorted([int(x) for x in input().split()])
ans = 1

for i in range(2):
    divisors = make_divisors(A[i])

    for divisor in divisors:
        indivisible_count = 0
        for j in range(N):
            if A[j] % divisor != 0:
                indivisible_count += 1

        if indivisible_count <= 1 and divisor > ans:
            ans = divisor

print(ans)

def make_divisors(n):
    divisors = []

    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return divisors

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

ans = 1
divisors = make_divisors(A[0]) + make_divisors(A[1])
divisors = sorted(set(divisors), reverse=True)

for divisor in divisors:
    indivisible_count = 0
    for i in range(N):
        if A[i] % divisor != 0:
            indivisible_count += 1

    if indivisible_count <= 1:
        ans = divisor
        break

print(ans)


from math import gcd

n = int(input())
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
fromRight = [0] * n
fromRight[0] = a[n - 1]
for i in range(1, n):
    fromLeft[i] = gcd(fromLeft[i - 1], a[i])
    fromRight[i] = gcd(fromRight[i - 1], a[n - i - 1])
ret = fromLeft[n - 1]
for i in range(n):
    if i == 0:
        curGcd = fromRight[n - 2]
    elif i == n - 1:
        curGcd = fromLeft[n - 2]
    else:
        curGcd = gcd(fromLeft[i - 1], fromRight[n - i - 2])
    ret = max(ret, curGcd)
print(ret)

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

n = int(input())
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
fromRight = [0] * n
fromRight[0] = a[n - 1]
for i in range(1, n):
    fromLeft[i] = gcd(fromLeft[i - 1], a[i])
    fromRight[i] = gcd(fromRight[i - 1], a[n - i - 1])
ret = fromLeft[n - 1]
for i in range(n):
    if i == 0:
        curGcd = fromRight[n - 2]
    elif i == n - 1:
        curGcd = fromLeft[n - 2]
    else:
        curGcd = gcd(fromLeft[i - 1], fromRight[n - i - 2])
    ret = max(ret, curGcd)
print(ret)


import fractions
from functools import reduce
import copy

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

ans = 1
for i in range(N):
    a = copy.copy(A)
    a.pop(i)
    g = gcd_list(a)
    if g > ans:
        ans = g
print(ans)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort(reverse=True)
    return divisors

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

ans = 1
for i in range(2):
    div_list = make_divisors(A[i])

    for div_i in div_list:
        wrong_count = 0

        for A_i in A:
            if A_i % div_i != 0:
                wrong_count += 1

        if wrong_count <= 1 and div_i > ans:
            ans = div_i

print(ans)


n = int(input())
a = [int(i) for i in input().split()]
m = len(list(filter(lambda x: x < 0, a)))
s = sum(map(abs, a))
if m % 2 == 0 or a in 0:
    print(s)
else:
    print(s - 2 * min(a))

n = int(input())
a = [int(i) for i in input().split()]
m = len(list(filter(lambda x: x < 0, a)))
s = [abs(i) for i in a]
if m % 2 == 0 or 0 in a:
    print(sum(s))
else:
    print(sum(s) - 2 * min(s))


from sys import stdin, setrecursionlimit
from bisect import bisect_right

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

    if n == 1:
        print(abs(sum(a)))
        exit()

    idx = bisect_right(a, 0)

    if idx % 2 == 0:
        print(sum(a[idx:]) - sum(a[:idx]))
    else:
        print(sum(a[idx:]) - sum(a[:idx]) - 2 * min(-a[idx - 1], a[idx]))

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

from sys import stdin, setrecursionlimit
from bisect import bisect_right

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

    idx = bisect_right(a, 0)

    if idx % 2 == 0:
        print(sum(a[idx:]) - sum(a[:idx]))
    elif idx == n:
        print(a[idx - 1] - sum(a[: idx - 1]))
    else:
        print(sum(a[idx:]) - sum(a[:idx]) - 2 * min(-a[idx - 1], a[idx]))

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


import numpy as np
from math import inf

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

dp = np.zeros((N + 1, 2))
dp[0][1] = -inf
# dp[i][0]:=1-indexedで、a_iとa_i+1を反転させない場合の最大値
# dp[i][1]:=1-indexedで、a_iとa_i+1を反転させる場合の最大値

for i, aa in enumerate(a, 0):
    dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
    dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)
print(dp[N][0])

import numpy as np

inf = float("inf")

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

dp = np.zeros((N + 1, 2))
dp[0][1] = -inf
# dp[i][0]:=1-indexedで、a_iとa_i+1を反転させない場合の最大値
# dp[i][1]:=1-indexedで、a_iとa_i+1を反転させる場合の最大値

for i, aa in enumerate(a, 0):
    dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
    dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)
print(int(dp[N][0]))


from bisect import bisect_left

n = int(input())
a = tuple(sorted(map(int, input().split())))
j = bisect_left(a, 0)

p = a[j:]
m = a[:j]

if len(m) % 2 == 0:
    print(sum(p) - sum(m))
else:
    print(sum(p[1:]) - sum(m[:-1]) + abs(p[0] + m[-1]))

from bisect import bisect_left

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

j = bisect_left(a, 0)
m = a[:j]

if len(m) % 2 == 0:
    print(sum(b))
else:
    print(sum(b) - min(b) * 2)


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

B = map(abs, A)
if len([a for a in A if a < 0]) % 2 == 1:
    print(sum(B) - min(B))
else:
    print(sum(B))

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

B = [abs(a) for a in A]
if len([a for a in A if a < 0]) % 2 == 1:
    print(sum(B) - 2 * min(B))
else:
    print(sum(B))


from functools import lru_cache
import sys

sys.setrecursionlimit(10000000)

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

@lru_cache(maxsize=None)
def rec(i, reverse):
    if i == N - 1:
        return A[i] * reverse

    num_normal = rec(i + 1, 1) + (A[i] * reverse)
    num_reverse = rec(i + 1, -1) + (-1 * A[i] * reverse)

    return max(num_normal, num_reverse)

print(rec(0, 1))

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

minus_count = 0

for a in A:
    if a < 0:
        minus_count += 1

total = 0
min_num = 10**9

for a in A:
    total += abs(a)
    min_num = min(min_num, abs(a))

if minus_count % 2 == 1:
    total -= 2 * min_num

print(total)


N = int(input())
A = [int(input()) for _ in range(N)]

sum_A = sum(A)
MOD = 998244353

dp1 = [0] * (sum_A + 1)
dp2 = [0] * (sum_A + 1)
dp1[0] = dp2[0] = 1

for a in A:
    dp1_ = [0] * (sum_A + 1)
    dp2_ = [0] * (sum_A + 1)
    for i in range(sum_A + 1):
        # R に塗った場合
        if i + a <= sum_A:
            dp1_[i + a] += dp1[i]
            dp2_[i + a] += dp2[i]
        # G, B に塗った場合
        dp1_[i] += dp1[i] * 2
        dp2_[i] += dp2[i]
    dp1 = dp1_
    dp2 = dp2_

ans = pow(3, N)
for i in range(sum_A + 1):
    if i * 2 >= sum_A:
        ans -= dp1[i] * 3
    if i * 2 == sum_A:
        ans += dp2[i] * 3
print(ans % MOD)

N = int(input())
A = [int(input()) for _ in range(N)]

sum_A = sum(A)
MOD = 998244353

dp1 = [0] * (sum_A + 1)
dp2 = [0] * (sum_A + 1)
dp1[0] = dp2[0] = 1

for a in A:
    dp1_ = [0] * (sum_A + 1)
    dp2_ = [0] * (sum_A + 1)
    for i in range(sum_A + 1):
        if i - a >= 0:
            # R に塗れる場合
            dp1_[i] = (dp1[i - a] + dp1[i] * 2) % MOD
            dp2_[i] = (dp2[i - a] + dp2[i]) % MOD
        else:
            dp1_[i] = (dp1[i] * 2) % MOD
            dp2_[i] = dp2[i]
    dp1, dp2 = dp1_, dp2_

ans = pow(3, N, MOD)
for i in range(sum_A + 1):
    if i * 2 >= sum_A:
        ans = (ans - dp1[i] * 3 + MOD * 3) % MOD
    if i * 2 == sum_A:
        ans = (ans + dp2[i] * 3) % MOD
print(ans)


# -*- coding: utf-8 -*-
N = int(input())
S = list(str(input()))
K = int(input())

for i in range(N):
    if S[i] != S[K]:
        S[i] = "*"
"".join(S)
print(S)

# -*- coding: utf-8 -*-
N = int(input())
S = list(str(input()))
K = int(input())

for i in range(N):
    if S[i] != S[K - 1]:
        S[i] = "*"

Z = "".join(S)
print(Z)


input()
S = input()
K = int(input())

c = S[K]

print("".join([v if v == c else "*" for v in S]))

input()
S = input()
K = int(input())

c = S[K - 1]

print("".join([v if v == c else "*" for v in S]))


n = int(input())
s = input()
k = int(input())
result = []

for x in s:
    if x != s[k]:
        result.append("*")
    else:
        result.append(x)

print("".join(result))

n = int(input())
s = input()
k = int(input())
result = []

for x in s:
    if x != s[k - 1]:
        result.append("*")
    else:
        result.append(x)

print("".join(result))


N = int(input())
S = list(input())
K = int(input())

target = S[K]
ans = ""
for s in S:
    ans += s if s == target else "*"
print(ans)

N = int(input())
S = list(input())
K = int(input())

target = S[K - 1]
ans = ""
for s in S:
    ans += s if s == target else "*"
print(ans)


n = int(input())
s = str(input())
k = int(input())

char = s[k]
result = ""
for x in s:
    if x == char:
        result += char
    else:
        result += "*"
print(result)

n = int(input())
s = str(input())
k = int(input())

char = s[k - 1]
result = ""
for x in s:
    if x == char:
        result += char
    else:
        result += "*"
print(result)


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

res = float("inf")

if "." not in S or "#" not in S:
    res = 0

for i in range(N):
    res = min(res, S[:i].count("#") + S[i:].count("."))

print(res)

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

res = float("inf")

# if "#" not in S or "." not in S:
#     res = 0

counts = []
counts.append((0, 0))
a, b = 0, 0
for s in S:
    if s == "#":
        a += 1
    elif s == ".":
        b += 1
    counts.append((a, b))

for i in range(N + 1):
    res = min(res, counts[i][0] + counts[-1][1] - counts[i][1])

print(res)


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

for i in range(N - 1, -1, -1):
    if S[i] == ".":
        right_white = i
        break

print(min(S.count("."), S[:right_white].count("#")))

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

white = [0] * (N + 1)
for i in range(N):
    if S[i] == ".":
        white[i + 1] = white[i] + 1
    else:
        white[i + 1] = white[i]

ans = N
for i in range(N + 1):
    tmp = (i - white[i]) + (white[-1] - white[i])
    if tmp < ans:
        ans = tmp

print(ans)


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

print((t // a) * b)

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

total = 0

if a > b:
    total = 2 * a - 1
elif b > a:
    total = 2 * b - 1
else:
    total = 2 * a

print(total)

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


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

if a >= b:
    tmp1 = a
    a -= 1
else:
    tmp2 = b
    b -= 1

if a >= b:
    tmp2 = a
else:
    tmp2 = b

print(tmp1 + tmp2)

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

if a >= b:
    tmp1 = a
    a -= 1
else:
    tmp1 = b
    b -= 1

if a >= b:
    tmp2 = a
else:
    tmp2 = b

print(tmp1 + tmp2)


n = int(input())
h = map(int, input().split())
total = 1
max_value = h[0]
for i in range(1, n):
    if max_value <= h[i]:
        total += 1
    max_value = max(max_value, h[i])
print(total)

n = int(input())
h = list(map(int, input().split()))
total = 1
max_value = h[0]
for i in range(1, n):
    if max_value <= h[i]:
        total += 1
    max_value = max(max_value, h[i])
print(total)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03072/Python/s924267077.py", line 4, in <module>
    max_value = h[0]
TypeError: 'map' object is not subscriptable


n = int(input())
h = [int(x) for x in input().split()]
c = 0
for i in range(n):
    if h[i] >= max(h[:i]):
        c += 1
print(c)

n = int(input())
h = [int(x) for x in input().split()]
c = 1

for i in range(1, n):
    if h[i] >= max(h[:i]):
        c += 1
print(c)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03072/Python/s836485359.py", line 5, in <module>
    if h[i] >= max(h[:i]):
ValueError: max() arg is an empty sequence


n = int(input().split())
h = list(map(int, input().split()))
height = h[0]
counter = 0
for i in h:
    if h[i] >= height:
        counter += 1
        height = h[i]

print(counter)

n = int(input())
h = list(map(int, input().split()))
height = h[0]
counter = 0
for i in range(n):
    if h[i] >= height:
        counter += 1
        height = h[i]

print(counter)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03072/Python/s611455430.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'


n = int(input())
h_list = map(int, input().split())
highest = max(h_list)
count = 1

for i in range(1, n):
    if highest <= h_list[i]:
        count += 1

print(count)

n = int(input())
h_list = list(map(int, input().split()))
highest = 0
count = 0

for i in range(n):
    if highest <= h_list[i]:
        count += 1
        highest = h_list[i]

print(count)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03072/Python/s767322373.py", line 7, in <module>
    if highest <= h_list[i]:
TypeError: 'map' object is not subscriptable


def main():
    N, K = map(int, input().split())
    S = input()
    nums = []
    now = 1
    cnt = 0
    for s in S:
        if int(s) == now:
            cnt += 1
        else:
            nums.append(cnt)
            now ^= 1
            cnt = 1
    if cnt > 0:
        nums.append(cnt)
    if len(nums) % 2 == 0:
        nums.append(0)
    add = 2 * K + 1
    ans = 0
    for cnt in range(0, len(nums), 2):
        tmp = 0
        left = cnt
        right = min(cnt + add, len(nums))
        for j in range(left, right):
            tmp += nums[j]
        ans = max(tmp, ans)
    print(ans)

main()

def main():
    N, K = map(int, input().split())
    S = input()
    nums = []
    now = 1
    cnt = 0
    for s in S:
        if int(s) == now:
            cnt += 1
        else:
            nums.append(cnt)
            now ^= 1
            cnt = 1
    if cnt > 0:
        nums.append(cnt)
    if len(nums) % 2 == 0:
        nums.append(0)
    add = 2 * K + 1
    ans = 0
    left = 0
    right = 0
    tmp = 0
    for cnt in range(0, len(nums), 2):
        nleft = cnt
        nright = min(cnt + add, len(nums))
        while nleft > left:
            tmp -= nums[left]
            left += 1
        while nright > right:
            tmp += nums[right]
            right += 1
        ans = max(tmp, ans)
    print(ans)

main()


N, K = map(int, input().split())
S = input()
L = [0]
prev = S[0]
num = 1
for s in S[1:]:
    if s == prev:
        num += 1
    else:
        L.append(num)
        num = 1
        prev = s
L.append(num)
# print(L)
for i in range(1, len(L)):
    L[i] += L[i - 1]
# print(L)
left = 0
if S[0] == "1":
    right = min(2 * K + 1, len(L) - 1)
else:
    right = min(2 * K, len(L) - 1)
num = 0
while right < len(L):
    # print("L[" + str(right) + "] - L[" + str(left) + "] = " + str(L[right] - L[left]))
    num = max(num, L[right] - L[left])
    if left == 0 and S[0] == "0":
        left += 1
    else:
        left += 2
    right += 2
if S[-1] == "0" and len(S) > 1:
    right -= 1
    # print("L[" + str(right) + "] - L[" + str(left) + "] = " + str(L[right] - L[left]))
    num = max(num, L[right] - L[left])
print(num)

N, K = map(int, input().split())
S = input()
if S == "0":
    print(1)
    exit()
if S.count("0") == N:
    print(N)
    exit()
L = [0]
prev = S[0]
num = 1
for s in S[1:]:
    if s == prev:
        num += 1
    else:
        L.append(num)
        num = 1
        prev = s
L.append(num)
# print(L)
for i in range(1, len(L)):
    L[i] += L[i - 1]
# print(L)
left = 0
if S[0] == "1":
    right = min(2 * K + 1, len(L) - 1)
else:
    right = min(2 * K, len(L) - 1)
num = 0
while right < len(L):
    # print("L[" + str(right) + "] - L[" + str(left) + "] = " + str(L[right] - L[left]))
    num = max(num, L[right] - L[left])
    if left == 0 and S[0] == "0":
        left += 1
    else:
        left += 2
    right += 2
if S[-1] == "0":
    right -= 1
    # print("L[" + str(right) + "] - L[" + str(left) + "] = " + str(L[right] - L[left]))
    num = max(num, L[right] - L[left])
print(num)


from itertools import product

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

ab = [ai + bi for (ai, bi) in product(a, b)]
ab.sort(reverse=True)
abc = [abi + ci for (abi, ci) in product(ab[: min(k, x * y * z)], c)]
abc.sort(reverse=True)

for abci in abc[: min(k, x * y * z)]:
    print(abci)

#!/usr/bin/env python3
import sys

def solve(a: int, b: int, c: int, d: int, e: int, k: int):
    print("Yay!" if e - a <= k else ":(")

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    e = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(a, b, c, d, e, k)

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03075/Python/s634556284.py", line 3, in <module>
    x, y, z, k = list(map(int, input().split()))
ValueError: not enough values to unpack (expected 4, got 1)


times = [int(input()) for i in range(5)]
cost = 0
p_times = [time % 10 for time in times]
if sum(p_times) == 0 and min(p_times) > 0:
    last_order = False
else:
    last_order = min([i for i in p_times if i > 0])
    last_order_idx = p_times.index(last_order)

if last_order:
    cost = times.pop(last_order_idx)

for time in times:
    if time % 10 == 0:
        cost += time
    else:
        cost += time + (10 - time % 10)

print(cost)

times = [int(input()) for i in range(5)]
cost = 0
p_times = [time % 10 for time in times]

if (sum([i % 10 for i in p_times]) == 0) & (min(times) > 0):
    last_order = False
else:
    last_order = min([i for i in p_times if i > 0])
    last_order_idx = p_times.index(last_order)

if last_order:
    cost = times.pop(last_order_idx)

for time in times:
    if time % 10 == 0:
        cost += time
    else:
        cost += time + (10 - time % 10)

print(cost)


dishes = [int(input()) for _ in range(5)]

dishes = sorted(dishes, key=lambda x: 10 - int(str(x)[-1]))
a = list()
b = list()
for d in dishes:
    if d % 10 == 0:
        a.append(d)
    else:
        b.append(d)
b = [d + 10 - d % 10 for d in b[:-1]] + [b[-1]]
dishes = a + b
# print(sum(dishes))
#
print(1)

dishes = [int(input()) for _ in range(5)]

dishes = sorted(dishes, key=lambda x: 10 - int(str(x)[-1]))
a = list()
b = list()
for d in dishes:
    if d % 10 == 0:
        a.append(d)
    else:
        b.append(d)
if len(b) > 0:
    b = [d + 10 - d % 10 for d in b[:-1]] + [b[-1]]
dishes = a + b
print(sum(dishes))


menu = [int(input()) for _ in range(5)]
ans = 0
mod = []
for time in menu:
    if time % 10 == 0:
        ans += time
    else:
        ans += time
        mod.append(10 - time % 10)
mod.remove(max(mod))
ans += sum(mod)
print(ans)

menu = [int(input()) for _ in range(5)]
ans = 0
mod = []
for time in menu:
    if time % 10 == 0:
        ans += time
    else:
        ans += time
        mod.append(10 - time % 10)
try:
    mod.remove(max(mod))
    ans += sum(mod)
except:
    pass
print(ans)


n = [int(input()) for _ in range(5)]
first_digit = []
for num in n:
    z = int(str(num)[-1])
    if z > 0:
        first_digit.append(z)

# print(first_digit)
t = 0
for i in range(len(n)):
    t += -(-n[i] // 10) * 10
print(t - (10 - min(first_digit)))

n = [int(input()) for _ in range(5)]
first_digit = []
for num in n:
    z = int(str(num)[-1])
    if z > 0:
        first_digit.append(z)

# print(first_digit)
t = 0
for i in range(len(n)):
    t += -(-n[i] // 10) * 10
if len(first_digit) == 0:
    print(t)
else:
    print(t - (10 - min(first_digit)))


# A = int(input())
# B = int(input())
# C = int(input())
# D = int(input())
# E = int(input())
M = [int(input()) for _ in range(5)]
m = []
T = 0
for i in range(5):
    if M[i] % 10 == 0:
        T += M[i]
    else:
        T += M[i]
        T += 10 - M[i] % 10
        m.append(M[i] % 10)
print(T - (10 - min(m)))

M = [int(input()) for _ in range(5)]
m = []
T = 0
for i in range(5):
    if M[i] % 10 == 0:
        T += M[i]
    else:
        T += M[i]
        T += 10 - M[i] % 10
        m.append(M[i] % 10)
print(T - (10 - (10 if not m else min(m))))


def main():
    K = [int(input()) for _ in range(5)]
    ans = []
    A = []
    for k in K:
        a = k % 10
        if a == 0:
            ans.append(k)
        else:
            ans.append(k + (10 - a))
            A.append(a)
    print(sum(ans) - (10 - min(A)))

if __name__ == "__main__":
    main()

def main():
    K = [int(input()) for _ in range(5)]
    ans = []
    A = [0]
    for k in K:
        a = k % 10
        if a == 0:
            ans.append(k)
        else:
            ans.append(k + (10 - a))
            A.append(10 - a)
    print(sum(ans) - max(A))

if __name__ == "__main__":
    main()


L = [input() for i in range(1, 6)]

li = list(filter(lambda x: x[-1] != "0", L))
last = int(sorted(li, key=lambda x: x[-1])[0])

t = sum(map(int, L)) - last
print(t + (10 - (t % 10)) + last)

import math

L = [int(input()) for i in range(5)]

total = 0
sub = 0
for i in L:
    if i % 10 == 0:
        total += i
    else:
        rest = 10 - (i % 10)
        if rest > sub:
            sub = rest
        total += math.ceil(i / 10) * 10

print(total - sub)


one = []
ten = []

menu = [int(input()) for i in range(5)]

for i in range(5):
    one.append(menu[i] % 10)
    ten.append(menu[i] // 10)

for i in range(5):
    if one[i] == 0:
        one[i] = 10

one_min = min(one)

for i in range(5):
    if one[i] == 10:
        one[i] = 0

for i in range(5):
    if one_min == one[i]:
        one_min_idx = i

total = 0

for i in range(5):
    if one_min_idx != i:
        if one[i] == 0:
            total += ten[i] * 10
        else:
            total += ten[i] * 10 + 10

total += menu[one_min_idx]

print(total)

one = []

menu = [int(input()) for i in range(5)]

for i in range(5):
    one.append(10 - menu[i] % 10)

for i in range(5):
    if one[i] == 10:
        one[i] = 0

total = 0
cnt = 0
for i in range(5):
    if cnt == 0 and one[i] == max(one):
        total += menu[i]
        cnt = 1
    else:
        total += menu[i]
        total += one[i]

print(total)


dish = [int(input()) for x in range(5)]
hitoketa = list(map(int, [str(x)[-1] for x in dish]))

last = 999
for i in hitoketa:
    if not i % 10 == 0:
        last = min(last, i)

last = dish[hitoketa.index(last)]
ans = last
skip = False
for i in dish:
    if i == last and not skip:
        skip = True
    elif i % 10 == 0:
        ans += i
    else:
        ans += (i // 10 + 1) * 10

print(ans)

dish = [int(input()) for x in range(5)]
hitoketa = list(map(int, [str(x)[-1] for x in dish]))

last = 999
for i in hitoketa:
    if not i % 10 == 0:
        last = min(last, i)

if last != 999:
    last = dish[hitoketa.index(last)]
else:
    last = dish[0]

ans = last
skip = False

for i in dish:
    if i == last and not skip:
        skip = True
    elif i % 10 == 0:
        ans += i
    else:
        ans += (i // 10 + 1) * 10

print(ans)


orders = [int(input()) for _ in range(5)]

rest = []
time = 0
for order in orders:
    if order % 10 == 0:
        time += order
    else:
        rest.append(order)

rest_mods = list(map(lambda x: x % 10, rest))
min_mods_index = rest_mods.index(min(rest_mods))
for i in range(len(rest)):
    time += rest[i]
    if i != min_mods_index:
        time += 10 - rest[i] % 10
print(time)

orders = [int(input()) for _ in range(5)]

rest = []
time = 0
for order in orders:
    if order % 10 == 0:
        time += order
    else:
        rest.append(order)

rest_mods = list(map(lambda x: x % 10, rest))

if len(rest_mods) > 0:
    min_mods_index = rest_mods.index(min(rest_mods))
    for i in range(len(rest)):
        time += rest[i]
        if i != min_mods_index:
            time += 10 - rest[i] % 10
else:
    time += sum(rest)
print(time)


A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

orders = [A, B, C, D, E]
max_fp = 10
ans = 0

for i, order in enumerate(orders):
    if order % 10 < max_fp and order % 10 != 0:
        max_fp = order % 10
        last_order = i

for i, order in enumerate(orders):
    if i == last_order or order % 10 == 0:
        ans += order
    else:
        ans += (order // 10 + 1) * 10

print(ans)

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

orders = [A, B, C, D, E]
max_fp = 10
ans = 0
last_order = 0

for i, order in enumerate(orders):
    if order % 10 < max_fp and order % 10 != 0:
        max_fp = order % 10
        last_order = i

for i, order in enumerate(orders):
    if i == last_order or order % 10 == 0:
        ans += order
    else:
        ans += (order // 10 + 1) * 10

print(ans)


order_time = [0, 0, 0, 0, 0]
order = len(order_time)
time = 0
last_order = 9
count_change = 0

for i in range(0, order):
    order_time[i] = int(input())
    if (order_time[i] % 10 != 0) and (order_time[i] % 10 <= last_order % 10):
        last_order = order_time[i]
        count_change += 1

if count_change == 0:
    last_order = order_time[i]

for i in range(0, order):
    if order_time[i] % 10 != 0:
        time += order_time[i] // 10 * 10 + 10
    else:
        time += order_time[i]

time -= last_order // 10 * 10 + 10
time += last_order

print(time)
order_time = [0, 0, 0, 0, 0]
order = len(order_time)
time = 0
last_order = 9
count_change = 0

for i in range(0, order):
    order_time[i] = int(input())
    if (order_time[i] % 10 != 0) and (order_time[i] % 10 <= last_order % 10):
        last_order = order_time[i]
        count_change += 1

for i in range(0, order):
    if order_time[i] % 10 != 0:
        time += order_time[i] // 10 * 10 + 10
    else:
        time += order_time[i]

if count_change == 0:
    last_order = order_time[i]
else:
    time -= last_order // 10 * 10 + 10
    time += last_order

print(time)

order_time = [0, 0, 0, 0, 0]
order = len(order_time)
time = 0
last_order = 9
count_change = 0

for i in range(0, order):
    order_time[i] = int(input())
    if (order_time[i] % 10 != 0) and (order_time[i] % 10 <= last_order % 10):
        last_order = order_time[i]
        count_change += 1

for i in range(0, order):
    if order_time[i] % 10 != 0:
        time += order_time[i] // 10 * 10 + 10
    else:
        time += order_time[i]

if count_change == 0:
    last_order = 0
else:
    time -= last_order // 10 * 10 + 10
    time += last_order

print(time)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03076/Python/s884853631.py", line 33, in <module>
    order_time[i] = int(input())
EOFError: EOF when reading a line


five_dish = [int(input()) for _ in range(5)]
idx = None
maxdiff = 0
result = 0
for i in range(len(five_dish)):
    tmp = five_dish[i] % 10
    if tmp == 0:
        pass
    else:
        if 10 - tmp > maxdiff:
            maxdiff = 10 - tmp
            idx = i
        else:
            pass
for j in range(len(five_dish)):
    if j == idx:
        pass
    else:
        if five_dish[j] % 10 == 0:
            result += five_dish[j]
        else:
            result += five_dish[j] + (10 - (five_dish[j] % 10))
result += five_dish[idx]
print(result)

five_dish = [int(input()) for _ in range(5)]
idx = 0
maxdiff = 0
result = 0
for i in range(len(five_dish)):
    tmp = five_dish[i] % 10
    if tmp != 0:
        if 10 - tmp > maxdiff:
            maxdiff = 10 - tmp
            idx = i
for j in range(len(five_dish)):
    if j == idx:
        continue
    else:
        if five_dish[j] % 10 == 0:
            result += five_dish[j]
        else:
            result += five_dish[j] + (10 - (five_dish[j] % 10))
result += five_dish[idx]
print(result)


import math

time_list = list()

for _ in range(5):
    time_list.append(int(input()))

def key_func(x):
    if x < 100:  # 2桁 or 1桁の場合
        if x % 10 == 0:
            return 10
        return x % 10  # ex: 19の場合は9を返す
    else:
        if x % 100 == 0:
            return 10
        return x % 100  # ex: 123の場合は3を返す

time_list.sort(key=key_func, reverse=True)

# print(time_list)

ans = sum
for i, time in enumerate(time_list):
    if i < len(time_list) - 1:
        ans += math.ceil(time / 10) * 10
    else:
        ans += time

print(ans)

import math

time_list = list()

for _ in range(5):
    time_list.append(int(input()))

# 全探索
ans = 1e6
for i in range(len(time_list)):
    tmp = 0
    for j in range(len(time_list)):
        if i == j:
            tmp += time_list[i]
            continue
        tmp += math.ceil(time_list[j] / 10) * 10
    ans = min(tmp, ans)

print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03076/Python/s039938039.py", line 27, in <module>
    ans += math.ceil(time / 10) * 10
TypeError: unsupported operand type(s) for +=: 'builtin_function_or_method' and 'int'


import math

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cities = [a, b, c, d, e]
min_val = 10
for i, x in enumerate(cities):
    if x < min_val:
        min_val = x
        idx = i

ans = 0 if idx == 0 else idx

ans += math.ceil(n / min_val)
ans = ans + 4 - idx
print(ans)

import math

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cities = [a, b, c, d, e]
min_val = 1e18
for i, x in enumerate(cities):
    if x < min_val:
        min_val = x
        idx = i

ans = 0 if idx == 0 else idx

ans += math.ceil(n / min_val)
ans = ans + 4 - idx
print(ans)


from math import ceil

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

min_move = min(A, B, C, D, E)

ans = ceil(N / min_move) + 4

print(ans)


N = int(input())
a = [int(input) for _ in range(5)]

print(N // min(a) + 5)

from math import ceil

N = int(input())
a = [int(input()) for _ in range(5)]

print(ceil(N / min(a)) + (5 - 1))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03077/Python/s850924049.py", line 2, in <module>
    a = [int(input) for _ in range(5)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03077/Python/s850924049.py", line 2, in <listcomp>
    a = [int(input) for _ in range(5)]
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'


N = int(input())
n = [int(input()) for _ in range(N)]
min_n = min(n)
print(N // min_n + (1 if (0 != N % min_n) else 0) + N - 1)

N = int(input())
n = [int(input()) for _ in range(5)]
min_n = min(n)
ans = N // min_n + 4 + (1 if (0 != N % min_n) else 0)
print(ans)


import math

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cities = [a, b, c, d, e]
min_val = 1e6
for i, x in enumerate(cities):
    if x < min_val:
        min_val = x
        idx = i

ans = 0 if idx == 0 else idx

ans += math.ceil(n / min_val)
ans = ans + 4 - idx
print(ans)

import math

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cities = [a, b, c, d, e]
min_val = 1e18
idx = 0
for i, x in enumerate(cities):
    if x < min_val:
        min_val = x
        idx = i

ans = 0 if idx == 0 else idx

ans += math.ceil(n / min_val)
ans = ans + 4 - idx
print(ans)


from math import ceil

def main(N, A, B, C, D, E):
    loads = [A, B, C, D, E]
    min_val = min(loads)
    min_index = loads.index(min_val)

    res = min_index + ceil(N / min_val) + (5 - (min_index + 1))

    return res

if __name__ == "__main__":
    N = input()
    A = input()
    B = input()
    C = input()
    D = input()
    E = input()
    print(main(N, A, B, C, D, E))

from math import ceil

def main(N, A, B, C, D, E):
    loads = [A, B, C, D, E]
    min_val = min(loads)
    min_index = loads.index(min_val)

    res = min_index + ceil(N / min_val) + (5 - (min_index + 1))

    return res

if __name__ == "__main__":
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())
    print(main(N, A, B, C, D, E))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03077/Python/s219806680.py", line 21, in <module>
    print(main(N, A, B, C, D, E))
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03077/Python/s219806680.py", line 9, in main
    res = min_index + ceil(N / min_val) + (5 - (min_index + 1))
TypeError: unsupported operand type(s) for /: 'str' and 'str'


print(-(-int(input()) // min([int(input()) for i in range(5)])) + 4)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03077/Python/s377505366.py", line 1, in <module>
    print(-(-(int(input())) // min([int(input() for i in range(5))])) + 4)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'generator'


n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

items = [a, b, c, d, e]
pps = [0] * 5
pps[0] = n
time = 0
flg = True
while flg:
    carry = 0
    for i, (item, pp) in enumerate(zip(items, pps)):
        pp_bef = pp
        num = pp - item
        if num < 0:
            num = 0
        pps[i] = num + carry
        pp_aft = num
        carry = pp_bef - pp_aft
    time += 1
    if pps == [0] * 5:
        flg = False
print(time)

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

import math

items = [a, b, c, d, e]
min_item = min(items)
min_idx = items.index(min_item)
n_times = math.ceil(n / min_item)
print(len(items) + n_times - 1)


X, Y, Z, K = [int(_) for _ in input().split()]
As = [int(_) for _ in input().split()]
Bs = [int(_) for _ in input().split()]
Cs = [int(_) for _ in input().split()]

As.sort()
Bs.sort()
Cs.sort()

choice_stack = [(len(As) - 1, len(Bs) - 1, len(Cs) - 1)]
choice_stack_next = []
choice_log = set()
sums = []

j = 0
while True:
    for Ai, Bi, Ci in choice_stack:
        sums.append(As[Ai] + Bs[Bi] + Cs[Ci])
        cA = (max(0, Ai - 1), Bi, Ci)
        cB = (Ai, max(0, Bi - 1), Ci)
        cC = (Ai, Bi, max(0, Ci - 1))
        if not (cA in choice_log):
            choice_stack_next.append(cA)
            choice_log.add(cA)
        if not (cB in choice_log):
            choice_stack_next.append(cB)
            choice_log.add(cB)
        if not (cC in choice_log):
            choice_stack_next.append(cC)
            choice_log.add(cC)

    sums.sort()
    print(sums.pop())
    choice_stack = [_ for _ in choice_stack_next]
    choice_stack_next.clear()
    j += 1
    if j >= K:
        break

X, Y, Z, K = [int(_) for _ in input().split()]
As = [int(_) for _ in input().split()]
Bs = [int(_) for _ in input().split()]
Cs = [int(_) for _ in input().split()]

As.sort()
Bs.sort()
Cs.sort()

choice_stack = [(As[-1] + Bs[-1] + Cs[-1], len(As) - 1, len(Bs) - 1, len(Cs) - 1)]
choice_log = set()

j = 0
while True:
    choice_stack.sort()
    chosen_sum, Ai, Bi, Ci = choice_stack.pop()

    print(chosen_sum)

    step_A = (As[max(0, Ai - 1)] + Bs[Bi] + Cs[Ci], max(0, Ai - 1), Bi, Ci)
    step_B = (As[Ai] + Bs[max(0, Bi - 1)] + Cs[Ci], Ai, max(0, Bi - 1), Ci)
    step_C = (As[Ai] + Bs[Bi] + Cs[max(0, Ci - 1)], Ai, Bi, max(0, Ci - 1))

    if not (step_A in choice_log):
        choice_stack.append(step_A)
        choice_log.add(step_A)
    if not (step_B in choice_log):
        choice_stack.append(step_B)
        choice_log.add(step_B)
    if not (step_C in choice_log):
        choice_stack.append(step_C)
        choice_log.add(step_C)

    j += 1
    if j >= K:
        break


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

d = []
for i in range(x):
    for j in range(y):
        d.append(a[i] + b[j])
d.sort(reverse=True)

e = []
for i in range(k):
    for j in range(z):
        e.append(d[i] + c[j])
e.sort(reverse=True)

for i in range(k):
    print(e[i])

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

d = []
for i in range(x):
    for j in range(y):
        d.append(a[i] + b[j])
d.sort(reverse=True)

e = []
for i in range(min(len(d), k)):
    for j in range(z):
        e.append(d[i] + c[j])
e.sort(reverse=True)

for i in range(k):
    print(e[i])

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03078/Python/s896173078.py", line 15, in <module>
    e.append(d[i] + c[j])
IndexError: list index out of range