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

now = 0
count = 0
while True:
    if now == 0 and count != 0:
        print(-1)
        break

    if now == 1:
        print(count)
        break

    now = A[now] - 1
    count += 1

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

now = 0
count = 0
while True:
    if count >= N:
        print(-1)
        break

    if now == 1:
        print(count)
        break

    now = A[now] - 1
    count += 1


N = int(input())
a = [int(input()) for _ in range(N)]
seen_list = []
n = 1
ans = 0
while True:
    if n in seen_list:
        print(-1)
        exit()
    else:
        if n == 2:
            print(ans)
            exit()
        else:
            seen_list.append(n)
            n = a[n - 1]
            ans += 1

from collections import defaultdict

N = int(input())
a = [int(input()) for _ in range(N)]
seen_list = defaultdict(int)
n = 1
ans = 0
while True:
    if seen_list[n] == 1:
        print(-1)
        exit()
    else:
        if n == 2:
            print(ans)
            exit()
        else:
            seen_list[n] = 1
            n = a[n - 1]
            ans += 1


n = int(input())
a = [int(input()) for _ in range(n)]
L = []
cnt = 0
i = 0
while True:
    if i in L:
        print(-1)
        break
    else:
        L.append(i)
        i = a[i] - 1
        cnt += 1
        if i == 1:
            print(cnt)
            break

n = int(input())
a = [int(input()) for _ in range(n)]
L = [0] * n
cnt = 0
i = 0
while True:
    if L[i] == 1:
        print(-1)
        break
    else:
        L[i] = 1
        i = a[i] - 1
        cnt += 1
        if i == 1:
            print(cnt)
            break


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

button_history = [1]
while True:
    next_button = a_list[button_history[-1] - 1]
    if next_button == 2:
        print(len(button_history))
        break
    elif next_button in button_history:
        print(-1)
        break
    else:
        button_history.append(next_button)

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

button_history = [1]
current_button = 1
num_manipulation = -1

for i in range(1, N + 1):
    current_button = a_list[current_button - 1]
    if current_button == 2:
        num_manipulation = i
        break

print(num_manipulation)


n = int(input())
a = [0] + [int(input()) for _ in range(n)]

pos = 1
cnt = 0
while True:
    cnt += 1
    if a[pos] == 1:
        print(-1)
        break
    elif a[pos] == 2:
        print(cnt)
        break
    pos = a[pos]

n = int(input())
a = [0] + [int(input()) for _ in range(n)]

pos = 1
for i in range(n):
    pos = a[pos]
    if pos == 2:
        print(i + 1)
        break
else:
    print(-1)


n = int(input())
buttons = [input() for i in range(n)]
buttons_int = [int(b) - 1 for b in buttons]
button = 0
count = 0
history_list = []
i = 0
while i < n:
    if button == i:
        button = buttons_int[i]
        count += 1
        if button == 1:
            print(count)
            exit()
        if i in history_list:
            print(-1)
            exit()
        else:
            history_list.append(i)
        i = 0
    else:
        i += 1

n = int(input())
buttons = [input() for i in range(n)]
buttons_int = [int(b) - 1 for b in buttons]
button = 0
for count in range(1, n + 1):
    button = buttons_int[button]
    if button == 1:
        print(count)
        exit()
print(-1)


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    i = 1
    c = 0
    v = [0]
    while A[i - 1] not in v:
        if A[i - 1] == 2:
            print(c + 1)
            return
        v.append(i)
        i = A[i - 1]
        c += 1
    print(-1)

main()

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    i = 1
    c = 0
    v = [0] * (N + 1)
    while v[i] == 0:
        if A[i - 1] == 2:
            print(c + 1)
            return
        v[i] = 1
        i = A[i - 1]
        c += 1
    print(-1)

main()


N = int(input())
A = [int(input()) for _ in range(N)]
pushed = [False] * N
pushed[0] = True
button = 0
count = 0
while True:
    count += 1
    button = A[button] - 1
    if button == 1:
        print(count)
        exit()
    if pushed[button]:
        print(-1)
        exit()
    pushed[button] = True


N = int(input())
a = [0 for _ in range(N)]
for i in range(N):
    a[i] = int(input())
c = 0
x = 1
dic = [1]
while 1:
    x = a[x - 1]
    if x == 2:
        c += 1
        break
    elif x in dic:
        c = -1
        break
    else:
        dic.append(x)
        c += 1
print(c)

N = int(input())
a = [0 for _ in range(N)]
for i in range(N):
    a[i] = int(input())
c = 0
x = 1
while x != 2:
    nex = a[x - 1]
    if not nex:
        c = -1
        break
    else:
        a[x - 1] = False
        c += 1
        x = nex
print(c)


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

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

cnt = 0
lit = 0

while lit != 1 and (lit != 0 or cnt == 0):
    lit = a[lit] - 1
    cnt += 1

if lit == 1:
    print(cnt)
else:
    print(-1)

N = int(input())
A = [int(input()) for _ in range(N)]
i = 0
done = {a - 1: False for a in A}
num = 0
while True:
    i = A[i] - 1
    num += 1
    if i == 1:
        print(num)
        exit()
    if done[i]:
        print(-1)
        exit()
    done[i] = True


N = int(input())
a = [0] + [int(input()) for _ in range(N)]
preid = 1
ans = 0
while True:
    tmp = preid
    ans += 1
    if a[preid] == 2:
        print(ans)
        break
    preid = a[preid]
    if a[tmp] == a[preid]:
        print(-1)
        break

N = int(input())
a = [0] + [int(input()) for _ in range(N)]
ans = 0
idx = 1
flag = False
for i in range(N):
    ans += 1
    if a[idx] == 2:
        print(ans)
        flag = True
        break
    idx = a[idx]
else:
    print(ans if flag else -1)


N = int(input())
a = [int(input()) for _ in range(N)]
pikaa = 1
ans = 0
while 1:
    pikaa = a[pikaa - 1]
    ans += 1
    if pikaa == 1:
        print(-1)
        exit()
    elif pikaa == 2:
        print(ans)
        exit()

N = int(input())
a = [int(input()) for _ in range(N)]
pikaa = 1
ans = 0
for _ in range(N):
    pikaa = a[pikaa - 1]
    ans += 1
    if pikaa == 2:
        print(ans)
        exit()
print(-1)


n = int(input())
nxt_btn = {i: int(input()) for i in range(1, n + 1)}

num = 0
crr_btn = 1
while True:
    num += 1
    if nxt_btn[crr_btn] == 1:
        num = -1
        break
    if nxt_btn[crr_btn] == 2:
        break
    crr_btn = nxt_btn[crr_btn]
print(num)

n = int(input())
nxt_btn = {i: int(input()) for i in range(1, n + 1)}

num = -1
crr_btn = 1
for i in range(1, n + 1):
    if nxt_btn[crr_btn] == 2:
        num = i
        break
    crr_btn = nxt_btn[crr_btn]
print(num)


N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a - 1)
Flags = [False] * N
Flags[0] = True
now = 0
cnt = 0
while now != 1:
    cnt += 1
    next_node = A[now]
    if Flags[next_node]:
        print("-1")
        exit()
    now = next_node
print(cnt)

N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a - 1)
Flags = [False] * N
Flags[0] = True
now = 0
cnt = 0
for _ in range(N):
    cnt += 1
    next_node = A[now]
    if next_node == 1:
        break
    if Flags[next_node]:
        print("-1")
        exit()
    Flags[next_node] = True
    now = next_node
print(cnt)


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

MOD = 1_000_000_007

if abs(N - M) > 1:
    print(0)
    exit(0)

dogs = 1
for i in range(1, N + 1):
    dogs *= i
    dogs %= MOD

monks = 1
for i in range(1, M + 1):
    monks *= i
    monks %= MOD

res = (dogs * monks) % MOD
if (N + M) % 2 == 0:
    res *= 2
    res %= MOD

print(res)

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

MOD = 1000000007

if abs(N - M) > 1:
    print(0)
    exit(0)

dogs = 1
for i in range(1, N + 1):
    dogs *= i
    dogs %= MOD

monks = 1
for i in range(1, M + 1):
    monks *= i
    monks %= MOD

res = (dogs * monks) % MOD
if (N + M) % 2 == 0:
    res *= 2
    res %= MOD

print(res)


from math import factorial

n, m = [int(i) for i in input().split()]
mod = 10e9 + 7

ans = 0
diff = abs(n - m)
if diff == 0:
    ans = (factorial(n) ** 2) * 2 % mod
elif diff == 1:
    ans = factorial(n) * factorial(m) % mod
print(ans)

from math import factorial

n, m = [int(i) for i in input().split()]
mod = 10**9 + 7

ans = 0
diff = abs(n - m)
if diff == 0:
    ans = (factorial(n) ** 2) * 2 % mod
elif diff == 1:
    ans = factorial(n) * factorial(m) % mod
print(ans)


from operator import itemgetter
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix

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

xyi = [[x, y, i] for i, (x, y) in enumerate(xy)]
row = []
col = []
cost = []

xyi.sort()
for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):
    row.append(i1)
    col.append(i2)
    cost.append(min(abs(x1 - x2), abs(y1 - y2)))

xyi.sort(key=itemgetter(1))
for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):
    row.append(i1)
    col.append(i2)
    cost.append(min(abs(x1 - x2), abs(y1 - y2)))

graph = csr_matrix((cost, (row, col)))
mst = minimum_spanning_tree(graph)
ans = mst.sum().astype(int)
print(ans)

from operator import itemgetter
from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix

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

xyi = [[x, y, i] for i, (x, y) in enumerate(xy)]
edge = set()

xyi.sort()
for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):
    c = min(abs(x1 - x2), abs(y1 - y2))
    edge.add((i1, i2, c))

xyi.sort(key=itemgetter(1))
for (x1, y1, i1), (x2, y2, i2) in zip(xyi, xyi[1:]):
    c = min(abs(x1 - x2), abs(y1 - y2))
    edge.add((i1, i2, c))

row, col, cost = zip(*edge)

graph = csr_matrix((cost, (row, col)), shape=(n, n))
mst = minimum_spanning_tree(graph, overwrite=True).astype(int)
ans = mst.sum()
print(ans)

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


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

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

x = []
y = []
for i, (ex, ey) in enumerate(xy):
    x.append([ex, i])
    y.append([ey, i])

x.sort()
y.sort()

u = []
v = []
c = []

def f(li):
    for (e1, i1), (e2, i2) in zip(li, li[1:]):
        dist = e2 - e1
        u.append(i1)
        v.append(i2)
        c.append(dist)

f(x)
f(y)

graph = csr_matrix((c, (u, v)))
mst = minimum_spanning_tree(graph).astype(np.int64)
ans = mst.sum()
print(ans)

from scipy.sparse.csgraph import minimum_spanning_tree
from scipy.sparse import csr_matrix
from operator import itemgetter

n = int(input())
xy = [list(map(int, input().split())) + [i] for i in range(n)]

edge = set()
for key in (itemgetter(0), itemgetter(1)):
    xy.sort(key=key)
    for (x1, y1, i1), (x2, y2, i2) in zip(xy, xy[1:]):
        d = min(abs(x1 - x2), abs(y1 - y2))
        edge.add((i1, i2, d))

u, v, c = zip(*edge)

graph = csr_matrix((c, (u, v)), shape=(n, n), dtype=int)
mst = minimum_spanning_tree(graph, overwrite=True).astype(int)
ans = mst.sum()
print(ans)

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


from collections import defaultdict
from heapq import heappop, heappush
from operator import itemgetter

N = int(input())
town = [[int(x) for x in input().split()] + [i] for i in range(N)]

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

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

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(dict)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src][dst] = weight

    def get_nodes(self):
        return self.graph.keys()

class Kruskal(object):
    def __init__(self, graph):
        self.edge = []
        self.total = 0

        N = len(graph)
        g = graph.graph
        uf = UnionFind(N)

        Q = []
        for src, v in g.items():
            for dst, cost in v.items():
                heappush(Q, (cost, (src, dst)))

        while len(self.edge) < N - 1 and Q:
            cost, edge = heappop(Q)
            if uf.find(edge[0]) != uf.find(edge[1]):
                self.total += cost
                self.edge.append(edge)
                uf.union(*edge)

g = Graph()
for i in range(2):
    town = sorted(town, key=itemgetter(i))
    for j in range(N - 1):
        t1, t2 = town[j], town[j + 1]
        d = t2[i] - t1[i]
        g.add_edge(t1[2], t2[2], d)
print(Kruskal(g).total)

import sys
from collections import defaultdict
from heapq import heappop, heappush
from operator import itemgetter

readline = sys.stdin.readline

N = int(readline())
town = [None] * N
for i in range(N):
    x, y = map(int, readline().split())
    town[i] = (i, x, y)

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

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

def Kruskal(edges):
    edge = []
    total = 0

    uf = UnionFind(N)
    Q = sorted(edges, reverse=True)

    while len(edge) < N - 1 and Q:
        cost, e = Q.pop()
        if uf.find(e[0]) != uf.find(e[1]):
            total += cost
            edge.append(edge)
            uf.union(*e)
    return total

edges = []
for xy in [1, 2]:
    town = sorted(town, key=itemgetter(xy))
    for i in range(N - 1):
        t1, t2 = town[i], town[i + 1]
        d = t2[xy] - t1[xy]
        edges.append((d, (t1[0], t2[0])))
print(Kruskal(edges))


import sys

from itertools import combinations

def solve(n, pairs):
    survivors = {v: {v} for v in range(1, n + 1)}
    for x, y in reversed(pairs):
        for v, srv in survivors.copy().items():
            if x in srv:
                if y in srv:
                    del survivors[v]
                else:
                    srv.add(y)
            elif y in srv:
                srv.add(x)
    return sum(su.isdisjoint(sv) for su, sv in combinations(survivors.values(), 2))

n, m = map(int, input().split())
pairs = []
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    pairs.append((x, y))
print(solve(n, pairs))

import sys

from itertools import combinations

def solve(n, pairs):
    survivors = {v: {v} for v in range(1, n + 1)}
    for x, y in reversed(pairs):
        for v, srv in survivors.copy().items():
            if x in srv:
                if y in srv:
                    del survivors[v]
                else:
                    srv.add(y)
            elif y in srv:
                srv.add(x)
    return sum(su.isdisjoint(sv) for su, sv in combinations(survivors.values(), 2))

n, m = map(int, input().split())
pairs = [tuple(map(int, line.split())) for line in sys.stdin.readlines()]
print(solve(n, pairs))


print("YES" if int("".join(x for x in input().split())) % 4 == 0 else "NO")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03693/Python/s741295906.py", line 1, in <module>
    print("YES" if int("".join(list(input()))) % 4 == 0 else "NO")
ValueError: invalid literal for int() with base 10: '4 3 2'


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

min_color = 0
max_color = 0

cnt = 0

color = [0] * 8

for i in a:
    if i < 400 and color[0] == 0:
        min_color += 1
        max_color += 1
        color[0] = 1

    elif 400 <= i and i < 800 and color[1] == 0:
        min_color += 1
        max_color += 1
        color[1] = 1

    elif 800 <= i and i < 1200 and color[2] == 0:
        min_color += 1
        max_color += 1
        color[2] = 1

    elif 1200 <= i and i < 1600 and color[3] == 0:
        min_color += 1
        max_color += 1
        color[3] = 1

    elif 1600 <= i and i < 2000 and color[4] == 0:
        min_color += 1
        max_color += 1
        color[4] = 1

    elif 2000 <= i and i < 2400 and color[5] == 0:
        min_color += 1
        max_color += 1
        color[5] = 1

    elif 2400 <= i and i < 2800 and color[6] == 0:
        min_color += 1
        max_color += 1
        color[6] = 1

    elif 2800 <= i and i < 3200 and color[7] == 0:
        min_color += 1
        max_color += 1
        color[7] = 1

    elif i >= 3200:
        max_color += 1
        cnt += 1

if cnt == N:
    min_color = 1

print(min_color, max_color)

r, g, b = map(int, input().split())
ans = r * 100 + g * 10 + b

print("YES" if ans % 4 == 0 else "NO")

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


import sys

input = sys.stdin.readline

def main():
    print("YES" if int(input()) % 4 == 0 else "NO")

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline

def main():
    print("YES" if int("".join(input().split())) % 4 == 0 else "NO")

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03693/Python/s962788387.py", line 11, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03693/Python/s962788387.py", line 7, in main
    print("YES" if int(input()) % 4 == 0 else "NO")
ValueError: invalid literal for int() with base 10: '4 3 2\\n'


print("NO " if int("".join(input().split())) % 4 else "YES")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03693/Python/s438012053.py", line 1, in <module>
    print("NO " if map(int, "".join(input().split())) % 4 else "YES")
TypeError: unsupported operand type(s) for %: 'map' and 'int'


n = int(input())
a = [*map(int, input().split())]
a.sort()
ans = 0
for i in range(n - 1):
    ans += a[i + 1] - a[i]
print(ans)

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


n = int(input())
a_list = [int(i) for i in input().split()]
print(max[a_list] - min(a_list))

n = int(input())
a_list = [int(i) for i in input().split()]
print(max(a_list) - min(a_list))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03694/Python/s482748657.py", line 3, in <module>
    print(max[a_list] - min(a_list))
TypeError: 'builtin_function_or_method' object is not subscriptable


N = int(input())
A = [int(input()) for i in range(N)]
print(max(A) - min(A))

N = int(input())
A = list(map(int, input().split()))
print(max(A) - min(A))

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03694/Python/s043066443.py", line 2, in <module>
    A = [int(input()) for i in range(N)]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03694/Python/s043066443.py", line 2, in <listcomp>
    A = [int(input()) for i in range(N)]
ValueError: invalid literal for int() with base 10: '2 3 7 9'


N = int(input())
an = list(map(int, input().split()))
over_cnt = 0
colors = []
for a in an:
    rate = a // 400
    if rate >= 8:
        over_cnt += 1
    elif rate not in colors:
        colors.append(rate)

min = len(colors)
max = min(len(colors) + over_cnt, 8)
print(min, max)

N = int(input())
an = list(map(int, input().split()))
over_cnt = 0
colors = []
for a in an:
    rate = a // 400
    if rate >= 8:
        over_cnt += 1
    elif rate not in colors:
        colors.append(rate)

print(max(len(colors), 1), len(colors) + over_cnt)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03695/Python/s943970974.py", line 13, in <module>
    max = min(len(colors) + over_cnt, 8)
TypeError: 'int' object is not callable


def main():
    _ = int(input())
    A = list(map(int, input().split()))
    c = [False] * (4800 // 400 - 1)
    d = [0] * (4800 // 400 - 1)
    for a in A:
        c[a // 400] = True
        d[a // 400] += 1
    mn = 1 if c[:8].count(True) == 0 else c[:8].count(True)
    mx = c[:8].count(True) + sum(d[8:])
    print(mn, mx)

main()

def main():
    _ = int(input())
    A = list(map(int, input().split()))
    c = [False] * (4800 // 400 + 1)
    d = [0] * (4800 // 400 + 1)
    for a in A:
        c[a // 400] = True
        d[a // 400] += 1
    mn = 1 if c[:8].count(True) == 0 else c[:8].count(True)
    mx = c[:8].count(True) + sum(d[8:])
    print(mn, mx)

main()


N = int(input())
a = list(map(int, input().split()))
colors = [0] * 9
for i in range(N):
    if 1 <= a[i] and a[i] <= 399:
        colors[0] = 1
    elif 400 <= a[i] and a[i] <= 799:
        colors[1] = 1
    elif 800 <= a[i] and a[i] <= 1199:
        colors[2] = 1
    elif 1200 <= a[i] and a[i] <= 1599:
        colors[3] = 1
    elif 1600 <= a[i] and a[i] <= 1999:
        colors[4] = 1
    elif 2000 <= a[i] and a[i] <= 2399:
        colors[5] = 1
    elif 2400 <= a[i] and a[i] <= 2799:
        colors[6] = 1
    elif 2800 <= a[i] and a[i] <= 3199:
        colors[7] = 1
    else:
        colors[8] += 1
if sum(colors[0:8] == 0) and colors[9] >= 1:
    MIN = 1
else:
    MIN = sum(colors[0:8])
MAX = sum(colors)

print(MIN, MAX)

N = int(input())
a = list(map(int, input().split()))
colors = [0] * 9
for i in range(N):
    if 1 <= a[i] and a[i] <= 399:
        colors[0] = 1
    elif 400 <= a[i] and a[i] <= 799:
        colors[1] = 1
    elif 800 <= a[i] and a[i] <= 1199:
        colors[2] = 1
    elif 1200 <= a[i] and a[i] <= 1599:
        colors[3] = 1
    elif 1600 <= a[i] and a[i] <= 1999:
        colors[4] = 1
    elif 2000 <= a[i] and a[i] <= 2399:
        colors[5] = 1
    elif 2400 <= a[i] and a[i] <= 2799:
        colors[6] = 1
    elif 2800 <= a[i] and a[i] <= 3199:
        colors[7] = 1
    else:
        colors[8] += 1

if sum(colors[0:8]) == 0 and colors[8] >= 1:
    MIN = 1
else:
    MIN = sum(colors[0:8])
MAX = sum(colors)

print(MIN, MAX)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03695/Python/s269664657.py", line 23, in <module>
    if sum(colors[0:8] == 0) and colors[9] >= 1:
TypeError: 'bool' object is not iterable


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

score = sum(s)
s.sort()
i = 0
while score % 10 == 0:
    score -= s[i]
    i += 1
    if score == 0:
        break
print(score)

import sys

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

a, b = map(int, readline().split())
ans = a + b if (a + b) < 10 else "error"
print(ans)

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


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

A = int(input())
B = int(input())

sum = A + B

if sum <= 10:
    print(sum)

elif sum > 10:
    print("error")

#!/usr/bin/env python
# _*_ coding: utf-8 _*_
a = input()
a.split()
a.split()[1]

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

sum = A + B

if sum < 10:
    print(sum)

elif sum >= 10:
    print("error")

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


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

def main():
    """Function."""
    s = str(input())

    check = set()
    for i in range(s):
        check.add(s[i])

    if len(s) != len(s):
        print("no")
    else:
        print("yes")

if __name__ == "__main__":
    main()

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

def main():
    """Function."""
    s = str(input())
    check = set()

    for i in range(len(s)):
        check.add(s[i])

    if len(s) != len(check):
        print("no")
    else:
        print("yes")

if __name__ == "__main__":
    main()

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03698/Python/s295275910.py", line 19, in <module>
    main()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03698/Python/s295275910.py", line 9, in main
    for i in range(s):
TypeError: 'str' object cannot be interpreted as an integer


import sys

input = sys.stdin.buffer.readline
n = int(input())
S = []
for _ in range(n):
    S.append(int(input()))
ans = 0
for i in range(1 << n):
    temp = 0
    for j in range(n):
        if (i >> j) & 1:
            temp += S[j]
    if temp % 10 == 0:
        temp = 0
    ans = max(temp, ans)
print(ans)

import sys

input = sys.stdin.buffer.readline
n = int(input())
S = []
for _ in range(n):
    S.append(int(input()))
S.sort()
goukei = sum(S)
if goukei % 10 != 0:
    print(goukei)
    exit()
ans = 0
for i in range(n):
    temp = goukei - S[i]
    if temp % 10 == 0:
        temp = 0
    ans = max(ans, temp)

print(ans)


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

dp = [set() for _ in range(n + 1)]
for i in range(n):
    dp[i + 1].update(dp[i])
    for x in dp[i]:
        dp[i + 1].add(x + s[i])
    dp[i + 1].add(s[i])

ans = max((x for x in dp[i + 1] if x % 10 != 0), default=0)
print(ans)

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

dp = [set() for _ in range(n + 1)]
for i in range(n):
    dp[i + 1].update(dp[i])
    for x in dp[i]:
        dp[i + 1].add(x + s[i])
    dp[i + 1].add(s[i])

ans = 0
for x in dp[i + 1]:
    if x % 10 != 0:
        ans = max(ans, x)
print(ans)


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

# total:累計, i:index
def dfs(total, i):
    if i == n:
        if total % 10 != 0:
            return total
        else:
            return 0
    return max(dfs(total, i + 1), dfs(total + s[i], i + 1))

print(dfs(0, 0))

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

total = sum(s)
s.sort()
if total % 10 != 0:
    print(total)
else:
    for i in range(n):
        if (total - s[i]) % 10 != 0:
            print(total - s[i])
            exit()
    print(0)


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

result = sum(s)

if result % 10 == 0:
    while True:
        min_s = min(s)
        if min_s % 10 == 0:
            s.remove(min_s)
        else:
            result -= min_s
            break

print(result)

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

result = sum(s)

if result % 10 == 0:
    for _ in range(N):
        min_s = min(s)
        if min_s % 10 == 0:
            s.remove(min_s)
        else:
            result -= min_s
            break

    if result % 10 == 0:
        result = 0

print(result)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from itertools import combinations

def main():
    N = int(input())
    S = [int(input()) for _ in range(N)]
    result = 0

    for i in range(1, N + 1):
        for c in list(combinations(S, i)):
            tmp = max([0 if sum(c) % 10 == 0 else sum(c)])
            result = max(result, tmp)
    print(result)

if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    S = [int(input()) for _ in range(N)]

    S.sort()
    result = sum(S)

    if result % 10 == 0:
        for s in S:
            if s % 10:
                print(result - s)
                exit()
    else:
        print(result)
        exit()

    print(0)

if __name__ == "__main__":
    main()


N = int(input())
S = sorted([int(input()) for _ in range(N)])
s = sum(S)
if s % 10 != 0:
    print(s)
    exit()

for si in range(S):
    if si % 10 != 0:
        print(s - si)
        exit()

print(0)

N = int(input())
S = sorted([int(input()) for _ in range(N)])
s = sum(S)
if s % 10 != 0:
    print(s)
    exit()

for si in S:
    if si % 10 != 0:
        print(s - si)
        exit()

print(0)

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


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

left = 0
right = 10**9
mid = (left + right) // 2
while right - left > 1:
    mid = (left + right) // 2
    count = 0
    for i in range(n):
        if h[i] - mid * b > 0:
            if (h[i] - mid * b) % (a - b) == 0:
                count += (h[i] - mid * b) // (a - b)
            else:
                count += (h[i] - mid * b) // (a - b) + 1
    if mid - count >= 0:
        right = mid
    else:
        left = mid
print(right)

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

left = 0
right = 10**10
mid = (left + right) // 2
while right - left > 1:
    mid = (left + right) // 2
    count = 0
    for i in range(n):
        if h[i] - mid * b > 0:
            if (h[i] - mid * b) % (a - b) == 0:
                count += (h[i] - mid * b) // (a - b)
            else:
                count += (h[i] - mid * b) // (a - b) + 1
    if mid - count >= 0:
        right = mid
    else:
        left = mid
print(right)


import sys

import numpy as np

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

n, k = map(int, input().split())
aaa = np.fromiter(sys.stdin, dtype=np.int64)
aaa = np.insert(aaa, 0, 0)
acc = np.add.accumulate(aaa) - np.arange(0, k * n + 1, k)
dct = {v: i for i, v in enumerate(np.unique(acc), start=1)}
bit = Bit(n)
ans = 0
for d in acc:
    i = dct[d]
    ans += bit.sum(i)
    bit.add(i, 1)
print(ans)

import sys

import numpy as np

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

n, k = map(int, input().split())
aaa = np.fromiter(sys.stdin, dtype=np.int64)
aaa = np.insert(aaa, 0, 0)
acc = np.add.accumulate(aaa) - np.arange(0, k * n + 1, k)
dct = {v: i for i, v in enumerate(np.unique(acc), start=1)}
bit = Bit(len(dct))
ans = 0
for d in acc:
    i = dct[d]
    ans += bit.sum(i)
    bit.add(i, 1)
print(ans)


from itertools import combinations

def main(n: int, a: int, b: int):

    if a > b:
        print(0)
        return
    elif a == b:
        print(1)
        return

    if n < 3:
        if n == 1:
            print(0)
        elif n == 2:
            print(2)

        return

    ans = 2
    ans += sum(1 for _ in combinations(range(a, b + 1), n - 2))

    print(ans)

if __name__ == "__main__":
    n, a, b = map(int, input().split())

    main(n, a, b)

def main(n: int, a: int, b: int):
    if a > b:
        print(0)
        return

    if n == 1:
        if a == b:
            print(1)
        else:
            print(0)
        return

    if n == 2:
        if a > b:
            print(0)
        else:
            print(1)
        return

    print((n - 2) * (b - a) + 1)

if __name__ == "__main__":
    n, a, b = map(int, input().split())

    main(n, a, b)


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03711/Python/s276766245.py", line 5, in <module>
    if L(x) == L(y):
TypeError: 'list' object is not callable


import sys

group1 = [1, 3, 5, 7, 8, 10, 12]
group2 = [4, 6, 9, 11]
group3 = [2]

input_x = int(sys.argv[1])
input_y = int(sys.argv[2])

exist_group1 = group1.count(input_x) + group1.count(input_y)
exist_group2 = group2.count(input_x) + group2.count(input_y)
exist_group3 = group3.count(input_x) + group3.count(input_y)

if exist_group1 == 2 or exist_group2 == 2 or exist_group3 == 2:
    print("Yes")
else:
    print("No")

group1 = [1, 3, 5, 7, 8, 10, 12]
group2 = [4, 6, 9, 11]
group3 = [2]

input = list(map(int, input().split()))
input_x = int(input[0])
input_y = int(input[1])

exist_group1 = group1.count(input_x) + group1.count(input_y)
exist_group2 = group2.count(input_x) + group2.count(input_y)
exist_group3 = group3.count(input_x) + group3.count(input_y)

if exist_group1 == 2 or exist_group2 == 2 or exist_group3 == 2:
    print("Yes")
else:
    print("No")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03711/Python/s235468671.py", line 7, in <module>
    input_x = int(sys.argv[1])
IndexError: list index out of range


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

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

ans = -float("inf")
for i in range(n, 2 * n + 1):
    fh = a[:i].copy()
    fh.sort(reverse=True)
    sh = a[i:].copy()
    sh.sort()
    score = sum(fh[:n]) - sum(sh[:n])
    ans = max(ans, score)

print(ans)

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

import heapq

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

fh_sum = 0
fh = []
sh_sum = 0
sh = []
for i in range(n):
    heapq.heappush(fh, a[i])
    fh_sum += a[i]
    heapq.heappush(sh, -a[-(i + 1)])
    sh_sum += a[-(i + 1)]

fh_sums = [fh_sum]
sh_sums = [sh_sum]
for k in range(n, 2 * n):
    fh_sum += a[k]
    heapq.heappush(fh, a[k])
    fh_sum -= heapq.heappop(fh)
    fh_sums.append(fh_sum)
    sh_sum += a[-(k + 1)]
    heapq.heappush(sh, -a[-(k + 1)])
    sh_sum += heapq.heappop(sh)
    sh_sums.append(sh_sum)

sh_sums = sh_sums[::-1]

ans = -float("inf")
for fh_sum, sh_sum in zip(fh_sums, sh_sums):
    score = fh_sum - sh_sum
    ans = max(ans, score)

print(ans)


a, b, c = map(int, input().split)
if a <= c <= b:
    print("Yes")
else:
    print("No")

a, b, c = map(int, input().split())
if a <= c <= b:
    print("Yes")
else:
    print("No")

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


A, B, C = int(input().split())
if A <= C and C <= B:
    print("Yes")
else:
    print("No")

A, B, C = map(int, input().split())
if A <= C and C <= B:
    print("Yes")
else:
    print("No")

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


N, M = map(int, input().split())
road = [0] * N

for _ in range(N):
    a, b = [int(i) for i in input().split()]
    road[a - 1] += 1
    road[b - 1] += 1
for r in road:
    print(r)

N, M = map(int, input().split())
road = [0] * N

for _ in range(M):
    a, b = [int(i) for i in input().split()]
    road[a - 1] += 1
    road[b - 1] += 1
for r in road:
    print(r)

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


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

cnt = [0] * n

for i in range(m):
    cnt[ab[i][0] - 1] += 1
    cnt[ab[i][1] - 1] += 1

for i in range(n):
    print(cnt(i))

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

cnt = [0] * n

for i in range(m):
    cnt[ab[i][0] - 1] += 1
    cnt[ab[i][1] - 1] += 1

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

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03720/Python/s115921394.py", line 11, in <module>
    print(cnt(i))
TypeError: 'list' object is not callable


n, k = [int(i) for i in input().split()]
d = {}
for i in range(n):
    a, b = [int(i) for i in input().split()]
    if a in d:
        d[a] += b
    else:
        d[a] = b
c = []
for k, v in sorted(d.items(), key=lambda x: x[0]):
    c += [k] * v
print(c[k])

n, k = [int(i) for i in input().split()]
cnt = [0] * int(10e5)
for i in range(n):
    a, b = [int(i) for i in input().split()]
    cnt[a] += b

for i in range(1, len(cnt)):
    if k <= cnt[i]:
        print(i)
        break
    k -= cnt[i]


N, K = map(int, input().split())
array = []
for _ in range(N):
    a, b = map(int, input().split())
    array.extend([a] * b)
array.sort()
print(array[K - 1])

from collections import Counter

N, K = map(int, input().split())
c = Counter()
for _ in range(N):
    a, b = map(int, input().split())
    c[a] += b
for item in sorted(c.items(), key=lambda x: x[0]):
    if item[1] >= K:
        print(item[0])
        break
    else:
        K -= item[1]


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

def F(a, b, c):
    if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
        return 0
    if a == b == c:
        return -1
    return F((a + b) // 2, (b + c) // 2, (c + a) // 2) + 1

print(F(A, B, C))


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

while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    if a == b == c:
        print(-1)
        exit()
    a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2
    ans += 1
print(ans)

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

while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    if a == b == c:
        print(-1)
        exit()
    a, b, c = (b + c) // 2, (c + a) // 2, (a + b) // 2
    ans += 1
print(ans)

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


import sys

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    count = [0] * (N + 1)
    for _ in range(N):
        a, b = map(int, input().split())
        count[a] += 1
        count[b] += 1

    if all(c % 2 == 0 for c in count):
        ans = "YES"
    else:
        ans = "NO"
    print(ans)

if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    count = [0] * (N + 1)
    for _ in range(M):
        a, b = map(int, input().split())
        count[a] += 1
        count[b] += 1

    if all(c % 2 == 0 for c in count):
        ans = "YES"
    else:
        ans = "NO"
    print(ans)

if __name__ == "__main__":
    main()


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

count = [0 for i in range(N)]

for aibi in ab:
    ai = aibi[0]
    bi = aibi[1]

    if bi < ai:
        tmp = ai
        ai = bi
        bi = tmp

    for j in range(ai - 1, bi - 1):
        count[j] += 1

yes_or_no = True
for num in count:
    if num % 2 == 1:
        yes_or_no = False

if yes_or_no:
    print("YES")
else:
    print("NO")

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

count = [0 for i in range(N)]

# for aibi in ab:
#     ai = aibi[0]
#     bi = aibi[1]
#
#     if bi < ai:
#         tmp = ai
#         ai = bi
#         bi = tmp
#
#     for j in range(ai - 1, bi - 1):
#         count[j] += 1

for aibi in ab:
    ai = aibi[0]
    bi = aibi[1]
    if ai != 1 and bi != 1:
        count[ai - 1] += 1
        count[bi - 1] += 1
    else:
        if ai == 1:
            count[bi - 1] += 1
        else:
            count[ai - 1] += 1

yes_or_no = True
for num in count:
    if num % 2 == 1:
        yes_or_no = False

if yes_or_no:
    print("YES")
else:
    print("NO")


from collections import Counter

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

ctr = Counter(sum(X, []))
if all(v % 2 == 0 for v in ctr.values()):
    print("YES")
else:
    print("NO")

from collections import Counter

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

ctr = Counter()
for a, b in X:
    ctr[a] += 1
    ctr[b] += 1

if all(v % 2 == 0 for v in ctr.values()):
    print("YES")
else:
    print("NO")


from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        A[Si][Sj] = "."
        break

distance = INF

Q = deque([(0, Si, Sj)])
while Q:
    cnt, i, j = Q.popleft()

    if A[i][j] == "#":
        continue
    A[i][j] = "#"

    distance = min(distance, i, j, H - i - 1, W - j - 1)

    if cnt >= K:
        continue

    for ni, nj in ((i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)):
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
            Q.append((cnt + 1, ni, nj))

print(-(-distance // K) + 1)

from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        A[Si][Sj] = "c"
        break

distance = INF

Q = deque([(0, Si, Sj)])
while Q:
    cnt, i, j = Q.popleft()

    distance = min(distance, i, j, H - i - 1, W - j - 1)

    if cnt >= K:
        continue

    for ni, nj in ((i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)):
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
            A[ni][nj] = "c"
            Q.append((cnt + 1, ni, nj))

print(-(-distance // K) + 1)


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

if A[-1] == B[0] and B[-1] == C[0]:
    print("Yes")
else:
    print("No")

A, B, C = input().split()

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

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


import math

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

gcd = math.gcd(A, B)
if C % gcd == 0:
    print("YES")
else:
    print("NO")

import fractions

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

gcd = fractions.gcd(A, B)
if C % gcd == 0:
    print("YES")
else:
    print("NO")


from math import gcd

A, B, C = map(int, open(0).read().split())

if C % gcd(A, B) == 0:
    print("YES")
else:
    print("NO")

from fractions import gcd

A, B, C = map(int, open(0).read().split())

if C % gcd(A, B) == 0:
    print("YES")
else:
    print("NO")


N, W = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
    for j in range(W + 1):
        if j < X[i][0]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - X[i][0]] + X[i][1])

print(dp[-1][-1])

N, W = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

w0 = X[0][0]
ctr = [[] for _ in range(4)]
for w, v in X:
    ctr[w - w0].append(v)

for n in range(4):
    values = sorted(ctr[n], reverse=True)
    s = [0] * (len(values) + 1)
    for i in range(len(values)):
        s[i + 1] = s[i] + values[i]
    ctr[n] = s

ans = 0
for i in range(len(ctr[0])):
    for j in range(len(ctr[1])):
        for k in range(len(ctr[2])):
            for l in range(len(ctr[3])):
                tmp = ctr[0][i] + ctr[1][j] + ctr[2][k] + ctr[3][l]
                w = w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l
                if w <= W:
                    ans = max(ans, tmp)

print(ans)


#!/usr/bin/env python3

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0] * (W + 1) for i in range(N + 1)]
for i in range(N):
    for j in range(W + 1):
        if j < w[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])

print(dp[N][W])

#!/usr/bin/env python3

def rec(i, j):
    if (i, j) in dp:
        return dp[(i, j)]

    if i == N:
        res = 0
    elif j < w[i]:
        res = rec(i + 1, j)
    else:
        res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i])

    dp[(i, j)] = res
    return res

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = {}
print(rec(0, W))


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03737/Python/s377862248.py", line 1, in <module>
    print(str.upper(input()[0]) + str.upper(input()[0]) + str.upper(input()[0]))
EOFError: EOF when reading a line


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

if a > b:
    print("GREATER")
elif a < b:
    print("LESS")
else:
    print("EQUAL")

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

if a > b:
    print("GREATER")
elif a < b:
    print("LESS")
else:
    print("EQUAL")

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


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

if a > b:
    print("GREATER")
elif a < b:
    print("LESS")
elif a == b:
    print("EQUAL")

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

if a > b:
    print("GREATER")
elif a < b:
    print("LESS")
elif a == b:
    print("EQUAL")

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


a, b = map(int, input().split())
print("GREATER" if a > b else "LESS" if a < b else "EQUAL")

a, b = [int(input()) for _ in range(2)]
print("GREATER" if a > b else "LESS" if a < b else "EQUAL")

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


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

sum = a[0]
count = 0

if a[0] == 0:
    if a[1] > 0:
        sum -= 1
        count += 1
    elif a[1] < 0:
        sum += 1
        count += 1

for i in range(1, n):
    tmp = sum
    sum += a[i]
    while tmp > 0 and sum >= 0:
        sum -= 1
        count += 1
    while tmp < 0 and sum <= 0:
        sum += 1
        count += 1

print(count)

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

# +, -, +, -, ...
sum = 0
count = 0
for i in range(n):
    sum += a[i]
    if i % 2 == 0:
        if sum <= 0:
            count += abs(sum) + 1
            sum = 1
    else:
        if sum >= 0:
            count += abs(sum) + 1
            sum = -1

# -, +, -, +, ...
sum2 = 0
count2 = 0
for i in range(n):
    sum2 += a[i]
    if i % 2 == 0:
        if sum2 >= 0:
            count2 += abs(sum2) + 1
            sum2 = -1
    else:
        if sum2 <= 0:
            count2 += abs(sum2) + 1
            sum2 = 1

print(min(count, count2))


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

sum_an = []
tmp = 0
for a in an:
    tmp += a
    sum_an.append(tmp)

c = 0
before_positive = sum_an[0] <= 0
for i in range(n):
    if before_positive and sum_an[i] >= 0:
        p = abs(sum_an[i]) + 1
        c += p
        for j in range(i, n):
            sum_an[j] -= p
        before_positive = False
    elif not before_positive and sum_an[i] <= 0:
        p = abs(sum_an[i]) + 1
        c += p
        for j in range(i, n):
            sum_an[j] += p
        before_positive = True
    else:
        before_positive = not before_positive

print(c)

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

c1 = 0
c2 = 0
sum1 = 0  # 偶数番目が正
sum2 = 0  # 奇数番目が正
for i in range(n):
    sum1 += an[i]
    sum2 += an[i]
    if i % 2 == 0:
        if sum1 <= 0:
            p = abs(sum1) + 1
            c1 += p
            sum1 += p
        if sum2 >= 0:
            p = abs(sum2) + 1
            c2 += p
            sum2 -= p
    else:
        if sum1 >= 0:
            p = abs(sum1) + 1
            c1 += p
            sum1 -= p
        if sum2 <= 0:
            p = abs(sum2) + 1
            c2 += p
            sum2 += p

print(min(c1, c2))


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

def solve(i, s, k, sign):
    if i >= len(A):
        return k

    if sign * (s + A[i]) > 0:
        return solve(i + 1, s + A[i], k, sign * -1)
    else:
        return solve(i + 1, sign, k + abs(s + A[i]) + 1, sign * -1)

print(min(solve(0, 0, 0, 1), solve(0, 0, 0, -1)))

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

ret = float("inf")

sign = 1
s = 0
k = 0
for a in A:
    if sign * (s + a) > 0:
        s += a
    else:
        k += abs(s + a) + 1
        s = sign
    sign *= -1
ret = min(ret, k)

sign = -1
s = 0
k = 0
for a in A:
    if sign * (s + a) > 0:
        s += a
    else:
        k += abs(s + a) + 1
        s = sign
    sign *= -1

ret = min(ret, k)

print(ret)


def upper_or_lower(i):
    if A[i] < A[i + 1]:
        return "upper"
    elif A[i] > A[i + 1]:
        return "lower"
    else:
        return upper_or_lower(i + 1)

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

state = "upper"  # state が upper か lower で判定
ans = 1

# i = 0 の処理
if A[0] > A[1]:
    state = "lower"

for i in range(2, N):
    if (state == "upper") and (A[i - 1] > A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    elif (state == "lower") and (A[i - 1] < A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    else:
        continue

print(ans)

def upper_or_lower(i):
    if A[i] < A[i + 1]:
        return "upper"
    elif A[i] > A[i + 1]:
        return "lower"
    else:
        return upper_or_lower(i + 1)

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

state = "upper"  # state が upper か lower で判定
ans = 1

# i = 0 の処理
if (len(A) > 2) and (A[0] > A[1]):
    state = "lower"

for i in range(2, N):
    if (state == "upper") and (A[i - 1] > A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    elif (state == "lower") and (A[i - 1] < A[i]):
        ans += 1
        if i < N - 1:
            state = upper_or_lower(i)
    else:
        continue

print(ans)


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


from queue import deque

n, m = map(int, input().split())
links = [None] + [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)

s = 1
t = links[s].pop()
visited = deque([s, t])
while True:
    s_remains = links[s].difference(visited)
    s_flag, t_flag = True, True
    if s_remains:
        s = s_remains.pop()
        visited.appendleft(s)
        s_flag = False
    t_remains = links[t].difference(visited)
    if t_remains:
        t = t_remains.pop()
        visited.append(t)
        t_flag = False
    if s_flag and t_flag:
        break
print(len(visited))
print(*visited)

from queue import deque

n, m = map(int, input().split())
links = [None] + [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)

s = 1
path = deque([s])
visited = {s}

while True:
    s_remains = links[s] - visited
    if s_remains:
        s = s_remains.pop()
        path.appendleft(s)
        visited.add(s)
    else:
        break

t = 1

while True:
    t_remains = links[t] - visited
    if t_remains:
        t = t_remains.pop()
        path.append(t)
        visited.add(t)
    else:
        break

print(len(path))
print(*path)


o = list(input())
e = list(input())
for i in range(len(o)):
    print(o[i] + e[i], end="")

o = list(input())
e = list(input()) + [""]
for i, j in zip(o, e):
    print(i + j, end="")


n = int(input()) - 1
a = list(input())
while n and a:
    n -= 1
    a = [i for i in a if i in input()]
print(a)

n = int(input())

cnt = [10000] * 26

for i in range(n):
    s = input()
    tmp = [0] * 26
    for c in s:
        tmp[ord(c) - ord("a")] += 1
    for j in range(26):
        cnt[j] = min(cnt[j], tmp[j])

a = ""
for i in range(26):
    if cnt[i]:
        a = a + chr(ord("a") + i) * cnt[i]
print(a)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03761/Python/s024080261.py", line 5, in <module>
    a = [i for i in a if i in input()]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03761/Python/s024080261.py", line 5, in <listcomp>
    a = [i for i in a if i in input()]
EOFError: EOF when reading a line


n = int(input())
alphabet_histgram = [[0 for _ in range(n)] for _ in range(25)]
ord_a = ord("a")

for i in range(n):
    S = input()
    for c in S:
        alphabet_histgram[ord(c) - ord_a][i] += 1

ret = ""
for i, hist_c in enumerate(alphabet_histgram):
    ret += chr(ord_a + i) * min(hist_c)

print(ret)

n = int(input())
alphabet_histgram = [[0 for _ in range(n)] for _ in range(26)]
ord_a = ord("a")

for i in range(n):
    S = input()
    for c in S:
        alphabet_histgram[ord(c) - ord_a][i] += 1

ret = ""
for i, hist_c in enumerate(alphabet_histgram):
    ret += chr(ord_a + i) * min(hist_c)

print(ret)


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

sum_x = 0
for i in range(0, n):
    tmp_x = x[i]
    sum_x += sum(list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_x, x)))))

sum_y = 0
for i in range(0, m):
    tmp_y = y[i]
    sum_y += sum(list(filter(lambda ele: ele > 0, (map(lambda ele: ele - tmp_y, y)))))

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print(ans % divide_num)

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

sum_x = 0
for i in range(0, n):
    sum_x += i * x[i] - (n - (i + 1)) * x[i]

sum_y = 0
for i in range(0, m):
    sum_y += i * y[i] - (m - (i + 1)) * y[i]

ans = sum_x * sum_y

divide_num = pow(10, 9) + 7
print(ans % divide_num)


import sys

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

def restore(s):
    while len(s) > 1:
        s = s.replace("AA", "B")
        s = s.replace("BB", "A")
        s = s.replace("AB", "")
        s = s.replace("BA", "")
    return s

S = input()
T = input()
q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    r_s = restore(S[a - 1 : b])
    r_t = restore(T[c - 1 : d])
    print("YES") if r_s == r_t else print("NO")

import sys
from itertools import accumulate

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

def acc(li, n):
    res = [0] * (n + 1)
    for i in range(n):
        if li[i] == "A":
            res[i + 1] = 1
        elif li[i] == "B":
            res[i + 1] = 2
    return list(accumulate(res))

def restore(x, y, li):
    return (li[y] - li[x - 1]) % 3

S = input()
T = input()
N = len(S)
M = len(T)

acc_S = acc(S, N)
acc_T = acc(T, M)

q = int(input())
for _ in range(q):
    a, b, c, d = map(int, input().split())
    v_S = restore(a, b, acc_S)
    v_T = restore(c, d, acc_T)
    print("YES") if v_S == v_T else print("NO")


N = int(input())
member = sorted(map(int, input().split()))
ans = 0
while member:
    member.pop()
    ans += member.pop()
    member.pop(0)
print(ans)

N = int(input())
member = sorted(map(int, input().split()))
ans = sum(member[N::2])
print(ans)


from queue import deque

def dijkstra(s, d):
    queue = deque([(0, s)])
    paint = set()
    while queue:
        cost, v = queue.popleft()
        if cost > d:
            break
        paint.add(v)
        queue.extend((cost + 1, u) for u in links[v] if u not in paint)
    return paint

n, m = map(int, input().split())
links = [None] + [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)

q = int(input())
queries = [map(int, input().split()) for _ in range(q)]
painted = set()
colors = [0] * (n + 1)
while queries:
    v, d, c = queries.pop()
    paint = dijkstra(v, d) - painted
    for i in paint:
        colors[i] = c
    painted |= paint

for c in colors[1:]:
    print(c)

from queue import deque

def paint(s, d, c):
    queue = deque([(d, s)])
    while queue:
        remains, v = queue.popleft()
        if painted[v] >= remains:
            continue
        if colors[v] == 0:
            colors[v] = c
        painted[v] = remains
        if remains:
            queue.extend((remains - 1, u) for u in links[v])

n, m = map(int, input().split())
links = [None] + [set() for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    links[a].add(b)
    links[b].add(a)

q = int(input())
queries = [map(int, input().split()) for _ in range(q)]
colors = [0] * (n + 1)
painted = [-1] * (n + 1)
while queries:
    paint(*queries.pop())

for c in colors[1:]:
    print(c)


n = int(input())

ans = []
c = 1
can = (1 << 40) - 1
needs = 41

while n:
    if n >= can:
        n -= can
        ans.extend([c] * needs)
        c += 1
    else:
        can >>= 1
        needs -= 1

assert len(ans) <= 200

print(len(ans))
print(*ans)

def test():
    from itertools import combinations

    s = "111223111223"
    result = 0
    for k in range(1, len(s) // 2 + 1):
        for idx in combinations(range(len(s)), 2 * k):
            success = True
            for ii in range(k):
                if s[idx[ii]] != s[idx[ii + k]]:
                    success = False
                    break
            if success:
                result += 1
    print(result)

n = int(input())

factorials = [1, 1]
for i in range(2, 40):
    factorials.append(factorials[-1] * i)

patterns = {}
for i in range(2, 40):
    base = (1 << (i - 1)) - 1
    gain = base
    chars = i
    if gain > n:
        break
    if gain not in patterns or chars < patterns[gain][0]:
        patterns[gain] = (chars, (i,))
    if i % 2 == 1:
        continue

    a = i // 2
    ncr1 = factorials[i] // factorials[a] // factorials[a] - 1

    for b in range(1, a + 1):
        base2 = (1 << (2 * b - 1)) - 1
        ncr2 = factorials[2 * b] // factorials[b] // factorials[b] - 1
        gain = base + base2 + ncr1 * ncr2
        chars = i + 2 * b
        if gain > n:
            break
        if gain not in patterns or chars < patterns[gain][0]:
            patterns[gain] = (chars, (a, b))

        for c in range(1, b + 1):
            base3 = (1 << (2 * c - 1)) - 1
            ncr3 = factorials[2 * c] // factorials[c] // factorials[c] - 1
            gain = (
                base
                + base2
                + base3
                + ncr1 * ncr2 * ncr3
                + ncr1 * ncr2
                + ncr2 * ncr3
                + ncr3 * ncr1
            )
            chars = i + 2 * b + 2 * c
            if gain > n:
                break
            if gain not in patterns or chars < patterns[gain][0]:
                patterns[gain] = (chars, (a, b, c))

            for d in range(1, c + 1):
                base4 = (1 << (2 * d - 1)) - 1
                ncr4 = factorials[2 * d] // factorials[d] // factorials[d] - 1
                gain = base + base2 + base3 + base4 + ncr1 * ncr2 * ncr3 * ncr4
                gain += (
                    ncr1 * ncr2 * ncr3
                    + ncr1 * ncr2 * ncr4
                    + ncr1 * ncr3 * ncr4
                    + ncr2 * ncr3 * ncr4
                )
                gain += (
                    ncr1 * ncr2
                    + ncr1 * ncr3
                    + ncr1 * ncr4
                    + ncr2 * ncr3
                    + ncr2 * ncr4
                    + ncr3 * ncr4
                )
                chars = i + 2 * b + 2 * c + 2 * d
                if gain > n:
                    break
                if gain not in patterns or chars < patterns[gain][0]:
                    patterns[gain] = (chars, (a, b, c, d))

def dfs(use, i, remaining, total_char):
    if remaining == 0:
        return total_char <= 200

    for j in range(i, len(patterns)):
        gain, (chars, lengths) = patterns[j]
        if total_char + remaining * chars / gain > 200:
            break
        if gain > remaining:
            continue
        use.append(lengths)
        result = dfs(use, j, remaining - gain, total_char + chars)
        if result:
            return True
        use.pop()

    return False

patterns = sorted(patterns.items(), key=lambda item: item[0] / item[1][0], reverse=True)

use = []
result = dfs(use, 0, n, 0)
assert result

ans = []
c = 1
for lengths in use:
    if len(lengths) == 1:
        ans.extend([c] * lengths[0])
        c += 1
    else:
        for _ in range(2):
            for i, l in enumerate(lengths):
                ans.extend([c + i] * l)
        c += len(lengths)

print(len(ans))
print(*ans)


N = int(input())

min_l = len(str(N))
o_min_l = min_l

for i in range(1, N):
    if N % i == 0:
        j = int(N / i)
        min_l = min(min_l, max(len(str(i)), len(str(j))))
print(min_l)

import math

N = int(input())

min_l = len(str(N))

for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        j = int(N / i)
        min_l = min(min_l, max(len(str(i)), len(str(j))))
print(min_l)


# 入力 : 自然数     ex) 12
# 出力 : 約数リスト ex) [2, 2, 3]
def factorization(n):
    R = int(n)
    s = 0
    L = []
    div = 2
    while s == 0:
        for i in range(div, R + 1):
            if n % i == 0:
                n = n / i
                div = i
                if n == 1:
                    s = 1
                L.append(i)
                break
    return L

n = int(input())
if n == 1:
    print(1)
    exit()
divs = factorization(n)
N = [i for i in divs]  # N = bit探索する桁数
maxDigit = n
# Nの要素の全組み合わせが出力
for i in range(1, 1 << len(N)):
    output = []
    nonout = []
    outNum = 1
    nonOutNum = 1
    for j in range(len(N)):
        if ((i >> j) & 1) == 1:
            output.append(N[j])  # このjが今回探索するindexの1つ
            outNum *= N[j]
        else:
            nonout.append(N[j])
            nonOutNum *= N[j]
    # print("{} vs {}".format(outNum, nonOutNum))
    digitOut = 0
    digitNonOut = 0
    while outNum > 0:
        digitOut += 1
        outNum = int(outNum / 10)
    while nonOutNum > 0:
        digitNonOut += 1
        nonOutNum = int(nonOutNum / 10)
    if max(digitOut, digitNonOut) < maxDigit:
        maxDigit = max(digitOut, digitNonOut)
print(maxDigit)

# 入力 : 自然数     ex) 12
# 出力 : 約数リスト ex) [(2,2),(3,1)]
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

n = int(input())
if n == 1:
    print(1)
    exit()
fct = factorize(n)
maxDigit = n
for div in divisorize(fct):
    outNum = num(div)
    nonOutNum = int(n / outNum)
    digitOut = 0
    digitNonOut = 0
    while outNum > 0:
        digitOut += 1
        outNum = int(outNum / 10)
    while nonOutNum > 0:
        digitNonOut += 1
        nonOutNum = int(nonOutNum / 10)
    if max(digitOut, digitNonOut) < maxDigit:
        maxDigit = max(digitOut, digitNonOut)
print(maxDigit)


import math

N = int(input())

min_length = -1
for i in range(int(math.sqrt(N))):
    for j in range(i + 1):
        A = j + 1
        if N % A == 0:
            B = int(N / A)
            len_a = len(str(A))
            len_b = len(str(B))
            length = len_a if len_a >= len_b else len_b
            if min_length == -1 or length < min_length:
                # print("len:{}, A:{}, B:{}".format(length, A, B))
                min_length = length
print(min_length)

import math

N = int(input())

min_length = -1
for A in range(1, int(math.sqrt(N)) + 1, 1):
    if N % A == 0:
        B = int(N / A)
        len_a = len(str(A))
        len_b = len(str(B))
        length = len_a if len_a >= len_b else len_b
        if min_length == -1 or length < min_length:
            # print("len:{}, A:{}, B:{}".format(length, A, B))
            min_length = length
print(min_length)


import math

N = int(input())

for i in range(1, math.floor(math.sqrt(N))):
    if N % i == 0:
        factor = N / i

factor = int(factor)
print(len(str(factor)))

import math

N = int(input())

for i in range(1, math.ceil(math.sqrt(N)) + 1):
    if N % i == 0:
        factor1 = N / i
        factor2 = i

factor1 = int(factor1)

if factor1 < factor2:
    print(len(str(factor2)))
else:
    print(len(str(factor1)))


N = int(input())
res = 10**10 + 1
for A in range(1, N + 1):
    if N % A == 0:
        B = N // A
        a = len(str(A))
        b = len(str(B))
        if a > b:
            num = a
        else:
            num = b
        if res > num:
            res = num
print(res)

import math

N = int(input())
ans = float("Inf")
sq = int(math.sqrt(N)) + 1
for i in range(1, sq):
    if N % i == 0:
        a = len(str(i))
        b = len(str(N // i))
        if a > b:
            num = a
        else:
            num = b
        if ans > num:
            ans = num
print(ans)


from math import ceil, sqrt, floor, log10

N = int(input())

for i in range(ceil(sqrt(N)), N + 1):
    if N % i == 0:
        print(floor(log10(i)) + 1)
        break

from math import floor, sqrt, log10

N = int(input())

for i in range(floor(sqrt(N)), 0, -1):
    if N % i == 0:
        print(floor(log10(N // i)) + 1)
        break


import math

N = int(input())
tmp = math.isqrt(N)
while N % tmp:
    tmp -= 1
print(len(str(N // tmp)))

import math

N = int(input())

tmp = math.floor(math.sqrt(N))
while N % tmp:
    tmp -= 1
print(len(str(N // tmp)))


from math import sqrt, ceil, floor, log10

N = int(input())

min_f = ceil(log10(N))
for A in range(1, ceil(sqrt(N))):
    if N % A != 0:
        continue
    else:
        B = N // A
        f = floor(max(log10(A), log10(B))) + 1
        if f < min_f:
            min_f = f

print(f)

from math import sqrt, ceil, floor, log10

N = int(input())

min_f = floor(log10(N)) + 1
for A in range(1, ceil(sqrt(N)) + 1):
    if N % A != 0:
        continue
    else:
        B = N // A
        f = floor(max(log10(A), log10(B))) + 1
        if f < min_f:
            min_f = f

print(f)


n = int(input())

sqr = int(n**0.5)
l1 = len(str(sqr))

pf = {}
for i in range(2, int(n**0.5) + 1):
    while not n % i:
        pf[i] = pf.get(i, 0) + 1
        n //= i
if n > 1:
    pf[n] = 1

ls = sorted(pf.items(), key=lambda x: x[0], reverse=True)
l2 = len(str(ls[0][0]))

print(max(l1, l2))

n = int(input())
m = n * 1

if n == 1:
    print(1)
    exit()

sqr = int(n**0.5)
l1 = len(str(sqr))

pf = {}
for i in range(2, int(m**0.5) + 1):
    while not m % i:
        pf[i] = pf.get(i, 0) + 1
        m //= i
if m > 1:
    pf[m] = 1

ls = sorted(pf.items(), key=lambda x: x[0], reverse=True)
l2 = len(str(ls[0][0]))
other = n // ls[0][0]
l3 = len(str(other))

if l1 <= l2 < l3:
    print(l3)
else:
    print(max(l1, l2))


import math

num = int(input())
num_sqrt = int(math.sqrt(num))

A = num_sqrt
while num % A != 0:
    A += 1
B = int(num / A)
A, B = str(A), str(B)
ans = max(len(A), len(B))
print(ans)

import math

num = int(input())
num_sqrt = int(math.sqrt(num))

ans = 11
for A in range(1, num_sqrt + 1):
    if num % A == 0:
        B = int(num / A)
        A, B = str(A), str(B)
        now_ans = max(len(A), len(B))
        ans = min(ans, now_ans)
print(ans)


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

from math import factorial

def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))

n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if a == 1 or goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a, b + 1):
        total += comb(lastcount, i)

print(avg)
print(total)

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

from math import factorial

def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))

n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a - 1, b):
        if goods[a - 1] != goods[i]:
            break
        total += comb(lastcount, i + 1)

print("{}\\n{}".format(avg, total))


a, b = list(map(int, input().split()))
if a == "H":
    print(b)
else:
    if b == "H":
        print("D")
    else:
        print("H")

a, b = input().split()
if a == "H":
    print(b)
else:
    if b == "H":
        print("D")
    else:
        print("H")

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


a, b = map(int, input().split())
if a == "H":
    print(b)
else:
    if b == "H":
        print("D")
    else:
        print("H")

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


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

if b > a + w:
    print(b - a - w)
elif b + w < a:
    print(a - b - w)
else:
    print(0)
w, a, b = map(int, input().split())

if b > a + w:
    print(b - a - w)
elif b + w < a:
    print(a - b - w)
else:
    print(0)

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


X = int(input())
dp = set([0])

ans = 0
while X not in dp:
    ans += 1
    for i in list(dp):
        if i + ans not in dp:
            dp.add(i + ans)
        if i - ans not in dp:
            dp.add(i - ans)
print(ans)

X = int(input())

ans = 0
sums = 0
while sums < X:
    ans += 1
    sums += ans
print(ans)


X = int(input())
# X > 0 なのでマイナス方向にジャンプする選択肢は選ばない
cnt = 0
while X != 0:
    if X != cnt + 1:
        X -= cnt
    cnt += 1
print(cnt - 1)

X = int(input())
acc = 0
# X > 0 なのでマイナス方向にジャンプする選択肢は選ばない
for i in range(X + 1):
    acc += i
    if X <= acc:
        ans = i
        break
print(i)


from itertools import combinations

int_x = int(input())

answer = int_x

for i in range(1, int_x + 1):
    c = combinations(range(1, int_x + 1), i)
    for w_c in c:
        if sum(w_c) == int_x:
            answer = min(answer, max(w_c))
print(answer)

x = int(input())

w = 0
for i in range(1, x + 1):
    w += i
    if w >= x:
        print(i)
        exit(0)


n, m = map(int, input().split())
print([2, 1][m > 1])

x = int(input())
ans = i = 0
while i < x:
    ans += 1
    i += ans
print(ans)

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


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

x = int(input())
i, pos = 0, set([0])

while True:
    inner = False
    new_pos = set()
    for p in pos:
        if p + i == x or p - i == x:
            inner = True
            break
        new_pos.add(p)
        new_pos.add(p + i)
        new_pos.add(p - i)

    if inner:
        print(i)
        break

    pos = new_pos
    i += 1

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

x = int(input())

total = 0
for i in range(x + 1):
    total += i
    if total >= x:
        print(i)
        break


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

# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = N
ng = -1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    n = mid
    dp = set()
    dp.add(0)
    ans = set(x for x in range(max(0, K - A[n] + 1), K))
    for i in range(N):
        a = A[i]
        if i == n or a >= K:
            continue
        for j in range(K - a - 1, -1, -1):
            if j in dp:
                if j + a in ans:
                    rst = True
                    break
                else:
                    dp.add(j + a)
        else:
            rst = False
    if rst:
        ok = mid
    else:
        ng = mid
print(ok)

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

    # [ok, ng) - Maximum
    # (ng, ok] - Minimum
    # ok が 最終的な答え
    ok = N
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        n = mid
        dp = [0] * (K + 1)
        dp[0] = 1
        for i in range(N):
            a = A[i]
            if i == n or a >= K:
                continue
            for j in range(K, -1, -1):
                dp[min(K, j + a)] |= dp[j]
        rst = any(dp[k] for k in range(max(0, K - A[n]), K))
        if rst:
            ok = mid
        else:
            ng = mid
    print(ok)

main()


import numpy as np

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

dp_left = np.zeros((N + 1, K), dtype=bool)
dp_right = np.zeros((N + 1, K), dtype=bool)
dp_left[0, 0] = 1
dp_right[N, 0] = 1

for i in range(N):
    dp_left[i + 1] = dp_left[i]
    dp_right[N - i - 1] = dp_right[N - i]
    if (a := A[i]) < K:
        dp_left[i + 1, a:] |= dp_left[i, :-a]
    if (a := A[N - i - 1]) < K:
        dp_right[N - i - 1, a:] |= dp_right[N - i, :-a]

left_true = [np.nonzero(x)[0] for x in dp_left]
del dp_left
right_true = [np.nonzero(x)[0] for x in dp_right]
del dp_right

ans = 0
for i, a in enumerate(A):
    ss = np.searchsorted(right_true[i + 1], K - left_true[i]) - 1
    if all(right_true[i + 1][ss] + left_true[i] + a < K):
        ans += 1
print(ans)

import numpy as np

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

dp_left = np.zeros((N + 1, K), dtype=bool)
dp_right = np.zeros((N + 1, K), dtype=bool)
dp_left[0, 0] = 1
dp_right[N, 0] = 1

for i in range(N):
    dp_left[i + 1] = dp_left[i]
    dp_right[N - i - 1] = dp_right[N - i]
    if (a := A[i]) < K:
        dp_left[i + 1, a:] |= dp_left[i, :-a]
    if (a := A[N - i - 1]) < K:
        dp_right[N - i - 1, a:] |= dp_right[N - i, :-a]

ans = 0
for i, a in enumerate(A):
    left_true = np.nonzero(dp_left[i])[0]
    right_true = np.nonzero(dp_right[i + 1])[0]

    ss = np.searchsorted(right_true, K - left_true) - 1
    if all(right_true[ss] + left_true + a < K):
        ans += 1

print(ans)


#!/usr/bin/env python3

x = int(input())
S = {0}
i = 0
while x not in S:
    i += 1
    S = S | {s - i for s in S} | {s + i for s in S}
print(i)

#!/usr/bin/env python3

import math

print(math.ceil((-1 + (8 * int(input()) + 1) ** 0.5) / 2))


x = int(input())
t = 1
ds = {0}
while True:
    dc = ds.copy()
    for d in dc:
        if d + t == x or d - t == x:
            break
        ds.add(d + t)
        ds.add(d - t)
    else:
        t += 1
        continue
    break

print(t)

from math import ceil, sqrt

x = int(input())
print(ceil((-1 + sqrt(8 * x + 1)) / 2))


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

passengers = sorted([int(input()) for i in range(N)])
res = {}

for p in passengers:
    key = False
    for k in res.keys():
        if k <= p and p <= k + K and res[k] <= C - 1:
            res[k] += 1
            key = True
            break
    if not key:
        res[p] = 1
print(len(res))

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

passengers = sorted([int(input()) for i in range(N)])
res = 0
bus_time = passengers[0]
bus_count = C
for p in passengers:
    if bus_count == 0 or p - bus_time > K:
        res += 1
        bus_time = p
        bus_count = C - 1
    else:
        bus_count -= 1
if bus_count != C:
    res += 1
print(res)


def resolve():
    n, c, k = map(int, input().split())
    t = list(int(input()) for _ in range(n))
    t.sort()
    ans = 0
    limit = t[0] + k
    bus = 0
    for i in range(n):
        if t[i] <= limit:
            bus += 1
            if bus == c:
                ans += 1
                bus = 0
                if i < n:
                    limit = t[i + 1] + k
        else:
            ans += 1
            bus = 1
            limit = t[i] + k
    if bus > 0:
        ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()

def resolve():
    n, c, k = map(int, input().split())
    t = list(int(input()) for _ in range(n))
    t.sort()
    ans = 1
    limit = t[0] + k
    bus = 0
    for i in range(n):
        bus += 1
        if t[i] > limit or bus > c:
            limit = t[i] + k
            ans += 1
            bus = 1
    print(ans)

if __name__ == "__main__":
    resolve()


N, C, K = [int(i) for i in input().split()]
T = sorted([int(input())] for i in range(N))
ans = 1
limit = 0
ti = T[0]
for i in range(N - 1):
    limit += 1
    if ti + K < T[i + 1] or limit == C:
        ti = T[i + 1]
        ans += 1
        limit = 0
print(ans)

N, C, K = [int(i) for i in input().split()]
T = sorted([int(input()) for i in range(N)])
ans = 1
limit = 0
ti = T[0]
for i in range(N - 1):
    limit += 1
    if ti + K < T[i + 1] or limit == C:
        ti = T[i + 1]
        ans += 1
        limit = 0
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03785/Python/s415293443.py", line 8, in <module>
    if ti + K < T[i + 1] or limit == C:
TypeError: can only concatenate list (not "int") to list


from fractions import gcd
from functools import reduce

N, K = map(int, input().split())
A = list(map(int, input().split()))
g = reduce(gcd, A)
if K <= max(A) and K % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

from itertools import accumulate

N, *A = map(int, open(0).read().split())
A.sort()
acc = list(accumulate(A))
ans = N
for i in range(N - 1):
    if 3 * acc[i] < acc[i + 1]:
        ans = N - i - 1
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03786/Python/s206249495.py", line 1, in <module>
    from fractions import gcd
ImportError: cannot import name 'gcd' from 'fractions' (/usr/lib/python3.10/fractions.py)


N = int(input())
if N > 15:
    discount = N // 15
print(N * 800 - discount * 200)

N = int(input())
discount = 0
if N > 15:
    discount = N // 15
print(N * 800 - discount * 200)


i = int(input())
d = i * 800
b = i // 15

if 0 < b:
    c = d - (200 * b)
    print(c)
else:
    print(c)

i = int(input())
d = i * 800
b = i // 15

if 0 <= b:
    c = d - (200 * b)
    print(c)
else:
    print(c)


def main():
    N = int(input())
    ans = 1
    mod = 10**9 + 7
    for i in range(1, N + 1):
        ans *= i
    print(ans % mod)

if __name__ == "__main__":
    main()

import math

def main():
    N = int(input())
    ans = math.factorial(N)
    mod = 10**9 + 7
    print(ans % mod)

if __name__ == "__main__":
    main()


N = range(1, int(input()) + 1)
prod = 1
for i in N:
    prod *= i
print(prod % (10**9 + 7))

num = 1
for i in range(1, int(input()) + 1):
    num = (num * i) % (10**9 + 7)
print(num)


n = int(input())

i = 1
power = 1
while i <= n:
    power *= i
    i += 1
print(power % (10**9 + 7))

n = int(input())

i = 1
power = 1
while i <= n:
    if power >= 10**9 + 7:
        power %= 10**9 + 7
    power *= i
    i += 1
print(power % (10**9 + 7))


N = int(input())

power = 1
for i in range(1, N + 1):
    power *= i
print(power % (10**9 + 7))

import math

N = int(input())

print(math.factorial(N) % (10**9 + 7))


n = int(input())

def main(n):
    pre = 1
    for i in range(1, n):
        pre = pre * i
    return pre * n % (pow(10, 9) + 7)

ans = main(n)
print(ans)

n = int(input())

mod_num = pow(10, 9) + 7

def main(n):
    pre = 1
    for i in range(2, n + 1):
        pre = pre * i % mod_num
    return pre

ans = main(n)
print(ans)


n = int(input())

ans = 1

for i in range(n):
    ans *= i + 1

print(ans % 1000000007)

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

ans = 1

for i in range(n):
    ans *= i + 1
    ans %= 1000000007

print(ans)


N = int(input())
n = 1000000007
p = 1
for i in range(1, N + 1):
    p *= i
print(p % n)

N = int(input())
n = 1000000007
p = 1
for i in range(1, N + 1):
    p *= i
    p %= n
print(p)


N = int(input())
p = 1
for i in range(1, N + 1):
    p *= i
print(p % 1000000007)

import math

N = int(input())
print(math.factorial(N) % 1000000007)


n = int(input())
p = 1
for i in range(1, n + 1):
    p = p * i
print(p % 1000000007)

import math

n = int(input())
print(math.factorial(n) % 1000000007)


INF = 1000000000 + 7
N = int(input())
ans = 1
for i in range(1, N + 1):
    ans *= i

print(ans % INF)

INF = 1000000000 + 7
N = int(input())
ans = 1
for i in range(1, N + 1):
    ans = ans * i % INF

print(ans)


n, m = map(int, input().split())
c = 0
while n > 0 and m > 2:
    n -= 1
    m -= 2
    c += 1

while m >= 4:
    m -= 4
    c += 1
print(c)

n, m = map(int, input().split())
if n <= m // 2:
    m -= n * 2
    print(n + m // 4)
else:
    print(m // 2)


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

ans = 0

while True:
    if N >= 1 and M >= 2:
        N -= 1
        M -= 2
        ans += 1
    elif M >= 4:
        M -= 4
        ans += 1
    else:
        break
print(ans)

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

ans = 0

ans += min(N, M // 2)

N -= ans
M -= ans * 2

ans += M // 4

print(ans)


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

while m >= 2 and n >= 1:
    comb += 1
    m -= 2
    n -= 1

comb += m // 4

print(comb)

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

if 2 * n >= m:
    comb += m // 2
    m -= comb * 2
else:
    comb += n
    m -= 2 * n

comb += m // 4

print(comb)


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

ans = 0
while N > 0 and M > 0:
    if M < 2:
        break
    N -= 1
    M -= 2
    ans += 1

while M >= 4:
    M -= 4
    ans += 1

print(ans)

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

s, c = N, M // 2

ans = 0
if s > c:
    ans = c
else:
    ans = (M - s * 2) // 4 + s
print(ans)


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

cnt = 0
for _ in range(n):
    if m >= 2:
        m -= 2
        cnt += 1
for _ in range(m // 4):
    if m >= 4:
        m -= 4
        cnt += 1
print(cnt)

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

cnt = min(n, m // 2)
print(cnt + (m - cnt * 2) // 4)


from itertools import permutations

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

res = 0
for P in permutations(range(N), N):
    if P[0] != 0:
        continue
    for i in range(N - 1):
        if P[i + 1] not in G[P[i]]:
            break
    else:
        res += 1

print(res)

from itertools import permutations

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

res = 0
for P in permutations(range(N), N):
    if P[0] != 0:
        continue
    for i in range(N - 1):
        if P[i + 1] not in G[P[i]]:
            break
    else:
        res += 1

print(res)


import itertools

N, M = map(int, input().split())
edges = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]

res = 0
if M < N - 1:
    print(res)
else:
    for path in itertools.permutations(edges, N - 1):
        vertex = [True] * N
        v = 0
        vertex[v] = False
        for edge in path:
            if v in edge:
                nv = edge[0] if v == edge[1] else edge[1]
                if vertex[nv]:
                    vertex[nv] = False
                    v = nv
                    continue
            break
        else:
            res += 1
    print(res)

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

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

def dfs(node, track):
    if len(track) == N:
        global res
        res += 1
    else:
        for dst in [x for x in edges[node] if x not in track]:
            dfs(dst, track + tuple([dst]))

res = 0
dfs(0, tuple([0]))
print(res)


import itertools

N, M = map(int, input().split())
edges = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(M)]

res = 0
if M < N - 1:
    print(res)
else:
    for course in itertools.combinations(edges, N - 1):

        num_of_v = [0] * N
        for edge in course:
            num_of_v[edge[0]] += 1
            num_of_v[edge[1]] += 1
        if num_of_v[0] != 1 and max(num_of_v) != 2:
            continue

        for root in itertools.permutations(course):
            vertex = [False] + [True] * (N - 1)
            v = 0
            for edge in root:
                if v in edge:
                    nv = edge[0] if v == edge[1] else edge[1]
                    if vertex[nv]:
                        vertex[nv] = False
                        v = nv
                        continue
                break
            else:
                res += 1
    print(res)

def main():
    import sys
    from itertools import permutations

    # readline = sys.stdin.buffer.readline
    readlines = sys.stdin.readlines
    N, M = map(int, input().split())
    edge = [[0] * N for _ in range(N)]
    for s in readlines():
        a, b = map(int, s.split())
        a -= 1
        b -= 1
        edge[a][b] = 1
        edge[b][a] = 1

    cnt = 0
    for path in permutations(range(1, N)):
        path = [0] + list(path)
        for i in range(N - 1):
            v = path[i]
            nv = path[i + 1]
            if edge[v][nv] == 0:
                break
        else:
            cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()


import sys

sys.setrecursionlimit(500 * 500)

n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(n):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

visit = [0] * (n + 1)

def dfs(now, depth):
    if visit[now]:
        return 0
    if depth == n:
        return 1

    count = 0
    visit[now] = 1
    if graph[now]:
        for i in graph[now]:
            count += dfs(i, depth + 1)
    visit[now] = 0

    return count

ans = dfs(1, 1)
print(ans)

n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

visit = [0] * (n + 1)

def dfs(now, depth):
    if visit[now]:
        return 0
    if depth == n:
        return 1

    count = 0
    visit[now] = 1
    if graph[now]:
        for i in graph[now]:
            count += dfs(i, depth + 1)
    visit[now] = 0

    return count

ans = dfs(1, 1)
print(ans)


import sys

sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
graph = [set([]) for _ in range(M)]
for _ in range(M):
    a, b = map(int, input().split())
    graph[a - 1].add(b - 1)
    graph[b - 1].add(a - 1)

def dfs(graph, visited, v):
    if all(visited):
        return 1

    cnt = 0
    for u in graph[v]:
        if visited[u]:
            continue
        visited[u] = True
        cnt += dfs(graph, visited, u)
        visited[u] = False

    return cnt

visited = [False] * len(graph)
visited[0] = True
ans = dfs(graph, visited, 0)
print(ans)

import sys

sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
graph = [set([]) for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    graph[a - 1].add(b - 1)
    graph[b - 1].add(a - 1)

def dfs(graph, visited, v):
    if all(visited):
        return 1

    cnt = 0
    for u in graph[v]:
        if visited[u]:
            continue
        visited[u] = True
        cnt += dfs(graph, visited, u)
        visited[u] = False

    return cnt

visited = [False] * len(graph)
visited[0] = True
ans = dfs(graph, visited, 0)
print(ans)


inf = float("inf")
N, Ma, Mb = map(int, input().split())
ABC = []
for _ in range(N):
    a, b, c = map(int, input().split())
    ABC.append((a, b, c))

def cost(bits):
    sa = sb = sc = 0
    for i, (a, b, c) in enumerate(ABC):
        if not bits & 1 << i:
            continue
        sa += a
        sb += b
        sc += c
    return sc if sa * Mb == sb * Ma else inf

ans = min([cost(bits) for bits in range(1, 1 << N)])
print(ans if ans < inf else -1)

inf = float("inf")
N, Ma, Mb = map(int, input().split())
ABC = []
for _ in range(N):
    a, b, c = map(int, input().split())
    ABC.append((a, b, c))
dp = [[inf] * 420 for _ in range(420)]
dp[0][0] = 0
for a, b, c in ABC:
    for i in range(410, -1, -1):
        for j in range(410, -1, -1):
            if dp[i][j] < inf:
                dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)
ans = inf
n = 1
while max(Ma * n, Mb * n) < 420:
    ans = min(ans, dp[Ma * n][Mb * n])
    n += 1
print(ans if ans < inf else -1)


num_ints = int(input())
sum_ints = sum([int(i) for i in input().split()])

if sum % 2 == 0:
    print("YES")
else:
    print("NO")

num_ints = int(input())
sum_ints = sum([int(i) for i in input().split()])

if sum_ints % 2 == 0:
    print("YES")
else:
    print("NO")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03807/Python/s361602990.py", line 4, in <module>
    if sum % 2 == 0:
TypeError: unsupported operand type(s) for %: 'builtin_function_or_method' and 'int'


x = input()

if x < 1200:
    print("ABC")

else:
    print("ARC")

x = int(input())

if x < 1200:
    print("ABC")

else:
    print("ARC")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03813/Python/s733703116.py", line 4, in <module>
    if x < 1200:
TypeError: '<' not supported between instances of 'str' and 'int'


print("ARC" if int(input()) >= 1200 else "ABC")

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03813/Python/s654716081.py", line 1, in <module>
    print("ARC" if int(input) > 1200 else "ABC")
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'


s = input()

start = s.index("A")

for i in range(len(s), start, -1):
    if s[i] == "Z":
        print(i - start + 1)
        break

s = input()

start = s.index("A")

for i in range(len(s) - 1, start, -1):
    if s[i] == "Z":
        print(i - start + 1)
        break

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03814/Python/s942139210.py", line 6, in <module>
    if s[i] == "Z":
IndexError: string index out of range


Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03815/Python/s609603869.py", line 10, in <module>
    elif 6 <= ans <= 10:
NameError: name 'ans' is not defined. Did you mean: 'abs'?


N, M = [int(i) for i in input().split()]
road = [list() for i in range(N + 1)]
for i in range(M):
    a, b = [int(i) for i in input().split()]
    road[a].append(b)
    road[b].append(a)

def solve(before, visited, now):
    visited.append(now)
    print(visited)
    if len(visited) is N:
        return 1
    pattern = 0
    for way in road[now]:
        if way is now:
            continue
        if way in visited:
            continue
        pattern += solve(now, visited[:], way)
    return pattern

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

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03815/Python/s263394591.py", line 1, in <module>
    N, M = [int(i) for i in input().split()]
ValueError: not enough values to unpack (expected 2, got 1)


x = int(input())
ans = (x // 11) * 2
if x % 11:
    if x % 11 > 6:
        ans += 2
    else:
        ans += 1
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03817/Python/s232589342.py", line 2, in <module>
    print((x // 11) * 2 + (2 if x % 11 > 6 else 1))
TypeError: unsupported operand type(s) for //: 'str' and 'int'


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 0
e = 0
i = 0
while i < len(a):
    c += 1
    cai = 1
    while a[i] == a[i + 1]:
        cai += 1
        i += 1
    if cai % 2 == 0:
        e += 1
    i += 1
ans = c - (e % 2)
print(ans)

n = int(input())
a = list(map(int, input().split()))
a.sort()
c = 0
e = 0
i = 0
while True:
    c += 1
    cai = 1
    while i != n - 1 and a[i] == a[i + 1]:
        cai += 1
        if i != n - 1:
            i += 1
        else:
            break
    if cai % 2 == 0:
        e += 1
    if i != n - 1:
        i += 1
    else:
        break
ans = c - (e % 2)
print(ans)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03818/Python/s388445088.py", line 10, in <module>
    while a[i] == a[i + 1]:
IndexError: list index out of range


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

count = 0
for i in reversed(range(n)):
    c = b[i] * (-(-a[i] // b[i])) - a[i]
    for j in range(i):
        a[j] += c
    count += c
print(count)

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

count = 0
for i in reversed(range(n)):
    c = b[i] * (-(-a[i] // b[i])) - a[i]
    # for j in range(i):
    #    a[j] += c
    count += c
    if i >= 1:
        a[i - 1] += count
print(count)


N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

A = A[::-1]
B = B[::-1]
R = [0 for _ in range(N)]
for i, (a, b) in enumerate(zip(A, B)):
    r = a % b
    if r > 0:
        r = b - r
    R[i] = r

ans = 0
for i in range(0, N):
    r = R[i]
    ans += r
    for j in range(i + 1, N):
        rj = R[j]
        rj -= r
        R[j] = rj % B[j]

print(ans)

N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

A = A[::-1]
B = B[::-1]
R = [0 for _ in range(N)]
for i, (a, b) in enumerate(zip(A, B)):
    r = a % b
    if r > 0:
        r = b - r
    R[i] = r

ans = R[0]
for i in range(1, N):
    r = R[i]
    r = r - ans
    r = r % B[i]
    ans += r

print(ans)


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

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

print(cnt)

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

for i in range(n - 1, -1, -1):
    r = b[i] - (a[i] + cnt) % b[i]
    if r != b[i]:
        cnt += r
print(cnt)


import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
graph = [[] for _ in range(n)]
for i in range(1, n):
    graph[int(input()) - 1].append(i)

def dfs(x):
    arr = [dfs(y) for y in graph[x]]
    if not (arr):
        return 0
    arr.sort(reverse=True)
    return max(i + a for i, a in enumerate(arr, 1))

print(dfs(0))


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

a, b, c = input().split(",")
print(a, b, c)

Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03834/Python/s432875580.py", line 1, in <module>
    k, s = [int(x) for x in input().split()]
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03834/Python/s432875580.py", line 1, in <listcomp>
    k, s = [int(x) for x in input().split()]
ValueError: invalid literal for int() with base 10: 'happy,newyear,enjoy'


k, s = [int(i) for i in input().split()]
ans = 0
for x in range(k, -1, -1):
    for y in range(k, -1, -1):
        for z in range(k, -1, -1):
            if x + y + z is s:
                ans += 1
print(ans)

k, s = [int(i) for i in input().split()]
ans = 0
for x in range(k, -1, -1):
    for y in range(k, -1, -1):
        if 0 <= s - x - y <= k:
            ans += 1
print(ans)


# 0 ≦ X, Y, Z ≦ K
# X + Y + Z = S
# 2 ≦ K ≦ 2500
# 0 ≦ S ≦ 3K

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

cnt = 0
# X
for i in range(K + 1):
    if i > S:
        break
    # Y
    for j in range(K + 1):
        if i + j > S:
            break
        # Z
        for k in range(K + 1):
            if i + j + k > S:
                break
            if i + j + k == S:
                cnt += 1
print(cnt)

# 0 ≦ X, Y, Z ≦ K
# X + Y + Z = S
# 2 ≦ K ≦ 2500
# 0 ≦ S ≦ 3K

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

cnt = 0
# X
for i in range(K + 1):
    # Y
    for j in range(K + 1):
        Z = S - i - j
        if 0 <= Z and Z <= K:
            cnt += 1
print(cnt)


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

ans = 0

for i in range(k + 1):
    for j in range(k + 1):
        for h in range(k + 1):
            if h + i + j == s:
                ans += 1

print(ans)

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

ans = 0

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

print(ans)