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

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

l = [input() for i in range(a)]

l.sort()
print("".join(l))

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

l = [input() for i in range(b)]

l.sort()
print("".join(l))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

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

l = [input() for i in range(b)]

l = sorted(l)
new_l = ''.join(l)
print(new_l)
Problem p02696 (python)

Fixed submission:
import math
a, b, n = map(int, input().split())
x = min(b - 1, n)
print(math.floor(a * x / b) - a * math.floor(x / b))

Buggy submission (verdict: Runtime Error):
import numpy as np
a, b, n = map(int, input().split())
x = np.arange(1, b+1)
y = np.floor(a * x / b) - a * np.floor(x / b)
print(y)
print(int(y.max()))

Buggy submission (verdict: Runtime Error):
import numpy as np
a, b, n = map(int, input().split())
x = np.arange(1 + (n // b), n + 1)
y = np.floor(a * x / b) - a * np.floor(x / b)
print(int(y.max()))

Buggy submission (verdict: Runtime Error):
import numpy as np
a, b, n = map(int, input().split())
x = np.arange(1, n + 1)
y = np.floor(a * x / b) - a * np.floor(x / b)
print(int(y.max()))

Buggy submission (verdict: Runtime Error):
import numpy as np
a, b, n = map(int, input().split())
x = np.arange(1, n + 1)
y = np.floor(a * n / b) - a * np.floor(n / b)
print(int(y.max()))
Problem p02761 (python)

Fixed submission:
import sys
n, m = map(int, input().split())
d = [10] * n
if m == 0:
    if n == 1:
        print(0)
        sys.exit()
    else:
        print('1' + (n - 1) * '0')
        sys.exit()
for _ in range(m):
    s, c = map(int, input().split())
    s = s - 1
    if d[s] == 10:
        d[s] = c
    elif d[s] != c:
        print(-1)
        sys.exit()
if d[0] == 0:
    if n == 1:
        print(0)
        sys.exit()
    else:
        print(-1)
        sys.exit()
if d[0] == 10:
    d[0] = 1
for i in d:
    print(0, end='') if i == 10 else print(i, end='')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
import sys
s = []
c = []
d = [-1] * n
for _ in range(m):
    i, j = map(int, input().split())
    if i == 1 and j == 0:
        print(-1)
        sys.exit()
    if d[i-1] == -1 or d[i-1] == j:
        d[i-1] = j
    else:
        print(-1)
        sys.exit()
    s.append(i)
    c.append(j)

if max(s) > n:
    print(-1)
    sys.exit()
else:
    for i, j in enumerate(d):
        if j == -1:
            if i == 0:
                continue
            else:
                d[i] = 0
print(*d, sep='')
Problem p02780 (python)

Fixed submission:
import sys
n, k = map(int, input().split())
p = [int(i) for i in input().split()]
total = [0] * n
total[0] = sum(range(1, p[0] + 1)) / p[0]
max_value = 0
if k == 1:
    print(sum(range(1, max(p) + 1)) / max(p))
    sys.exit()
elif k == n:
    print(sum([sum(range(1, i + 1)) / i for i in p]))
    sys.exit()
for i in range(1, n):
    total[i] = total[i - 1] + sum(range(1, p[i] + 1)) / p[i]
    
    if i == k - 1:
        max_value = total[i]
    elif i >= k:
        max_value = max(max_value, total[i] - total[i - k])
print(max_value)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
def f(x):
    return sum(range(1, x + 1)) / x
p = [f(int(i)) for i in input().split()]
s = np.cumsum(p)
print(max(s[k-1], max(s[k:] - s[:n - k])))
Problem p02791 (python)

Fixed submission:
n = int(input())
p = [int(i) for i in input().split()]
count = 0
min_value = p[0]
for i in p:
    if i <= min_value:
        count += 1
        min_value = i
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = [int(i) for i in input().split()]
count = 0
min_value = p[0]
for i in enumerate(p):
    if i <= min_value:
        count += 1
        min_value = i
print(count)
Problem p02841 (python)

Fixed submission:
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
if m2 == m1+1 and d2 == 1:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
if m2 = m1+1 and d2 = 1:
    print(1)
else
    print(0)
Problem p02900 (python)

Fixed submission:
import math
from fractions import gcd
a, b = map(int, input().split())
g = gcd(a, b)
sqrt = math.floor(g ** 0.5)
factors = [1]
z = g
for i in range(2, sqrt + 1):
    if not z % i:
        factors.append(i)
        while z % i == 0:
            z //= i
if z > 1:
    factors.append(z)
print(len(factors))

Buggy submission (verdict: Runtime Error):
import math
from fractions import gcd
a, b = map(int, input().split())
g = gcd(a, b)
sqrt = math.floor(g ** 0.5)
factors = [1]
z = g
for i in range(2, sqrt + 1):
    if not z % i:
        factors.append(i)
        while z % i == 0:
            z //= i
if z > 1:
    factors.append(i)
print(len(factors))
Problem p02924 (python)

Fixed submission:
n = int(input())
ans = n * (n - 1) // 2
print(ans)

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

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.arange(1, n + 1)
b = np.hstack((np.arange(2, n + 1), 1))
print(np.sum(a % b))
Problem p02953 (python)

Fixed submission:
n = int(input())
h = [int(i) for i in input().split()]
h.reverse()
next = h[0]
import sys
for i in h[1:]:
    if i - next > 1:
        print('No')
        sys.exit()
    elif i - next == 1:
        next = i - 1
    else:
        next = i
print('Yes')

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
n = int(input())
h = [int(i) for i in input().split()]
if n == 1:
    print('Yes')
    sys.exit()

diff_h = np.diff(h)
diff_h[diff_h >= 0] = 0
if np.count_nonzero(diff_h) > 1:
    print('No')
elif np.min(diff_h) < -1:
    print('No')
else:
    a = diff_h.nonzero()
    a = a[0][0]
    if (h[a] == h[a-1]) and a>0:
        print('No')
    else:
        print('Yes')
Problem p03024 (python)

Fixed submission:
s = input()
print('YES') if (s.count('o')+15-len(s) >= 8) else print('NO')

Buggy submission (verdict: Runtime Error):
s = input()
print('YES') if (s.count('o')+15-len(k) >= 8) else print('NO')

Buggy submission (verdict: Runtime Error):
s = input()
print('YES') if s.count('o')+15-k >= 8 else print('NO')
Problem p03048 (python)

Fixed submission:
r,g,b,n = map(int, input().split())
count = 0
c0,c1,c2 = sorted([r,g,b])
for i in range(1+n//c2):
    rest1 = n - i*c2
    if rest1 < 0:
        break
    for j in range(1+rest1//c1):
        rest = n - i*c2 - j*c1
        if rest <0:
            break
        elif rest%c0 == 0:
            count += 1
print(count)

Buggy submission (verdict: Runtime Error):
r,g,b,n = map(int, input().split())
count = 0
c1,c2,c3 = sorted([r,g,b])
for i in range(1+n//c2):
    for j in range(1+n//c1):
        rest = n - i*c2 - j*c1
        if rest%c0 == 0 and rest >= 0:
            count += 1
print(count)
Problem p03059 (python)

Fixed submission:
A, B, T = map(int, input().split())

def biscuit_gen(A,B,T):
    total = 0
    num = int(T//A)
    return B*num

n = biscuit_gen(A,B,T)
print(n)

Buggy submission (verdict: Runtime Error):
A, B, T = map(int, input().split())

def biscuit_gen(A,B,T):
    total = 0
    num = int(T//A)
    return B*num

print(biscuit_gen(A,B,t))
Problem p03060 (python)

Fixed submission:
jewel = int(input())
value = [int(i) for i in input().split()]
cost = [int(i) for i in input().split()]
diff = [i-j for i,j in zip(value, cost)]
price = 0
for i in sorted(diff):
    if i>0:
        price += i

print(price)

Buggy submission (verdict: Runtime Error):
jewel = [i for i in input().split('\n')]
value = [int(i) for i in jewel[1].split()]
cost = [int(i) for i in jewel[2].split()]
diff = [i-j for i,j in zip(value, cost)]
price = 0
for i in sorted(diff):
    if i>0:
        price += i

print(price)
Problem p03110 (python)

Fixed submission:
n = int(input())
money = []
unit = []
for i in range(n):
    m, u = input().split()
    money.append(float(m))
    unit.append(u)

total = 0.0
for m, u in zip(money, unit):
    if u == 'JPY':
        total += m
    else:
        total += 380000.0*m
print(total)

Buggy submission (verdict: Runtime Error):
x = [i for i in input().rsplit(1)]
money = []
unit = []
for i in x[1:]:
    m, u = i.split()
    money.append(float(m))
    unit.append(u)

total = 0.0
for m, u in zip(money, unit):
    if u == 'JPY':
        total += m
    else:
        total += 380000.0*m

print(total)
Problem p03145 (python)

Fixed submission:
a, b, c = map(int, input().split())
area = int(1/2*a*b)
print(area)

Buggy submission (verdict: Runtime Error):
s = int(input())
n = 1
tmp = s
if s == 1 or s == 2:
    print(4)
else:
    for i in range(1, 1000000):
        if tmp == 4:
            n = i
            break
        elif tmp % 2 == 0:
            tmp = tmp//2
        else:
            tmp = 3*tmp + 1
    print(n+3)
Problem p03238 (python)

Fixed submission:
age = int(input())
if age == 1:
    print('Hello World')
else:
    a, b = [int(input()) for i in range(2)]
    print(a+b)

Buggy submission (verdict: Runtime Error):
mess = [int(i) for i in input().rsplit()]
if mess[0] == 1:
    print('Hello World')
else:
    print(mess[1]+mess[2])

Buggy submission (verdict: Runtime Error):
mess = [i for i in input().rsplit()]
if mess[0] == '1':
    print('Hello World')
else:
    print(int(mess[1])+int(mess[2]))
Problem p03293 (python)

Fixed submission:
s = input()
t = input()
x = len(s)
n = 0
if s == t:
    n = 1
else:
    for i in range(x):
        s = s[-1] + s[:-1]
        if s == t:
            n = 1
 
if n == 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
s, t = map(str, input().split())
x = len(s)
n = 0
if s == t:
    n = 1
else:
    for i in range(x):
        s = s[-1] + s[:-1]
        if s == t:
            n = 1

if n == 0:
    print('No')
else:
    print('Yes')
Problem p03308 (python)

Fixed submission:
x = int(input())
seq = [int(i) for i in input().split()]
print(max(seq)-min(seq))

Buggy submission (verdict: Runtime Error):
x = [int(i) for i in input().split()]
seq = x[1:]
print(max(seq)-min(seq))
Problem p03351 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
if abs(c-a) <= d:
    print('Yes')
elif abs(b-a) <= d and abs(c-b) <= d:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
x = int(input())
if x == 1:
    print(x)
else:
    n = 1
    for i in range(1,32):
        for j in range(2,10):
            m = i**j
            if m <= x and m > n:
                n = m
print(n)
Problem p03352 (python)

Fixed submission:
x = int(input())
if x == 1:
    print(x)
else:
    n = 1
    for i in range(1,32):
        for j in range(2,10):
            m = i**j
            if m <= x and m > n:
                n = m
    print(n)

Buggy submission (verdict: Runtime Error):
x = int(input())
if x == 1:
    print(1)
else:
    n = 1
    for i in range(1,32):
        for j in range(2,10):
            m = i**j
            if m <= x and m > n:
                n = m
print(n)
Problem p03399 (python)

Fixed submission:
a, b, c, d = [int(input()) for i in range(4)]
print(min([a,b])+min([c,d]))

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
print(min([a,b])+min([c,d]))

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
total = 0
if a > b:
    total += b
else:
    total += a

if c > d:
    total += d
else:
    total += c

print(total)
Problem p03544 (python)

Fixed submission:
n = int(input())
f = [0] * (n+1)
f[0] = 2
f[1] = 1
for i in range(2,n+1):
    f[i] = f[i-1] + f[i-2]
print(f[-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
f = [0] * n
f[0] = 2
f[1] = 1
for i in range(2,n):
    f[i] = f[i-1] + f[i-2]
print(f[-1])
Problem p02576 (python)

Fixed submission:
import numpy as np

N, X, T = map(int, input().split())

for n in range(1,1000):
    if n>=N/X:
        break
    n+=1

print(T*n)

Buggy submission (verdict: Runtime Error):
import numpy as np

N, X, T = map(int, input().split())

for n in range(1:1000):
  if T*n >= np.ceil(N/X):
    break
print(T*n)
Problem p02957 (python)

Fixed submission:
input_arr = input().split(" ")
A = int(input_arr[0])
B = int(input_arr[1])

# AとBの偶奇が一致する場合 存在する
# AとBの偶奇が一致しない場合 存在しない

if (A % 2 != B % 2):
    print("IMPOSSIBLE")
else:
    k = int((A + B) / 2)
    print(k)

Buggy submission (verdict: Runtime Error):
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

k = 0
for i in range(len(p_arr)):
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
if k < 2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
input_arr = [input() for i in range(2)]
N = input_arr[0]
p_arr = input_arr[1].split(' ')

for i in range(len(p_arr)):
    k = 0
    if int(p_arr[i]) == i + 1:
        pass
    else:
        k += 1
print(k)
if k < 2:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
A, B = int(input()), int(input())

# AとBの偶奇が一致する場合 存在する
# AとBの偶奇が一致しない場合 存在しない

if (A % 2 != B % 2):
    print("IMPOSSIBLE")
else:
    k = int((A + B) / 2)
    print(k)
Problem p02971 (python)

Fixed submission:
n = int(input())
arr = [int(input()) for _ in range(n)]
ar = sorted(arr)
mx = ar[-1]
sc = ar[-2]

for ele in arr:
    if ele == mx:
        print(sc)
    else:
        print(mx)

Buggy submission (verdict: Runtime Error):
sn = int(input())
arr = [int(input()) for _ in range(n)]
arr.sort()
mx = arr[-1]
sc = arr[-2]

for ele in arr:
    if ele == mx:
        print(sc)
    else:
        print(mx)
Problem p03037 (python)

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

l_max = 0
r_min = n

for _ in range(m):
    x, y = map(int, input().split())
    l_max = max(l_max, x)
    r_min = min(r_min, y)

print(len([i for i in range(l_max, r_min + 1)]))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = [i for i in range(1, n + 1)]

for _ in range(m):
    x, y = map(int, input().split())
    tmp = [i for i in range(x, y + 1)]
    for ele in tmp:
        ans.remove(ele)
print(n - len(ans))
Problem p02683 (python)

Fixed submission:
import copy
 
N,M,X = map(int,input().split())
 
res = 10**8
 
C = [0] * N
A = [0] * N
 
for i in range(N):
    L = list(map(int,input().split()))
    C[i] = L[0]
    A[i] = L[1:]
 
def check_x(a):
    for i in range(len(a)):
        if a[i] < X:
            return False
    return True
 
# n…2^12(12bit)の整数
def calc_money_under(n):
    global res

    understand = [0] * M
    money = 0
    for s in range(N):
        if (n >> s) & 1:
            money += C[s]
            for j in range(M):
                understand[j] += A[s][j]
            #print(understand)
    
    if check_x(understand):
        res = min(money, res)
    return
 
for n in range(2**N):
    calc_money_under(n)
 
if res == 10**8:
    print(-1)
else:
    print(res)

Buggy submission (verdict: Runtime Error):
import copy

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

res = 10**8

C = [0] * N
A = [0] * N

for i in range(N):
    L = list(map(int,input().split()))
    C[i] = L[0]
    A[i] = L[1:]

def sum_l(a,b):
    for i in range(len(a)):
        a[i] += b[i]
    return a

def check_x(a):
    for i in range(len(a)):
        if a[i] < X:
            return False
    return True

# n…2^12(12bit)の整数
def calc_money_under(n):
    understand = [0] * M
    money = 0
    for s in range(N):
        if (n >> s) == 1:
            money += C[s]
            #tmp = copy.copy(understand)
            understand = copy.copy([x + y for (x,y) in zip(understand, A[s])])
            print(understand)
    
    if check_x(understand):
        res = min(sum(money), res)
    return

for n in range(2**N):
    calc_money_under(n)

if res == 10**8:
    print(-1)
else:
    print(res)
Problem p02838 (python)

Fixed submission:
import numpy as np

n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    s += 2 ** i * c1 * (n - c1)
    arr = arr >> 1

print(s % mod)

Buggy submission (verdict: Runtime Error):
n = int(input())
arr = np.array([int(i) for i in input().split()])
mod = 10 ** 9 + 7
s = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    s += 2 ** i * c1 * (n - c1)
    arr = arr >> 1

print(s % mod)
Problem p03331 (python)

Fixed submission:
n = input()
ans = 0
for ele in n:
  ans+=int(ele)
if ans==1:
  print(10)
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
n = input()
def sum_keta(m):
	sum_wa = 0
	while m>0:
		sum_wa = sum_wa + m%10
		m = int(m/10)

	return sum_wa

if sum_keta(n) == 1:
	print(10)
else:
	print(sum_keta(n))
Problem p02709 (python)

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

N = int(input())
infants = []
for i, A in enumerate(map(int, input().split(' '))):
    infants.append((-A, i + 1))
infants.sort()
dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)]


def search(i, l):
    # i番目の幼児を見ていて左にl人配置している
    if i == N:
        return 0
    if dp[i][l] != -1:
        return dp[i][l]
    (act_val, pos) = infants[i]
    act_val = -act_val
    ans = max(search(i + 1, l + 1) + abs(l + 1 - pos) * act_val,
              search(i + 1, l) + abs(N - i + l - pos) * act_val)
    dp[i][l] = ans
    return ans


print(search(0, 0))

Buggy submission (verdict: Runtime Error):
N = int(input())
infants = []
for i, A in enumerate(map(int, input().split(' '))):
    infants.append((-A, i + 1))
infants.sort()
dp = [{} for _ in range(N)]


def search(i, l):
    # i番目の幼児を見ていて左にl人配置している
    if i == N:
        return 0
    if l in dp[i]:
        return dp[i][l]
    (act_val, pos) = infants[i]
    act_val = -act_val
    ans = max(search(i + 1, l + 1) + abs(l + 1 - pos) * act_val,
              search(i + 1, l) + abs(N - i + l - pos) * act_val)
    dp[i][l] = ans
    return ans


print(search(0, 0))
Problem p02765 (python)

Fixed submission:
N, R = map(int, input().split(" "))
if N >= 10:
  print(R)
else:
  print(R + 100 * (10 - N))

Buggy submission (verdict: Runtime Error):
N, R = map(int, input().split(" "))
if N >= 10:
  print(R)
else:
  print(R + 100 * (10 - K))
Problem p02803 (python)

Fixed submission:
import collections

H, W = map(int, input().split(" "))
mp = []
for _ in range(H):
    mp.append(input().strip())


def bfs(sh, sw, mp):
    que = collections.deque()
    que.append((sh, sw))
    dist = [[-1 for _ in range(W)] for _ in range(H)]
    dist[sh][sw] = 0

    while que:
        h, w = que.popleft()
        for (dh, dw) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            if h + dh < 0 or w + dw < 0 or h + dh >= H or w + dw >= W:
                continue
            if mp[h + dh][w + dw] == '.' and dist[h + dh][w + dw] == -1:
                dist[h + dh][w + dw] = dist[h][w] + 1
                que.append((h + dh, w + dw))

    ans = 0
    for row in dist:
        ans = max(ans, max(row))
    return ans


ans = 0
for h in range(H):
    for w in range(W):
        if mp[h][w] == '.':
            ans = max(ans, bfs(h, w, mp))
print(ans)

Buggy submission (verdict: Runtime Error):
import collections

H, W = map(int, input().split(" "))
mp = []
for _ in range(H):
    mp.append(input().strip())


def bfs(sh, sw, mp):
    que = collections.deque()
    que.append((sh, sw, 0))
    dist = [[float('inf') for _ in range(W)] for _ in range(W)]

    while len(que) > 0:
        h, w, d = que.popleft()
        if dist[h][w] != float('inf'):
            continue
        dist[h][w] = d
        for (dh, dw) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            if h + dh < 0 or w + dw < 0 or h + dh >= H or w + dw >= W:
                continue
            if mp[h + dh][w + dw] == '#':
                continue
            que.append((h + dh, w + dw, d + 1))
    return dist


for h in range(H):
    for w in range(W):
        if mp[h][w] == '.':
            tmp_dist = bfs(h, w, mp)
            break

sh, sw = (h, w)
for h in range(H):
    for w in range(W):
        if mp[h][w] == '.' and tmp_dist[sh][sw] >= tmp_dist[h][w]:
            sh = h; sw = w
dist = bfs(sh, sw, mp)

ans = 0
for h in range(H):
    for w in range(W):
        if mp[h][w] == '.':
            ans = max(ans, dist[h][w])
print(ans)
Problem p02806 (python)

Fixed submission:
N = int(input())
s, t = [], []
for i in range(N):
  s_i, t_i = input().split(" ")
  t_i = int(t_i)
  s.append(s_i)
  t.append(t_i)
X = input()

idx = 0
while idx < N:
  if s[idx] == X:
    idx += 1
    break
  idx += 1

ans = 0
for i in range(idx, N):
  ans += t[i]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
s, t = [], []
for i in range(N):
  s_i, t_i = [input().split(" ")]
  t_i = int(t_i)
  s.append(s_i)
  t.append(t_i)
X = input()

idx = 0
while idx < N:
  if s[idx] == X:
    idx += 1
    break
  idx += 1

ans = 0
for i in range(idx, N):
  ans += t[i]
print(ans)
Problem p02841 (python)

Fixed submission:
m1, d1 = map(int, input().split(" "))
m2, d2 = map(int, input().split(" "))
print(1 if m2 == m1 + 1 else 0)

Buggy submission (verdict: Runtime Error):
m1, d1 = map(int, input().split(" "))
m2, d2 = map(int, input().split(" "))
print(1 if m2 = m1 + 1 else 0)
Problem p02845 (python)

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

N = int(input())
A = list(map(int, input().strip().split(" ")))
dp = {i: dict() for i in range(N)}
mod = 10 ** 9 + 7

def f(i, ma, mi):
    if i == N:
        return 1
    if (ma, mi) in dp[i]:
        return dp[i][(ma, mi)]
    if A[i] != ma and A[i] != mi and A[i] != i - ma - mi:
        dp[i][(ma, mi)] = 0
        return 0

    ans = 0
    # iがr, b, gを被って矛盾がないかを見ていく
    if A[i] == ma:
        ans += f(i + 1, ma + 1, mi)
    if A[i] == mi:
        if ma > mi + 1:
            ans += f(i + 1, ma, mi + 1)
        else:
            ans += f(i + 1, mi + 1, ma)
    if A[i] == i - ma - mi:
        ans += f(i + 1, ma, mi)

    dp[i][(ma, mi)] = ans % mod
    return ans % mod

print(f(0, 0, 0) % mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split(" ")))
dp = dict()
mod = 10 ** 9 + 7

def f(i, r, b):
    if i == N:
        return 1
    if (i, r, b) in dp:
        return dp[(i, r, b)]
    ans = 0
    # iがr, b, gを被って矛盾がないかを見ていく
    if A[i] == r:
        ans += f(i + 1, r + 1, b)
    if A[i] == b:
        ans += f(i + 1, r, b + 1)
    if A[i] == i - r - b:
        ans += f(i + 1, r, b)

    dp[(i, r, b)] = ans % mod
    return dp[(i, r, b)]

print(f(0, 0, 0) % mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split(" ")))
dp = dict()
mod = 10 ** 9 + 7

def f(i, r, b, g):
    if i == N:
        return 1
    if (i, r, b, g) in dp:
        return dp[(i, r, b, g)]
    ans = 0
    # iがr, b, gを被って矛盾がないかを見ていく
    if A[i] == r:
        ans += f(i + 1, r + 1, b, g)
    if A[i] == b:
        ans += f(i + 1, r, b + 1, g)
    if A[i] == g:
        ans += f(i + 1, r, b, g + 1)

    dp[(i, r, b, g)] = ans % mod
    return dp[(i, r, b, g)]

print(f(0, 0, 0, 0) % mod)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split(" ")))
dp = dict()
mod = 10 ** 9 + 7

def f(i, r, b, g):
    if i == N:
        return 1
    if (i, r, b, g) in dp:
        return dp[(i, r, b, g)]
    ans = 0
    # iがr, b, gを被って矛盾がないかを見ていく
    if A[i] == r:
        ans += f(i + 1, r + 1, b, g)
    if A[i] == b:
        ans += f(i + 1, r, b + 1, g)
    if A[i] == g:
        ans += f(i + 1, r, b, g + 1)

    dp[(i, r, b, g)] = ans % mod
    return ans

print(f(0, 0, 0, 0) % mod)
Problem p02882 (python)

Fixed submission:
import math

def check(a, b, x, deg):
    theta = math.radians(deg)
    if b * math.cos(theta) >= a * math.sin(theta):
        return (a * a) * (b - a * math.tan(theta) / 2.0) >= x
    else:
        return (b * b * a) / (2.0 * math.tan(theta)) >= x


a, b, x = map(float, input().split(" "))
high, low = 90, 0   # [low, high)
while (high - low) > 1e-10:
    mid = (high + low) / 2
    if check(a, b, x, mid):
        low = mid
    else:
        high = mid
print(low)

Buggy submission (verdict: Runtime Error):
import numpy as np

a, b, x = map(float, input().split(" "))
print(np.arctan(2 / a * (b - x / (a ** 2)) / np.pi * 180)