Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pysnooper # @pysnooper.snoop()
from pprint import pprint as pp
from pprint import pformat as pf

def solve_odd(n, m):
    for i in range(m):
        print(i + 1, n - (i + 1))

def solve_even(n, m):
    offset = 1
    half = int(n / 2)
    diff = half - 1
    for i in range(m):
        start = offset
        end = start + diff
        if i % 2 != 0:
            start += half
            end += half
            # for next 2 loop
            offset += 1
        print(start, end)
        # for next loop
        diff -= 1



if __name__ == '__main__':
    n, m = map(int, input().split())
    if n % 2 == 0:
        solve_even(n, m)
    else:
        solve_odd(n, m)


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

from pprint import pprint as pp
from pprint import pformat as pf

def solve_odd(n, m):
    for i in range(m):
        print(i + 1, n - (i + 1))

def solve_even(n, m):
    offset = 1
    half = int(n / 2)
    diff = half - 1
    for i in range(m):
        start = offset
        end = start + diff
        if i % 2 != 0:
            start += half
            end += half
            # for next 2 loop
            offset += 1
        print(start, end)
        # for next loop
        diff -= 1



if __name__ == '__main__':
    n, m = map(int, input().split())
    if n % 2 == 0:
        solve_even(n, m)
    else:
        solve_odd(n, m)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
List = list(map(int, input().split(" ")))
a = 1
for i in range(n):
    m = List.count(a)
    a += 1
    print(m)

Fixed submission:
N = int(input())
List = list(map(int,input().split()))
List2 = [0]*N
for i in range(N-1):
    List2[List[i-1]-1] += 1 
for j in List2:
    print(j)
Buggy python submission (verdict: Runtime Error):
n = int(input())
x,y = map(int,input().split())
print(1 / (1 / x + 1 / y))

Fixed submission:
n = int(input())
def f(x):
    return 1 / x
List = list(map(int, input().split()))
List2 = [x for x in map(f, List)]
s = sum(List2)
print(1 / s)
Buggy python submission (verdict: Runtime Error):
x, y = int(input())
print(x/y)

Fixed submission:
x,y = map(int,input().split())
print(x/y)

Buggy python submission (verdict: Runtime Error):
x, y = int(input())
print(y/x)

Fixed submission:
x,y = map(int,input().split())
print(x/y)
Buggy python submission (verdict: Runtime Error):
r = int(input())
l = int(input())
print((r-1)*(l-1))

Fixed submission:
n,m = map(int,input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
N = int(input())

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

print(len(List()))


Fixed submission:
i = int(input())
List = []
for j in range(i):
    List.append(int(input()))
print(len(set(List)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    b_i, c_i = map(int, input().split())
    b.append(b_i)
    c.append(c_i)

res = {}
for a_i in a:
    if not a_i in res:
        res[a_i] = 0
    res[a_i] += 1

for b_i, c_i in zip(b, c):
    num = res[b_i] if b_i in res else 0
    res[b_i] = 0
    if not c_i in res:
        res[c_i] = 0
    res[c_i] += num

    ans = 0
    for key, val in res.items():
        ans += key * val
    print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    b_i, c_i = map(int, input().split())
    b.append(b_i)
    c.append(c_i)


res = {}
for a_i in a:
    if not a_i in res:
        res[a_i] = 0
    res[a_i] += 1

ans = 0
for key, val in res.items():
    ans += key * val

for b_i, c_i in zip(b, c):
    num = res[b_i] if b_i in res else 0
    res[b_i] = 0
    if not c_i in res:
        res[c_i] = 0
    res[c_i] += num

    ans += (c_i - b_i) * num

    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    b_i, c_i = map(int, input().split())
    b.append(b_i)
    c.append(c_i)

res = [0 for _ in range(10 ** 5 + 1)]
for a_i in a:
    res[a_i] += 1

for b_i, c_i in zip(b, c):
    num = res[b_i]
    res[b_i] = 0
    res[c_i] += num

    ans = 0
    for i in range(len(res)):
        ans += i * res[i]
    print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    b_i, c_i = map(int, input().split())
    b.append(b_i)
    c.append(c_i)


res = {}
for a_i in a:
    if not a_i in res:
        res[a_i] = 0
    res[a_i] += 1

ans = 0
for key, val in res.items():
    ans += key * val

for b_i, c_i in zip(b, c):
    num = res[b_i] if b_i in res else 0
    res[b_i] = 0
    if not c_i in res:
        res[c_i] = 0
    res[c_i] += num

    ans += (c_i - b_i) * num

    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
res = 1
for a_i in a:
    if 0 == a_i:
        print(0)
        exit(0)
    elif res > 10 ** 18:
        res = -1
    else:
        res *= a_i

print(-1 if res > 10 ** 18 else res)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
res = 1
for a_i in a:
    if 0 == a_i:
        print(0)
        exit(0)
    elif res > 10 ** 18:
        continue
    else:
        res *= a_i

print(-1 if res > 10 ** 18 else res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
res = 1
for a_i in a:
    res *= a_i

print(-1 if res > 10 ** 18 else res)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
res = 1
for a_i in a:
    if 0 == a_i:
        print(0)
        exit(0)
    elif res > 10 ** 18:
        continue
    else:
        res *= a_i

print(-1 if res > 10 ** 18 else res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())

my_dict = {}
for i, c in enumerate(s):
    if not c in my_dict:
        my_dict[c] = []
    my_dict[c].append(i)

lst = []
for key, value in my_dict.items():
    lst.append(value)

if 3 > len(lst):
    print(0)
    exit(0)

cnt = 0
for i in lst[0]:
    for j in lst[1]:
        for k in lst[2]:
            i_, j_, k_ = sorted([i, j, k])
            if j_ - i_ != k_ - j_:
                cnt += 1
print(cnt)


Fixed submission:
n = int(input())
s = input()

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

for i in range(len(s)-2):
    for j in range(i + 1, len(s)-1):
        k = 2 * j - i
        if k < n and (s[k] != s[j] and s[j] != s[i] and s[i] != s[k]):
            cnt -= 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
n, x, y = map(int, input().split())
x -= 1
y -= 1

k = [0 for _ in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        dist = min(j-i, abs(x-i)+1+abs(j-y))
        if dist < n:
            k[dist] += 1
[for i in range(1, len(k)):
    print(k[i])]


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

k = [0 for _ in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        dist = min(j-i, abs(x-i)+1+abs(j-y))
        if dist < n:
            k[dist] += 1
for i in range(1, len(k)):
    print(k[i])

Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())
x -= 1
y -= 1

k = [0 for _ in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        dist = min([j-i, abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x)])
        if dist < n:
            k[dist] += 1
for i in range(1, len(k)):
    print(k[i])


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

k = [0 for _ in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        dist = min(j-i, abs(x-i)+1+abs(j-y))
        if dist < n:
            k[dist] += 1
for i in range(1, len(k)):
    print(k[i])
Buggy python submission (verdict: Runtime Error):
from collections import deque

s = deque(input())
len_queries = int(input())
queries = [input().split() for _ in range(len_queries)]

is_forward = True
for query in queries:
    if "1" == query[0]:
        is_forward = not is_forward
    else:
        if is_forward:
            insert_index = 0 if "1" == query[1] else len(s)
            s.insert(insert_index, query[2])
        else:
            insert_index = len(s) if "1" == query[1] else 0
            s.insert(insert_index, query[2])
if not is_forward:
    s.reverse()
print("".join(s))


Fixed submission:
from collections import deque

s = deque(input())
len_queries = int(input())
queries = [input().split() for _ in range(len_queries)]

is_forward = True
for query in queries:
    if "1" == query[0]:
        is_forward = not is_forward
    else:
        if is_forward:
            if "1" == query[1]:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if "1" == query[1]:
                s.append(query[2])
            else:
                s.appendleft(query[2])
if not is_forward:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
len_queries = int(input())
queries = [input().split() for _ in range(len_queries)]

is_forward = True
for query in queries:
    if "1" == query[0]:
        is_forward = not is_forward
    else:
        if is_forward:
            insert_index = 0 if "1" == query[1] else len(s)
            s.insert(insert_index, query[2])
        else:
            insert_index = len(s) if "1" == query[1] else 0
            s.insert(insert_index, query[2])
if not is_forward:
    s.reverse()
print("".join(s))


Fixed submission:
from collections import deque

s = deque(input())
len_queries = int(input())
queries = [input().split() for _ in range(len_queries)]

is_forward = True
for query in queries:
    if "1" == query[0]:
        is_forward = not is_forward
    else:
        if is_forward:
            if "1" == query[1]:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if "1" == query[1]:
                s.append(query[2])
            else:
                s.appendleft(query[2])
if not is_forward:
    s.reverse()
print("".join(s))
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())
denom = 10 ** 9 + 7

total = 0
cur = 1
for r in range(1, n + 1):
    cur = cur * (n - r + 1) // r
    if a == r or b == r:
        continue
    total += cur
print(total % denom)


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

mod = 10 ** 9 + 7


def comb(n, r):
    bunshi = 1
    for i in range(n-r+1, n+1):
        bunshi = bunshi * i % mod
    bunbo = 1
    for i in range(1, r + 1):
        bunbo = bunbo * i % mod
    return bunshi * pow(bunbo, mod - 2, mod) % mod


ans = (pow(2, n, mod) - 1 - comb(n, a) - comb(n, b) + 2 * mod) % mod
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

h = int(input())
h_dash = h if h % 2 == 0 else h - 1


def f(n):
    if n == 2:
        return 3
    return f(n // 2) * 2 + 1


print(f(h_dash))


Fixed submission:
h = int(input())

n = 1
while h >= 2 ** n:
    n += 1
print(2 ** n - 1)
Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = min(a for a, _ in ab)
dp = [10 ** 18 for _ in range(h + max_a)]
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))


Fixed submission:
inf = 10 ** 18
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a, _ in ab)
dp = [inf] * (h + max_a)
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))

Buggy python submission (verdict: Time Limit Exceeded):
inf = 10 ** 18

h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a, _ in ab)
dp = [inf for _ in range(h + max_a)]
dp[0] = 0
for i in range(1, h + max_a):
    min_dp = inf
    for a, b in ab:
        if 0 > i - a:
            continue
        min_dp = min(min_dp, dp[i-a] + b)
    dp[i] = min_dp
print(min(dp[h:]))


Fixed submission:
inf = 10 ** 18
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a, _ in ab)
dp = [inf] * (h + max_a)
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
graph = [[] for _ in range(n)]
colors = [-1 for _ in range(n-1)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    graph[a].append([b, i])


num_children = -1


def dfs(graph, cur, parent, num_children):
    if 0 == len(graph[cur]):
        return num_children
    num_edges = len(graph[cur])
    if not (None == parent):
        num_edges += 1
    num_children = max(num_children, num_edges)
    for child in graph[cur]:
        num_children = dfs(graph, child[0], cur, num_children)
    return num_children


def dfs_color(graph, cur, parent_edge_color, num_colors):
    color = 0
    for child in graph[cur]:
        if parent_edge_color == color:
            color += 1
        colors[child[1]] = color+1
        dfs_color(graph, child[0], color, num_colors)
        color += 1


num_children = dfs(graph, 0, None, num_children)
dfs_color(graph, 0, -1, num_children)
print(num_children)
for color in colors:
    print(color)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)

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


num_children = -1


def dfs(graph, cur, parent, num_children):
    if 0 == len(graph[cur]):
        return num_children
    num_edges = len(graph[cur])
    if not (None == parent):
        num_edges += 1
    num_children = max(num_children, num_edges)
    for child in graph[cur]:
        num_children = dfs(graph, child[0], cur, num_children)
    return num_children


def dfs_color(graph, cur, parent_edge_color, num_colors):
    color = 0
    for child in graph[cur]:
        if parent_edge_color == color:
            color += 1
        colors[child[1]] = color+1
        dfs_color(graph, child[0], color, num_colors)
        color += 1


num_children = dfs(graph, 0, None, num_children)
dfs_color(graph, 0, -1, num_children)
print(num_children)
for color in colors:
    print(color)
Buggy python submission (verdict: Runtime Error):
import math
(a, b, x) = map(int, input().split())

theta = 0
if x < (a ** 2) * b / 2:
  theta = math.pi / 2 - math.atan(2 * x / a / b ** 2)
else:
  theta = math.pi / 2 - math.atan(a ** 3 / 2 / (a ** 2 * b - x))
print(theta * 180 / math.pi)


Fixed submission:
import math
(a, b, x) = map(int, input().split())

theta = 0
if x < (a ** 2) * b / 2:
    theta = math.pi / 2 - math.atan(2 * x / a / b ** 2)
else:
    if a ** 2 * b == x:
        theta = 0
    else:
        theta = math.pi / 2 - math.atan(a ** 3 / 2 / (a ** 2 * b - x))
print(theta * 180 / math.pi)

Buggy python submission (verdict: Runtime Error):
import math
(a, b, x) = map(int, input().split())
theta = math.pi / 2 - math.atan(a ** 3 / 2 / (a ** 2 * b - x))
print(theta * 180 / math.pi)


Fixed submission:
import math
(a, b, x) = map(int, input().split())

theta = 0
if x < (a ** 2) * b / 2:
    theta = math.pi / 2 - math.atan(2 * x / a / b ** 2)
else:
    if a ** 2 * b == x:
        theta = 0
    else:
        theta = math.pi / 2 - math.atan(a ** 3 / 2 / (a ** 2 * b - x))
print(theta * 180 / math.pi)
Buggy python submission (verdict: Runtime Error):
n, k, q = map(int, input().split())
a = []
for i in range(q):
    a[i] = int(input()) - 1
score = [0 for _ in range(n)]

for a_i in a:
    score[a_i] += 1

for i in range(n):
    result = k - q + score[i]
    print("Yes" if result > 0 else "No")


Fixed submission:
(n, k, q) = map(int, input().split())
a = [int(input()) for _ in range(q)]
points = [0 for _ in range(n)]

for i, answer in enumerate(a):
    points[answer-1] += 1

for i, p in enumerate(points):
    result = "Yes" if k - q + p > 0 else "No"
    print(result)

Buggy python submission (verdict: Runtime Error):
n, k, q = map(int, input().split())
a = []
for i in range(q):
    a[i] = int(input()) - 1
score = [0 for _ in range(n)]

for a_i in a:
    score[a_i] += 1

for i in range(n):
    result = k - q + score[i]
    print("YES" if result > 0 else "NO")


Fixed submission:
(n, k, q) = map(int, input().split())
a = [int(input()) for _ in range(q)]
points = [0 for _ in range(n)]

for i, answer in enumerate(a):
    points[answer-1] += 1

for i, p in enumerate(points):
    result = "Yes" if k - q + p > 0 else "No"
    print(result)
Buggy python submission (verdict: Time Limit Exceeded):
(n, m) = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse = True)

while m > 0:
    found = False
    for i in range(n-1):
        if a[i] < a[i+1]:
            a[i+1] = int(a[i+1] / 2)
            found = True
            break
    if not found:
        a[0] /= 2
    m -= 1
sum = 0
for a_i in a:
    sum += int(a_i)
print(sum)


Fixed submission:
import math
import heapq

(n, m) = map(int, input().split())
a = []
for a_i in input().split():
    heapq.heappush(a, -1 * int(a_i))

for i in range(m):
    a_i = heapq.heappop(a)
    heapq.heappush(a, a_i / 2)

sum = 0
for a_i in a:
    sum += int(-1 * a_i)
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [sorted(input()) for _ in range(n)]


def is_anagram(s_i, s_j):
    for k in range(10):
        if s_i[k] != s_j[k]:
            return False
    return True


num = 0
for i in range(n):
    for j in range(i + 1, n):
        if is_anagram(s[i], s[j]):
            num += 1
print(num)


Fixed submission:
n = int(input())
s = [sorted(input()) for _ in range(n)]
sorted_s = sorted(s)

num = 0
num_same = 1
prev = sorted_s[0]
for i in range(1, len(sorted_s)):
    if prev != sorted_s[i]:
        num += int(num_same * (num_same - 1) / 2)
        num_same = 1
        prev = sorted_s[i]
    else:
        num_same += 1
num += int(num_same * (num_same - 1) / 2)
print(num)

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [input() for _ in range(n)]


def is_anagram(s_i, s_j):
    for k in range(10):
        found = False
        for l in range(10):
            if s_i[k] == s_j[l]:
                found = True
                break
        if not found:
            return False
    return True


num = 0
for i in range(n):
    for j in range(i + 1, n):
        if i == j:
            continue
        if is_anagram(s[i], s[j]):
            num += 1
            records[i].append(j)
print(num)


Fixed submission:
n = int(input())
s = [sorted(input()) for _ in range(n)]
sorted_s = sorted(s)

num = 0
num_same = 1
prev = sorted_s[0]
for i in range(1, len(sorted_s)):
    if prev != sorted_s[i]:
        num += int(num_same * (num_same - 1) / 2)
        num_same = 1
        prev = sorted_s[i]
    else:
        num_same += 1
num += int(num_same * (num_same - 1) / 2)
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
(n, m) = map(int, input().split())
counts = [0 for _ in range(n)]
for _ in range(m):
    gate_i = list(map(int, input().split()))
    for i in range(gate_i[0] - 1, gate_i[1]):
        counts[i] += 1
counts.sort()
ans = 0
for count in counts:
    ans += 1 if m == count else 0
print(ans)


Fixed submission:
(n, m) = map(int, input().split())


def intersect(lhs, rhs):
    if lhs[1] < rhs[0] or rhs[1] < lhs[0]:
        return [0, 0]
    min_value = lhs[0] if lhs[0] > rhs[0] else rhs[0]
    max_value = lhs[1] if lhs[1] < rhs[1] else rhs[1]
    return [min_value, max_value]


ans = [-1, 2 * 10 ** 5]
for _ in range(m):
    ans = intersect(ans, list(map(int, input().split())))
    if 0 == ans[0] and 0 == ans[1]:
        print(0)
        exit(0)
print(ans[1] - ans[0] + 1)
Buggy python submission (verdict: Runtime Error):
"""
dfs活用問題
- 2部グラフ作成
- https://atcoder.jp/contests/abc126/tasks/abc126_d
"""
from collections import deque

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


def dfs_recursive(n, graph):
    def dfs(graph, colors, cur, depth):
        colors[cur] = depth % 2
        for child in graph[cur]:
            child_index = child[0]
            if -1 != colors[child_index]:
                continue
            dfs(graph, colors, child_index, depth + child[1])
    colors = [-1 for _ in range(n)]
    dfs(graph, colors, 0, 0)
    for i in colors:
        print(i)


def dfs_with_queue(n, grpah):
    q = deque()
    ans = [-1 for _ in range(n)]
    q.append(0)
    ans[0] = 0
    while 0 != len(q):
        v = q.popleft()
        for neigbhor in graph[v]:
            u = neigbhor[0]
            w = neigbhor[1]
            if -1 != ans[u]:
                continue
            ans[u] = (ans[v] + w) % 2
            q.append(u)
        for i in ans:
            print(i)


dfs_recursive(n, graph)


Fixed submission:
from collections import deque

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


q = deque()
ans = [-1 for _ in range(n)]
q.append(0)
ans[0] = 0
while 0 != len(q):
    v = q.popleft()
    for neigbhor in graph[v]:
        u = neigbhor[0]
        w = neigbhor[1]
        if -1 != ans[u]:
            continue
        ans[u] = (ans[v] + w) % 2
        q.append(u)

for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    r = a % b
    return b if 0 == r else gcd(b, r)


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


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


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


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


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

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    r = a % b
    return b if 0 == r else gcd(b, r)


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


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


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


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


n = int(input())
a = list(map(int, input().split()))
l = [0 for _ in range(n)]
r = [0 for _ in range(n)]
for i in range(n-1):
    l_i = 0 if 0 == i else l[i]
    l[i+1] = gcd(l_i, a[i])
for i in range(n)[::-1]:
    r_i1 = 0 if i == n-1 else r[i+1]
    r[i] = gcd(r_i1, a[i])
m = []
for i in range(n):
    r_i1 = 0 if i == n-1 else r[i+1]
    m.append(gcd(l[i], r_i1))
print(max(m))
Buggy python submission (verdict: Runtime Error):
N = int(input())
n = [int(input()) for _ in range(N)]
min_n = min(n)
print(N // min_n + (1 if (0 != N % min_n) else 0) + N - 1)


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