Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
num = N
if N <= abs(N - K):
  print(N)
else:
  while N <= num:
    num = N
    N = abs(N - K)
  print(num)

Fixed submission:
N,K = map(int,input().split())
ans1 = N % K
ans2 = abs(ans1 - K)
if ans1 <= ans2:
  print(ans1)
else:
  print(ans2)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
num = N
if N <= abs(N - K)
  print(N)
else:
  while N <= num:
    num = N
    N = abs(N - K)
  print(num)

Fixed submission:
N,K = map(int,input().split())
ans1 = N % K
ans2 = abs(ans1 - K)
if ans1 <= ans2:
  print(ans1)
else:
  print(ans2)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
num = N
if N <= abs(N -K)
  print(N)
else:
  while N <= num:
    num = N
    N = abs(N - K)
  print(num)

Fixed submission:
N,K = map(int,input().split())
ans1 = N % K
ans2 = abs(ans1 - K)
if ans1 <= ans2:
  print(ans1)
else:
  print(ans2)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
num = N
while N <= num:
  num = N
  N = abs(N - K)

print(num)

Fixed submission:
N,K = map(int,input().split())
ans1 = N % K
ans2 = abs(ans1 - K)
if ans1 <= ans2:
  print(ans1)
else:
  print(ans2)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
num = 0
while True:
  num = N
  N = abs(N - K)
  if N >= num:
    print(num)
    break

Fixed submission:
N,K = map(int,input().split())
ans1 = N % K
ans2 = abs(ans1 - K)
if ans1 <= ans2:
  print(ans1)
else:
  print(ans2)
Buggy python submission (verdict: Runtime Error):
K, N = map(int, input().split())
A = list(map(int, input().split()))
new = []
for i in range(N-1):
    new.append(A[i+1]-A[i])
new.append(K + A[0] - A[-1])
new.sort()
print(sum(new[:y-1]))

Fixed submission:
K, N = map(int, input().split())
A = list(map(int, input().split()))
new = []
for i in range(N-1):
    new.append(A[i+1]-A[i])
new.append(K + A[0] - A[-1])
new.sort()
print(sum(new[:-1]))

Buggy python submission (verdict: Runtime Error):
import numpy as np
K, N = map(int, input().split())
A = list(map(int, input().split()))
new = []
for i in range(N-1):
    new.append(A[i+1]-A[i])
new.append(K + A[0] - A[-1])
new.sort()
print(sum(new[:y-1]))

Fixed submission:
K, N = map(int, input().split())
A = list(map(int, input().split()))
new = []
for i in range(N-1):
    new.append(A[i+1]-A[i])
new.append(K + A[0] - A[-1])
new.sort()
print(sum(new[:-1]))

Buggy python submission (verdict: Runtime Error):
import numpy as np
K, N = map(int, input().split())
A = list(map(int, input().split()))
new = []
for i in range(N-1):
    new.append(A[i+1]-A[i])
new.append(K + A[0] - A[-1])
new.sort()
print(sum(new[:y-1]

Fixed submission:
K, N = map(int, input().split())
A = list(map(int, input().split()))
new = []
for i in range(N-1):
    new.append(A[i+1]-A[i])
new.append(K + A[0] - A[-1])
new.sort()
print(sum(new[:-1]))
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int,input().split())
if (c − a − b > 0) and (4 * a * b < (c − a − b)**2):
  print('Yes')
else:
  print('No')

Fixed submission:
a, b, c = map(int,input().split())
if (c - a - b > 0) and (4 * a * b < (c - a - b)**2):
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int,input().split())
if c − a − b > (0 and 4 * a * b) < (c − a − b)**2:
  print('Yes')
else:
  print('No')

Fixed submission:
a, b, c = map(int,input().split())
if (c - a - b > 0) and (4 * a * b < (c - a - b)**2):
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a, b, c = map(int,input().split())
if c − a − b > 0 and 4 * a * b < (c − a − b)**2:
  print('Yes')
else:
  print('No')

Fixed submission:
a, b, c = map(int,input().split())
if (c - a - b > 0) and (4 * a * b < (c - a - b)**2):
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
x,y,z = map(int,input().split())
if c − a − b > 0 and 4 * a * b < (c − a − b)**2:
  print('Yes')
else:
  print('No')


Fixed submission:
a, b, c = map(int,input().split())
if (c - a - b > 0) and (4 * a * b < (c - a - b)**2):
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
s = list(map(int,input().split()))
if s[0] <= 1 and s[1] <= 2:
    if s[2] <= 1 and s[3] <= 2:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif s[2] <= 1 and s[3] <= 2:
    print('YYMM')
else:
    print('NA')

Fixed submission:
s = input()
s1 = int(s[0]+s[1])
s2 = int(s[2]+s[3])
if s1 == s2 == 0:
    print('NA')
elif s1 <= 12 and s2 <= 12 and s1 >= 1 and s2 >= 1:
    print('AMBIGUOUS')
elif s1 <= 12 and s1 >= 1:
    print('MMYY')
elif s2 <= 12 and s2 >= 1:
    print('YYMM')
else:
    print('NA')
Buggy python submission (verdict: Runtime Error):
n = int(input())

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

ans = []


def dfs(s, c):
    for i in range(ord('a'), ord(c) + 2):
        now = s + chr(i)
        if len(now) == n:
            ans.append(now)
        elif i > ord(c):
            dfs(now, chr(i))
        else:
            dfs(now, c)


dfs('a', 'a')

for c in ans:
    print(c)


Fixed submission:
import collections
s = collections.deque(list(input()))
q = int(input())
cnt = 0
for i in range(q):
    fc = input().split()
    if fc[0] == '1':
        cnt += 1
    else:
        if cnt == 1:
            fc[1] = '1' if fc[1] == '2' else '2'
        if fc[1] == '1':
            s.appendleft(fc[2])
        else:
            s.append(fc[2])
    cnt %= 2
s = list(s)
if cnt == 1:
    s.reverse()
print(*s, sep='')
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
total = pow(2, n, mod) - 1
product = 1
div = 1
for i in range(1, max(a, b) + 1):
    product *= (n - i + 1)
    div *= i
    if i == a or i == b:
        total -= product // div
print(total % mod)

Fixed submission:
n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7
# Pythonのpowは繰り返し二乗法で実装されている
ans = pow(2, n, MOD) - 1
product = 1
div = 1
for i in range(1, b + 1):
    product = product * (n - i + 1) % MOD
    div = div * i % MOD
    if i == a or i == b:
        # 逆元を求める
        ans -= product * pow(div, MOD - 2, MOD)
print(ans % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())


def pow_k(x, n):
    res = 1
    while n > 0:
        if n & 1:
            res *= x
        x *= x
        n //= 2
    return res


total = pow_k(2, n) - 1

now = 1
div = 1
for i in range(max(a, b) + 1):
    now *= (n - i)
    div *= i + 1
    if i == a - 1 or i == b - 1:
        total -= now // div
print(total % (10 ** 9 + 7))

Fixed submission:
n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7
# Pythonのpowは繰り返し二乗法で実装されている
ans = pow(2, n, MOD) - 1
product = 1
div = 1
for i in range(1, b + 1):
    product = product * (n - i + 1) % MOD
    div = div * i % MOD
    if i == a or i == b:
        # 逆元を求める
        ans -= product * pow(div, MOD - 2, MOD)
print(ans % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())


def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x


total = pow_k(2, n) - 1

now = 1
div = 1
ans = 0
for i in range(max(a, b) + 1):
    now *= (n - i)
    div *= i + 1
    if i == a-1 or i == b-1:
        total -= now // div
print(total % (10 ** 9 + 7))

Fixed submission:
n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7
# Pythonのpowは繰り返し二乗法で実装されている
ans = pow(2, n, MOD) - 1
product = 1
div = 1
for i in range(1, b + 1):
    product = product * (n - i + 1) % MOD
    div = div * i % MOD
    if i == a or i == b:
        # 逆元を求める
        ans -= product * pow(div, MOD - 2, MOD)
print(ans % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())


def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x


total = pow_k(2, n) - 1

now = 1
div = 1
ans = 0
for i in range(max(a, b) + 1):
    now *= (n - i)
    div *= i + 1
    if i == a-1 or i == b-1:
        total -= now // div
print(total % (10 ** 9 + 7))


Fixed submission:
n, a, b = map(int, input().split())
MOD = 10 ** 9 + 7
# Pythonのpowは繰り返し二乗法で実装されている
ans = pow(2, n, MOD) - 1
product = 1
div = 1
for i in range(1, b + 1):
    product = product * (n - i + 1) % MOD
    div = div * i % MOD
    if i == a or i == b:
        # 逆元を求める
        ans -= product * pow(div, MOD - 2, MOD)
print(ans % MOD)
Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

dp = [float("inf")] * (2 * h + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])

ans = float('inf')
for j in range(h, 2 * h + 1):
    ans = min(ans, dp[j])
print(ans)

Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])

ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)

Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

dp = [float("inf")] * (3 * h)
dp[0] = 0
for i in range(h):
    for j in range(n):
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])

ans = float('inf')
for j in range(h, 2 * h + 1):
    ans = min(ans, dp[j])
print(ans)

Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])

ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)

Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

dp = [float("inf")] * (3 * h)
dp[0] = 0
for i in range(h):
    for j in range(n):
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])

ans = float('inf')
for j in range(h, 2 * h + 1):
    ans = min(ans, dp[n][j])
print(ans)


Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])

ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
import sys
input = sys.stdin.readline


def main():
    def lcm(x, y):
        return (x * y) // fractions.gcd(x, y)

    n = int(input())
    a = list(map(int, input().split()))
    num = 1
    for i in range(n):
        num = lcm(num, a[i])
    ans = 0
    for i in range(n):
        ans += num // a[i]
        ans %= 10 ** 9 + 7
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = int(input())
a = list(map(int, input().split()))
num = 1
for i in range(n):
    num = lcm(num, a[i])
ans = 0
for i in range(n):
    ans += num // a[i]
print(ans % (10 ** 9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = int(input())
a = list(map(int, input().split()))
num = 1
for i in range(n):
    num = lcm(num, a[i])
ans = 0
for i in range(n):
    ans += num // a[i]
    ans %= 10 ** 9 + 7
print(ans)


Fixed submission:
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = int(input())
a = list(map(int, input().split()))
num = 1
for i in range(n):
    num = lcm(num, a[i])
ans = 0
for i in range(n):
    ans += num // a[i]
print(ans % (10 ** 9 + 7))
Buggy python submission (verdict: Runtime Error):
s = input()
week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
for i in len(s):
    if s == week[i]:
        print(7 - i)
        break


Fixed submission:
s = input()
week = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
for i in range(7):
    if s == week[i]:
        print(7 - i)
        break
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())


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

    divisors.sort()
    return divisors


def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True


ans = 1
divs = make_divisors(math.gcd(a, b))
for num in divs:
    if is_prime(num):
        ans += 1
print(ans)

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


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

    divisors.sort()
    return divisors


def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True


ans = 1
divs = make_divisors(fractions.gcd(a, b))
for num in divs:
    if is_prime(num):
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for i in range(n)]
# 必要な日数の照準にソートする
jobs.sort()
# 次に選ぶバイト候補の保存場所
money = []
ans = 0

# より制約の強い、最終リミットに近い日に行うバイトの割当てから攻めていく
for limit in range(1, m + 1):
    for a, b in jobs:
        # limit日までに報酬のもらえるアルバイトを抽出
        if a == limit:
            # 次に選ぶバイト候補に追加
            heapq.heappush(money, -b)
        elif a > limit:
            break
    # 要素数が空の場合のエラー処理
    if money != []:
        ans += heapq.heappop(money) * (-1)

print(ans)


Fixed submission:
import heapq
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for i in range(n)]
# 必要な日数の照準にソートする
jobs.sort()
# 次に選ぶバイト候補の保存場所
money = []
ans = 0

i = 0
# より制約の強い、最終リミットに近い日に行うバイトの割当てから攻めていく
for limit in range(1, m + 1):
    # limit日までに報酬のもらえるアルバイトを抽出
    while i < n and jobs[i][0] <= limit:
        a = jobs[i][0]
        b = jobs[i][1]
        # 次に選ぶバイト候補に追加
        heapq.heappush(money, -b)
        i += 1
    # 要素数が空の場合のエラー処理
    if money != []:
        ans -= heapq.heappop(money)

print(ans)
Buggy python submission (verdict: Runtime Error):
N,L = map(int, input().split())
list = []
sum = 0
min = 10000
sign = 1
for i in range(1,N+1):
    sum += L+i-1
    list.append(L+i-1)
for num in list:
    if min > abs(num):
        min = abs(num)
        if num > 0:
            sign = 1
        else:
            sign = -1
print(sum-min*sign)


Fixed submission:
M = input()
S = list(M)

result = "Good"
for str in S:
    if M.count(str+str) > 0:
        result = "Bad"
        break
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
L,R = map(int,input().split())
a = []
for i in range(L,R+1):
    a.append(i)

for i in range(1,M):
    b = []
    l,r = map(int,input().split())
    for j in range(l,r+1):
        b.append(j)
    a = list(set(a) & set(b))

print(len(a))


Fixed submission:
N,M = map(int,input().split())

l_max = 1
r_min = N
for i in range(0,M):
    l,r = map(int,input().split())
    if l_max < l:
        l_max = l
    if r_min > r:
        r_min = r

if l_max > r_min:
    print(0)
else:
    print(r_min-l_max+1)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
L = []
R = []
total = 0
for i in range(0,M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
for i in range(1,N+1):
    for j in range(0,M):
        if L[j] <= i <= R[j]:
            if j == M-1:
                total += 1
        else:
            break

print(total)


Fixed submission:
N,M = map(int,input().split())

l_max = 1
r_min = N
for i in range(0,M):
    l,r = map(int,input().split())
    if l_max < l:
        l_max = l
    if r_min > r:
        r_min = r

if l_max > r_min:
    print(0)
else:
    print(r_min-l_max+1)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))

for i in range(0,M):
    b,c = map(int,input().split())
    for j in range(0,b):
        A.append(c)

A.sort()

result = 0
start = len(A)-1
for k in range(start,start-N,-1):
    result += A[k]
print(result)


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
cards = []
for i in range(0,N):
    cards.append((A[i],1))

for i in range(0,M):
    b,c = map(int,input().split())
    cards.append((c,b))

cards.sort()
cards.reverse()

result = 0
total = N
for num, cnt in cards:
    total -= cnt
    result += num*cnt
    if total < 0:
        result += num * total
        break
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))

for i in range(0,M):
    b,c = map(int,input().split())
    for j in range(0,b):
        A.append(c)

A.sort()
A.reverse()

result = 0
for k in range(0,N):
    result += A[k]
print(result)


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
cards = []
for i in range(0,N):
    cards.append((A[i],1))

for i in range(0,M):
    b,c = map(int,input().split())
    cards.append((c,b))

cards.sort()
cards.reverse()

result = 0
total = N
for num, cnt in cards:
    total -= cnt
    result += num*cnt
    if total < 0:
        result += num * total
        break
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))
B = []
C = []
for i in range(0,M):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)

A.sort()

for i in range(0,M):
    for j in range(0,B[i]):
        if C[i] > A[j]:
            A[j] = C[i]
        else:
            break
    A.sort()

result = 0
for num in A:
    result += num
print(result)


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
cards = []
for i in range(0,N):
    cards.append((A[i],1))

for i in range(0,M):
    b,c = map(int,input().split())
    cards.append((c,b))

cards.sort()
cards.reverse()

result = 0
total = N
for num, cnt in cards:
    total -= cnt
    result += num*cnt
    if total < 0:
        result += num * total
        break
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
A = list(map(int,input().split()))
B = []
C = []
for i in range(0,M):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)

A.sort()

for i in range(0,M):
    for j in range(0,B[i]):
        if C[i] > A[0]:
            A[0] = C[i]
            A.sort()
        else:
            break

result = 0
for num in A:
    result += num
print(result)


Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
cards = []
for i in range(0,N):
    cards.append((A[i],1))

for i in range(0,M):
    b,c = map(int,input().split())
    cards.append((c,b))

cards.sort()
cards.reverse()

result = 0
total = N
for num, cnt in cards:
    total -= cnt
    result += num*cnt
    if total < 0:
        result += num * total
        break
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
 
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
 
N = int(input())
a = list(map(int, input().split()))
ans = [0]*N
for i in range(0, N):
    tmp = a.pop(0)
    ans[i] = gcd_list(a)
    a.append(tmp)
 
ans.sort()
print(ans[N-1])

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
L = [0] * n
R = [0] * n
for i in range(1, n):
    L[i] = fractions.gcd(a[i - 1], L[i - 1])
    R[n - 1 - i] = fractions.gcd(a[n - i], R[n - i])
for i in range(0, n):
    ans[i] = fractions.gcd(L[i], R[i])
ans.sort()
print(ans[n - 1])

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce


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


N = int(input())
a = list(map(int, input().split()))
ans = [0]*N
for i in range(0, N):
    tmp = a.pop(0)
    ans[i] = gcd_list(a)
    a.append(tmp)

ans.sort()
print(ans[N-1])


Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
L = [0] * n
R = [0] * n
for i in range(1, n):
    L[i] = fractions.gcd(a[i - 1], L[i - 1])
    R[n - 1 - i] = fractions.gcd(a[n - i], R[n - i])
for i in range(0, n):
    ans[i] = fractions.gcd(L[i], R[i])
ans.sort()
print(ans[n - 1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
k = int(input())
result = []

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

print("".join(result))


Fixed submission:
n = int(input())
s = input()
k = int(input())
result = []

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

print("".join(result))
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
ans = [0] * q
for i in range(q):
    l, r = map(int, input().split())
    substr = str(s[l - 1:r])
    ans[i] = substr.count("AC")
print(*ans, sep='\n')

Fixed submission:
n, q = map(int, input().split())
s = input()
cum = [0] * (n + 1)
for i in range(2, n + 1):
    cum[i] = cum[i - 1]
    if s[i - 2:i] == "AC":
        cum[i] += 1

ans = [0] * q

for i in range(q):
    l, r = map(int, input().split())
    ans[i] = cum[r] - cum[l]
print(*ans, sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
ans = [0] * q
for i in range(q):
    l, r = map(int, input().split())
    substr = str(s[l - 1:r])
    ans[i] = substr.count("AC")
print(*ans, sep='\n')

Fixed submission:
n, q = map(int, input().split())
s = input()
cum = [0] * (n + 1)
for i in range(2, n + 1):
    cum[i] = cum[i - 1]
    if s[i - 2:i] == "AC":
        cum[i] += 1

ans = [0] * q

for i in range(q):
    l, r = map(int, input().split())
    ans[i] = cum[r] - cum[l]
print(*ans, sep='\n')
Buggy python submission (verdict: Runtime Error):
h = list(map(int, input().split()))
ans = 0
while sum(h) != 0:
    left = float("inf")
    right = float("inf")
    for i in range(n):
        if h[i] > 0:
            left = i
            break
    for j in range(i + 1, n):
        if h[j] <= 0:
            right = j
            break
    if right == float("inf"):
        right = n
    for i in range(left, right):
        h[i] -= 1
    ans += 1
print(ans)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
ans = 0
while sum(h) != 0:
    left = float("inf")
    right = float("inf")
    for i in range(n):
        if h[i] > 0:
            left = i
            break
    for j in range(i + 1, n):
        if h[j] <= 0:
            right = j
            break
    if right == float("inf"):
        right = n
    for i in range(left, right):
        h[i] -= 1
    ans += 1
print(ans)