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

Fixed submission:
import sys
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    sys.exit()

mod = 10**9 + 7
n = (x+y) // 3
a = min(
    (2 * x - y) // 3, (2 * y - x) // 3
)


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


N = max(x, y)
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)

ans = cmb(n, a, mod)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import math
x, y = map(int, input().split())


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


w = (x + y) / 3
a = (- x + 2*y) // 3

if w.is_integer():
    w = int(w)
else:
    print(0)
    sys.exit()

ans = combinations_count(w, a) % (10**9 + 7)
print(ans)
Problem p02915 (python)

Fixed submission:
n = int(input())
print(n*n*n)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))
ans = 0
for l in range(N-1):
    first = max(P[l], P[l+1])
    second = min(P[l], P[l+1])
    r = l+2
    ans += second
    while r < N:
        w = P[r]
        r += 1
        if second <= w <= first:
            second = w
        elif first < w:
            second = first
            first = w
        ans += second

print(ans)
Problem p03013 (python)

Fixed submission:
import numpy as np
n, m = map(int, input().split())
stairs = set([int(input()) for i in range(m)])
ans = [1] * (n+1)
mod = 10**9 + 7
if 1 in stairs:
    ans[1] -= 1
for i in range(2, n+1):
    if i in stairs:
        ans[i] = 0
    else:
        ans[i] = ans[i-1] + ans[i-2]

print(ans[-1]%mod)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = map(int, input().split())
stairs = set([int(input()) for i in range(m)])
ans = np.ones(n+1)
mod = 10**9 + 7
if 1 in stairs:
    ans[1] -= 1
for i in range(2, n+1):
    if i in stairs:
        ans[i] = 0
    else:
        ans[i] = ans[i-1] + ans[i-2]

print(int(ans[-1]) % mod)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, m = map(int, input().split())
stairs = set([int(input()) for i in range(m)])
ans = np.ones(n+1)
mod = 10**9 + 7
if 1 in stairs:
    ans[1] -= 1
for i in range(2, n+1):
    if i in stairs:
        ans[i] = 0
    else:
        ans[i] = ans[i-1] + ans[i-2]

print(int(ans[-1] % mod))
Problem p03036 (python)

Fixed submission:
r, d, x_2000 = map(int, input().split())
ans = [0]*11
ans[0] = x_2000
for i in range(1, 11):
    ans[i] = r * ans[i-1] - d
    print(ans[i])

Buggy submission (verdict: Runtime Error):
r, d, x_2000 = map(int, input().split())
ans = []*11
ans[0] = x_2000
for i in range(1, 11):
    ans[i] = r * ans[i-1] - d
    print(ans[i])
Problem p03137 (python)

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = [x[i]-x[i-1] for i in range(1,m)]
l.sort(reverse=True)
ans = x[m-1] - x[0]
if n >= m:
    print(0)
else:
    for i in range(n-1):
        ans -= l[i]
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = [x[i]-x[i-1] for i in range(1,m)]
l.sort(reverse=True)
ans = x[m-1] - x[0]
if len(x) == 1:
    print(ans)
else:
    for i in range(n-1):
        ans -= l[i]
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = [x[i]-x[i-1] for i in range(1,m)]
ans = x[m-1] - x[0] 
if len(x) == 1:
    print(ans)
else:
    for i in range(n-1):
        ans -= max(l)
        l.remove(max(l))
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = [x[i]-x[i-1] for i in range(1,m)]
ans = x[m-1] - x[0] 
if len[x] == 1:
    print(ans)
else:
    for i in range(n-1):
        ans -= max(l)
        l.remove(max(l))
    print(ans)
Problem p02623 (python)

Fixed submission:
from sys import stdin
from sys import setrecursionlimit
from itertools import accumulate
import bisect

n,m,k = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))

aa = [0]+list(accumulate(a))
bb = [0]+list(accumulate(b))
ma = 0

for i,j in  enumerate(aa):
    if j > k:
        break
    nowa = i
    nowb = bisect.bisect(bb,k-j)-1
    ma = max(ma,nowa+nowb)

print(ma)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n,m,k = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))

nowa = 0
nowb = 0

li = []
total = 0

while total <= k:
    if nowa == n and nowb == m:
        break
    if nowa == n and nowb < m:
        total += b[nowb]
        li.append(b[nowb])
        nowb += 1
    elif nowa < n and nowb == m:
        total += b[nowb]
        li.append(b[nowb])
        nowa += 1  
    elif a[nowa] <= b[nowb]:
        total += a[nowa]
        li.append(a[nowa])
        nowa += 1
    elif a[nowa] > b[nowb]:
        total += b[nowb]
        li.append(b[nowb])
        nowb += 1

if sum(li) <= k:
    print(len(li))
else:
    print(len(li)-1)
Problem p02682 (python)

Fixed submission:
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

a,b,c,d = map(int,stdin.readline().rstrip().split())

if d > a+b:
    print(a-(d-a-b))
elif d < a:
    print(d)
else:
    print(a)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

a,b,c,d = map(int,stdin.readline().rstrip().split())

li = [1]*a+[0]*b+[-1]*c

print(sum(li[:d]))
Problem p02735 (python)

Fixed submission:
from queue import deque

h,w = map(int,input().split())
li = [input() for _ in range(h)]

inf = 10**10
dx = [1,0]
dy = [0,1]
que = deque()

#そのマスにたどり着くまでに色が変わった最小の回数を保存するリスト
flip_count = [[inf for i in range(w)]for j in range(h)]

if li[0][0] == "#":
    flip_count[0][0] = 1
else:
    flip_count[0][0] = 0

que.append([0,0])

while que:
    k = que.popleft()
    x = k[0]
    y = k[1]
    for i,j in zip(dx,dy):
        nx = x + i
        ny = y + j
        if nx >= w or ny >= h:
            continue
        if flip_count[ny][nx] == inf:
            que.append([nx,ny])
        if li[ny][nx] != li[y][x]:
            flip_count[ny][nx] = min(flip_count[ny][nx],flip_count[y][x]+1)
        else:
            flip_count[ny][nx] = min(flip_count[ny][nx],flip_count[y][x])

if li[-1][-1] == "#":
    flip_count[-1][-1] += 1

print(flip_count[-1][-1]//2)

Buggy submission (verdict: Runtime Error):
from sys import stdin,setrecursionlimit
from collections import deque
h,w = [int(x) for x in stdin.readline().rstrip().split()]
li = [["" for i in range(w)]for j in range(h)]
point = 0
for i in range(h):
    s = stdin.readline().rstrip()
    point += s.count(".")
    for j in range(w):
        li[i][j] = s[j]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
que = deque()
lin = [[inf for i in range(w)]for j in range(h)]
lin[0][0] = 0#ここをスタートの座標に変えること
que.append([0,0])
Problem p02771 (python)

Fixed submission:
from sys import stdin
li = list(map(int,stdin.readline().rstrip().split()))
li = list(set(li))
if len(li) == 2:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
#解法その１
a,b,c = map(int,input().split())
if a == b != c:
    print("Yes")
elif a == c != b:
    print("Yes")
elif b == c != a:
    print("Yes")
else:
    print("No")
#解法その２
li = list(map(int,input().split()))
li2 = set(li)#liの中の被っている要素を排除する（例：3 2 2 > 3 2）
if len(li2) == 2:#かぶり要素を排除したときのリスト内部の個数が２になっている
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
li = list(map(int,input.split()))
li2 = set(li2)#liの中の被っている要素を排除する（例：3 2 2 > 3 2）
if len(li2) == 2:#かぶり要素を排除したときのリスト内部の個数が２になっている
    print("Yes")
else:
    print("No")
Problem p02862 (python)

Fixed submission:
from sys import stdin
import math
import bisect
import heapq
import numpy as np
from math import factorial
mod = 1000000007
x,y = [int(x) for x in stdin.readline().rstrip().split()]

if (x+y)%3 != 0:
    print(0)
    exit()

a = (2*x-y)//3
b = (2*y-x)//3

if a < 0 or b < 0:
    print(0)
    exit()

def combination(n,r,mod=10**9+7):
    r=min(r,n-r)
    up,down=1,1
    for i in range(r):
        up=up*(n-i)%mod
        down=down*(i+1)%mod
    return up*pow(down,mod-2,mod)%mod

print(combination(a+b,a))

Buggy submission (verdict: Runtime Error):
from sys import stdin
import math
import bisect
import heapq
import numpy as np
from math import factorial

x,y = [int(x) for x in stdin.readline().rstrip().split()]

if (x+y)%3 != 0:
    print(0)
    exit()

a = (2*x-y)//3
b = (2*y-x)//3

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

print(combinations_count(a+b,a)%(10**9+7))
Problem p02891 (python)

Fixed submission:
# AGC039A - Connection and Disconnection
from itertools import groupby


def main():
    S = input().rstrip()
    K = int(input())
    cnt = [len(tuple(s)) for _, s in groupby(S)]  # count of continuous characters
    if S[0] == S[-1] and K > 1:
        if len(cnt) == 1:  # one character
            ans = cnt[0] * K // 2
        else:  # first (= last) character in S + characters inside S
            ans = cnt[0] // 2 + cnt[-1] // 2 + (cnt[0] + cnt[-1]) // 2 * (K - 1)
            ans += sum(i // 2 for i in cnt[1:-1]) * K
    else:
        ans = sum(i // 2 for i in cnt) * K
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

def cou(st):
    li = []
    point = 1
    for i in range(len(st)-1):
        if st[i] == st[i+1]:
            point += 1
            if i == len(st)-2:
                li.append(point)
        else:
            li.append(point)
            point = 1
    return li

lin = cou(s)

if len(lin) == 1:
    print(lin[0]*k//2)
    exit()

if k > 1:
    if s[0] == s[-1]:
        lin[-1] += lin[0]
else:
    if len(s) == 1:
        print(0)
        exit()

point = 0
for i in range(1,len(lin)):
    point += lin[i]//2
point = point*k+lin[0]//2
print(point)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from itertools import groupby

s = stdin.readline().rstrip()
k = int(stdin.readline().rstrip())

san = s*2

def cou(st):
    li = []
    point = 1
    for i in range(len(st)-1):
        if st[i] == st[i+1]:
            point += 1
            if i == len(st)-2:
                li.append(point)
        else:
            li.append(point)
            point = 1
    return li

lin = cou(s)

if len(lin) == 1:
    print(lin[0]*k//2)
    exit()

if k >= 1:
    if s[0] == s[-1]:
        lin[-1] += lin[0] 

point = 0
for i in range(1,len(lin)):
    point += lin[i]//2
point = point*k+lin[0]//2
print(point)
Problem p02915 (python)

Fixed submission:
from sys import stdin
from math import factorial
n = int(stdin.readline().rstrip())
print(n**3)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from math import factorial

n = int(stdin.readline().rstrip().split())

print(n**3)
Problem p02933 (python)

Fixed submission:
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

if n >= 3200:
    print(s)
else:
    print("red")

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rsprit())
s = stdin.readline().rstrip()

if n >= 3200:
    print(s)
else:
    print("red")
Problem p02948 (python)

Fixed submission:
import heapq
from sys import stdin

n,m = map(int,stdin.readline().rstrip().split())
jobs = [[] for i in range(m)]

for i in range(n):
    tmp,tmp2 = map(int,stdin.readline().rstrip().split())
    if(tmp>m):
        continue
    jobs[m-tmp].append(tmp2)
ans = 0
h=[]
for i in range(m-1,-1,-1):
    for b in jobs[i]:
        heapq.heappush(h,-b)
    if(len(h)!=0):
        a = -heapq.heappop(h)
        ans += a
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
from sys import stdin

n,m = map(int,stdin.readline().rstrip().split())
jobs = [[] for i in range(m)]

for i in range(n):
    tmp,tmp2 = map(int,stdin.readline().rstrip().split())
    if(tmp>m):
        continue
    jobs[m-tmp].append(tmp2)
print(jobs)
ans = 0
h=[]
for i in range(m-1,-1,-1):
    for b in jobs[i]:
        heapq.heappush(h,-b)
    print(h)
    if(len(h)!=0):
        a = -heapq.heappop(h)
        ans += a
print(ans)
Problem p02959 (python)

Fixed submission:
from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
fa = min(A[0],B[0])
fb = min(A[1],B[0]-fa)
point += fb
point += fa
for i in range(1,n):
    fc = min(A[i]-fb,B[i])
    point += fc
    fb = min(A[i+1],B[i]-fc)
    point += fb
print(point)

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
fa = min(A[0],B[0])
fb = min(A[1],B[0]-f00)
point += fb
point += fa
for i in range(1,n):
    fc = min(A[i]-fb,B[i])
    point += fc
    fb = min(A[i+1],B[i]-fc)
    point += fb
print(point)

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
f00 = min(A[0],B[0])
f12 = min(A[1],B[0]-f00)
point += f12
point += f0
for i in range(1,n):
    f11 = min(A[i]-f12,B[i])
    point += f11
    f12 = min(A[i+1],B[i]-f11)
    point += f12
print(point)

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
A = list(map(int,stdin.readline().rstrip().split()))
B = list(map(int,stdin.readline().rstrip().split()))
point = 0
f00 = min(A[0],B[0])
f12 = min(A[1],B[0]-f00)
point += f12
point += f0
for i in range(1,n):
    f11 = min(A[i]-f12,B[i])
    point += f11
    f12 = min(A[i+1],B[i]-f11)
    point += f12
print(point)
Problem p03013 (python)

Fixed submission:
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]

lin = [0]*(n+1)

if m != 0:
    for i in range(m):
        lin[int(stdin.readline().rstrip())] = -1

dp = [-1]*(n+1)

dp[0] = 1

if lin[1] == -1:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,n+1):
    if lin[i] == -1:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[n]%(10**9+7))

Buggy submission (verdict: Runtime Error):
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
lin = [int(stdin.readline().rstrip()) for _ in range(m)]

for i in range(len(lin)-1):
    if lin[i] + 1 == lin[i+1]:
        print(0)
        exit()

dp = [-1 for _ in range(n+1)]
dp[0] = 1
if lin[0] == 1:
    dp[1] = 0
else:
    dp[1] = 1
for i in range(2,n+1):
    if i in lin:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[n]%(10**9+7))

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

a,b = [int(x) for x in stdin.readline().rstrip().split()]
li = [int(stdin.readline().rstrip()) for _ in range(b)]

if a == 1:
    print(1)
    exit()

elif a == 2:
    if b == 0:
        print(2)
        exit()
    else:
        print(1) 
        exit()

for k in range(len(li)-1):
    if li[k] +1 == li[k+1]:
        print(0)
        exit()

def stair_cal(x):
    if x == 1:
        return(x)
    elif x == 2:
        return(x)
    elif x == 0:
        return(1)
    lin = [1,2]
    for i in range(2,x):
        lin.append(lin[i-2]+lin[i-1])
    return(lin[-1])

li2 = []

li2.append(li[0]-1)

for i in range(1,b):
    li2.append(li[i]-li[i-1]-1)

li2.append(a-li[-1])

point = 1

for e in range(len(li2)):
    point = point*stair_cal(li2[e])%(10**9+7)

print(point)

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

a,b = [int(x) for x in stdin.readline().rstrip().split()]
li = [int(stdin.readline().rstrip()) for _ in range(b)]

if a == 1:
    print(1)
    exit()

elif a == 2:
    if b == 0:
        print(0)
        exit()
    else:
        print(1) 
        exit()

for k in range(len(li)-1):
    if li[k] +1 == li[k+1]:
        print(0)
        exit()

def stair_cal(x):
    if x == 1:
        return(x)
    elif x == 2:
        return(x)
    elif x == 0:
        return(1)
    lin = [1,2]
    for i in range(2,x):
        lin.append(lin[i-2]+lin[i-1])
    return(lin[-1])

li2 = []

li2.append(li[0]-1)

for i in range(1,b):
    li2.append(li[i]-li[i-1]-1)

li2.append(a-li[-1])

point = 1

for e in range(len(li2)):
    point = point*stair_cal(li2[e])%(10**9+7)

print(point)
Problem p03075 (python)

Fixed submission:
from sys import stdin

li = [int(stdin.readline().rstrip()) for _ in range(5)]
k = int(stdin.readline().rstrip())

from itertools import combinations
lin = list(combinations(li, 2))

for i in range(len(lin)):
    if abs(lin[i][0]-lin[i][1]) > k:
        print(":(")
        exit()

print("Yay!")

Buggy submission (verdict: Runtime Error):
from sys import stdin

li = [int(stdin.readline().rstrip()) for _ in range(5)]
k = int(stdin.readline().rstrip())

from itertools import combinations
lin = list(combinations(li, 2))

for i in li:
    if abs(lin[i][0]-lin[i][1]) > k:
        print(":(")
        exit()

print("Yay!")
Problem p03221 (python)

Fixed submission:
from sys import stdin
import bisect

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [[]for i in range(n)]
lin2 = []
li3 = []
for j in range(m):
    lin[li[j][0]-1].append(li[j][1])
    lin2.append(li[j][0]-1)

for j in range(n):
    liv = sorted(lin[j])
    li3.append(liv)

for k in range(m):
    tosi = str(li[k][0]).zfill(6)
    ban =  str(bisect.bisect(li3[li[k][0]-1],li[k][1])).zfill(6)
    print(tosi+ban)

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

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [[]for _ in range(n)]
lin2 = []
for i in range(m):
    lin[li[j][0]-1].append(li[i][1])

for j in range(n):
    liv = sorted(lin[j])
    lin2.append(liv)

for k in range(m):
    tosi = str(li[k][0]).zfill(6)
    ban =  str(bisect.bisect(lin2[li[k][0]-1],li[k][1])).zfill(6)
    print(tosi+ban)

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

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

lin = [[]for i in range(n)]
lin2 = []
li3 = []
for j in range(m):
    lin[li[j][0]-1].append(li[j][1])
    lin2.append(li[j][0]-1)

for j in range(n):
    liv = sorted(lin[j])
    li3.append(liv)

for k in range(m):
    s = len(str(li[k][1]))
    v = len(str(li[j][0]))
    print("0"*(6-v)+str(li[k][0])+"0"*(6-s)+str(bisect.bisect(li3[li[k][0]-1],li[k][1])))
Problem p03242 (python)

Fixed submission:
from sys import stdin

s = stdin.readline().rstrip()
ns = ""
for i in s:
    if i =="1":
        ns += "9"
    else:
        ns += "1"

print(ns)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from itertools import groupby

n = int(stdin.readline().rstrip())

li = list(map(int,stdin.readline().rstrip().split()))

li1 = []
li2 = []

for i in range(n):
    if i % 2 == 0:
        li1.append(li[i])
    else:
        li2.append(li[i])

li1.sort()
li2.sort()

lin = []
lin2 = []

for key, value in groupby(li1):
    lin.append((key,len(list(value))))
for key, value in groupby(li2):
    lin2.append((key,len(list(value))))

lin.sort(key=lambda x:(x[1]))
lin2.sort(key=lambda x:(x[1]))

point = 0

if lin[-1][0] == lin2[-1][0] and lin[-1][1] == lin2[-1][1]:
    if len(lin) == 1:
        print(n//2)
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-2][1]-lin2[-1][1])
        else:
            print(n-lin[-1][1]-lin2[-2][1])

elif lin[-1][0] == lin2[-1][0]:
    if len(lin) == 1:
        print(n//2-lin2[-2][1])
    elif len(lin2) == 1:
        print(n//2-lin[-2][1])
    else:
        if lin[-2][1] >= lin2[-2][1]:
            print(n-lin[-1][1]-lin2[-2][1])
        else:
            print(n-lin[-2][1]-lin2[-1][1])
else:
    print(n-lin[-1][1]-lin2[-1][1])
Problem p03286 (python)

Fixed submission:
from sys import stdin
n = int(stdin.readline().rstrip())
def num(n):
    if n == 0:
        return ""
    if n%2 == 0:
        return num(n//(-2)) + "0"
    else:
        return num((n-1)//(-2)) + "1"
if n == 0:
    print(0)
    exit()
print(num(n))

Buggy submission (verdict: Runtime Error):
from sys import stdin
n = int(stdin.readline().rstrip())
def num(n):
    if n%2 == 0:
        return num(n//(-2)) + "0"
    else:
        return num(n//(-2)) + "1"

if n == 0:
    print(0)
    exit()

print(num(n))
Problem p03705 (python)

Fixed submission:
from sys import stdin
n,a,b = [int(x) for x in stdin.readline().rstrip().split()]

saisyou = a*(n-1)+b
saidai = b*(n-1)+a

if n == 1 and a!= b:
    print(0)
    exit()
elif a > b:
    print(0)
    exit()
else:
    print(saidai-saisyou+1)

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

print(max(b*(n-1)+a-(a*(n-1)+b)+1),0)
Problem p03724 (python)

Fixed submission:
from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
ab = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
li = [0 for _ in range(n+1)]
for a,b in ab:
    li[a] += 1
    li[b] += 1
for i in li:
    if i%2 == 1:
        print("NO")
        exit()
print("YES")

Buggy submission (verdict: Runtime Error):
from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
ab = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
li = [0 for _ in range(n+1)]
for a,b in ab:
    li[a] += 1
    li[b] += 1
for i in li:
    if i%2 == 1:
        print("NO")
        exit()
print("YES")
Problem p02596 (python)

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

K = int(input())

for i in [2,5]:
    if K%i==0:
        print(-1)
        exit()
t = 0
for i in range(K):
    t = (t*10+7)%K
    if t == 0:
        print(i+1)
        exit()
print(-1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)

K = int(input())

for i in [2,5]:
    if K%i==0:
        print(-1)
        exit()

def f(i,t,K):
    t2 = (t*10+7)%K
    if t2==0:
        print(i)
        exit()
    else:f(i+1,t2,K)
f(1,0,K)