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

Fixed submission:
import functools

def gcd(x,y):
    big = max(x,y)
    small = min(x,y)
    while small > 0:
        big, small = small, big % small

    return big

N,X = list(map(int,input().strip().split()))
xs = list(map(int,input().strip().split()))

diffs = [abs(X - x) for x in xs]

print(functools.reduce(gcd,diffs))

Buggy submission (verdict: Runtime Error):
import functools
import math

N,X = list(map(int,input().strip().split()))
xs = list(map(int,input().strip().split()))

diffs = [abs(X - x) for x in xs]

print(functools.reduce(math.gcd,diffs))
Problem p03282 (python)

Fixed submission:
S = input()

K = int(input())

index = 0
res = ""

while K > index and index < len(S):
    if S[index] == "1":
        res = "1"
    else:
        res = S[index]
        break;
    index += 1

print(res)

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

K = int(input())

tmp = 0
index = 0
res = ""

while K > tmp:
    if S[index] == "1":
        res = "1"
    else:
        res = S[index]
        break;
    index += 1

print(res)
Problem p03294 (python)

Fixed submission:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)  # 再帰定義

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


N = int(input().strip())
ar = list(map(int,input().strip().split()))

koubai = 1

for i in range(0,len(ar)):
    koubai = lcm(ar[i],koubai)

res = 0
koubai -= 1
for i in range(0,len(ar)):
    res += koubai % ar[i]
print(res)

Buggy submission (verdict: Runtime Error):
import math

N = int(input().strip())
ar = list(map(int,input().strip().split()))

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

koubai = 1

for i in range(0,len(ar)):
    koubai = lcm(ar[i],koubai)

res = 0
koubai -= 1
for i in range(0,len(ar)):
    res += koubai % ar[i]
print(res)
Problem p03568 (python)

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


def dfs(A_s, index,Bss):
    if index == N:
        tmp = 1
        for b in Bss:
            tmp *= b
        return 1 if tmp % 2 == 0 else 0
    b_mi = Bss.copy()
    b_mi.append(A_s[index] - 1)

    b = Bss.copy()
    b.append(A_s[index])

    b_pl = Bss.copy()
    b_pl.append(A_s[index] + 1)
    return dfs(A_s,index + 1, b_mi) + dfs(A_s,index + 1,b) + dfs(A_s,index + 1,b_pl)


print(dfs(As,0,[]))

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


def dfs(A_s, index,Bss):
    if index == N:
        tmp = 1
        for b in Bss:
            tmp *= b
        return 1 if tmp % 2 == 0 else 0
    b_mi = Bss.copy()
    b_mi.append(A_s[index] - 1)

    b = Bss.copy()
    b.append(A_s[index])

    b_pl = Bss.copy()
    b_pl.append(A_s[index] + 1)
    return dfs(A_s,index + 1, b_mi) + dfs(A_s,index + 1,b) + dfs(A_s,index + 1,b_pl)


print(dfs(As,0,[]))
Problem p03609 (python)

Fixed submission:
x,t = map(int,input().split())
 
print(max(x - t,0))

Buggy submission (verdict: Runtime Error):
x,t = map(int,input().split())

print(max(x - t),0)
Problem p03633 (python)

Fixed submission:
import itertools
import math


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


def lcm(left, right):
    return (left * right) // gcd(left, right)


N = int(input().strip())
Ts = []
for i in range(N):
    Ts.append(int(input().strip()))

res = 0
if len(Ts) == 0:
    res = 0
elif len(Ts) == 1:
    res = Ts[0]
else:
    res = int(lcm(Ts[0], Ts[1]))
    for T in Ts[2:]:
        res = int(lcm(res, T))

print(str(int(res)))

Buggy submission (verdict: Runtime Error):
import itertools
import math


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


def lcm(left, right):
    return (int(left) * int(right)) / int(gcd(left, right))


N = int(input().strip())
Ts = []
for i in range(N):
    Ts.append(int(input().strip()))

res = 0
if len(Ts) == 0:
    res = 0
elif len(Ts) == 1:
    res = Ts[0]
else:
    res = int(lcm(Ts[0], Ts[1]))
    for T in Ts[2:]:
        res = int(lcm(res, T))

print(str(int(res)))

Buggy submission (verdict: Runtime Error):
import itertools
import math


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


def lcm(left, right):
    return (int(left) * int(right)) / int(gcd(left, right))


N = int(input().strip())
Ts = []
for i in range(N):
    Ts.append(int(input().strip()))

res = int(lcm(Ts[0], Ts[1]))
for T in Ts[2:]:
    res = int(lcm(res, T))

print(str(int(res)))

Buggy submission (verdict: Runtime Error):
import itertools
import math


def lcm(left,right):
    return (int(left) * int(right)) / int(math.gcd(left,right))


N = int(input().strip())
Ts = []
for i in range(N):
    Ts.append(int(input().strip()))

res = int(lcm(Ts[0], Ts[1]))
for T in Ts[2:]:
    res = int(lcm(res, T))

print(int(res))

Buggy submission (verdict: Runtime Error):
import itertools
import math


def lcm(left,right):
    return (int(left) * int(right)) / int(math.gcd(left,right))


N = int(input().strip())
Ts = []
for i in range(N):
    Ts.append(int(input()))

res = int(lcm(Ts[0], Ts[1]))
for T in Ts[2:]:
    res = int(lcm(res, T))

print(int(res))
Problem p03644 (python)

Fixed submission:
N = int(input())
n = 1
while n <= N:
  n *= 2
     
print(n // 2)

Buggy submission (verdict: Runtime Error):
    N = int(input())
    n = 1
    while n <= N:
        n *= 2
     
    print(n // 2)

Buggy submission (verdict: Runtime Error):
N = int(intpu())
n = 1
while n < N:
  n *= 2
  
print(n // 2)
Problem p03699 (python)

Fixed submission:
N = int(input())
sl = []
for n in range(N):
    sl.append(int(input()))

sum = sum(sl)
sorted_sl = sorted(filter(lambda s: s % 10 != 0,sl))
if len(sorted_sl) == 0:
    print(0)
    exit()
count = 0
while sum % 10 == 0 and count < len(sorted_sl):
    sum -= sorted_sl[count]
    count += 1

print(sum)

Buggy submission (verdict: Runtime Error):
def get_sum(n, index, s, slist):
    if index == n:
        if s % 10 == 0:
            s = 0
        return s
    left = get_sum(n, index + 1, s + slist[index], slist)
    right = get_sum(n, index + 1, s, slist)
    return max(left, right)


N = int(input())
sl = []
for n in range(N):
    sl.append(int(input()))

sum = sum(sl)
sorted_sl = sorted(filter(lambda s: s % 10 == 0,sl))
if len(sorted_sl) == 0:
    print(0)
    exit()
count = 0
while sum % 10 == 0 and count < N:
    sum -= sorted_sl[count]
    count += 1

print(sum)
Problem p03103 (python)

Fixed submission:
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

sortAB = sorted(AB)

ans = 0
num = M
for i in sortAB:
    a,b = i
    if num >= b:
        num -= b
        ans += a* b
    else:
        ans += a * num
        break

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

sortAB = sorted(AB)

ans = 0
num = M
for i in sortAB:
    a,b = i
    if num >= b:
        num -= b
        ans += a* b
    else:
        ans += i * num
        break

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

A = []
B = []
for i in AB:
    a,b = i
    A.append(a)
    B.append(b)

sortA = sorted(A)

ans = 0
num = M
for i in sortA:
    ind = A.index(i)
    k = B[ind]
    if num > k:
        num -= k
        ans += i* k
    else:
        while True:
            if K == 0:
                break
            ans += i
            k -=1
print(ans)
Problem p03545 (python)

Fixed submission:
ABCD = input()

for i in range(1 << 3):
    total = int(ABCD[0])
    equation = ABCD[0]
    for j in range(3):
        if i & (1 << j):
            total += int(ABCD[j+1])
            equation += "+"
        else:
            total -= int(ABCD[j+1])
            equation += "-"    
        equation += ABCD[j+1]
    if total == 7:
        equation += "=7"
        print(equation)
        break

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

for i in range(1 << 3):
    total = ABCD[0]
    equation = str(ABCD[0])
    for j in range(3):
        if i & (1 << j):
            total += ABCD[j+1]
            equation += "+"
        else:
            total -= ABCD[j+1]
            equation += "-"    
        equation += str(ABCD[j+1])
    if total == 7:
        equation += "=7"
        print(equation)
        break

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

for i in range(1 << 3):
    total = ABCD[0]
    equation = str(ABCD[0])
    for j in range(3):
        if i & (1 << j):
            total += ABCD[j+1]
            equation.append("+")
        else:
            total -= ABCD[j+1]
            equation.append("-")    
        equation.append(ABCD[j+1])
    if total == 7:
        equation.append("=7")
        print(equation)
        break
Problem p04001 (python)

Fixed submission:
S = input()
ans = 0
for i in range(1 << (len(S)-1)):
    eq = S
    k = 0
    for j in range(len(S)-1):
        if i & (1 << j):
            eq = eq[:j+1+k] + "," + eq[j+1+k:]
            k +=1
        else:
            pass
    eq = eq.split(",")
    eq = list(map(int,eq))
    ans += sum(eq)
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
ans = 0
for i in range(1 << (len(S)-1)):
    eq = S
    for j in range(len(S)-1):
        if i & (1 << j):
            eq = eq[:j+1] + "," + eq[j+1:]
        else:
            pass
    eq = eq.split(",")
    eq = list(map(int,eq))
    ans += sum(eq)
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
ans = 0
for i in range(1 << (len(S)-1)):
    eq = S
    for j in range(len(S)-1):
        if i & (1 << j):
            eq = eq[:j+1] + "," + eq[j+1:]
        else:
            pass
    eq = eq.split(",")
    ans += sum(eq)
print(ans)
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split(' '))
if a % 2 == 0 or b % 2 == 0:
    print("Even")
else:
    print("Odd")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split(' ')
if a % 2 == 0 or b % 2 == 0:
    print('Even')
else:
    print("Odd")
Problem p02714 (python)

Fixed submission:
n = int(input())
s = input()

r = g = b = 0
for i in range(n):
    if s[i] == 'R':
        r += 1
    elif s[i] == 'G':
        g += 1
    else:
        b += 1

x = 0
for i in range(n):
    for j in range(i+1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            x += 1
print(r*g*b-x)

Buggy submission (verdict: Runtime Error):
from numba import njit
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline

N = int(input())
S = np.array(list(read().rstrip()), np.int8)

R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))


@njit
def f(S):
    N = len(S)
    ret = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = j + j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret


answer = R * B * G - f(S)
print(answer)
Problem p02934 (python)

Fixed submission:
import numpy as np
n = int(input())
a = np.array([input().split()], np.float64)
print(1/(1 / a).sum())

Buggy submission (verdict: Runtime Error):
import numpy as np
from decimal import Decimal
n = int(input())
a = list(map(int, input().split()))
S = np.int64(np.prod(a))
T = 0
for x in a:
    T += Decimal(S / x)
print(Decimal(S / T))

Buggy submission (verdict: Runtime Error):
import numpy as np
from decimal import Decimal
n = int(input())
a = list(map(int, input().split()))
S = np.prod(a)
T = 0
for x in a:
    T += Decimal(S / x)
print(Decimal(S / T))
Problem p02936 (python)

Fixed submission:
N, Q = map(int, input().split())
graph = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

C = [0] * (N + 1)
for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x

se = set([1])
stack = [1]
while stack:
    # print(C)
    x = stack.pop()
    for y in graph[x]:
        if y in se:
            continue
        stack.append(y)
        se.add(y)
        # 親x, 子y
        C[y] += C[x]

print(' '.join(str(i) for i in C[1:]))

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

N, Q = map(int, input().split())
Child = [[] for _ in range(N)]
X = np.zeros(N, np.int64)
Y = np.zeros(N, np.int64)
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    Child[a].append(b)
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    X[p] += x


def dfs(u, k):
    Y[u] += k
    for v in Child[u]:
        dfs(v, k + X[v])


dfs(0, X[0])
print(' '.join(str(y) for y in Y))

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

N, Q = map(int, input().split())
Child = np.zeros((N, N), np.bool)
X = np.zeros(N, np.int64)
Y = np.zeros(N, np.int64)
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    Child[a, b] = True
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    X[p] += x


def dfs(u, k):
    Y[u] += k
    for v, flag in enumerate(Child[u, :]):
        if flag:
            dfs(v, k + X[v])


dfs(0, X[0])
print(' '.join(str(y) for y in Y))

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

N, Q = map(int, input().split())
Child = np.zeros((N, N), np.bool)
X = np.zeros(N, np.int32)
Y = np.zeros(N, np.int32)
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    Child[a, b] = True
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    X[p] += x


def dfs(u, k):
    Y[u] += k
    for v in range(N):
        if Child[u, v]:
            dfs(v, k + X[v])


dfs(0, X[0])
print(' '.join(str(y) for y in Y))
Problem p03162 (python)

Fixed submission:
import numpy as np

n = int(input())
X = np.array([input().split() for _ in range(n)], np.int64)
dp = np.zeros((n + 1, 3), np.int64)
dp[0, 0] = dp[0, 1] = dp[0, 2] = 0
for i in range(n):
    for j in range(3):
        dp[i + 1, j] = X[i, j] + max(dp[i, k] for k in range(3) if j != k)
print(max(dp[n]))

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

n = int(input())
X = np.array([input().split() for _ in range(n)], np.int64)
dp = np.zeros((n + 1, 3), np.int64)
dp[0, 0] = dp[0, 1] = dp[0, 2] = 0
for i in range(n):
    for j in range(3):
        dp[i + 1, j] = X[i, j] + max(dp[i, k] for k in range(3) if j != k)
print(max(dp[n]))
Problem p03261 (python)

Fixed submission:
n = int(input())

s = [input() for i in range(n)]

def shiritori(s):
  if len(s) != len(set(s)):
    return False
  
  for i in range(n-1):
    if s[i][-1] != s[i+1][0]:
      return False
  
  return True

if __name__ == '__main__':
  if shiritori(s):
    print("Yes")
  else:
    print("No")

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

s = [input() for i in range(n)]

def shiritori(s):
  if len(s) != len(set(s)):
    return "No"
  
  for i in range(n-1):
    if s[i][-1] != s[i+1][0]:
      return "No"
  
  return "Yes"

shiritori()
Problem p02705 (python)

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

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int,input().split()))
a = [0 for _ in range(26)]
for i in l:
  a[i-1]+=1
  
for i in range(n):
  print(a[i])
Problem p02706 (python)

Fixed submission:
m_n = list(map(int,input().split()))
m = m_n[0]
n = m_n[1]
a = list(map(int,input().split()))
 
ans = m - sum(a)
 
if ans < 0:
  print(-1)
else:
  print(ans)

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

ans = m - sum(a)

if ans < 0:
  print(-1)
else:
  print(ans)
Problem p03739 (python)

Fixed submission:
import copy 

def resolve(List):
    # L[0]!=0を起点とする
    L = copy.deepcopy(List)
    cnt = 0
    s = L[0]
    for i in range(1,len(L)):
        a = L[i]
        if(s>0 and s+a>=0):
            L[i] = -s-1
            cnt += (s+a+1)
            s = -1
        elif(s<0 and s+a<=0):
            L[i] = -s+1
            cnt += (-s-a+1)
            s = 1
        else:
            s += a
    return cnt      

def ans(List):
    L = copy.deepcopy(List)
    a = L[0]
    c0,c1=0,0

    if (a>0):
        c0 = resolve(L)
        c1 = (a+1) + resolve([-1]+L[1:])
    elif (a<0):
        c0 = resolve(L)
        c1 = (-a+1) + resolve([1]+L[1:])
    else:
        c0 = 1 + resolve([1]+L[1:])
        c1 = 1 + resolve([-1]+L[1:])
    
    return(min(c0,c1))

def main():
    N = int(input())
    List = [int(x) for x in input().split(' ')]
    print(ans(List))

main()

Buggy submission (verdict: Runtime Error):
def resolve(SL):
    # L[0]!=0を起点とする
    cnt = 0
    for i in range(len(SL)-1):
        s0 = SL[i]
        s1 = SL[i+1]
        if(s0>0 and s1>=0):
            SL[(i+1):] = [s-(s1+1) for s in SL[(i+1):]]
            cnt += (s1+1)
        elif(s0<0 and s1<=0):
            SL[(i+1):] = [s+(-s1+1) for s in SL[(i+1):]]
            cnt += (-s1+1)  
#         print(SL)
    return cnt
           
def ans(L):
    SL = [sum(L[:(i+1)]) for i in range(len(L))]
    c0,c1=0,0
    
    if (L[0]>0):
        c0 = resolve(SL)
        c1 = (L[0]+1) + resolve(list(map(lambda x:x-(L[0]+1), SL)))
    elif (L[0]<0):
        c0 = resolve(L)
        c1 = (-L[0]+1) + resolve(list(map(lambda x:x+(-L[0]+1), SL)))
    else:
        c0 = 1 + resolve(list(map(lambda x:x+1, SL)))
        c1 = 1 + resolve(list(map(lambda x:x-1, SL)))
    
    return(min(c0,c1))

N = int(input())
L = [int(input(x)) for x in range(N)]

print(ans(L))
Problem p02958 (python)

Fixed submission:
def check(a):
  for i in range(1,len(a)):
    if a[i-1]>a[i]:
      return False
  return True
n=int(input())
a=list(map(int,input().split()))
if check(a):
  print('YES')
  exit()
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[i],a[j]=a[j],a[i]
    if check(a):
      print('YES')
      exit()
    a[i],a[j]=a[j],a[i]
print('NO')

Buggy submission (verdict: Runtime Error):
def check(a):
  for i in range(1,len(n)):
    if a[i-1]>a[i]:
      return False
  return True
n=int(input())
a=list(map(int,input().split()))
if check(a):
  print('YES')
  exit()
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[i],a[j]=a[j],a[i]
    if check(a):
      print('YES')
      exit()
    a[i],a[j]=a[j],a[i]
print('NO')
Problem p03032 (python)

Fixed submission:
n,k=map(int,input().split())
ls,lm,rs,rm=[0],[[0 for i in range(k+1)]for i in range(n+1)],[0],[[0 for i in range(k+1)]for i in range(n+1)]
v=list(map(int,input().split()))
ld=[]
rd=[]
for i in range(n):
    ls.append(ls[-1]+v[i])
    if v[i]<0:
        ld.append(v[i])
        ld=sorted(ld)
    for j in range(1,k+1):
        if j-1<len(ld):
            lm[i+1][j]=lm[i+1][j-1]+ld[j-1]
        else:
            lm[i+1][j]=lm[i+1][j-1]
    ii=n-i-1
    rs.append(rs[-1]+v[ii])
    if v[ii]<0:
        rd.append(v[ii])
        rd=sorted(rd)
    for j in range(1,k+1):
        if j-1<len(rd):
            rm[i+1][j]=rm[i+1][j-1]+rd[j-1]
        else:
            rm[i+1][j]=rm[i+1][j-1]


mx=-999999999
for w in range(k+1):
    for x in range(w+1):
        for y in range(x,w+1):
            for z in range(y,w+1):
                    a,b,c,d=x,y-x,z-y,w-z
                    if a+c<=n and len(ls)>a>=b and len(rs)>c>=d and ls[a]-lm[a][b]+rs[c]-rm[c][d]>mx:
                        # print(a,b,c,d,ls[a],lm[a][b],rs[c],rm[c][d],ls[a]-lm[a][b]+rs[c]-rm[c][d])
                        mx=ls[a]-lm[a][b]+rs[c]-rm[c][d]
print(mx)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
ls,lm,rs,rm=[0],[[0 for i in range(k+1)]for i in range(n+1)],[0],[[0 for i in range(k+1)]for i in range(n+1)]
v=list(map(int,input().split()))
ld=[]
rd=[]
for i in range(n):
    ls.append(ls[-1]+v[i])
    if v[i]<0:
        ld.append(v[i])
        ld=sorted(ld)
    for j in range(1,k+1):
        if j-1<len(ld):
            lm[i+1][j]=lm[i+1][j-1]+ld[j-1]
        else:
            lm[i+1][j]=lm[i+1][j-1]
    ii=n-i-1
    rs.append(rs[-1]+v[ii])
    if v[ii]<0:
        rd.append(v[ii])
        rd=sorted(rd)
    for j in range(1,k+1):
        if j-1<len(rd):
            rm[i+1][j]=rm[i+1][j-1]+rd[j-1]
        else:
            rm[i+1][j]=rm[i+1][j-1]


mx=-9999999999
for x in range(k+1):
    for y in range(x,k+1):
        for z in range(y,k+1):
            for w in range(z,k+1):
                a,b,c,d=x,y-x,z-y,w-z
                if a>=b and c>=d and len(lm)>b and len(rm)>d and ls[a]-lm[a][b]+rs[c]-rm[c][d]>mx:
                    # print(a,b,c,d,ls[a],lm[a][b],rs[c],rm[c][d],ls[a]+lm[a][b]+rs[c]+rm[c][d])
                    mx=ls[a]-lm[a][b]+rs[c]-rm[c][d]
print(mx)
Problem p03142 (python)

Fixed submission:
# coding: utf-8
import sys
sys.setrecursionlimit(100000)
n,m=map(int,input().split())
g=[set() for i in range(n)]
revg=[set() for i in range(n)]
for i in range(n+m-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].add(b)
    revg[b].add(a)
p=0
while True:
    if len(revg[p])==0:
        break
    for nxt in revg[p]:
        p=nxt
        break
ans=[-1 for i in range(n)]
ans[p]=0
def check(pos):
    for nxt in g[pos]:
        revg[nxt].remove(pos)
    for nxt in g[pos]:
        if len(revg[nxt])==0 and ans[nxt]==-1:
            ans[nxt]=pos+1
            check(nxt)
check(p)
print(*ans,sep='\n')

Buggy submission (verdict: Runtime Error):
# coding: utf-8
n,m=map(int,input().split())
g=[set() for i in range(n)]
revg=[set() for i in range(n)]
for i in range(n+m-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    g[a].add(b)
    revg[b].add(a)
p=0
while True:
    if len(revg[p])==0:
        break
    for nxt in revg[p]:
        p=nxt
        break
ans=[-1 for i in range(n)]
ans[p]=0
def check(pos):
    if len(g[pos])==0:
        return
    for nxt in g[pos]:
        revg[nxt].remove(pos)
    for nxt in g[pos]:
        if len(revg[nxt])==0 and ans[nxt]==-1:
            ans[nxt]=pos+1
            check(nxt)
check(p)
print(*ans,sep='\n')
Problem p03160 (python)

Fixed submission:
# coding: utf-8
n=int(input())
h=list(map(int,input().split()))
dp=[999999999 for i in range(n)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
input=lambda : sys.stdin.readline().rstrip('\n')

n=int(input())
h=list(map(int,input().split()))

dp=[10**18 for i in range(n)]
def cost(n):
    if n==0:
        return 0
    if n<0:
        return 10**18
    if dp[n]!=10**18:
        return dp[n]
    dp[n] = min(cost(n-1)+abs(h[n]-h[n-1]),cost(n-2)+abs(h[n]-h[n-2]))
    return dp[n]

print(cost(n-1))
Problem p03294 (python)

Fixed submission:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
 
n=int(input())
A=list(map(int,input().split()))
ans=1
for x in A:
    ans=ans*x//gcd(ans,x)
ans-=1
t=0
for x in A:
    t+=ans%x
print(t)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
A=list(map(int,input().split()))
ans=1
for x in A:
    ans=ans*x//math.gcd(ans,x)
ans-=1
t=0
for x in A:
    t+=ans%x
print(t)
Problem p03394 (python)

Fixed submission:
data=[]
for i in range(1,30001):
    if i%2==0 or i%3==0:
        data.append(i)
k=int(input())
if k==3:
    print(*[2,5,63])
elif k==4:
    print(*[2,5,20,63])
elif k==5:
    print(*[2,5,20,63,30])
else:
    ans=data[:k]
    sm=sum(ans)
    if sm%6==2:
        ans[4]=30000
    elif sm%6==3:
        ans[5]=30000
    elif sm%6==5:
        ans[5]=29998
    print(*ans)

Buggy submission (verdict: Runtime Error):
data=[]
for i in range(1,30001):
    if i%2==0 or i%3==0:
        data.append(i)
k=int(input())
if k==3:
    print(*[2,5,63])
elif k==4:
    print(*[2,5,20,63])
elif k==5:
    print(*[2,5,20,63,6])
ans=data[:k]
sm=sum(ans)
if sm%6==2:
    ans[4]=30000
elif sm%6==3:
    ans[5]=30000
elif sm%6==5:
    ans[5]=29998
print(*ans)
Problem p03469 (python)

Fixed submission:
# coding: utf-8
#map(int,input().split())
print('2018'+input()[4:])

Buggy submission (verdict: Runtime Error):
print(''.join((lambda s:s[3]='8')(list(input()))))