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

Fixed submission:
n = int(input())
d,m = divmod(n,2)
if m != 0:
    print(n*d)

else:
    print(n*(d - 1) + d)

Buggy submission (verdict: Runtime Error):
n = int(input())
d, m = divmod(n,2)
if m != 0
    print(n*d)

else:
    print(n*(d - 1) + d)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
print(np.sum(np.arange(n)))
Problem p02947 (python)

Fixed submission:
def count(data):
    dic = {}
    for d in data:
        if d in dic:
            dic[d] += 1
        else:
            dic[d] = 1
    return dic

n = int(input())
counts = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in counts:
        counts[s] += 1
    else:
        counts[s] = 1

ans = 0
for v in counts.values():
    ans += (v*(v-1))//2
print(ans)

Buggy submission (verdict: Runtime Error):
def count(data):
    dic = {}
    for d in data:
        if d in dic:
            dic[d] += 1
        else:
            dic[d] = 1
    return dic

n = int(input())
data = []
for _ in range(n):
    s = input()
    data.append(count(s))
ans = 0
for i in range(n):
    for ii in range(i+1, n):
        if data[i] == data[ii]|:
            ans += 1
print(ans)
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())
if r - l >= 2019:
    print(0)
    exit()

l = l%2019
r = r%2019

if l >= r:
    print(0)
else:
    ans = float('inf')
    for left in range(l, r):
        for right in range(left+1, r+1):
            ans = min(ans, (left*right)%2019)
    print(ans)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())
if r - l >= 2019:
    print(0)
    exit()

l = l%2019
r = r%2019

if l >= r:
    print(0)
else:
    ans = float('inf')
    for left in range(l, r+1):
        for right in range(left+1, r+1):
            # ans = min(ans, (left*right)%2019)
            score = (left*right)%2019
            if score < ans:
                print(f'{left}, {right}: {score}')
                ans = score
    print(ans)
Problem p03001 (python)

Fixed submission:
w, h, x, y = map(int, input().split())
multi = 1 if 2*x == w and 2*y == h else 0
print(w*h/2, multi)

Buggy submission (verdict: Runtime Error):
w, h, x, y = map(int, input().split())
multi = 1 if 2*x == w and 2**y == h else 0
print(w*b/2, multi)
Problem p03231 (python)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd (a, b) * b

n, m = map(int, input().split())
s = input()
t = input()

ans = lcm(n, m)

chk = {}

for i in range(n):
    d = ans//n
    chk[i*d] = s[i]
for i in range(m):
    d = ans//m
    if i*d in chk and chk[i*d] != t[i]:
        print(-1)
        exit()
print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd (a, b) * b

n, m = map(int, input().split())
s = input()
t = input()

ans = lcm(n, m)

chk = [None]*ans

for i in range(n):
    d = ans//n
    chk[i*d] = s[i]
for i in range(m):
    d = ans//m
    target = chk[i*d]
    if target is not None and target != t[i]:
        print(-1)
        exit()
print(ans)
Problem p03425 (python)

Fixed submission:
from operator import mul
from functools import reduce

def cmb(n,r):
    if n < r: return 0
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n = int(input())
ss = [input() for _ in range(n)]
march = ['M','A','R','C','H']
d = dict(zip(march, [0]*5))

nn = 0

for s in ss:
    if s[0] in march:
        d[s[0]] += 1
        nn += 1
if nn < 3:
    print(0)
    exit()

ans = cmb(nn, 3)
for i in d.values():
    if i >= 2:
        if i > 3:
            ans -= cmb(i, 3)
        ans -= cmb(i,2)*(nn-i)

print(int(ans))

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

march = ['M','A','R','C','H']
d = dict(zip(march, [0]*5))

nn = 0

for s in ss:
    if s[0] in march:
        d[s[0]] += 1
        nn += 1

ans = cmb(nn, 3)
for i in d.values():
    if i >= 2:
        if i > 3:
            ans -= cmb(i, 3)
        ans -= cmb(i,2)*(nn-i)

print(int(ans))

Buggy submission (verdict: Runtime Error):
from scipy.special import comb
def cmb(n,r):
    return comb(n, r)

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

march = ['M','A','R','C','H']
d = dict(zip(march, [0]*5))

nn = 0

for s in ss:
    if s[0] in march:
        d[s[0]] += 1
        nn += 1

ans = comb(nn, 3)
for i in d.values():
    if i >= 2:
        if i > 3:
            ans -= comb(i, 3)
        ans -= comb(i,2)*(nn-i)

print(int(ans))
Problem p03838 (python)

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

def cal(a,b):
    if a < b:
        dist1 = b - a
        dist2 = abs(b + a) + 1
        return min(dist1, dist2)
    elif a > b:
        if a >= 0 and b <= 0:
            return abs(a+b) + 1

        else:
            return a - b + 2

print(cal(a,b))

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

def cal(a,b):
    if a < b:
        dist1 = b - a
        dist2 = abs(b + a) + 1
        return min(dist1, dist2)
    elif a > b:
        if a >= 0 and b < 0:
            return abs(a+b) + 1
        else:
            dist1 = a - b + 2
        return min(dist1, dist2)

print(cal(a,b))
Problem p03945 (python)

Fixed submission:
import re
string = input()
ans = 0
for i in range(len(string)-1):
    if string[i] != string[i+1]:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
string = input()
ans = 0
for i in range(len(string)-1):
    if string[i] != string[i+1]:
        ans += 1
if string[-1] != string[-2]:
    ans += 1
if ans > 0:
    print(ans-1)
else:
    print(ans)
Problem p02612 (python)

Fixed submission:
import math
n = int(input())
print((math.floor((n - 1) / 1000) + 1) * 1000 - n)

Buggy submission (verdict: Runtime Error):
n = int(input())
print(n - (math.floor(n - 1 / 1000) + 1) * 1000)
Problem p02613 (python)

Fixed submission:
n = int(input())
ac = wa = tle = re = 0
for i in range(n):
  s = input()
  if s == "AC":
    ac += 1
  elif s == "WA":
    wa += 1
  elif s == "TLE":
    tle += 1
  elif s == "RE":
    re += 1
print("AC x", ac)
print("WA x", wa)
print("TLE x ", tle)
print("RE x", re)

Buggy submission (verdict: Runtime Error):
n = int(input())
ac = wa = tle = re = 0
for i in range(n):
  s = input()
  if s = "AC":
    ac += 1
  elif s = "WA":
    wa += 1
  elif s = "TLE":
    tle += 1
  elif s = "RE":
    re += 1
print("AC x", ac)
print("WA x", wa)
print("TLE x ", tle)
print("RE x", re)
Problem p02621 (python)

Fixed submission:
a = int(input())
print(a + a ** 2 + a ** 3)

Buggy submission (verdict: Runtime Error):
a = input()
print(a + a ** 2 + a ** 3)
Problem p02657 (python)

Fixed submission:
data = input().split()
print(int(data[0])*int(data[1]))

Buggy submission (verdict: Runtime Error):
print(int(input())*int(input()))
Problem p02687 (python)

Fixed submission:
print("ABC" if input() == "ARC" else "ARC")

Buggy submission (verdict: Runtime Error):
if input() == ABC:
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
if input() == ABC:print("ARC") else:print("ABC")
Problem p02717 (python)

Fixed submission:
data = input().split()
i = [int(n) for n in data]
res = "{} {} {}"
print(res.format(i[2], i[0], i[1]))

Buggy submission (verdict: Runtime Error):
data = input().split()

i = [int(n) for n in data]

print(f"{i[2]} {i[0]} {i[1]}")
Problem p02718 (python)

Fixed submission:
data = input().split()
 
n = int(data[0])
m = int(data[1])
 
pro = [int(s) for s in input().split()]
 
vote = 0
for i in pro:
  vote += i
 
s_pro = sorted(pro, reverse=True)

if s_pro[m - 1] < vote * 1 / (4 * m):
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
data = input().split()

n = int(data[0])
m = int(data[1])

pro = [int(s) for s in input().split()]

vote = 0
for i in pro:
  vote += i

pro.sort(reverse=true)

if pro[m - 1] < 1 / (4 * vote):
  print("No")
else:
  print("Yes")
Problem p02755 (python)

Fixed submission:
data = input().split()

a = int(data[0])
b = int(data[1])

n = min(int(a / 0.08), int(b / 0.1))

def lookup():    
    for i in range(n, 10000):
        tax_a = int(i * 0.08)
        tax_b = int(i * 0.1)
        if tax_a == a and tax_b == b:
            print(i)
            return
    print(-1)

lookup()

Buggy submission (verdict: Runtime Error):
data = input().split

a = int(data[0])
b = int(data[1])

pricea = a // 0.08
priceb = b // 0.1

if a == b:
  ans = a
elif a + 1 == b:
  ans = b
elif a == b + 1:
  ans = a
else:
  ans = -1
  
print(ans)
Problem p02765 (python)

Fixed submission:
data = input().split()

n = int(data[0])
r = int(data[1])

if n < 10:
  ans = r + 100 * (10 - n)
else:
  ans = r

print(ans)

Buggy submission (verdict: Runtime Error):
data = input().split()
if int(data[0]) > 10:
  ans = data[1]
else:
  ans = data[1] - 100 * (10 - int(data[0]))
 
print(ans)

Buggy submission (verdict: Runtime Error):
data = input().split()
if int(data[0]) > 10:
  ans = data[1]
else:
  ans = 100 * (10 - data[0])

print(ans)
Problem p02772 (python)

Fixed submission:
n = int(input())
data = input().split()
 
ans = "APPROVED"
 
for i in range(n):
  num = int(data[i])
  if num % 2 == 0:
    if num % 3 != 0 and num % 5 != 0:
      ans = "DENIED"
      break  
 
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
data = input().split()
 
ans = "APPROVED"
 
for i in range(n):
  num = int(data[i])
  if num % 2 == 0 and (num % 3 != 0 or num % 5 != 0)
    ans = "DENIED"
    break
 
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
data = input().split()

ans = "APPROVED"

for i in range(n):
  num = int(data[i])
  if !(num % 6 == 0 or num % 10 == 0):
    ans = "DENIED"
    break

print(ans)
Problem p02786 (python)

Fixed submission:
import math
 
n = int(input())
kaisu = math.log2(n) + 1
ans = 0
 
for i in range(int(kaisu)):
  ans += 2 ** i
 
print(ans)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
kaisu = math.log2(n)
ans = 0

for i in range(kaisu):
  ans += 2 ** i

print(ans)
Problem p02789 (python)

Fixed submission:
data = input().split()
 
n = data[0]
m = data[1]
 
if n == m:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
data = input()

n = int(data[0])
m = int(data[1])

if n == m:
  print("Yes")
else:
  print("No")
Problem p02811 (python)

Fixed submission:
data = input().split()
k = int(data[0])
x = int(data[1])
 
if k * 500 >= x:
  print("Yes")
else:
  print("No")

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

if k * 500 >= x:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
data = input().spilt()

k = int(data[0])
x = int(data[1])

if x <= 500 * k:
  print("Yes")
else:
  print("No")
Problem p02574 (python)

Fixed submission:
# E - Coprime

import math
from functools import reduce

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

if reduce(math.gcd, a) > 1:
    print("not coprime")
    exit()

def factors(n):
    """Return the list of prime factors of n."""
    fac = set()
    sqrtn = math.sqrt(n)
    d = 2
    while d <= sqrtn:
        if n % d == 0:
            fac.add(d)
            n //= d
        else:
            d += 1
    if n > 1:
        fac.add(n)
    return fac

count = [0] * (10 ** 6 + 1)
for x in a:
    for f in factors(x):
        count[f] += 1
        if count[f] > 1:
            print("setwise coprime")
            exit()
print("pairwise coprime")

Buggy submission (verdict: Runtime Error):
# E - Coprime

import math
from functools import reduce
from itertools import chain
from collections import Counter

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

if reduce(math.gcd, a) > 1:
    print("not coprime")
    exit()

def factors(n):
    """Return the list of prime factors of n."""
    fac = set()
    d = 2
    while d <= math.sqrt(n):
        if n % d == 0:
            fac.add(d)
            n //= d
        else:
            d += 1
    if n > 1:
        fac.add(n)
    return fac

c = Counter(chain.from_iterable(map(factors, a)))
if max(c.values()) > 1:
    print("setwise coprime")
else:
    print("pairwise coprime")
Problem p02702 (python)

Fixed submission:
# D - Multiple of 2019

s = input()

# pow[k] = 10 ** k % 2019
pow = [1]
while len(pow) <= 1 or pow[-1] > 1:
    pow.append(pow[-1] * 10 % 2019)
n = len(pow) - 1  # 10 ** n == 1 mod 2019

# memo[i % n][m] = (int(s[:i+1]) % 2019 == mであるiの個数)
memo = [[0] * 2019 for i in range(n)]
memo[n - 1][0] = 1  # memo[-1][0] = 1

count = 0  # int(s[i:j+1]) == 0 mod 2019 である(i,j)の個数
mod = 0
for j, c in enumerate(s):
    mod = (mod * 10 + int(c)) % 2019  # mod = int(s[:j+1]) % 2019
    for i in range(1, n + 1):
        m = mod * pow[n - i] % 2019  # m == mod * 10 ** (-i) mod 2019
        count += memo[(j - i + n) % n][m]
    memo[j % n][mod] += 1

print(count)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# D - Multiple of 2019

s = input()

count = 0
counter = Counter([0])

suffix = 0
pow = 1
for i in range(len(s) - 1, -1, -1):
    suffix = (int(s[i]) * pow + suffix) % 2019
    pow = pow * 10 % 2019
    count += counter[suffix]
    counter[suffix] += 1

print(count)
Problem p02996 (python)

Fixed submission:
from itertools import accumulate

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

# earliest deadline first
AB.sort(key=lambda x: x[1])

# 累積時刻とデッドライン
tB = accumulate(AB, lambda x, y: (x[0] + y[0], y[1]))

yes = all(t <= b for t, b in tB)
print('Yes' if yes else 'No')

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

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

# earliest deadline first
AB.sort(key=lambda x: x[1])

# 累積時刻とデッドライン
tB = accumulate(AB, lambda x, y: (x[0] + y[0], y[1]))

yes = all(t <= b for t, b in tB)
print('Yes' if yes else 'No')
Problem p03061 (python)

Fixed submission:
# math.gcd is introduced in python 3.5
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a

N = int(input())
A = [int(a) for a in input().split()]

# L[i] = gcd(A[:i + 1])
# R[i] = gcd(A[i:])
L = [0] * N
L[0] = A[0]
for i in range(1, N):
    L[i] = gcd(L[i-1], A[i])
R = [0] * N
R[-1] = A[-1]
for i in range(N - 2, -1, -1):
    R[i] = gcd(R[i+1], A[i])

G = [0] * N
G[0]  = R[1]
G[-1] = L[-2]
for i in range(1, N - 1):
    G[i] = gcd(L[i-1], R[i+1])

print(max(G))

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
A = [int(a) for a in input().split()]

# L[i] = gcd(A[:i + 1])
# R[i] = gcd(A[i:])
L = [0] * N
L[0] = A[0]
for i in range(1, N):
    L[i] = math.gcd(L[i-1], A[i])
R = [0] * N
R[-1] = A[-1]
for i in range(N - 2, -1, -1):
    R[i] = math.gcd(R[i+1], A[i])

G = [0] * N
G[0]  = R[1]
G[-1] = L[-2]
for i in range(1, N - 1):
    G[i] = math.gcd(L[i-1], R[i+1])

print(max(G))
Problem p03074 (python)

Fixed submission:
import itertools

N, K = map(int, input().split())
S = input()
assert len(S) == N

# list of run-length
runlen = [len(list(g)) for k, g in itertools.groupby(S)]

# runlen starts and ends with the length of a run of '1'
if S[0] == '0':
    runlen = [0] + runlen
if S[-1] == '0':
    runlen = runlen + [0]

# list of sum of runlen[i : i + k]
k = 2 * K + 1
s = sum(runlen[:k])
sublen = [s]
for i in range(2, N - k, 2):
    s -= sum(runlen[i - 2 : i])
    s += sum(runlen[i - 2 + k : i + k])
    sublen.append(s)

print(max(sublen))

Buggy submission (verdict: Runtime Error):
import itertools

N, K = map(int, input().split())
S = input()
assert len(S) == N

# list of run-length
runlen = [len(list(g)) for k, g in itertools.groupby(S)]

# runlen starts and ends with the length of a run of '1'
if S[0] == '0':
    runlen = [0] + runlen
if S[-1] == '0':
    runlen = runlen + [0]

# list of sum of runlen[i : i + k]
k = 2 * K + 1
sublen = [sum(runlen[i : i + k]) for i in range(0, N - k, 2)]

print(max(sublen))
Problem p03241 (python)

Fixed submission:
import math

N, M = map(int, input().split())

if N == 1:
    print(M)
else:
    d = max(d for d in range(1, math.ceil(M / (N - 1))) if M % d == 0)
    print(d)

Buggy submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())

d = max(d for d in range(1, math.ceil(M / (N - 1))) if M % d == 0)
print(d)
Problem p03262 (python)

Fixed submission:
import fractions

N, X   = map(int, input().split())
x = list(map(int, input().split()))
assert len(x) == N

x.sort()

# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]

# distance between the first city and the start point
dist.append(abs(x[0] - X))

def listgcd(xs):
    g = xs[0]
    for i in range(1, len(xs)):
        g = fractions.gcd(g, xs[i])
    return g

print(listgcd(dist))

Buggy submission (verdict: Runtime Error):
import fraction

N, X   = map(int, input().split())
x = list(map(int, input().split()))
assert len(x) == N

x.sort()

# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]

# distance between the first city and the start point
dist.append(abs(x[0] - X))

def listgcd(xs):
    g = xs[0]
    for i in range(1, len(xs)):
        g = fraction.gcd(g, xs[i])
    return g

print(listgcd(dist))

Buggy submission (verdict: Runtime Error):
import math

N, X   = map(int, input().split())
x = list(map(int, input().split()))
assert len(x) == N

x.sort()

# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]

# distance between the first city and the start point
dist.append(abs(x[0] - X))

def listgcd(xs):
    g = xs[0]
    for i in range(1, len(xs)):
        g = math.gcd(g, xs[i])
    return g

print(listgcd(dist))
Problem p03267 (python)

Fixed submission:
L = int(input())

def decompose(L):
    if L < 3:
        return [L]
    r = L % 3
    return [r] + decompose((L - r) // 3)

dec = decompose(L)

N = len(dec) + 1
edge = []

for w in range(dec[-1]):
    edge.append((N-1, N, w))

base = dec[-1]
for i in range(len(dec) - 2, -1, -1):
    for w in range(3):
        edge.append((i+1, i+2, w * base))
    base = 3 * base
    for w in range(dec[i]):
        edge.append((i+1, N, base + w))
    base += dec[i]

M = len(edge)
print(N, M)
for e in edge:
    print(' '.join(map(str, e)))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

from math import log2, floor

L = int(input())

N = floor(log2(L)) + 1
edge = []

# 長さ0の辺
for i in range(1, N):
    edge.append((i, i+1, 0))

# 長さ2**(i-1)の辺
for i in range(1, N):
    edge.append((i, i+1, 2**(i-1)))

# ここまでで長さ0,...,X-1のパスが完成
X = 2 ** (N-1)

# 残りの辺
while L > X:
    r = floor(log2(L - X))
    edge.append((r + 1, N, X))
    X += 2 ** r

# 出力
M = len(edge)
print(N, M)
for e in edge:
    print(' '.join(map(str, e)))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env pypy3
# -*- coding: utf-8 -*-

from math import log2, floor

L = int(input())

N = floor(log2(L)) + 1
edge = []

# 長さ0の辺
for i in range(1, N):
    edge.append((i, i+1, 0))

# 長さ2**(i-1)の辺
for i in range(1, N):
    edge.append((i, i+1, 2**(i-1)))

# ここまでで長さ0,...,X-1のパスが完成
X = 2 ** (N-1)

# 残りの辺
while L > X:
    r = floor(log2(L - X))
    edge.append((r + 1, N, X))
    X += 2 ** r

# 出力
M = len(edge)
print(N, M)
for e in edge:
    print(' '.join(map(str, e)))
Problem p03274 (python)

Fixed submission:
N, K   = map(int, input().split())
x = list(map(int, input().split()))
assert len(x) == N

m = min(x[i] - x[i-K+1] + min(abs(x[i]), abs(x[i-K+1])) for i in range(K-1, N))
print(m)

Buggy submission (verdict: Runtime Error):
N, K   = map(int, input().split())
x = list(map(int, input().split()))
assert len(x) == N

m = min(x[i] - x[i-K+1] + min(abs(x[i], abs(x[i-K+1])) for i in range(K-1, N))
print(m)
Problem p03288 (python)

Fixed submission:
R = int(input())

if R < 1200:
  print('ABC')
elif R < 2800:
  print('ARC')
else:
  print('AGC')

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
from math import ceil
 
D, G = [int(t) for t in input().split()]
p = []
c = []
for i in range(D):
    p_, c_ = [int(t) for t in input().split()]
    p.append(p_)
    c.append(c_)
 
def minsolve(G, p, c, i):
    """100i点以下の問題だけでGを達成する最小問題数"""
    if i <= 0:
        return float('inf')
    n = min(ceil(G / (100 * i)), p[i-1])
    s = 100 * i * n
    if n == p[i-1]:
        s += c[i-1]
    if s >= G:
        return min(n, minsolve(G, p, c, i-1))
    else:
        return min(n + minsolve(G - s, p, c, i-1), minsolve(G, p, c, i-1))
 
m = min(minsolve(G, p, c, i) for i in range(1, D+1))
print(m)
Problem p03550 (python)

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

from sys import stdin

def solve(a):
  n = len(a)
  xmemo = [0 for i in range(n)]  # player X の手番での最適スコア
  ymemo = [0 for i in range(n)]  # player Y 　　　〃

  # 自分がj (< i) 枚目, 相手がi枚目を持っている
  for i in range(n - 2, -1, -1):
    # 自分が取り切ったときのスコア
    f = abs(a[i] - a[n - 1])
    # j, i の差が何枚でも同じ
    xmemo[i] = max([f] + [ymemo[jj] for jj in range(i + 1, n - 1)])
    ymemo[i] = min([f] + [xmemo[jj] for jj in range(i + 1, n - 1)])

  return xmemo[1]

N, Z, W = map(int, stdin.readline().split())
a       = map(int, stdin.readline().split())
if len(a) != N: raise

# Z, Wを山の先頭に置く
a = [Z, W] + a

print(solve(a))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python
# coding: utf-8

from sys import stdin

memo = {}

# それぞれ z 枚目, w 枚目を持っている局面での最適解
def solve(z, w, player):
  global a, memo
  n = max(z, w) + 1  # 取り終わっている枚数
  if n == len(a): return abs(a[z] - a[w])
  if (z, w, player) in memo: return memo[(z, w, player)]

  m      = 0   if player == 0 else 1000000000
  minmax = max if player == 0 else min
  for i in range(n, len(a)):
    if player == 0: zz = i; ww = w
    else:           ww = i; zz = z
    m = minmax(m, solve(zz, ww, 1 - player))
  memo[(z, w, player)] = m
  return m

N, Z, W = map(int, stdin.readline().split())
a       = map(int, stdin.readline().split())
if len(a) != N: raise

# Z, Wを山の先頭に置く
a = [Z, W] + a

print(solve(0, 1, 0))
Problem p03565 (python)

Fixed submission:
#!/usr/bin/python

# AtCoder Beginner Contest 076
# C - Dubious Document 2

from sys import stdin

def match(S, pos, T):
  for i in range(len(T)):
    if S[pos + i] != '?' and S[pos + i] != T[i]:
      return False
  return True

def solve(S, T):
  minS = '~' * len(S)
  for pos in range(len(S) - len(T) + 1):
    # S[pos : pos + len(T)] matches T ?
    if match(S, pos, T):
      S_ = S[:pos] + T + S[pos + len(T):]       # replace the mid part with T
      S_ = [c if c != '?' else 'a' for c in S_] # replace '?' with 'a'
      if minS > S_: minS = S_
  return ''.join(minS) if minS[0] != '~' else 'UNRESTORABLE'

S = stdin.readline().strip()
T = stdin.readline().strip()
print(solve(S, T))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python

# AtCoder Beginner Contest 076
# C - Dubious Document 2

from sys import stdin

def match(S, pos, T):
  for i in range(len(T)):
    if S[pos + i] != '?' and S[pos + i] != T[i]:
      return False
  return True

def solve(S, T):
  minS = '~' * len(S)
  for pos in range(len(S) - len(T) + 1):
    # S[pos : pos + len(T)] matches T ?
    if match(S, pos, T):
      S_ = S[:pos] + T + S[pos + len(T):]       # replace the mid part with T
      S_ = [c if c != '?' else 'a' for c in S_] # replace '?' with 'a'
      if minS > S_: minS = S_
  return ''.join(minS) if minS[0] != '~' else 'UNRESTORABLE'

S = stdin.readline().strip()
T = stdin.readline().strip()
print(solve(S, T))
Problem p02969 (python)

Fixed submission:
r = int(input())

print(3 * (r * r))

Buggy submission (verdict: Runtime Error):
n = int(input())

a = [int(input()) for i in range(n)]
a_max = max(a)
a2 = a[:]
a2.remove(a_max)
a_second_max = max(a2)

for i in range(n):
    if a[i] == a_max:
        print(a_second_max)
    else:
        print(a_max)