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

Fixed submission:
S = str(input())
l = 0
r = 0
ans = 0
tmp = S[0]
if tmp == ">":
    r = 1
else:
    l = 1
for i in range(1,len(S)):
    if tmp == ">" and S[i] == "<":
        ans += max(l, r) * (max(l, r) + 1) / 2 + min(l, r) * (min(l, r) - 1) / 2
        l = 1
        r = 0
        tmp = S[i]
    else:
        if S[i] == ">":
            r += 1
        else:
            l += 1
        tmp = S[i]
ans += max(l, r) * (max(l, r) + 1) / 2 + min(l, r) * (min(l, r) - 1) / 2
print(int(ans))

Buggy submission (verdict: Runtime Error):
S = str(input())
S += "<"
l = 0
r = 0
ans = 0
tmp = ">"
for i in range(len(s)):
    if tmp == ">" and S[i] == "<":
        ans += max(l, r) * (max(l, r) + 1) / 2 + min(l, r) - 1
        l = 1
        r = 0
        tmp = S[i]
    else:
        if S[i] == ">":
            r += 1
        else:
            l += 1
        tmp = S[i]
print(ans)
Problem p02891 (python)

Fixed submission:
S = str(input())
K = int(input())
tmp = 1
cnt1 = 0
cnt2 = 0
for i in range(1, len(S)):
    if S[i-1] == S[i]:
        tmp += 1
    else:
        cnt1 += tmp // 2
        tmp = 1
if tmp == len(S):
        print(len(S) * K // 2)
        exit()
if tmp > 1:
    cnt1 += tmp//2
S2 = S + S
tmp = 1
for i in range(1, len(S2)):
    if S2[i-1] == S2[i]:
        tmp += 1
    else:
        cnt2 += tmp // 2
        tmp = 1
if tmp > 1:
    cnt2 += tmp//2
if K == 1:
    print(cnt1)
else:
    print((cnt2 - cnt1) * (K-2) + cnt2)

Buggy submission (verdict: Runtime Error):
S = str(input())
K = int(input())
tmp = 1
cnt = 0
for i in range(1, len(S)):
    if S[i-1] == S[i]:
        tmp += 1
    else:
        cnt += tmp // 2
        tmp = 1
if tmp > 1:
    cnt += tmp//2
if S[0] == S[-1]:
    if S[0] != S[1] and S[-1] != S[-2]:
        print(cnt * K + K - 1)
    else:
        print(cnt * K)
else:
    print(cnt * K)
Problem p02897 (python)

Fixed submission:
N = int(input())
if N % 2 == 0:
    print(0.5)
else:
    print((N // 2 + 1) / N)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
i = 2
cnt = 0
tmpA, tmpB = A, B
while i**2 <= min(tmpA, tmpB) and i <= min(A,B):
    if A % i == 0 and B % i == 0:
        cnt += 1
        while A % i == 0 and B % i == 0:
            A //= i
            B //= i
    i += 1
if cnt == 0 and min(A, B) != 1:
    cnt += 1
if cnt == 0 and max(A,B) % min(A,B) == 0:
    cnt += 1
print(cnt + 1)
Problem p02933 (python)

Fixed submission:
a = int(input())
s = str(input())
if a < 3200:
    print("red")
else:
    print(s)

Buggy submission (verdict: Runtime Error):
def main():
	import sys
	sys.setrecursionlimit(700000)
	N, Q = map(int, input().split())
	d = [[] for i in range(N)]

	for i in range(N-1):
		a, b = map(int, input().split())
		a -= 1
		b -= 1
		d[b].append(a)
		d[a].append(b)

	ans = [0]*N

	for i in range(Q):
		p, x = map(int, input().split())
		p -= 1
		ans[p] += x

	def dfs(cur, parent):
		for child in d[cur]:
			if child != parent:
				ans[child] += ans[cur]
				dfs(child,cur)
	dfs(0,-1) 
	print(*ans)
    
main()
Problem p02948 (python)

Fixed submission:
import heapq

N, M = map(int, input().split())
l = [0 for i in range(N)]

for i in range(N):
    A, B = map(int, input().split())
    l[i] = [A,-B]
l.sort()

tmp = []
ans = 0
j = 0

for i in range(1, M + 1):
    while j < N:
        A, B = l[j][0], -l[j][1]
        memo = [-B, A]
        if A <= i:
            heapq.heappush(tmp, memo)
            j += 1
        else:
            break
    if len(tmp) > 0:
        ans -= heapq.heappop(tmp)[0]
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
l = [0 for i in range(N)]

for i in range(N):
    A, B = map(int, input().split())
    l[i] = [A,-B]
l.sort()

tmp = []
ans = 0

for i in range(1, M + 1):
    while l[i][0] <= i:
        heapq.heappush(tmp, l[i])
    ans -= heapq.heappop(tmp)[1]
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
dp = [[0 for i in range(M+1)] for j in range(N+1)]
l = [0 for i in range(N)]
for i in range(N):
    A,B = map(int, input().split())
    l[i] = [-A, -B]
l.sort()
tmp = 1
for n in range(1, N+1):
    for m in range(tmp):
        if -l[n-1][0]  + m <= M:
            dp[n][m] = max(dp[n][m], dp[n-1][m-1] - l[n-1][1])
            tmp += 1
        dp[n][m-1] = max(dp[n][m-1], dp[n-1][m-1])
print(max(dp[N]))
Problem p02990 (python)

Fixed submission:
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
def com(n,r):
    if n<r:
        return 0
    return int(factorial(n) // factorial(r) // factorial(n-r))
for i in range(1,K+1):
    comb = com(N-K+1,i)
    sec = com(K-1,i-1)
    print((comb * sec)%mod)

Buggy submission (verdict: Runtime Error):
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
def com(n,r):
    return int(factorial(n) // factorial(r) // factorial(n-r))
for i in range(1,K+1):
    comb = com(N-K+1,i)
    sec = com(K-1,i-1)
    print((comb * sec)%mod)

Buggy submission (verdict: Runtime Error):
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
def com(n,r):
    return int(factorial(n) / factorial(r) / factorial(n-r))
for i in range(1,K+1):
    comb = com(N-K+1,i)
    sec = com(K-1,i-1)
    print((comb * sec)%mod)

Buggy submission (verdict: Runtime Error):
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
for i in range(1,K+1):
    comb = int(factorial(N-K+1) / factorial(i) / factorial(N-K+1-i) % mod)
    sec = int(factorial(K-1) / factorial(i-1) / factorial(K-i) % mod)
    print((comb * sec)%mod)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(700000)
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
for i in range(1,K+1):
   
    comb = int(factorial(K-1) / factorial(i-1) / factorial(K-i) % mod)
   
    
    sec = int(factorial(N-K+1) / factorial(N-K-i+1) / factorial(i) % mod)
   
    print((comb * sec)%mod)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(700000)
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
for i in range(1,K+1):
    try:
        comb = int(factorial(K-1) / factorial(i-1) / factorial(K-i) % mod)
    except ValueError:
        comb = 1
    try:
        sec = int(factorial(N-K+1) / factorial(N-K-i+1) / factorial(i) % mod)
    except ValueError:
        sec = 1
    print((comb * sec)%mod)

Buggy submission (verdict: Runtime Error):
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
for i in range(1,K+1):
    try:
        comb = int(factorial(K-1) / factorial(i-1) / factorial(K-i))
    except ValueError:
        comb = 1
    try:
        sec = int(factorial(N-K+1) / factorial(N-K-i+1) / factorial(i))
    except ValueError:
        sec = 1
    print((comb * sec)%mod)

Buggy submission (verdict: Runtime Error):
from math import factorial
N,K = map(int, input().split())
mod = 10**9 + 7
for i in range(1,K+1):
    comb = int(factorial(K-1) / factorial(i-1) / factorial(K-i))
    try:
        sec = int(factorial(N-K+1) / factorial(N-K-i+1) / factorial(i))
    except ValueError:
        sec = 1
    print((comb * sec)%mod)
Problem p03013 (python)

Fixed submission:
N,M = map(int, input().split())
dp = [0 for i in range(N+1)]
dp[0] = 1
dp[1] = 1
for i in range(M):
    dp[int(input())] = None
for i in range(2,N+1):
    if dp[i] != None:
        if dp[i-2] != None:
            dp[i] += dp[i-2]
        if dp[i-1] != None:
            dp[i] += dp[i-1]
mod = 10**9 + 7
print(dp[N]%mod)

Buggy submission (verdict: Runtime Error):
import math
N,M = map(int, input().split())
def C(a,b):
    return math.factorial(a+b)/(math.factorial(a)*math.factorial(b))
def pattern(n):
    ans = 0
    i = 0
    while n - 2*i >= 0:
        ans += C(n-i*2,i)
        i += 1
    return ans
ans = 1
mod = 10**9 + 7
l = [0 for i in  range(M)]
for i in range(1,M):
    l[i] = int(input()) - l[i-1] -2
if N-l[M-1]-2 >= 0:
    l.append(N-l[M-1]-2)
l.sort()
for i in range(len(l)):
    if i != 0 and l[i] == l[i-1]:
        ans *= tmp
    else:
        ans *= pattern(l[i])
    ans = ans%mod
    tmp = pattern(l[i])
print(int(ans))
Problem p03038 (python)

Fixed submission:
N,M = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
BCs = [0 for i in range(M)]
for i in range(M):
    BCs[i] = list(map(int, input().split()))
BCs.sort(key=lambda x: x[1])
mark = 0
ans = 0
for i in reversed(range(M)):
    B = BCs[i][0]
    C = BCs[i][1]
    j = mark
    if As[j] >= C:
        break
    while As[j] < C and B > 0:
        As[j] = C
        j += 1
        if j >= N:
            break
        B -= 1
    
    ans += (j - mark)*C
    mark = j
    if j >= N:
        break
    
for i in range(mark,N):
    ans += As[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
BCs = [0 for i in range(M)]
for i in range(M):
    BCs[i] = list(map(int, input().split()))
BCs.sort(key=lambda x: x[1])
mark = 0
ans = 0
for i in reversed(range(M)):
    B = BCs[i][0]
    C = BCs[i][1]
    j = mark
    if As[j] >= C:
        break
    while As[j] < C and B > 0:
        As[j] = C
        j += 1
        B -= 1
    ans += (j - mark)*C
    mark = j
    
for i in range(mark,N):
    ans += As[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
BCs = [0 for i in range(M)]
for i in range(M):
    BCs[i] = list(map(int, input().split()))
BCs.sort(key=lambda x: x[1])
mark = 0
ans = 0
for i in reversed(range(M)):
    B = BCs[i][0]
    C = BCs[i][1]
    j = mark
    if As[j] >= C:
        break
    while As[j] < C and B > 0:
        As[j] = C
        j += 1
        B -= 1
    ans += (j - mark)*C
    mark = j
    
for i in range(mark,N):
    ans += As[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
BCs = [0 for i in range(M)]
for i in range(M):
    BCs[i] = list(map(int, input().split()))
BCs.sort(key=lambda x: x[1])
for i in reversed(range(M)):
    B = BCs[i][0]
    C = BCs[i][1]
    j = 0
    while As[j] < C and B > 0:
        As[j] = C
        j += 1
        B -= 1
    As.sort()

ans = 0
for i in range(N):
    ans += As[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
BCs = [0 for i in range(M)]
for i in range(M):
    BCs[i] = list(map(int, input().split()))
BCs.sort(key=lambda x: x[1])
for i in range(M):
    B = BCs[i][0]
    C = BCs[i][1]
    j = 0
    while As[j] < C and B > 0:
        As[j] = C
        j += 1
        B -= 1
    As.sort()

ans = 0
for i in range(N):
    ans += As[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
for i in range(M):
    B,C = map(int, input().split())
    j = 0
    while As[j] < C and B > 0:
        As[j] = C
        j += 1
        B -= 1
    As.sort()
ans = 0
for i in range(N):
    ans += As[i]

print(ans)
Problem p03137 (python)

Fixed submission:
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
d = [0]*m
for i in range(1,m):
    d[i] = x[i]-x[i-1]
d.sort()
if n < m:
    d = d[1:m-n+1]
else:
    d = [0]
ans = 0
for i in range(len(d)):
    ans += d[i]
print(ans)

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

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
d = [0]*m
for i in range(1,m):
    d[i] = x[i]-x[i-1]
d.sort()
ans = 0
if n < m:
    for i in range(0,n+2):
        ans += d[i]
print(ans)
Problem p03221 (python)

Fixed submission:
N, M = map(int, input().split())
from collections import defaultdict
d = defaultdict(list)
for i in range(M):
    P,Y = map(int, input().split())
    d[P].append([Y,i])
l = [0 for i in range(M)] 
cnt = 0   
for key in d:
    data = sorted(d[key])
    tmp = 0
    for i in range(len(data)):
        l[cnt] = [str(key).zfill(6) + str(tmp+1).zfill(6), data[i][1]]
        cnt += 1
        tmp += 1
l.sort(key = lambda x: x[1])
for i in range(M):
    print(l[i][0])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
d = {}
l = [[] for i in range(M)]
for i in range(M):
    P,Y = map(str, input().split())
    P = "0" * (6-len(P)) + P
    d[P] += [int(Y)]
    l[i] = [P,int(Y)]
for i in range(M):
    tmp = str((sorted(d[l[i][0]]).index(l[i][1]))+1)
    print(l[i][0] + "0" * (6-len(tmp)) + tmp)
Problem p03242 (python)

Fixed submission:
n = str(input())
m = ""
for i in range(3):
    if n[i] == "1":
        m += "9"
    else:
        m += "1"
print(m)

Buggy submission (verdict: Runtime Error):
n = str(input())
for i in range(3):
    if n[i] == "1":
        n[i] = "9"
    else:
        n[i] = "1"
print(n)
Problem p02659 (python)

Fixed submission:
from decimal import *
i = input().split()
a = int(i[0])
b = Decimal(i[1])
print(int(a * b))

Buggy submission (verdict: Runtime Error):
from decimal import *
i = input().split()
a = int(i[0])
b = Decimal(i[1])i
print(int(a * b))
Problem p02897 (python)

Fixed submission:
N = int(input())
odd_count = 0
for i in range(1,N+1):
	if i % 2 == 1:
		odd_count += 1
print(odd_count/N)

Buggy submission (verdict: Runtime Error):
from math import sqrt
def get_divisor(num):
	arr = [i for i in range(1,int(sqrt(num))) if num % i == 0]
	arr += [num // i for i in reversed(arr)]
	return arr

def get_common(num1, num2):
	list_a = get_divisor(num1)
	list_b = get_divisor(num2)
	return [i for i in list_a if i in list_b]

def prime_ch(num):
	if num == 1:
		return False
	for i in list(range(2,int(sqrt(num))+1)):
		if num % i == 0:
			return False
	return True


A,B = list(map(int,input().split()))[:2]
common = get_common(A,B)
c_prime = [p for p in common if prime_ch(p)]
print((len(c_prime)+1))

Buggy submission (verdict: Runtime Error):
N = int(input())
odd_count = 0
for i in range(1,N+1):
  if i % 2 = 1:
  	odd_count+=1
print(odd_count/N)
Problem p03041 (python)

Fixed submission:
length_and_index = list(map(int,input().split(' ')))
input_str = list(input()[:length_and_index[0]])
input_str[length_and_index[1]-1] = chr(ord(input_str[length_and_index[1]-1])+32)
out = "".join(str(x) for x in input_str)
print(out)

Buggy submission (verdict: Runtime Error):
from math import log2

def prob(num, dice, K):
	times = int(log2(K/num) + 1)
	base  = 1/dice
	if times < 0:
		times = 0
	p = base * pow(0.5,times)
	return p

def sum_prob(dice, K):
	probabilty = 0
	for i in range(1,dice+1):
		probabilty += prob(i, dice, K)
	return probabilty


inputs = list(map(float,input().split(' ')))[:2]
dice = inputs[0]
K = inputs[1]
probabilty = sum_prob(dice, K)
print(probabilty)
Problem p03317 (python)

Fixed submission:
import math
n, k = map(int, input().split())
a = input()
print(math.ceil((n-1)/(k-1)))

Buggy submission (verdict: Runtime Error):
import math
n, k = map(int, input().split())
a = input()
print(math.celi(n-1/k-1))
Problem p03774 (python)

Fixed submission:
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    mindis = 10 ** 9
    for j in range(m):
        dis = abs(s[i][0] - p[j][0]) + abs(s[i][1] - p[j][1])
        if mindis > dis:
            point = j+1
            mindis = dis
    print(point)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    mindis = 10 ** 9
    for j in range(m):
        dis = abs(s[i][0] - p[j][0]) + abs(s[i][1] - p[j][1])
        if mindis > dis:
            p = j+1
            mindis = dis
    print(p)
Problem p03805 (python)

Fixed submission:
import itertools
na = lambda: list(map(int, input().split()))

n, m = na()
t = [[0] * 10 for _ in range(10)]
for _ in range(m):
    a, b = na()
    a -= 1
    b -= 1
    t[a][b] = t[b][a] = 1

ans = 0
for l in itertools.permutations(range(n)):
    if l[0]: continue
    flag = 1
    for i in range(1, n):
        if t[l[i]][l[i-1]] == 0:
            flag = 0
            break
    if flag:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
na = lambda: list(map(int, input().split()))

n, m = na()
t = [[0] * 10 for _ in range(10)]
for _ in range(m):
    a, b = na()
    a -= 1
    b -= 1
    t[a][b] = t[b][a] = 1

ans = 0
for l in itertools.permutations(range(m)):
    if l[0]: continue
    flag = 1
    for i in range(1, n):
        if t[l[i]][l[i-1]] == 0:
            flag = 0
            break
    if flag:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
na = lambda: list(map(int, input().split()))

n, m = na()
t = [[0] * 10 for _ in range(10)]
for _ in range(m):
    a, b = na()
    a -= 1
    b -= 1
    t[a][b] = t[b][a] = 1

ans = 0
for l in itertools.permutations(range(m)):
    if l[0]: continue
    flag = 1
    for i in range(1, n):
        if t[l[i]][l[i-1]] == 0:
            flag = 0
    if flag:
        ans += 1

print(ans)
Problem p02552 (python)

Fixed submission:
n = int(input())

if(n == 0):
    print(1)
elif(n == 1):
    print(0)

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

if(n == 0):
    print(1)
else if(n == 1):
    print(0)

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

if(n == 0):
    printf(1)
else if(n == 1):
    printf(0)

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

if(n == 0):
    printf(1)
if(n == 1):
    printf(0)

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

if(n == 0):
    printf(1)
if(n == 1):
    printf("0")
Problem p02629 (python)

Fixed submission:
N = int(input())

bitts = ''
ans = ''

dic = 'abcdefghijklmnopqrstuvwxyz'

while (N > 0):
    N -= 1
    
    b = N // 26
    mod = N - 26 * b
    bitts += str(mod)
    
    ans += dic[mod]
    
    N = N // 26
    

print(ans[::-1])

Buggy submission (verdict: Runtime Error):

def main():
    import collections

    N = int(input())
    A_s = list(map(int, input().split()))
    Q = int(input())

    summ = sum(A_s)
    CNT_A = collections.Counter(A_s)


    for i in range(Q):
        before, after = map(int, input().split())
        
        tmp_cnt = CNT_A[before]
        
        if (tmp_cnt > 0):
            tmp_before = CNT_A[before] * (after - before)
            summ += tmp_before

            N_before=CNT_A[before]

            del CNT_A[before]
            N_after = CNT_A[after]
            
            if (N_after > 0):
                CNT_A[after] = N_after + N_before
            else:
                CNT_A[after] = N_before
            
        
        print(summ)


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

Fixed submission:
import collections

N = int(input())
S = list(input() for i in range(N))
S.sort()

common = collections.Counter(S).most_common()
N_common = common[0][1]

candidates = [cand for cand in common if cand[1] == N_common]

for i in sorted(candidates):
    print(i[0])

Buggy submission (verdict: Runtime Error):
mport collections

N = int(input())
S = []

for i in range(N):
    S.append(input())

S.sort()
counter = collections.Counter(S)

tmp = counter.most_common()

if (len(tmp) == 1):
    print(tmp[0][0])
else:
    for i in range(len(tmp)-1):
        print(tmp[i][0])
        if (tmp[i][1] != tmp[i + 1][1]):
            break
Problem p02779 (python)

Fixed submission:
import collections

N = int(input())
A = list(input().split())
a = len(collections.Counter(A))
n = len(A)

if (a == n):
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(input().split())
a = len(collections.Counter(A))
n = len(A)

if (a == n):
    print('Yes')
else:
    print('No')
Problem p02819 (python)

Fixed submission:
import numpy as np

def judge_prime(num):
    FLAG = True
    
    for i in range(2, int(np.sqrt(num))+1):
        if (num%i == 0):
            FLAG = False
    
    if (num == 2):
        FLAG = True
    
    return(FLAG)

X = int(input())

while (True):
    flag = judge_prime(X)
    
    if (flag):
        break
    
    X += 1

print(X)

Buggy submission (verdict: Runtime Error):
def judge_prime(num):
    FLAG = True
    
    for i in range(2, int(np.sqrt(num))+1):
        if (num%i == 0):
            FLAG = False
    
    if (num == 2):
        FLAG = True
    
    return(FLAG)

X = int(input())

while (True):
    flag = judge_prime(X)
    
    if (flag):
        break
    
    X += 1

print(X)
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
DP = [1 for i in range(N+1)]
MOD = 10**9 + 7

for i in range(M):
    DP[int(input())] = 0

for i in range(2,N+1):
    
    if (DP[i] != 0):
        DP[i] = DP[i-1] + DP[i-2]
print(DP[N]%MOD)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

DP = [-1 for i in range(N+1)]
stair = [0 for i in range(N+1)]
DP[0] = DP[1] = 1
stair[0] = stair[1] = 1
MOD = 10**9 + 7

for i in range(M):
    index = int(input())
    stair[index] = 0
    DP[index] = 0

def DP_top_down(num):

    if (DP[num] == 0): # broken
        return(0)

    elif (DP[num] == 1): # done
        answer = stair[num]
    
    else:
        answer = DP_top_down(num-2) + DP_top_down(num-1)
        stair[num] = answer # I forgot this operation!
        DP[num] = 1        

    return(answer)

answer = DP_top_down(N)
print(answer%MOD)
Problem p03077 (python)

Fixed submission:
import math
n = int(input())
lists = [int(input()) for i in range(5)]

print(math.ceil(n/min(lists)) + 4)

Buggy submission (verdict: Runtime Error):
n = int(input())
lists = [int(input()) for i in range(5)]
city = [0,0,0,0,0]
time = 0
phase = 1

while sum(city) < n*5:
    for i in range(phase):
        city[i] = min(n,city[i] + lists[i])
        for j in range(5):
            if city[j] > 0:
                phase = max(phase,j+2)
    time += 1

print(time)

Buggy submission (verdict: Runtime Error):
n = int(input())
lists = [int(input()) for i in range(5)]
city = [0,0,0,0,0]
time = 0
phase = 1

while sum(city) < 25:
    for i in range(phase):
        city[i] = min(5,city[i] + lists[i])
        for j in range(5):
            if city[j] > 0:
                phase = max(phase,j+2)
    time += 1

print(time)

Buggy submission (verdict: Runtime Error):

n = int(input())
lists = [int(input()) for i in range(5)]
city = [0,0,0,0,0]
time = 0
phase = 1

while sum(city) < 25:
    for i in range(phase):
        city[i] = min(5,city[i] + lists[i])
        for j in range(5):
            if city[j] > 0:
                phase = max(phase,j+2)
    time += 1

print(time)
Problem p02793 (python)

Fixed submission:
import sys
import fractions
sys.setrecursionlimit(100000)
def lcm(x,y):
    return x//fractions.gcd(x,y)*y

n = int(input())
a = list(map(int,input().split()))
LCM=a[0]
for i in a:
  LCM = lcm(LCM,i)
ans=0
for i in a:
  ans += LCM//i
  
print(int(ans)%1000000007)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
def gcd(x,y):
  if y==0:
      return x
  return gcd(y,x%y)
def lcm(x,y):
    return x/gcd(x,y)*y

n = int(input())
a = list(map(int,input().split()))
LCM=a[0]
for i in a:
  LCM = lcm(LCM,i)
ans=0
for i in a:
  ans += LCM/i
  ans %= 1000000007
  
print(int(ans))

Buggy submission (verdict: Runtime Error):
def gcd(x,y):
  if y==0:
      return x
  return gcd(y,x%y)
def lcm(x,y):
    return x/gcd(x,y)*y

n = int(input())
a = list(map(int,input().split()))
LCM=a[0]
for i in a:
  LCM = lcm(LCM,i)
ans=0
for i in a:
  ans += LCM/i
  ans %= 1000000007
  
print(int(ans))