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

Fixed submission:
ma=input()
mb=input()
mc=input()
mdic={"a":ma,"b":mb,"c":mc}
m="a"
ndic={"a":0,"b":-1,"c":-1}
while ndic[m]<len(mdic[m]):
  m=mdic[m][ndic[m]]
  ndic[m]+=1
print(m.upper())

Buggy submission (verdict: Runtime Error):
mb=input()
mc=input()
mdic={"a":ma,"b":mb,"c":mc}
m="a"
ndic={"a":0,"b":-1,"c":-1}
while ndic[m]<len(mdic[m]):
  m=mdic[m][ndic[m]]
  ndic[m]+=1
print(m.upper())

Buggy submission (verdict: Runtime Error):
ma=input()
mb=input()
mc=input()
mdic={"a":ma,"b":mb,"c":mc}
m="a"
i=0
ndic={"a":0,"b":0,"c":0}
while ndic[m]=<len(mdic[m]):
  m=mdic[m][ndic[m]]
  ndic[m]+=1
print(m.upper())
Problem p04011 (python)

Fixed submission:
n=int(input())
k=int(input())
x=int(input())
y=int(input())
if n<=k:
  ans=n*x
else:
  ans=k*x+y*(n-k)
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
k=int(input())
x=int(input())
y=int(input())
if n=<k:
  ans=n*x
else:
  ans=k*x+y*(n-k)
print(ans)
Problem p04012 (python)

Fixed submission:
s=input()
d={}
for i in s:
  d[i]=d.get(i,0)+1
for i in set(s):
  if d[i]%2==1:
    print("No")
    break
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
s=input()
d={}
for i in s:
  d.get(i,0)+=1
for i in set(s):
  if d[i]%2==1:
    print("No")
    break
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
s=input()
d={}
for i in s:
  d.get(i,0)+=1
for i in set(s):
  if i%2==1:
    print("No")
    break
else:
  print("Yes")
Problem p03030 (python)

Fixed submission:
n=int(input())
res = []
for i in range(n):
    s,p=map(str, input().split())
    res += [(s,int(p))]
res1=res
res = sorted(res, key=lambda x:(x[0],-x[1]))
for i in range(n):
    print(res1.index(res[i])+1)

Buggy submission (verdict: Runtime Error):
n=int(input())
res=[]
for i in range(n):
    s,p=max(str,input().split())
    res.append([s,int(p)])
res1=res
res=sorted(res,key=lambda x:(x[0], -x[1]))
for i in range(n):
	print(res1.index(res[i])+1)

Buggy submission (verdict: Runtime Error):
n=int(input())
res=[]
for i in range(n):
	s,p=max(str,input().split())
    res.append([s,int(p)])
res1=res
res=sorted(res,key=lambda x:(x[0], -x[1]))
for i in range(n):
	print(res1.index(res[i])+1)

Buggy submission (verdict: Runtime Error):
n=int(input())
res=[]
for i in range(n):
	s,p=max(str,input().split())
    res.append([s,int(p)])
res1=res
res=sorted(res,key=lambda x:x[0], -x[1])
for i in range(n):
	print(res1.index(res[i])+1)
Problem p02658 (python)

Fixed submission:
from sys import stdin
input = stdin.readline

n = int(input())
a = list(map(int, input().split()))
ans = 1
flag = True

for ta in a:
    ans *= ta
    if (ans > 10 ** 18):
        flag = False
        ans = 1

if (flag or ans == 0):
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;

int main()
{
    int n;
    cin>>n;
    ll ans = 1ll;

    bool flag = true;
    REP(i,n) {
        ll nans = ans;
        ll a;
        cin>>a;
        nans *= a;

        if (nans > (ll)1e18 || nans < ans) {
            flag = false;
        }
        ans = nans;
    }
    cout<<(flag || ans == 0 ? ans : -1)<<endl;

    return 0;
}
Problem p02687 (python)

Fixed submission:
#from sys import stdin
#input = stdin.readline

s = input()

if s == 'ABC':
	print('ARC')
else:
	print('ABC')

Buggy submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline

from collections import deque

X = int(input())
s = {}
q = deque()

q.append([1, 0])
while True:
	ab = q.popleft()
	tmp = ab[0] ** 5 - ab[1] ** 5
	if (tmp == X):
		print(ab[0], ab[1])
		quit()
	elif (tmp > X):
		q.append([ab[0] - 1, ab[1]])
		q.append([ab[0], ab[1] - 1])
	else:
		q.append([ab[0] + 1, ab[1]])
		q.append([ab[0], ab[1] - 1])
Problem p02705 (python)

Fixed submission:
import math
r = int(input())
print(2 * math.pi * r)
quit()

Buggy submission (verdict: Runtime Error):
import math
r = input()
print(2 * math.pi * r)
quit()

Buggy submission (verdict: Runtime Error):
import math

r = input()

print(2 * math.pi * r)
Problem p03385 (python)

Fixed submission:
s = sorted(input())
if s[0] == 'a' and s[1] == 'b' and s[2] == 'c':
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
s = sort(input())
if s[0] == 'a' and s[1] == 'b' and s[2] == 'c':
	print('Yes')
else:
	print('No')
Problem p02599 (python)

Fixed submission:
class BIT:
    # 1-indexed
    def __init__(self, n):
        self.size = n + 1
        self.bit = [0] * self.size

    def add(self, i, x):
        """Add x to a[i]."""
        while i < self.size:
            self.bit[i] += x
            i += i & -i

    def sumup(self, i):
        """Sum a[1]~a[i]."""
        res = 0
        while i > 0:
            res += self.bit[i]
            i -= i & -i
        return res

    def query(self, i, j):
        """Sum a[i]~a[j]."""
        return self.sumup(j) - self.sumup(i - 1)


N, Q = map(int, input().split())
C = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(Q)]

ans = [0] * Q
last_appeared = [0] * (N + 1)
bit = BIT(N + 1)
rm = 0
for i, (l, r) in sorted(enumerate(X), key=lambda x: x[1][1]):
    for j in range(rm + 1, r + 1):
        if last_appeared[C[j - 1]] > 0:
            bit.add(last_appeared[C[j - 1]], -1)
        last_appeared[C[j - 1]] = j
        bit.add(j, 1)

    rm = r
    ans[i] = bit.query(l, r)

print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):

import numpy as np

N, Q = map(int, input().split())
C = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(Q)]

ctr = []
tmp = [0] * (max(C) + 1)
ctr.append(tmp[:])
for i in range(N):
    tmp[C[i]] += 1
    ctr.append(tmp[:])
ctr = np.array(ctr)

for l, r in X:
    print(sum((ctr[r] - ctr[l - 1]) > 0))
Problem p02632 (python)

Fixed submission:
K = int(input())
S = input()

MAX = 2 * 10 ** 6 + 1
MOD = 10 ** 9 + 7

# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    
# Inverse factorial
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(range(1, MAX + 1)):
    finv[i - 1] = finv[i] * i % MOD

def comb(n, k):
    if n < k or k < 0:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % MOD

N = len(S)
ans = 0
for i in range(K + 1):
    tmp = (pow(25, K - i, MOD) * pow(26, i, MOD)) % MOD
    ans += comb(N + K - i - 1, N - 1) * tmp
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()

MAX = 10 ** 6 + 100
MOD = 10 ** 9 + 7

# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    
# Inverse factorial
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(range(1, MAX + 1)):
    finv[i - 1] = finv[i] * i % MOD

def comb(n, k):
    if n < k or k < 0:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % MOD

N = len(S)
ans = 0
for i in range(K + 1):
    tmp = (pow(25, K - i, MOD) * pow(26, i, MOD)) % MOD
    ans += comb(N + K - i - 1, N - 1) * tmp
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()

MAX = 10 ** 6 + 100
MOD = 10 ** 9 + 7

# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    
# Inverse factorial
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(range(1, MAX + 1)):
    finv[i - 1] = finv[i] * i % MOD

def comb(n, k):
    if n < k or k < 0:
        return 0
    return fac[n] * finv[k] * finv[n - k]

N = len(S)
ans = 0
for i in range(K + 1):
    tmp = (pow(25, K - i, MOD) * pow(26, i, MOD)) % MOD
    ans += comb(N + K - i - 1, N - 1) * tmp
    ans %= MOD
print(ans)
Problem p02665 (python)

Fixed submission:
N, *A = map(int, open(0).read().split())

cnt = [0] * (N + 1)
cnt[0] = 1
for i in range(N):
    cnt[i + 1] = (cnt[i] - A[i]) * 2

ans = 0
cur = 0
for i in reversed(range(N + 1)):
    cur += A[i]
    ans += min(cnt[i], cur)
        
if all(cnt[i] >= A[i] for i in range(N + 1)):
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
N, *A = map(int, open(0).read().split())

cnt = [[0, 0] for _ in range(N + 1)]
cnt[-1] = [A[-1], A[-1]]
exists = True
for i in reversed(range(N)):
    if i > 45:
        cnt[i] = [cnt[i + 1][0] + A[i][0]] * 2
    else:
        nex_min = cnt[i + 1][0] // 2 + cnt[i + 1][0] % 2
        nex_max = cnt[i + 1][1] // 2 + cnt[i + 1][1] % 2
        lim = pow(2, i)
        if lim < nex_min + A[i]:
            exists = False
            break
        
        cnt[i][0] = min(lim, nex_min + A[i])
        cnt[i][1] = min(lim, cnt[i + 1][1] + A[i])

if exists:
    print(sum(v for _, v in cnt))
else:
    print(-1)
Problem p02698 (python)

Fixed submission:
from bisect import bisect_left
from collections import deque

N = int(input())
A = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]
for u, v in X:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

INF = 10 ** 9 + 7
dp = [INF] * (N + 1)
dp[0] = -INF
rb = [[] for _ in range(N)]
ans = [0] * N

# DFS
q = deque([(0, 0)])  # (current, parent)
while q:
    u, p = q.pop()

    # Roll back
    if p is None:
        i, x = rb[u].pop()
        dp[i] = x
        continue

    # Update dp
    i = bisect_left(dp, A[u])
    rb[u].append((i, dp[i]))
    dp[i] = A[u]

    # Calc ans
    ans[u] = max(i, ans[p])

    # Go to next
    q.append((u, None))
    for v in graph[u]:
        if v == p:
            continue
        q.append((v, u))

print(*ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect

N = int(input())
A = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]
for u, v in X:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

INF = 10 ** 9 + 7
dp = [INF] * (N + 1)
dp[0] = -INF
ans = [0] * N

def dfs(u, p=-1):
    # Update dp
    i = bisect(dp, A[u])
    old = dp[i]
    dp[i] = A[u]

    # Calc ans
    ans[u] = i
    if p != -1:
        ans[u] = max(ans[u], ans[p])

    # Go to next
    for v in graph[u]:
        if v == p:
            continue
        dfs(v, u)

    # Restore
    dp[i] = old

dfs(0)
print(*ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect

N = int(input())
A = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]
for u, v in X:
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

INF = 10 ** 9 + 7
dp = [INF] * N
dp[0] = -INF
ans = [0] * N

def dfs(u, p=-1):
    # Update dp
    i = bisect(dp, A[u])
    old = dp[i]
    dp[i] = A[u]

    # Calc ans
    ans[u] = i
    if p != -1:
        ans[u] = max(ans[u], ans[p])

    # Go to next
    for v in graph[u]:
        if v == p:
            continue
        dfs(v, u)

    # Restore
    dp[i] = old

dfs(0)
print(*ans)
Problem p02715 (python)

Fixed submission:
N, K = map(int, input().split())

def func(n):
    r = n
    for i in range(2, n + 1):
        if i ** 2 > n:
            break

        if n % i == 0:
            r -= r // i
            while n % i == 0:
                n //= i
        
    if n > 1:
        r -= r // n
    return r


MOD = 10 ** 9 + 7
ans = 0
for i in range(1, K + 1):
    ans += func(i) * pow(K // i, N, MOD)
print(ans % MOD)

Buggy submission (verdict: Runtime Error):

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

MOD = 10 ** 9 + 7
ans = 0
ctr = [0] * (N + 1)

for x in reversed(range(1, N + 1)):
    ctr[x] = pow(K // x, N, MOD)
    for y in range(2 * x, N + 1, x):
        ctr[x] -= ctr[y]

ans = 0
for n in range(1, K + 1):
    ans += n * ctr[n]
    ans %= MOD

print(ans)
Problem p02727 (python)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

z = sorted(p)[-X:] + sorted(q)[-Y:] + r
print(sum(sorted(z)[-(X+Y):]))

Buggy submission (verdict: Runtime Error):

X, Y, A, B, C = map(int, input().split())
P = sorted(map(int, input().split()))
Q = sorted(map(int, input().split()))
R = sorted(map(int, input().split()))

ans = 0
for _ in range(X):
    if P[-1] > R[-1]:
        ans += P.pop()
    else:
        ans += R.pop()

for _ in range(Y):
    if Q[-1] > R[-1]:
        ans += Q.pop()
    else:
        ans += R.pop()

print(ans)
Problem p02742 (python)

Fixed submission:
H, W = map(int, input().split())

ans = H * W
if H == 1 or W == 1:
    print(1)
elif ans % 2 == 1:
    print(ans // 2 + 1)
else:
    print(ans // 2)

Buggy submission (verdict: Runtime Error):
ans = (H * W)
if ans % 2 == 1:
    print(ans // 2 + 1)
else:
    print(ans // 2)
Problem p02774 (python)

Fixed submission:
N, K, *A = map(int, open(0).read().split())

neg = sorted([-a for a in A if a < 0])
pos = sorted([a for a in A if a >= 0])

def _count_pair_neg(x):
    x = -x
    res = 0

    MAX = len(pos)
    i = 0
    for n in reversed(neg):
        while i < MAX and n * pos[i] < x:
            i += 1
            
        res += MAX - i
    return res


def _count_pair_pos(x):
    res = 0

    # Negative list
    i = 0
    MAX = len(neg)
    for n in reversed(neg):
        if n * n <= x:
            res -= 1
            
        while i < MAX and neg[i] * n <= x:
            i += 1
        res += i
        
    # Positive list
    i = 0
    MAX = len(pos)
    for n in reversed(pos):
        if n * n <= x:
            res -= 1
            
        while i < MAX and pos[i] * n <= x:
            i += 1
        res += i
        
    # Devide by 2 for counting the same pair twice
    res //= 2
    res += len(neg) * len(pos)
    return res


def count_pair(x):
    if x < 0:
        return _count_pair_neg(x)
    
    return _count_pair_pos(x)


# Bounds
lb = 0
ub = 2 * 10 ** 18 + 2

while ub - lb > 1:
    mid = (ub + lb) // 2
    if count_pair(mid - 10 ** 18 - 1) < K:
        lb = mid
    else:
        ub = mid

print(ub - 10 ** 18 - 1)

Buggy submission (verdict: Runtime Error):
N, K, *A = map(int, open(0).read().split())

neg = sorted([-a for a in A if a < 0])
pos = sorted([a for a in A if a >= 0])

def _count_pair_neg(x):
    x = -x
    res = 0

    MAX = len(neg)
    i = 0
    for n in reversed(neg):
        while i < MAX and n * pos[i] < x:
            i += 1
            
        res += len(pos) - i
    return res


def _count_pair_pos(x):
    res = 0

    # Negative list
    i = 0
    MAX = len(neg)
    for n in reversed(neg):
        if n * n <= x:
            res -= 1
            
        while i < MAX and neg[i] * n <= x:
            i += 1
        res += i
        
    # Positive list
    i = 0
    MAX = len(pos)
    for n in reversed(pos):
        if n * n <= x:
            res -= 1
            
        while i < MAX and pos[i] * n <= x:
            i += 1
        res += i
        
    # Devide by 2 for counting the same pair twice
    res //= 2
    res += len(neg) * len(pos)
    return res


def count_pair(x):
    if x < 0:
        return _count_pair_neg(x)
    
    return _count_pair_pos(x)


# Bounds
lb = 0
ub = 2 * 10 ** 18 + 2

while ub - lb > 1:
    mid = (ub + lb) // 2
    if count_pair(mid - 10 ** 18 - 1) < K:
        lb = mid
    else:
        ub = mid

print(ub - 10 ** 18 - 1)
Problem p02782 (python)

Fixed submission:
r1, c1, r2, c2 = map(int, input().split())

MAX = 2 * 10 ** 6 + 2
MOD = 10 ** 9 + 7

# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    
# Inverse factorial
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(range(1, MAX + 1)):
    finv[i - 1] = finv[i] * i % MOD

def f(r, c):
    return fac[r + c] * finv[r] * finv[c]

ans = 0
for i in range(c1, c2 + 1):
    ans += f(r2, i + 1) - f(r1 - 1, i + 1)
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):

r1, c1, r2, c2 = map(int, input().split())

MAX = 10 ** 6 + 1
MOD = 10 ** 9 + 7

# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1

# Inverse
inv = [0] * (MAX + 1)
inv[1] = 1

# Inverse factorial
finv = [0] * (MAX + 1)
finv[0] = 1
finv[1] = 1

for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


def f(r, c):
    return fac[r + c] * finv[r] * finv[c] % MOD


ans = 0
for i in range(c1, c2 + 1):
    ans += f(r2, i + 1) - f(r1 - 1, i + 1)
    ans %= MOD
print(ans)
Problem p02814 (python)

Fixed submission:
from fractions import gcd
from functools import reduce

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

def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

def sub_by_2(n):
    cnt = 0
    while n % 2 == 0:
        cnt += 1
        n //= 2
    return cnt

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

lcm_2 = [sub_by_2(v // 2) for v in A]
if all(lcm_2[0] == v for v in lcm_2):
    num = lcm_list([v // 2 for v in A])
    ans = M // num
    print(ans // 2 + ans % 2)
else:
    print(0)

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

N, M, *A = map(int, open(0).read().split())

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

n = reduce(lcm, [v // 2 for v in A])
print(-(-(M // n) // 2))
Problem p02839 (python)

Fixed submission:
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

AB = [list(map(lambda x, y: abs(x - y), a, b)) for a, b in zip(A, B)]
dp = [[[0] * 12801 for _ in range(W + 1)] for _ in range(H + 1)]
dp[0][0][0] = 1

for h in range(H):
    for w in range(W):
        ab = AB[h][w]
        for i in range(10000):
            if dp[h][w][i] == 1:
                dp[h+1][w][i+ab] = 1
                dp[h+1][w][abs(i-ab)] = 1
                dp[h][w+1][i+ab] = 1
                dp[h][w+1][abs(i-ab)] = 1

for i in range(1000):
    if dp[H][W-1][i] == 1:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

AB = [list(map(lambda x, y: abs(x - y), a, b)) for a, b in zip(A, B)]
dp = [[[0] * 10001 for _ in range(W + 1)] for _ in range(H + 1)]
dp[0][0][0] = 1

for h in range(H):
    for w in range(W):
        ab = AB[h][w]
        for i in range(10000):
            if dp[h][w][i] == 1:
                dp[h+1][w][i+ab] = 1
                dp[h+1][w][abs(i-ab)] = 1
                dp[h][w+1][i+ab] = 1
                dp[h][w+1][abs(i-ab)] = 1

for i in range(1000):
    if dp[H][W-1][i] == 1:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

AB = [list(map(lambda x, y: abs(x - y), a, b)) for a, b in zip(A, B)]

dp = [[[0] * 10001 for _ in range(W + 1)] for _ in range(H + 1)]
dp[0][0][0] = 1

for h in range(H):
    for w in range(W):
        ab = AB[h][w]
        for i in range(10000):
            if dp[h][w][i] == 1:
                dp[h+1][w][i+ab] = 1
                dp[h+1][w][abs(i-ab)] = 1
                dp[h][w+1][i+ab] = 1
                dp[h][w+1][abs(i-ab)] = 1

for i in range(10000):
    if dp[H][W-1][i] == 1:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

AB = [list(map(lambda x, y: abs(x - y), a, b)) for a, b in zip(A, B)]

dp = [[[0] * 6401 for _ in range(W + 1)] for _ in range(H + 1)]
dp[0][0][0] = 1

for h in range(H):
    for w in range(W):
        ab = AB[h][w]
        for i in range(6400):
            if dp[h][w][i] == 1:
                dp[h+1][w][i+ab] = 1
                dp[h+1][w][abs(i-ab)] = 1
                dp[h][w+1][i+ab] = 1
                dp[h][w+1][abs(i-ab)] = 1

for i in range(6400):
    if dp[H][W-1][i] == 1:
        print(i)
        break
Problem p02882 (python)

Fixed submission:
from math import atan, pi
a, b, x = map(int, input().split())

if x > (a ** 2 * b / 2):
    print(atan(2 * (a ** 2 * b - x) / a ** 3) * 180 / pi)
else:
    print(atan((a * b ** 2) / (2 * x)) * 180 / pi)

Buggy submission (verdict: Runtime Error):
import math

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

if a ** 2 * b * 0.5 < x:
    d = a ** 3 / (2 * (a ** 2 * b - x))
else:
    d = 2 * x / (a * b ** 2)
print(90 - math.atan(d) * 180 / math.pi)

Buggy submission (verdict: Runtime Error):
import math

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

if a ** 2 * b * 0.5 < x:
    d = a ** 3 / (2 * (a ** 2 * b - x))
else:
    d = 2 * x / (a * b ** 2)
print(90 - math.degrees(math.atan(d)))
Problem p02900 (python)

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


def prime_factor(n):
    d = set()
    for i in range(2, n + 1):
        if i * i > n:
            break
        while n % i == 0:
            d.add(i)
            n //= i
            
    if n != 1:
        d.add(n)
    return d

a = prime_factor(A)
b = prime_factor(B)
print(len(set(a) & set(b)) + 1)

Buggy submission (verdict: Runtime Error):

A, B = map(int, input().split())

divisor = []
for i in range(1, int(A ** 0.5) + 1):
    if A % i == 0:
        divisor.append(i)
        if i != A // i:
            divisor.append(A // i)

divisor = sorted(v for v in divisor if B % v == 0)
lim = divisor[-1]
ok = [True] * (lim + 1)
ans = 0
for v in divisor:
    if ok[v]:
        ans += 1
        ok[v] = False
        if v != 1:
            for i in range(2 * v, lim + 1, v):
                ok[i] = False

print(ans)