Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from math import gcd


A, B, C, D = map(int, input().split())
lcm = C * D // gcd(C, D)
print(
    B - B//C - B//D + B//lcm
    - ((A-1) - (A-1)//C - (A-1)//D + (A-1)//lcm)
)

Fixed submission:
from fractions import gcd


A, B, C, D = map(int, input().split())
lcm = C * D // gcd(C, D)
print(
    B - B//C - B//D + B//lcm
    - ((A-1) - (A-1)//C - (A-1)//D + (A-1)//lcm)
)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
L, R = map(int, input().split())
CARDS = {i for i in range(L,R+1)}

for i in range(M-1):
    L, R = map(int, input().split())
    CARDS &= {card for card in range(L,R+1)}
    if CARDS == set():
        break

print(len(CARDS))

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

for _ in range(M):
    L, R = map(int, input().split())
    Ls.add(L)
    Rs.add(R)

print(len([i for i in range(max(Ls), min(Rs)+1)]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
CARDS = {i for i in range(1,N+1)}

for i in range(M):
    L, R = map(int, input().split())
    CARDS &= {card for card in range(L,R+1)}

print(len(CARDS))

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

for _ in range(M):
    L, R = map(int, input().split())
    Ls.add(L)
    Rs.add(R)

print(len([i for i in range(max(Ls), min(Rs)+1)]))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
cards = sorted(list(map(int, input().split())))
operation = []

for _ in range(M):
    operation.append(tuple(map(int, input().split())))

operation.sort(key=lambda x:x[1], reverse=True)

for ope in operation:
    FLG = False
    for j in range(ope[0]):
        if cards[j] < ope[1]:
            cards[j] = ope[1]
        else:
            FLG = True
            break
    if FLG:
        break
    cards.sort()

print(sum(cards))

Fixed submission:
from collections import deque


N, M = map(int, input().split()) 
operation = [[1, card] for card in map(int, input().split())]

for _ in range(M):
    operation.append(list(map(int, input().split())))

operation.sort(key=lambda x:x[1], reverse=True)
operation = deque(operation)

maximum = 0
for _ in range(N):
    maximum += operation[0][1]
    operation[0][0] -= 1
    if operation[0][0] == 0:
        operation.popleft()

print(maximum)

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

for _ in range(M):
    B, C = map(int, input().split())
    for i in range(B):
        if cards[i] < C:
            cards[i] = C
        else:
            break
    cards.sort()

print(sum(cards))

Fixed submission:
from collections import deque


N, M = map(int, input().split()) 
operation = [[1, card] for card in map(int, input().split())]

for _ in range(M):
    operation.append(list(map(int, input().split())))

operation.sort(key=lambda x:x[1], reverse=True)
operation = deque(operation)

maximum = 0
for _ in range(N):
    maximum += operation[0][1]
    operation[0][0] -= 1
    if operation[0][0] == 0:
        operation.popleft()

print(maximum)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)


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

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


count = 0
def dfs(v, seen, temp=0):
    global count
    seen[v] = 1
    if to[v]:
        for nv in to[v]:
            dfs(nv, seen, temp + 1)
    else:
        count = max(count, temp)


def main():
    ans = 0
    seen = [0] * N
    for i in range(N):
        if not seen[i]:
            dfs(i, seen)
            ans = max(ans, count)
    print(ans)


if __name__ == "__main__":
    main()

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


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

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

# dp[i] : iを始点とする最長経路
dp = [0] * N
seen = [0] * N

def dfs(v):
    if seen[v]:
        return dp[v]
    seen[v] = 1
    res = 0
    for nv in to[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return res


def main():
    ans = 0
    for i in range(N):
        ans = max(ans, dfs(i))
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)


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

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


count = 0
def dfs(v, temp=0):
    global count
    if to[v]:
        for nv in to[v]:
            dfs(nv, temp + 1)
    else:
        count = max(count, temp)


def main():
    ans = 0
    for i in range(N):
        dfs(i)
        ans = max(ans, count)
    print(ans)


if __name__ == "__main__":
    main()

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


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

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

# dp[i] : iを始点とする最長経路
dp = [0] * N
seen = [0] * N

def dfs(v):
    if seen[v]:
        return dp[v]
    seen[v] = 1
    res = 0
    for nv in to[v]:
        res = max(res, dfs(nv) + 1)
    dp[v] = res
    return res


def main():
    ans = 0
    for i in range(N):
        ans = max(ans, dfs(i))
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))

z = 1
for i in range(k):
    z = z * a[i]

for i in range(n-k):
    t = a[k+i] * z / a[i]
    if z < t:
        print("Yes")
    else:
        print("No")
    z = t

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

for i in range(n-k):
    if a[k+i] > a[i]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
if v <= w:
    print("NO")
elif (b-a)%(v-w) == 0 and (b-a)//(v-w)+1 > t:
    print("NO")
elif -(-(b-a)//(v-w)) > t:
    print("NO") 
else:
    print("YES")

Fixed submission:
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

if v == w:
    print("NO")
else:
    if w > v:
        print("NO")
    else:
        if abs(b-a) / (v-w) <= t:    
            print("YES")
        else:
            print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

ans = a[0]
for i in range(1,n):
    ans *= a[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)

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

ans = a[0]
if a.count(0) == 0:
    for i in range(1,n):
        ans *= a[i]
        if ans > 10**18:
            ans = -1
            break
else:
    ans = 0
print(ans)

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

ans = a[0]
for i in range(1,n):
    ans *= a[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)

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

ans = a[0]
if a.count(0) == 0:
    for i in range(1,n):
        ans *= a[i]
        if ans > 10**18:
            ans = -1
            break
else:
    ans = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(2*n*math.pi)

Fixed submission:
n = int(input())
print(2*n*3.14159264)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = [input() for i in range(q)]
rvs = 1
for i in range(q):
    if query[i] == "1":
        rvs = rvs * (-1)
    else:
        if query[i][2:3] == "1":
            if rvs == 1:
                s = query[i][4:5] + s
            else:
                s = s + query[i][4:5]
        else:
            if rvs == -1:
                s = query[i][4:5] + s
            else:
                s = s + query[i][4:5]
if rvs == -1:
    s = s[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())
query = [input() for i in range(q)]
rvs = 1
s1 = ""
for i in range(q):
    if query[i] == "1":
        rvs = rvs * (-1)
    else:
        if query[i][2:3] == "1":
            if rvs == 1:
   #             s = query[i][4:5] + s
                s1 = s1 + query[i][4:5]
            else:
                s = s + query[i][4:5]
        else:
            if rvs == -1:
    #            s = query[i][4:5] + s
                s1 = s1 + query[i][4:5]
            else:
                s = s + query[i][4:5]
if rvs == -1:
    s = s[::-1] + s1
else:
    s = s1[::-1] + s
#print(rvs,s1,s)
print(s)
Buggy python submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
  #  print(g1[n],g2[r],g2[n-r])
    return g1[n] * g2[r] * g2[n-r] % mod

x,y = map(int,input().split())
n = (2*y-x)/3
m = (2*x-y)/3

if n <= 0 or m <= 0:
    print(0)
elif int(n) != n or int(m) != m:
    print(0)
else:
    mod = 10**9+7 #出力の制限
    N = n+m
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    
    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
    ans = cmb(n+m,n,mod)
    print(ans)

Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
  #  print(g1[n],g2[r],g2[n-r])
    return g1[n] * g2[r] * g2[n-r] % mod

x,y = map(int,input().split())
n = (2*y-x)/3
m = (2*x-y)/3

if n < 0 or m < 0:
    print(0)
elif int(n) != n or int(m) != m:
    print(0)
else:
    n = int(n)
    m = int(m)
    mod = 10**9+7 #出力の制限
    N = n+m
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    
    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
    ans = cmb(n+m,n,mod)
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

ans = []
for i in range(n):
    ans.append(str(a.index(i+1)+1))

print(" ".join(ans))

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

ans = [0 for i in range(n)]
for i,j in enumerate(a,1):
    ans[j-1] = str(i)
    
print(" ".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(n):
    ans += i
print(ans)

Fixed submission:
n = int(input())
print((n*(n-1))//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
ai = 0
bi = 0
while 1:
    if max(b) == 0:
        break
    if a[ai] < b[bi]:
        ans += a[ai]
        b[bi] -= a[ai]
        a[ai] = 0
        ai += 1
    elif a[ai] == b[bi]:
        ans += a[ai]
        b[bi] = 0
        a[ai] = 0
        ai += 1
        bi += 1
    else:
        ans += b[bi]
        a[ai] -= b[bi]
        b[bi] = 0
        if ai > bi:
            bi += 1
        else:
            ai += 1
            bi += 1
 #   print(a)
 #   print(b)
 #   print(ai,bi)
    if ai >= n+1 or bi >= n:
        break
print(ans)

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

ans = 0
"""
ai = 0
bi = 0
while 1:
    if max(b) == 0:
        break
    if a[ai] < b[bi]:
        ans += a[ai]
        b[bi] -= a[ai]
        a[ai] = 0
        ai += 1
    elif a[ai] == b[bi]:
        ans += a[ai]
        b[bi] = 0
        a[ai] = 0
        ai += 1
        bi += 1
    else:
        ans += b[bi]
        a[ai] -= b[bi]
        b[bi] = 0
        if ai > bi:
            bi += 1
        else:
            ai += 1
            bi += 1
 #   print(a)
 #   print(b)
 #   print(ai,bi)
    if ai >= n+1 or bi >= n:
        break
print(ans)
"""
for i in range(n):
    if b[i] >= a[i] + a[i+1]:
        ans += a[i] + a[i+1]
        a[i+1] = 0
    else:
        if b[i] >= a[i]:
            ans += b[i]
            a[i+1] -= (b[i]-a[i])
        else:
            ans += b[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
n,x = map(int,input().split())
l = list(map(int,input().split()))

ans = 0
d = 0
while 1:
    if d > x:
        break
    d += l[ans]
    ans += 1
print(ans)

Fixed submission:
n,x = map(int,input().split())
l = list(map(int,input().split()))

ans = [0]
for i in range(n):
    ans.append(ans[i]+l[i])
count = 0
for i in ans:
    if i <= x:
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]

check = []
for i in range(n-1):
    for j in range(i+1,n):
        check.append([xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]])

ans = 10**9
for i in check:
    b = []
    for j in range(n):
        b.append([xy[j][0]-i[0],xy[j][1]-i[1]])
    c = n
    for j in range(n):
        if b[j] in xy:
            c -= 1
    if c < ans:
        ans = c
print(c)

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

check = []
for i in range(n-1):
    for j in range(i+1,n):
        check.append([xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]])
#print(check)
ans = 10**9
for i in check:
    b = []
    for j in range(n):
        b.append([xy[j][0]-i[0],xy[j][1]-i[1]])
    c = n
    for j in range(n):
        if b[j] in xy:
            c -= 1
    if c < ans:
        ans = c
if n == 1:
    print(1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b,c,d = map(int,input().split())
S = input()

ans = 0
def aaa(s,g):
    global ans
    if S[s:g].count("##") == 0:
        ans += 1
    
def bbb(s,g):
    global ans
    if S[s:g].count("##") == 0:
        ans += 1
        return(1)
    else:
        return(0)
        
if c < d:
    aaa(b,d)
    aaa(a,c)
else:
    flag = bbb(b,d)
 #   print(ans)
    if flag == 1:
        for i in range(b,d+1):
            if S[i-1:i] != "#":
                k = S[:i-1] + "#" + S[i:]
   #             print(k,i)
                if k[a:c].count("##") == 0:
                    flag = 2
                    break
        if flag == 2:
            aaa(a,c)
#    print(flag)
  #  print(ans)

if ans == 2:
    print("Yes")
else:
    print("No")

Fixed submission:
n,a,b,c,d = map(int,input().split())
S = input()
 
ans = 0
def aaa(s,g):
    global ans
    if S[s:g].count("##") == 0:
        ans += 1
    
def bbb(s,g):
    global ans
    if S[s:g].count("##") == 0:
        ans += 1
        return(1)
    else:
        return(0)

def ccc(s,g):
    global ans
    if S[s:g].count("##") == 0:
        return(1)
    else:
        return(0)
        
if c < d:
    aaa(b,d)
    aaa(a,c)
else:
    flag = bbb(b,d)
    flag2 = ccc(a,c)
 #   print(ans)
    if flag == 1 and flag2 == 1:
        for i in range(b,d+1):
      #      print(i)
            if S[i-1:i] != "#":
                k = S[i-2:i-1] + "#" + S[i:i+1]
      #          print(k,i)
                if k.count("##") == 0:
                    ans += 1
                    break
#    print(flag)
#    print(ans)
 
if ans == 2:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]

a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
d = []
for i in bc:
    for j in range(i[0]):
        d.append(i[1])
#print(d)

if len(d) < n:
    for i in range(n-len(d)):
        d.append(0)

ans = 0
for i in range(n):
    if a[i] < d[i]:
        ans += d[i]
    else:
        ans += a[i]
print(ans)

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]

for i in a:
    bc.append([1,i])
bc.sort(key=lambda x:x[1],reverse=True)
#print(bc)
ans = 0
for i in bc:
    d = min(i[0],n)
 #   print(d)
    ans += i[1] * d
    n -= d
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]

a.sort()
bc.sort(key=lambda x:x[1],reverse=True)

ans = 0
for i in bc:
  #  print(a)
    count = 0
    for j in range(min(i[0],len(a))):
        if a[j] < i[1]:
            count += 1
        else:
            break
    if count == 0:
        break
    ans += i[1]*count
    a = a[count:]
print(ans+sum(a))

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]

for i in a:
    bc.append([1,i])
bc.sort(key=lambda x:x[1],reverse=True)
#print(bc)
ans = 0
for i in bc:
    d = min(i[0],n)
 #   print(d)
    ans += i[1] * d
    n -= d
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]

a.sort()
bc.sort(key=lambda x:x[1],reverse=True)
ans = 0
for i in bc:
  #  print(a)
    count = 0
    for j in range(min(i[0],len(a))):
        if a[j] < i[1]:
            ans += i[1]
            count += 1
        else:
            break
    a = a[count:]
print(ans+sum(a))

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]

for i in a:
    bc.append([1,i])
bc.sort(key=lambda x:x[1],reverse=True)
#print(bc)
ans = 0
for i in bc:
    d = min(i[0],n)
 #   print(d)
    ans += i[1] * d
    n -= d
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]

a.sort()
bc.sort(key=lambda x:x[1],reverse=True)

for i in bc:
    k = 0
    for j in range(i[0]):
        if a[i[0]-j-1] < i[1]:
            k = i[0]-j
            break
    a = [i[1] for l in range(k)] + a[k:]
  #  print(a)
    a.sort()
print(sum(a))

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]

for i in a:
    bc.append([1,i])
bc.sort(key=lambda x:x[1],reverse=True)
#print(bc)
ans = 0
for i in bc:
    d = min(i[0],n)
 #   print(d)
    ans += i[1] * d
    n -= d
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
R,G,B,N = map(int,input().split())
ans = 0
for r in range(int(N/R)+1):
    for g in range(int(N/G)+1):
        if N-(r*R+g*G) >= 0 and (N-(r*R+g*G))%B == 0:
        #    print(r,g,(N-(r*R+g*G))%B)
            ans += 1
print(ans)

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

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

ans = 0
A = 0
B = 0
BA = 0
for i in s:
    ans += i.count("AB")
    if i[0:1] != "B" and i[-1:] == "A":
        A += 1
    elif i[0:1] == "B" and i[-1:] != "A":
        B += 1
    elif i[0:1] == "B" and i[-1:] == "A":
        BA += 1

#print(ans)
#print(A,B,BA)

while 1:
    if BA == 0 or A == B:
        break
    if A >= B:
        B += 1
    else:
        A += 1
    BA -= 1
#print(A,B,BA)
if A == 0 and B == 0:
    BA -= 1
print(ans + min(A,B) + BA)

Fixed submission:
R,G,B,N = map(int,input().split())
ans = 0
for r in range(int(N/R)+1):
    for g in range(int((N-r*R)/G)+1):
        if N-(r*R+g*G) >= 0 and (N-(r*R+g*G))%B == 0:
        #    print(r,g,(N-(r*R+g*G))%B)
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())

def yakusu(n):
    l = []
    for i in range(1,int(math.sqrt(n))+1):
 #       print(i)
        if n%i == 0:
            l.append(i)
            l.append(n//i)
    return(l)

l = yakusu(n)

ans = 0
for m in l[1:]:
    if n == int(n/(m-1))*m:
        ans += m-1
    
#print(l)
print(ans)

Fixed submission:
import math
n = int(input())

def yakusu(n):
    l = []
    for i in range(1,int(math.sqrt(n))+1):
 #       print(i)
        if n%i == 0:
            l.append(i)
            l.append(n//i)
    return(l)

l = yakusu(n)

ans = 0
for m in l:
    if m-1 > 0 and n == int(n/(m-1))*m:
        ans += m-1
    
#print(l)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0

def chr(a,l):
#    print(a,l)
    if a == n:
        x = 0
        y = 0
        for i in range(n):
            x += v[i]*l[i]
            y += c[i]*l[i]
        return(x-y)
    else:
        l[a] = 1
        ans1 = chr(a+1,l)
        l[a] = 0
        ans2 = chr(a+1,l)
    return(max(ans1,ans2))
    
l = [0 for i in range(n)]
print(chr(0,l))

Fixed submission:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = []
def chr(a,l,r):
    global ans
    if a == n:
        ans.append(r-l)
    else:
        chr(a+1,l+c[a],r+v[a])
        chr(a+1,l,r)
chr(0,0,0)
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

if n == 2:
    print(max(a))
else:
    l = [-1]
    r = []
    
    def gcd(x,y):
        while y != 0:
            x, y = y, x%y
    #        print(x,y)
        return(x)
    
    for i in range(n-1):
        m = a[i+1:][0]
        if len(a[i+1:]) == 1:
            m = a[i+1:][0]
        elif len(a[i+1:]) > 1:
            for j in a[i+1:]:
                m = gcd(m,j)
        r.append(m)
        m2 = a[:i+1][0]
        if len(a[:i+1]) == 1:
            m2 = a[:i+1][0]
        elif len(a[:i+1]) > 1:
            for j in a[:i+1]:
                m2 = gcd(m2,j)
        l.append(m2)
    r.append(-1)
 #   print(r)
  #  print(l)
    ans = 0
    for i in range(n):
        if l[i] == -1:
            ans = max(ans,r[i])
        elif r[i] == -1:
            ans = max(ans,l[i])
        else:
            ans = max(ans,gcd(l[i],r[i]))
    print(ans)

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

if n == 2:
    print(max(a))
else:
    l = [0 for i in range(n)]
    r = [0 for i in range(n)]
    
    def gcd(x,y):
        while y != 0:
            x, y = y, x%y
    #        print(x,y)
        return(x)
    
    for i in range(1,n):
        l[i] = gcd(l[i-1],a[i-1])
        r[n-i-1] = gcd(r[n-i],a[n-i])
  #  print(l)
  #  print(r)
    ans = 0
    for i in range(n):
        if l[i] == -1:
            ans = max(ans,r[i])
        elif r[i] == -1:
            ans = max(ans,l[i])
        else:
            ans = max(ans,gcd(l[i],r[i]))
    print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
ans = []
a = 0
for i in range(len(s)):
    if s[i] == "A":
        a += 1
    elif s[i] == "C":
        a += 1
    elif s[i] == "G":
        a += 1
    elif s[i] == "T":
        a += 1
    else:
        ans.append(a)
        a = 0
print(max(ans))

Fixed submission:
s = input()
ans = [0]
for i in range(len(s)):
    if s[i] == "A":
        ans[-1] += 1
    elif s[i] == "C":
        ans[-1] += 1
    elif s[i] == "G":
        ans[-1] += 1
    elif s[i] == "T":
        ans[-1] += 1
    else:
        ans.append(0)
print(max(ans))