Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]

count = float('inf')
if n == 3:
    for i in range(100, 1000):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                 count = i
elif n == 2:
    for i in range(10, 100):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i
elif n == 1:
    for i in range(0, 10):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i

if count == float('inf'):
    print(-1)
else:
    print(

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

count = float('inf')
if n == 3:
    for i in range(100, 1000):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                 count = i
elif n == 2:
    for i in range(10, 100):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i
elif n == 1:
    for i in range(0, 10):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i

if count == float('inf'):
    print(-1)
else:
    print(count)

Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]

count = float('inf')
if n == 3:
    for i in range(100, 1000):
        a = str(i)
        if int(a[s[0][0]-1]) == int(s[0][1]) and int(a[s[1][0]-1]) == int(s[1][1]) and int(a[s[2][0]-1]) == int(s[2][1]):
             if i < count:
                 count = i
elif n == 2:
    for i in range(10, 100):
        a = str(i)
        if int(a[s[0][0]-1]) == int(s[0][1]) and int(a[s[1][0]-1]) == int(s[1][1]):
            if i < count:
                count = i
elif n == 1:
    for i in range(0, 10):
        a = str(i)
        if int(a[s[0][0]-1]) == int(s[0][1]):
            if i < count:
                count = i

if count == float('inf'):
    print(-1)
else:
    print(count)


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

count = float('inf')
if n == 3:
    for i in range(100, 1000):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                 count = i
elif n == 2:
    for i in range(10, 100):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i
elif n == 1:
    for i in range(0, 10):
        a = str(i)
        if all(int(a[s[j][0]-1]) == int(s[j][1]) for j in range(m)):
            if i < count:
                count = i

if count == float('inf'):
    print(-1)
else:
    print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6       # N は必要分だけ用意する
fact = [1, 1]     # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]      # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

n,a,b = map(int, input().split())
ans = 2**n -1 -cmb(n,a,p) -cmb(n,b,p)
print(ans)

Fixed submission:
def comb(n, r, p):
    numer = 1
    denom = 1
 
    for i in range(n-r+1, n+1):
        numer = numer * i % p
    for i in range(1, r+1):
        denom = denom * i % p
    return numer * pow(denom, p-2, p) % p
 
p = pow(10, 9) + 7
n, a, b = map(int, input().split())
print(((pow(2, n, p) - comb(n, a, p) - comb(n, b, p) - 1)) % p)

Buggy python submission (verdict: Runtime Error):
n,a,b = map(int, input().split())
s = 0

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

mod = 10**9+7 #出力の制限
N = 10**4
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 )


for i in range(n):
    s += cmb(n,i,mod)

s -= cmb(n,a,mod)
s -= cmb(n,b,mod)
print(s)

Fixed submission:
def comb(n, r, p):
    numer = 1
    denom = 1
 
    for i in range(n-r+1, n+1):
        numer = numer * i % p
    for i in range(1, r+1):
        denom = denom * i % p
    return numer * pow(denom, p-2, p) % p
 
p = pow(10, 9) + 7
n, a, b = map(int, input().split())
print(((pow(2, n, p) - comb(n, a, p) - comb(n, b, p) - 1)) % p)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
for i in range(n):
    s.append(input())

count = []
for i in range(n):
    count.append(s.count(s[i]))

a = max(count)
ans = []
for i in range(n):
    if count[i] == a:
        if not(s[i] in ans):
            ans.append(s[i])

ans.sort()
for i in ans:
    print(i)

Fixed submission:
import collections
n = int(input())
s = list(input() for i in range(n))
counted = collections.Counter(s)

m = max(counted.values())
chars = [key for key, value in counted.items()
             if value == m]
chars.sort()
for i in range(len(chars)):
    print(chars[i])
Buggy python submission (verdict: Runtime Error):
h = int(input())
count = 0
def dfs(h):
    global count
    count += 1
    if h == 1:
        quit()
    else:
            dfs(h//2)
            dfs(h//2)

dfs(h)
print(count)

Fixed submission:
h,a = map(int, input().split())
count = 0

while h > 0:
  h -= a
  count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())

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

print(lcm(a,b))

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

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

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

print(lcm(a,b))
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())

if A >= 1 and A <= 9 and B >= 1 and B <= 9:
  print(A*B)
else:
  print(-1)

Fixed submission:
a, b = map(int, input().split())
if (1 <= a and a <= 9 and 1 <= b and b <= 9):
  print(a*b)
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
A,B,C,X = int(input() for i in range(4))
print([500*a+100*b+50*c for c in range(C+1) for b in range(B+1) for a in range(A+1)].count(X))

Fixed submission:
A,B,C,X=[int(input()) for i in range(4)]
print([500*a+100*b+50*c for c in range(C+1) for b in range(B+1) for a in range(A+1)].count(X))

Buggy python submission (verdict: Runtime Error):
A,B,C,X = int(input() for i in range(4))
print([500*a+100*b+50*c for a in range(A+1) for b in range(B+1) for c in range(C+1)].count(X))

Fixed submission:
A,B,C,X=[int(input()) for i in range(4)]
print([500*a+100*b+50*c for c in range(C+1) for b in range(B+1) for a in range(A+1)].count(X))
Buggy python submission (verdict: Runtime Error):
n = input()

def dfs(i, f, s):
    if i == 3:
        if s==7:
            return f+"=7"
    return dfs(i+1, f+"+"+n[i+1], s+int(n[i+1])) or dfs(i+1, f+"-"+n[i+1], s-int(n[i+1]))

print(dfs(0, n[0], int(n[0])))

Fixed submission:
s = input()

def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + "=7")
            exit()
    else:
        dfs(i+1, f + "+" + s[i+1], sum + int(s[i+1]))
        dfs(i+1, f + "-" + s[i+1], sum - int(s[i+1]))

dfs(0, s[0], int(s[0]))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mx = 0
for i in range(min(n, k + 1)):
	for j in range(min(k - i + 1, n - i + 1)):
		summa = 0
		b = []
		for t in range(i):
			b.append(a[t])
		for t in range(n - j, n):
			b.append(a[t])
		z = k - i - j
		b.sort()
		for x in b:
			if x < 0 and z > 0:
				z -= 1
			else:
				summa += x
		mx = max(mx, summa)
print(mx)


Fixed submission:
a, b = map(int, input().split())
a = a * 3 + b
print(a // 2)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mx = 0
for i in range(min(n + 1, k + 1)):
	for j in range(min(k - i + 1, n - i + 1)):
		summa = 0
		b = []
		for t in range(i):
			b.append(a[t])
		for t in range(n - j, n):
			b.append(a[t])
		z = k - i - j
		b.sort()
		for x in b:
			if x < 0 and z > 0:
				z -= 1
			else:
				summa += x
		mx = max(mx, summa)
print(mx)


Fixed submission:
a, b = map(int, input().split())
a = a * 3 + b
print(a // 2)
Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

x = [a[0]]
y = [b[0]]
for i in range(1, n):
    x.append(x[i-1] + a[i])
for i in range(1, m):
    y.append(y[i-1] + b[i])
    
t = 0
i = 0
j = 0
ans = 0
l = 0
r = 0
while i < n or j < m:
    if i < n and x[i]-l <= y[j]-r:
        t += a[i]
        l += a[i]
        i += 1
    elif j < m:
        t += b[j]
        r += b[j]
        j += 1
    if t > k:
        break
    ans += 1

print(ans)
            

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

x = [0]
y = [0]
for i in range(n):
    x.append(x[i] + a[i])
    
for i in range(m):
    y.append(y[i] + b[i])
    
i = 0
j = m
ans = 0
while i <= n and 0 <= j:
    if x[i] + y[j] <= k:
        ans = max(ans, i + j)
        i += 1
    else:
        j -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

ans = 0
for i in range(n):
    x = s[i]
    for j in range(i, n):
        if s[j] != x:
            y = s[j]
            for k in range(j, n):
                if s[k] not in (x, y) and j-i != k-j:
                    ans += 1

print(ans)

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

r, g, b = 0, 0, 0
for si in s:
    if si == "R":
        r += 1
    elif si == "G":
        g += 1
    else:
        b += 1
        
ans = r * g * b

d = 0
for i in range(n-2):
    for j in range(i, n-1):
        k = j + j - i
        if k < n and s[i] != s[j] and s[k] not in (s[i], s[j]):
            d += 1
        
print(ans - d)
Buggy python submission (verdict: Runtime Error):
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]

t = [[0] * w for _ in range(h)]
n = 0
rows = []
for i in range(h):
    if s[i].count("#") == 0:
        rows.append(i)
    else:
        if s[i][0] == "#":
            for j in range(w):
                if s[i][j] == "#":
                    n += 1
                t[i][j] = n
        else:
            n += 1
            f = 0
            for j in range(w):
                if f and s[i][j] == "#":
                    n += 1
                elif s[i][j] == "#":
                    f = 1
                t[i][j] = n

if rows[-1] == h-1:
    for k in range(h)[::-1]:
        if t[k][j] != 0:
            for j in range(w):
                t[rows[-1]][j] = t[k][j]
            break
        
for i in rows:
    for k in range(i+1, h):
        if t[k][j] != 0:
            for j in range(w):
                t[i][j] = t[k][j]
            break

for i in range(h):
    print(*t[i])

Fixed submission:
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]

t = [[0] * w for _ in range(h)]
n = 0
rows = []
for i in range(h):
    if s[i].count("#") == 0:
        rows.append(i)
    else:
        if s[i][0] == "#":
            for j in range(w):
                if s[i][j] == "#":
                    n += 1
                t[i][j] = n
        else:
            n += 1
            f = 0
            for j in range(w):
                if f and s[i][j] == "#":
                    n += 1
                elif s[i][j] == "#":
                    f = 1
                t[i][j] = n

if rows != [] and rows[-1] == h-1:
    for k in range(h)[::-1]:
        if t[k][j] != 0:
            for j in range(w):
                t[rows[-1]][j] = t[k][j]
            break
        
for i in rows:
    for k in range(i+1, h):
        if t[k][j] != 0:
            for j in range(w):
                t[i][j] = t[k][j]
            break

for i in range(h):
    print(*t[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse = True)

ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i] < l[j] + l[k]:
                ans += 1
            else:
                break

print(ans)

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(n):
    for j in range(i+1, n):
        x = bisect.bisect_left(l, l[i] + l[j])
        ans += x - j - 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse = True)

ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i] < l[j] + l[k]:
                ans += 1

print(ans)

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(n):
    for j in range(i+1, n):
        x = bisect.bisect_left(l, l[i] + l[j])
        ans += x - j - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

print(*[a.index(i) + 1 for i in range(1, n + 1)])

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

l = sorted(range(len(a)), key=a.__getitem__)
for i in l:
    print(i + 1, end = " ")

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

l = []
for i in range(1, n + 1):
    l.append(a.index(i) + 1)
    
print(*l)

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

l = sorted(range(len(a)), key=a.__getitem__)
for i in l:
    print(i + 1, end = " ")

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

for i in range(1, n + 1):
    print(a.index(i) + 1, end = " ")

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

l = sorted(range(len(a)), key=a.__getitem__)
for i in l:
    print(i + 1, end = " ")

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

for _ in range(n):
    i = a.index(min(a))
    print(i + 1, end = " ")
    a[i] = n + 1

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

l = sorted(range(len(a)), key=a.__getitem__)
for i in l:
    print(i + 1, end = " ")
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

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

x = fractions.gcd(a,b)
ans = []

i = 2
y = int(x**0.5)
while True:
    if x%i == 0:
        x //= i
        ans.append(i)
    elif x == 1:
        break
    else:
        i += 1

print(len(set(ans))+1)

Fixed submission:
import fractions

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

x = fractions.gcd(a,b)
ans = []

i = 2
y = int(x**0.5)
for j in range(10000000):
    if x%i == 0:
        x //= i
        ans.append(i)
        i = 2
        y = int(x**0.5)
    elif i == y:
        ans.append(x)
        break
    else:
        i += 1

print(len(set(ans))+1)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

for i in range(1, n + 1):
    if q - a.count(i) >= k:
        print("No")
    else:
        print("Yes")

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

for i in a:
    p[i - 1] += 1

for i in p:
    if q - i >= k:
        print("No")
    else:
        print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
l = [[0] * n for _ in range(n)]
ans = 0

for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if i >= j and s[i] == s[j]:
            l[i][j] += 1
            
            if i < n-1 and j < n-1 and l[i+1][j+1] > 0:
                l[i][j] += l[i+1][j+1]
                
        now = min(l[i][j], i - j)
        ans = max(ans, now)

print(ans)

Fixed submission:
n = int(input())
s = input()
l = [[0] * n for _ in range(n)]
ans = 0

for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if i >= j and s[i] == s[j]:
            l[i][j] += 1
            
            if i < n-1 and j < n-1 and l[i+1][j+1] > 0:
                l[i][j] += l[i+1][j+1]
                
        now = min(l[i][j], i - j)
        ans = max(ans, now)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
l = [[0] * n for _ in range(n)]
ans = 0

for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if s[i] == s[j]:
            l[i][j] += 1
            
            if i < n-1 and j < n-1 and l[i+1][j+1] > 0:
                l[i][j] += l[i+1][j+1]
                
        now = min(l[i][j], i - j)
        ans = max(ans, now)

print(ans)

Fixed submission:
n = int(input())
s = input()
l = [[0] * n for _ in range(n)]
ans = 0

for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if i >= j and s[i] == s[j]:
            l[i][j] += 1
            
            if i < n-1 and j < n-1 and l[i+1][j+1] > 0:
                l[i][j] += l[i+1][j+1]
                
        now = min(l[i][j], i - j)
        ans = max(ans, now)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import math

n = int(input())

a = [str(sorted(input())) for _ in range(n)]
a.sort()
s = set(a)

l = []
for i in s:
    l.append(a.count(i))

ans = 0
for i in l:
    if i == 1:
        pass
    else:
        ans += (i-1) * i // 2

print(ans)

Fixed submission:
import collections

n = int(input())

a = [str(sorted(input())) for _ in range(n)]
a.sort()
s = set(a)

c = collections.Counter(a)

ans = 0
for i in c.values():
        ans += (i-1) * i // 2

print(ans)

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

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

c = []
for i in s:
    c.append(collections.Counter(i))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if c[i] == c[j]:
            ans += 1
            
print(ans)

Fixed submission:
import collections

n = int(input())

a = [str(sorted(input())) for _ in range(n)]
a.sort()
s = set(a)

c = collections.Counter(a)

ans = 0
for i in c.values():
        ans += (i-1) * i // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = int(input())

for i in range(1, int(s**0.5)+1)[::-1]:
    if s%i == 0:
        x = i
        y = s//i
        break

print(0, 0, 0, x, y, 0)

Fixed submission:
s = int(input())

x1 = 10**9
y1 = 1
x2 = (10**9 - s%10**9)%10**9
y2 = (s+x2) // 10**9

print(0, 0, x1, y1, x2, y2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
    print(max(a[:i] + a[i+1:]))

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
m1 = max(a)
mi = a.index(m1)
m2 = max(a[:mi] + a[mi+1:])

for i in range(n):
    if i == mi:
        print(m2)
    else:
        print(m1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = list(set(a))

if sum(a) == 0:
    pass
elif a.count(max(b)) == 2*n/3 and a.count(0) == n/3:
    pass
elif b[0] ^ b[1] == b[2]:
    pass
else:
    print("No")
    exit()
    
print("Yes")

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

if len(b) != 3:
    if sum(a) == 0:
        pass
    elif a.count(max(b)) == 2*n/3 and a.count(0) == n/3:
        pass
    else:
        print("No")
        exit()
else:
    if b[0] ^ b[1] == b[2] and a.count(b[0]) == a.count(b[1]) == a.count(b[2]):
        print("Yes")
        exit()
    else:
        print("No")
        exit()
        
print("Yes")
Buggy python submission (verdict: Runtime Error):
import math

def combinations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())
for i in range(k):
    if i == 0 or i == k-1:
        print(combinations((n - k + 1), i+1) % (10 ** 9 + 7))
    else:
        print(combinations((n - k + 1), i+1) * (k-1) % (10 ** 9 + 7))

Fixed submission:
import math

def combinations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())
for i in range(k):
    if n-k+1 < i+1:
        print(0)
        continue
    if i == 0 or i == k-1:
        print(combinations((n - k + 1), i+1) % (10 ** 9 + 7))
    else:
        print(combinations((n - k + 1), i+1) * combinations(k-1, i) % (10 ** 9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce

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

l = []
for i in range(n):
    a_except_for_i = a[:i] + a[i + 1:]
    l.append(reduce(fractions.gcd, a_except_for_i))
print(max(l))

Fixed submission:
import fractions
from functools import reduce

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

l = [0]
r = [0]
for i in range(n):
    l.append(fractions.gcd(l[i], a[i]))
    r.append(fractions.gcd(r[i], a[-(i + 1)]))

m = [fractions.gcd(l[i], r[-(i + 2)]) for i in range(n)]
print(max(m))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

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

l = []
for i in range(n):
    a_except_for_i = a[:i] + a[i + 1:]
    l.append(reduce(math.gcd, a_except_for_i))

Fixed submission:
import fractions
from functools import reduce

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

l = [0]
r = [0]
for i in range(n):
    l.append(fractions.gcd(l[i], a[i]))
    r.append(fractions.gcd(r[i], a[-(i + 1)]))

m = [fractions.gcd(l[i], r[-(i + 2)]) for i in range(n)]
print(max(m))

Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

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

l = []
for i in range(n):
    a_except_for_i = a[:i] + a[i + 1:]
    l.append(reduce(math.gcd, a_except_for_i))
print(max(l))

Fixed submission:
import fractions
from functools import reduce

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

l = [0]
r = [0]
for i in range(n):
    l.append(fractions.gcd(l[i], a[i]))
    r.append(fractions.gcd(r[i], a[-(i + 1)]))

m = [fractions.gcd(l[i], r[-(i + 2)]) for i in range(n)]
print(max(m))
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

f = [0]*(n-1)
for i in range(n-1):
    if s[i:i+2] == "AC":
        f[i] = 1

for l, r in lr:
    print(sum(f[l-1:r-1]))

Fixed submission:
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

f = [0]*(n)
x = 0
for i in range(n):
    f[i] = x
    if s[i:i+2] == "AC":
        x += 1
        
for l, r in lr:
    print(f[r-1] - f[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

f = [0]*(n-1)
for i in range(n-1):
    if s[i:i+2] == "AC":
        f[i] = 1

for l, r in lr:
    print(sum(f[l-1:r-1]))

Fixed submission:
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

f = [0]*(n)
x = 0
for i in range(n):
    f[i] = x
    if s[i:i+2] == "AC":
        x += 1
        
for l, r in lr:
    print(f[r-1] - f[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

f = [1 if s[i:i+2] == "AC" else 0 for i in range(n-1)]

for l, r in lr:
    print(sum(f[l-1:r-1]))

Fixed submission:
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

f = [0]*(n)
x = 0
for i in range(n):
    f[i] = x
    if s[i:i+2] == "AC":
        x += 1
        
for l, r in lr:
    print(f[r-1] - f[l-1])