Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02713 (python)

Fixed submission:
k = int(input())
 
def gcd2(a,b):
    if b == 0:
        return a
    return gcd2(b,a%b)

def gcd3(a,b,c):
    return gcd2(gcd2(a,b), c)

ans = 0
for i in range(1,k+1):
    for j in range(i,k+1):
        for m in range(j, k+1):
            if i == j == m:
                ans += gcd3(i,j,m)
            elif i == j or j == m:
                ans += gcd3(i,j,m)*3
            else:
                ans += gcd3(i,j,m)*6

print(ans)

Buggy submission (verdict: Runtime Error):
k = int(input())
 
def gcd2(a,b):
    return gcd2(b,a%b)

def gcd3(a,b,c):
    return gcd2(gcd2(a,b), c)

ans = 0
for i in range(1,k+1):
    for j in range(i,k+1):
        for m in range(j, k+1):
            if i == j == m:
                ans += gcd3(i,j,m)
            elif i == j or j == m:
                ans += gcd3(i,j,m)*3
            else:
                ans += gcd3(i,j,m)*6

print(ans)
Problem p02718 (python)

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

s = sum(a)
a.sort()

if all(a[-i-1] >= s/4/m for i in range(m)):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
k,m = map(int, input().split())
a = list(map(int, input().split()))

# リストaの総投票数をsに格納する
s = sum(a)

# リストaを降順にソートする
a.sort(reverse=True)

if a[m] >= s*(1/4/m):
    print('Yes')
else:
    print('No')
Problem p02761 (python)

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 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(

Buggy 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)
Problem p02768 (python)

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 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)
Problem p02783 (python)

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

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

print(count)

Buggy 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)
Problem p03448 (python)

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 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))

Buggy 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))
Problem p03545 (python)

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 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])))
Problem p03029 (python)

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

Buggy 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)

Buggy 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)
Problem p02855 (python)

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 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])
Problem p02975 (python)

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 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")
Problem p03061 (python)

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 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))

Buggy 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))
Problem p03282 (python)

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

for i in range(len(s)):
    if s[i] != "1" and i+1 <= k:
        print(s[i])
        exit()

print(1)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

for i in len(s):
    if s[i] != "1" and i+1 <= k:
        print(s[i])
        exit()

print(1)
Problem p03578 (python)

Fixed submission:
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
d.sort()
t.sort()

a = 0
b = 0
cnt = 0
last = t[-1]
for i in range(a, n):
    for j in range(b, m):
        if d[i] == t[j]:
            cnt += 1
            b = j+1
            break
        elif d[i] < t[j]:
            break

if cnt == m:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
d.sort()
t.sort()

l = [0] * (d[-1] + 1)
for i in d:
    l[i] += 1

for i in t:
    l[i] -= 1

l.sort()
if l[0] >= 0:
    print("YES")
else:
    print("NO")
Problem p03627 (python)

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

f = 0
x = 0
for i in range(len(a)-1):
    if a[i] == a[i+1] != x:
        f += 1
    if f == 1:
        x = a[i]
        f += 1
        if a.count(x) >= 4:
          f = 3
    if f >= 3:
        print(x*a[i])
        exit()
print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

f = 0
x = 0
for i in range(len(a)):
    if a[i] == a[i+1] != x:
        f += 1
    if f == 1:
        x = a[i]
        f += 1
        if a.count(x) >= 4:
          f = 3
    if f >= 3:
        print(x*a[i])
        exit()
print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

l = [0] * (a[0]+10)
f = 0
for i in a:
    l[i-1] += 1
    if l[i-1] == 2 or l[i-1] == 4:
        f += 1
    if f == 1:
        x = i
        f += 1
    if f == 3:
        print(x*i)
        exit()
print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

l = [0] * (a[0])
f = 0
for i in a:
    l[i-1] += 1
    if l[i-1] == 2:
        f += 1
    if f == 1:
        x = i
        f += 1
    if f == 3:
        print(x*i)
        exit()
print(0)
Problem p03665 (python)

Fixed submission:
from scipy.misc import comb

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

odd = 0
even = 0
for x in a:
    if x % 2 == 1:
        odd += 1
    else:
        even += 1

s_even = 0
for i in range(even+1):
    s_even += comb(even, i, exact=True)

s_odd = 0
ans = 0
if p == 0:
    for i in range(odd+1)[::2]:
        s_odd += comb(odd, i, exact=True)
        ans = s_even * s_odd
else:
    for i in range(odd)[1::2]:
        s_odd += comb(odd, i, exact=True)
        ans = s_even * s_odd

print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

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

odd = 0
even = 0
for x in a:
    if x % 2 == 1:
        odd += 1
    else:
        even += 1

s_even = 0
for i in range(even):
    s_even += comb(even, i+1, exact=True)

s_odd = 0
ans = 0
if p == 0:
    for i in range(odd)[1::2]:
        s_odd += comb(odd, i+1, exact=True)
        ans = max(1,s_even) * max(1,s_odd) + s_odd
else:
    for i in range(odd)[::2]:
        s_odd += comb(odd, i+1, exact=True)
        ans = max(1,s_even) * max(1,s_odd) + s_odd

print(ans)
Problem p03673 (python)

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

if n%2 == 1:
    r = a[::-2]
    l = a[1::2]
else:
    r = a[::-2]
    l = a[::2]
    
print(*r,end=" ")
print(*l)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

if n%2 == 1:
    r = a[::-2]
    l = a[1::2]
else:
    r = a[::-2]
    l = a[::2]
    
print(*r,*l)
Problem p03848 (python)

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

if n%2:
    a = a[1:]

x = n%2 + 1
for i in range(len(a))[::2]:
    if a[i] != x:
        print(0)
        exit()
    x += 2

print(2**(n//2) % (10**9+7))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int, input().split())))

x = n%2 + 1
for i in range(n)[n%2+2::2]:
    if a[i] != a[i+1] or a[i] - x != 2:
        print(0)
        exit()
    x = a[i]
    
print(2**(n//2) % (10**9+7)
Problem p03759 (python)

Fixed submission:
a, b, c = map(int, input().split())
if b-a == c-b : print('YES')
else: print('NO')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input())
if b-a == c-b : print('YES')
else: print('NO')
Problem p03760 (python)

Fixed submission:
O = input()
E = input()
p = ""
for i in range(len(O)):
    p += O[i]
    if(i < len(E)):
        p += E[i]
print(p)

Buggy submission (verdict: Runtime Error):
O = input()
E = input()
p = ""
for i in range(len(O)):
    p += O[i]
    if(i - 1 < len(E)):
        p += E[i]
print(p)
Problem p03292 (python)

Fixed submission:
def solution(a):
    return max(a) - min(a)
 
def main():
    a = [int(i) for i in raw_input().strip().split()]
    print solution(a)
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def solution(a):
    return max(a) - min(a)
 
def main():
    a = [int(i) for i in raw_input().strip().aplit()]
    print solution(a)

if __name__ == '__main__':
    main()
Problem p02684 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, k = map(int, input().split())
a = list(map(int, input().split()))

length = [-1] * n
path = [-1, []]
route = []


def func(now, depth):
    global path, length, a, route
    route.append(now)
    if length[now] == -1:
        length[now] = depth
        func(a[now]-1, depth+1)
    else:
        path = [length[now], route[length[now]:depth]]


func(0, 0)

if (k < path[0]):
    print(route[k] + 1)
else:
    tmp = k - path[0]
    tmp %= len(path[1])
    print(path[1][tmp] + 1)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))

length = [-1] * n
path = [-1, -1]
route = []


def func(now, depth):
    global path, length, a, route
    route.append(now)
    if length[now] == -1:
        length[now] = depth
        func(a[now]-1, depth+1)
    else:
        path = [length[now], depth - length[now]]


func(0, 0)

print(route[path[0]+(k-path[0]) % path[1]]+1)
Problem p02761 (python)

Fixed submission:
N,M = map(int,input().split())
sc = [[0,0]]*M
ans = [0]*N
f = True
ans = -1
for i in range(M):
    sc[i] = list(map(int,input().split()))

for i in range(1000):
    str_i = list(str(i))
    if (len(str_i) == N):
        f = True
        for j in range(M):
            f &= (str_i[sc[j][0]-1] == str(sc[j][1]))
        if (f):
            ans = i
            break

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
sc = [[0,0]]*M
ans = [0]*N
f = True
ans = -1
for i in range(M):
    sc[i] = list(map(int,input().split()))

for i in range(1000):
    str_i = str(i)
    if (len(str_i) == N):
        f = True
        for j in range(M):
            f &= (str_i[sc[i][0]-1] == str(sc[i][1]))
        if (f):
            ans = i
            break

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
sc = [[0,0]]*M
ans = [0]*N
f = True
for i in range(M):
    sc[i] = list(map(int,input().split()))

for i in range(M):
    ans[sc[i][0]-1] = str(sc[i][1])

sc.sort()
for i in range(M-1):
    if (sc[i][0] == sc[i+1][0]):
        if (sc[i][1] != sc[i+1][1]):
            f = False

if (f):
    for i in range(M):
        ans[i] = str(ans[i])

    if (ans[0] == "0"):
        if (N == 1):
            print(0)
        else:
            print(-1)
    else:
        print("".join(ans))
else:
    print(-1)
Problem p02865 (python)

Fixed submission:
n = int(input())
if (n % 2 == 0):print(n//2-1)
else : print(n//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
db = [0] * n
MOD = 998244353

#距離iの頂点の数をdb[i]に保存
for i in range(n):
    db[d[i]] += 1

#末尾に連続する0を削除
if (db[n-1] == 0):
    l = n-1
    for i in range(1,n):
        tmp = db[n-i]
        if (tmp == 0) : l = n-i 
        else : break
    
    del db[l:n]


if (d[0] != 0)|(db[0] != 1):
    print(0)
    exit()
if (len(db) <= 2):
    print(len(db)-1)
    exit()

db.append(1)
ans = 1

for i in range(len(db)-1):
    tmp = (db[i]**db[i+1]) % MOD
    ans *= tmp

print(ans)
Problem p02882 (python)

Fixed submission:
# D Water_Bottle
import math
a,b,x = map(int,input().split(" "))
x /= a
if (x == a*b):
    #水筒が満タンの場合
    print(0)
elif (x > a*b/2):
    #水筒の半分の容積より水の容積が大きかった場合
    ha = a/2
    print(90-math.degrees(math.atan(ha/(b-(x/a)))))
else:
    #水の容積が水筒の半分の容積以下だった場合
    c = 2*x/b
    print(90-math.degrees(math.atan(c/b)))

Buggy submission (verdict: Runtime Error):
# D Water_Bottle
import math
a,b,x = map(int,input().split(" "))
x /= a
if (x > a*b/2):
    #水筒の半分の容積より水の容積が大きかった場合
    ha = a/2
    print(90-math.degrees(math.atan(ha/(b-(x/a)))))
else:
    #水の容積が水筒の半分の容積以下だった場合
    c = 2*x/b
    print(90-math.degrees(math.atan(c/b)))
Problem p02900 (python)

Fixed submission:
import fractions
import math

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

g = fractions.gcd(a,b)
ans = 0
sqrtg = math.ceil(math.sqrt(g))
for i in range(2,sqrtg):
    #割り切れるなら割り切れなくなるまでiで割り続ける
    if (g%i == 0):
        ans += 1
        while (g % i == 0):
            g //= i
            
if (g != 1):
    ans += 1
print(ans+1)

Buggy submission (verdict: Runtime Error):
import math

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

g = math.gcd(a,b)
ans = 0
sqrtg = math.ceil(math.sqrt(g))+1
for i in range(2,sqrtg):
    #割り切れるなら割り切れなくなるまでiで割り続ける
    if ((g // i * i == g)):
        ans += 1
        while (g // i * i == g):
            g //= i

print(ans+1)
Problem p02995 (python)

Fixed submission:
from fractions import gcd
a = list(map(int,input().split()))

def fun(x,c,d):
    return x - div(x,c) - div(x,d) + div(x,c*d//gcd(c,d))

def div(a,b):
    return a // b

print(fun(a[1],a[2],a[3])-fun(a[0]-1,a[2],a[3]))

Buggy submission (verdict: Runtime Error):
from math import gcd
a = list(map(int,input().split()))

def fun(x,c,d):
    return x - div(x,c) - div(x,d) + div(x,c*d//gcd(c,d))

def div(a,b):
    return a // b

print(fun(a[1],a[2],a[3])-fun(a[0]-1,a[2],a[3]))
Problem p03061 (python)

Fixed submission:
from fractions import gcd as m_gcd

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


def gcd(a, b):
    if a == 0 or b == 0:
        return max(a, b)
    return m_gcd(a, b)


l = [0] * (n + 2)
r = [0] * (n + 2)
ans = [0] * n

for i in range(1, n+1):
    l[i] = gcd(l[i - 1], a[i - 1])
    r[n - i + 1] = gcd(r[n - i + 2], a[n - i])

for i in range(1, n + 1):
    ans[i-1] = gcd(l[i-1], r[i+1])

print(max(ans))

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = sorted(input().split(" "))
    ans = [0]*N
    for i in range(N):
        tmp = A[i]
        if (i == N-1):
            A[i] = A[N-2]
        else :
            A[i] = A[N-1]
        ans.append(recursive_gcd(N,A))
        A[i] = tmp
    print(max(ans))


def recursive_gcd(n,array):
    if (n <= 2):
        return gcd_euclid(int(array[0]),int(array[1]))
    else:
        return gcd_euclid(recursive_gcd(n-1,array),int(array[n-1]))

# http://d.hatena.ne.jp/sh-2/20100320/1269039543 から引用
def gcd_euclid(u, v) :
  while (0 != v) :
    r = u % v
    u = v
    v = r
  return u
#引用ここまで

if __name__ == "__main__":
    main()
Problem p03150 (python)

Fixed submission:
s = list(input())
ls = len(s)
key = "keyence"
if "".join(s) == key:
    print("YES")
    exit()
f = False
for l in range(ls):
    for r in range(l + 1, ls):
        f |= "".join(["".join(s[:l]), "".join(s[r:])]) == key

print("YES" if f else "NO")

Buggy submission (verdict: Runtime Error):
s = input()
key = "keyence"
ptr = 0

for c in s:
    if c == key[ptr]:
        ptr += 1

print("YES" if ptr == 7 else "NO")
Problem p03200 (python)

Fixed submission:
s = list(input())
ls = len(s)
ss = sorted(s, reverse=True)
cnt = [0, 0]
ans = 0
w = 0

while ss[w] == "W":
    w += 1
    if ls == w:
        break

for i in range(ls):
    if s[i] == "B":
        ans += w + cnt[0] - i
    else:
        ans += i - cnt[1]
    cnt[s[i] != "B"] += 1

print(ans//2)

Buggy submission (verdict: Runtime Error):
s = list(input())
ls = len(s)
ss = sorted(s, reverse=True)
cnt = [0, 0]
ans = 0
w = 0
while ss[w] == "W":
    w += 1

for i in range(ls):
    if s[i] == "B":
        ans += w + cnt[0] - i
    else:
        ans += i - cnt[1]
    cnt[s[i] != "B"] += 1

print(ans//2)