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

Fixed submission:
n, x = map(int, input().split())
xi = list(map(int, input().split()))

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

def gcd_l(*numbers):
	ret = numbers[0]
	for n in numbers[1:]:
		ret = gcd(ret, n)
	return ret

xi = map(lambda y:abs(y-x), xi)
print(gcd_l(*xi))

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

import fraction

def gcd(*numbers):
	ret = numbers[0]
	for n in numbers[1:]:
		ret = fraction.gcd(ret, n)
	return ret

xi = map(lambda y:abs(y-x), xi)
print(gcd(*xi))

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

import fraction

def gcd(*numbers):
	ret = numbers[0]
	for n in numbers[1:]:
		ret = fraction.gcd(ret, n)
    return ret

xi = map(lambda y:abs(y-x), xi)
print(gcd(*xi))

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

import fraction
import functools

def gcd(*numbers):
    return functools.reduce(fraction.gcd, numbers)

xi = map(lambda y:y-x, xi)
print(gcd(*xi))

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

import fraction
import reduce

def gcd(*numbers):
    return functools.reduce(fraction.gcd, numbers)

xi = map(lambda y:y-x, xi)
print(gcd(*xi))

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

import math
import fraction
from functools import reduce

def gcd(*numbers):
    return reduce(fraction.gcd, numbers)

xi = map(lambda y:y-x, xi)
print(gcd(*xi))

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

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

xi = map(lambda y:y-x, xi)
print(gcd(*xi))
Problem p03323 (python)

Fixed submission:
a, b = list(map(int, input().split()))
 
s = 16
for i in range(16):
	if i%2 == 0:
		if a > 0:
			s -= 1
			a -= 1
	else:
		if b > 0:
			s -= 1
			b -= 1
	if s < 0:
		break
 
if a > 0 or b > 0:
	print(':(')
else:
	print('Yay!')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
 
s = 16
for i in range(16):
	if i%2 == 0:
		if a > 0:
			s -= 1
			a -= 1
	else:
		if b > 0:
			s -= 1
			b -= 1
	if s < 0:
		break
 
if a > 0 or b > 0:
	print(':(')
else:
	print('Yay!')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())

s = 16
for i in range(16):
	if i%2 == 0:
		if a > 0:
			s -= 1
			a -= 1
	else:
		if b > 0:
			s -= 1
			b -= 1
	if s < 0:
		break

if a > 0 or b > 0:
	print(':(')
else:
	print('Yay!')
Problem p03324 (python)

Fixed submission:
d, n = map(int, input().split())

c = 0
i = 1
while True:
	if i % 100 != 0:
		c += 1
	if c == n:
		break
	i += 1

print(i * (100**(d)))

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

print([i for i in range(1, n+1) if i % (100**(d)) != 0][-1] * (100**(d)))
Problem p03337 (python)

Fixed submission:
a, b = map(int, input().split())
 
print(max(a+b, a-b, a*b))

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

print(max(a+b, a-b, a*b)
Problem p03339 (python)

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

ms = n
a = 0
b = s.count('E')
for i in range(n):
	if(i != 0 and s[i-1] == 'W'):
		a += 1
	if(s[i] == 'E'):
		b -= 1
	# print(s[0:i], s[i+1:n], s[0:i].count('W'), s[i+1:n].count('E'), a, b)
	# c = s[0:i].count('W')
	# c += s[i+1:n].count('E')
	c = a + b
	if(ms > c):
		ms = c

print(ms)

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

ms = n
for i in range(n):
	c = s[0:i].count('W')
	c += s[i+1:n].count('E')
	print(s[0:i], s[i+1:n], c)
	if(ms >= c):
		ms = c
	else:
		break

print(ms)
Problem p03353 (python)

Fixed submission:
import re

str = input()
k = int(input())

strl = list(set([c for c in str]))
strl.sort()

substring = []
for h in strl:
	compiled = re.compile(h)
	st = 0
	m = compiled.search(str, st)
	while m:
		sub = m.start()
		for i in range(sub, min(len(str), sub+5)):
			t = str[sub:i+1]
			if(not (t in substring)):
				substring.append(t)
		st = sub + 1
		m = compiled.search(str, st)
	
	if(len(substring)-len(strl) >= k-1):
		break


substring.sort()
print(substring[k-1])

Buggy submission (verdict: Runtime Error):
import re

str = input()
k = int(input())

strl = list(set([c for c in str]))
strl.sort()

substring = []
for h in strl:
	compiled = re.compile(h)

	i = 0
	while i >= 0:
		m = compiled.search(str, i)
		if m:
			sub = m.start()
			for i in range(sub, len(str)):
				t = str[sub:i+1]
				if(not (t in substring)):
					substring.append(t)
			substring.sort()
			if(len(substring)-len(strl) >= k-1):
				break
			i = sub + 1
		else:
			break
	else:
		continue
	break


substring.sort()
print(substring[k-1])

Buggy submission (verdict: Runtime Error):
str = input()
k = int(input())

strl = []
for c in str:
    if(not (c in strl)):
        strl.append(c)
strl.sort()

substring = []
for h in strl:
	sub = str.find(h)
	for i in range(sub, len(str)-1):
		t = str[sub:i+1]
		if(not (t in substring)):
			substring.append(t)
		# substring.sort()
		# if(substring[k-1] is str[sub:i+1]):
			# break
	# else:
		# continue
	# break


substring.sort()
print(substring[k-1])
Problem p03611 (python)

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

r = [0] * (10**5+2)
for i in range(N):
    r[a[i]] += 1
    r[a[i]+1] += 1
    r[a[i]+2] += 1

print(max(r))

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

N = int(input())
a = np.array(list(map(int, input().split())))

r = np.zeros(10**5+2)
for i in range(N):
    r[a[i]] += 1
    r[a[i]+1] += 1
    r[a[i]+2] += 1

print(int(r.max()))
Problem p02840 (python)

Fixed submission:
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X, D = map(int, raw_input().split())
if D == 0:
    if X == 0:
        print 1
    else:
        print N + 1
    exit()
if D < 0:
    X = X + D * (N - 1)
    D = -D
m1 = {}
m2 = {}
m1[0] = D
m2[0] = -D
ans = 1
for i in range(1, N + 1):
    p1 = (X + X + D * (i - 1)) * i / 2
    p2 = (X + D * (N - 1) + X + D * (N - i)) * i / 2
    rem = p1 % D
    if rem in m1:
        ans += max(0, (p2 - max(m1[rem], p1)) / D + 1)
        ans += max(0, (min(p2, m2[rem]) - p1) / D + 1)
    else:
        ans += (p2 - p1) / D + 1
    m1[rem] = p2 + D
    m2[rem] = p1 - D
print ans

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, X, D = map(int, raw_input().split())
if D < 0:
    X = X + D * (N - 1)
    D = -D
m1 = {}
m2 = {}
m1[0] = D
m2[0] = -D
ans = 1
for i in range(1, N + 1):
    p1 = (X + X + D * (i - 1)) * i / 2
    p2 = (X + D * (N - 1) + X + D * (N - i)) * i / 2
    rem = p1 % D
    if rem in m1:
        ans += max(0, (p2 - max(m1[rem], p1)) / D + 1)
        ans += max(0, (min(p2, m2[rem]) - p1) / D + 1)
    else:
        ans += (p2 - p1) / D + 1
    m1[rem] = p2 + D
    m2[rem] = p1 - D
print ans
Problem p03025 (python)

Fixed submission:
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

def rev_mod(num):
	pow_num = MOD - 2
	mod_num = MOD
	pow_cur = num
	ret = 1
	while pow_num > 0:
		if pow_num % 2 == 1:
			ret *= pow_cur
			ret %= mod_num
		pow_cur *= pow_cur
		pow_cur %= mod_num
		pow_num /= 2
	return ret

N, A, B, C = map(int, raw_input().split())

ans = 0

for loop in range(2):
    cnt = 0
    P = 1
    comb = 1
    PA = (A * rev_mod(A + B)) % MOD
    PB = (B * rev_mod(A + B)) % MOD
    PCm = 100 * rev_mod(100 - C) % MOD
    for i in range(N - 1):
        P *= PA
        P %= MOD

    for i in range(N):
        ans += PCm * (N + i) % MOD * P % MOD * comb % MOD * PA
        ans %= MOD
        P *= PB
        P %= MOD
        comb *= N + i
        comb *= rev_mod(i + 1)
        comb %= MOD
    A, B = B, A
print ans

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

def rev_mod(num):
	pow_num = MOD - 2
	ret = 1
	while pow_num > 0:
        ret *= num * (pow_num % 2)
        ret %= MOD
		num *= num
		num %= MOD
		pow_num /= 2
	return ret

N, A, B, C = map(int, raw_input().split())

ans = 0

for loop in range(2):
    cnt = 0
    P = 1
    comb = 1
    PA = (A * rev_mod(A + B)) % MOD
    PB = (B * rev_mod(A + B)) % MOD
    PCm = 100 * rev_mod(100 - C) % MOD
    for i in range(N - 1):
        P *= PA
        P %= MOD

    for i in range(N):
        ans += PCm * (N + i) % MOD * P % MOD * comb % MOD * PA
        ans %= MOD
        P *= PB
        P %= MOD
        comb *= N + i
        comb %= MOD
        comb *= rev_mod(i + 1)
        comb %= MOD
    A, B = B, A
print ans
Problem p03106 (python)

Fixed submission:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

A, B, K = map(int, raw_input().split())

cnt = 0

for i in range(1, max(A, B) + 1)[::-1]:
    if A % i == 0 and B % i == 0:
        cnt += 1
    if cnt == K:
        print i
        exit()

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split());print([i for i in range(A,0,-1)if1>A%i+B%i][K-1])

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split());print[i for i in range(A,0,-1)if 1>A%i+B%i][K-1]

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,input().split());print[i for i in range(A,0,-1)if1>A%i+B%i][K-1]

Buggy submission (verdict: Runtime Error):
A,B,K=map(int,raw_input().split());print[i for i in range(A,0,-1)if1>A%i+B%i][K-1]
Problem p03111 (python)

Fixed submission:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, A, B, C = map(int, raw_input().split())
l = [int(input()) for i in range(N)]

ans = 10 ** 12

for i in range(4 ** N):
  S = [0, 0, 0, 0]
  hoge = i
  cost = -30
  for j in range(N):
    S[hoge % 4] += l[j]
    if hoge % 4 < 3:
      cost += 10
    hoge /= 4
  if S[0] * S[1] * S[2] == 0:
    continue
  ans = min(ans, cost + abs(S[0] - A) + abs(S[1] - B) + abs(S[2] - C))

print ans

Buggy submission (verdict: Runtime Error):
N, A, B, C = map(int,input().split())
ans = [[0, 0, 0, 0]]
for i in range(N): ans = [[p[j] + int(input()) * (i == j) for j in [0, 1, 2]] + [p[3]+(i < 3)] for p in ans for i in range(4)]
print(min(abs(p[0] - A) + abs(p[1] - B) + abs(p[2] - C) + p[3] * 10 - 30 for p in ans if min(p[:3]) > 0))
Problem p03128 (python)

Fixed submission:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, M = map(int, raw_input().split())
cost = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
A = map(int, raw_input().split())

DP = [0] + [-1] * N
ans = [0] * N + [0]

for i in range(1, N + 1):
    for j in range(10)[::-1]:
        if not j in A:
            continue
        if cost[j] > i:
            continue
        if DP[i - cost[j]] < 0:
            continue
        if DP[i] < DP[i - cost[j]] + 1:
            DP[i] = DP[i - cost[j]] + 1
            ans[i] = j

S = ""
pos = N
while pos != 0:
    S += str(ans[pos])
    pos -= cost[ans[pos]]

print S

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, M = map(int, raw_input().split())
cost = [0,2,5,5,4,5,6,3,7,6]
A = sorted(map(int, raw_input().split()))

DP = [0] + [-1] * N * 2
ans = [0, 0] * N

for i in range(1, N + 1):
    for j in A:
        pos = i - cost[j]
        if min(pos, DP[pos], DP[pos] + 1 - DP[i]) >= 0:
            DP[i], ans[i] = DP[pos] + 1, j

S, pos = "", N
while pos:
    S += str(ans[pos])
    pos -= cost[ans[pos]]

print S

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, M = map(int, raw_input().split())
cost = [0,2,5,5,4,5,6,3,7,6]
A = sorted(map(int, raw_input().split()))

DP = [0] + [-1] * N
ans = [0, 0] * N

for i in range(1, N + 1):
    for j in A:
        pos = i - cost[j]
        if min(pos, DP[pos], DP[pos] + 1 - DP[i]) >= 0:
            DP[i], ans[i] = DP[pos] + 1, j

S, pos = "", N
while pos:
    S += str(ans[pos])
    pos -= cost[ans[pos]]

print S
Problem p03166 (python)

Fixed submission:
import itertools as ite
import math
import random
import sys

INF = 10 ** 18
MOD = 10 ** 9 + 7

sys.setrecursionlimit(1000000)

N, M = map(int, raw_input().split())
E = [[] for i in range(N + 1)]
for i in range(M):
    x, y = map(int, raw_input().split())
    E[x].append(y)

m = {}
def func(pos):
    if pos in m:
        return m[pos]
    ret = 0
    for to in E[pos]:
        ret = max(ret, func(to) + 1)
    m[pos] = ret
    return ret

print max(func(i) for i in range(1, N + 1))

Buggy submission (verdict: Runtime Error):
import itertools as ite
import math
import random

INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = map(int, raw_input().split())
E = [[] for i in range(N + 1)]
for i in range(M):
    x, y = map(int, raw_input().split())
    E[x].append(y)

m = {}
def func(pos):
    if pos in m:
        return m[pos]
    ret = 0
    for to in E[pos]:
        ret = max(ret, func(to) + 1)
    m[pos] = ret
    return ret

print max(func(i) for i in range(1, N + 1))
Problem p03458 (python)

Fixed submission:
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N, K = map(int, raw_input().split())
DP = [[0] * (K + 1) for i in range(K + 1)]
bias = 0

for i in range(N):
    x, y, c = raw_input().split()
    x, y, c = int(x), int(y), (c == 'W')
    if (x / K + y / K + c) % 2 == 0:
        DP[y % K + 1][x % K + 1] += 1
    else:
        DP[y % K + 1][x % K + 1] -= 1
        bias += 1

for i in range(K):
    for j in range(K + 1):
        DP[i + 1][j] += DP[i][j]

for i in range(K + 1):
    for j in range(K):
        DP[i][j + 1] += DP[i][j]

ans = 0

for i in range(K + 1):
    for j in range(K + 1):
        S1 = DP[i][j] * 2 - DP[i][K] - DP[K][j] + DP[K][K]
        S2 = DP[i][K] + DP[K][j] - DP[i][j] * 2
        ans = max(ans, S1, S2)

print ans + bias

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N, K = map(int, raw_input().split())
DP = [[0] * (K + 1) for i in range(K + 1)]
bias = 0

for i in range(N):
    x, y, c = raw_input().split()
    x, y, c = int(x), int(y), (c == 'W')
    p = (x / K + y / K + c) % 2
    DP[y % K + 1][x % K + 1] += -1 ** p
    bias += p

for i in range(K): for j in range(K + 1): DP[i + 1][j] += DP[i][j]
for i in range(K + 1): for j in range(K): DP[i][j + 1] += DP[i][j]

ans = 0

for i in range(K + 1):
    for j in range(K + 1):
        S1 = DP[i][j] * 2 - DP[i][K] - DP[K][j] + DP[K][K]
        S2 = DP[i][K] + DP[K][j] - DP[i][j] * 2
        ans = max(ans, S1, S2)

print ans + bias
Problem p03704 (python)

Fixed submission:
import itertools as ite
import math
import random

INF = 10 ** 18
MOD = 10 ** 9 + 7

def func(diff, cnt9, cnt0):
    if cnt9 <= 0:
        return (diff == 0)
    num = int("9" * cnt9 + "0" * cnt0)
    ret = 0
    for i in range(-9, 10):
        if abs(diff + i * num) < num:
            MUL = 9 - abs(i) + 1
            MUL -= (cnt0 == 0)
            ret += func(diff + i * num, cnt9 - 2, cnt0 + 1) * MUL
    return ret

D = input()

ans = 0
for d in range(1, 21):
    MUL = 1 if d % 2 == 1 else 10
    ans += func(D, d, 0) * MUL
print ans

Buggy submission (verdict: Runtime Error):
def f(d,x,y):n=int("9"*x+"0"*y);return d==0if x<1else sum(f(d+i*n,x-2,y+1)*(10-abs(i)-(y<1))for i in range(-9,10)if abs(d+i*n)<n)
D=input();print sum(f(D,i,0)*(10-i%2*9)for i in range(1,21))
Problem p03160 (python)

Fixed submission:
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
rage=range #lol
for i in rage(1,n):
    if i==1: dp[i]=dp[i-1]+abs(h[i]-h[i-1])
    else: 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):
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*n
rage=range #lol
for i in rage(1,n):
    dp[i]=10**9;
    for j in range(1,k+1):
        if i-j<0:
            break;
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])
Problem p02789 (python)

Fixed submission:
N, M = map(int, input().split())
if N == M:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
print("Yes" if int(input()) == int(input()) else "No")
Problem p02992 (python)

Fixed submission:
MOD = 10 ** 9 + 7


def main(N, K):
  W = []
  i = 1
  while i <= N:
    v = N // i
    j = N // v
    # keys.append((v, j - i + 1))
    W.append(j - i + 1)
    i += j - i + 1

  l = len(W)
  dp = [0] * l

  total = 0
  for i, w in enumerate(W):
    total += w
    dp[l - i - 1] = total

  for i in range(2, K + 1):
    tmp = [0] * l
    total = 0
    for j, w in enumerate(W):
      v = dp[j] * w
      total += v
      total %= MOD
      tmp[l - j - 1] = total

    dp = tmp

  return dp[0]


if __name__ == '__main__':
  N, K = map(int, input().strip().split())
  # import time
  # t = time.time()
  print(main(N, K))
  # print(time.time() - t)

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7


def main():
  N, K = map(int, input().strip().split())
  dp1 = {}
  dp2 = {}

  counter = {}
  i = 1
  while i < N:
    v = N // i
    j = N // v
    counter[v] = j - i + 1
    i += j - i + 1

  keys = sorted(counter.items(), reverse=True)

  total = 0
  for nj, v in keys:
    total += v
    dp1[nj] = total

  for i in range(2, K + 1):
    dp2 = {}
    # dp[i] = {}
    total = 0
    for nj, w in keys:
      j = N // nj
      v = dp1[j] * w
      total += v
      total %= MOD
      dp2[nj] = total

    dp1 = dp2

  return dp2[1]
  # for k, v in dp.items():
  #   print(k, sorted(v.items(), reverse=True))

  # return dp[K][1]


if __name__ == '__main__':
  print(main())
Problem p03044 (python)

Fixed submission:
from collections import deque

N = int(input())

A = {}
COLOR = [1] * N

for _ in range(N - 1):
  u, v, w = map(int, input().strip().split(' '))
  if u not in A: A[u] = {}
  if v not in A: A[v] = {}
  A[u][v] = w
  A[v][u] = w


def test(key, total_w=0):
  if key not in A:
    return

  COLOR[key - 1] = 0 if total_w % 2 == 0 else 1

  v = A.pop(key)
  for k, w in v.items():
    test(k, w + total_w)


queue = deque()
queue.append((1, 0))
current_key = 1

while len(queue) > 0:
  key, w = queue.popleft()
  if key not in A:
    continue

  COLOR[key - 1] = 0 if w % 2 == 0 else 1

  for child in A.pop(key).items():
    if child[0] in A:
      queue.append((child[0], w + child[1]))

for c in COLOR:
  print(c)

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

A = {}
COLOR = [1] * N

for _ in range(N - 1):
  u, v, w = map(int, input().strip().split(' '))
  if u not in A: A[u] = {}
  if v not in A: A[v] = {}
  A[u][v] = w
  A[v][u] = w


def test(key, total_w=0):
  if key not in A:
    return

  COLOR[key - 1] = 0 if total_w % 2 == 0 else 1

  v = A.pop(key)
  for k, w in v.items():
    test(k, w + total_w)


test(1)

for c in COLOR:
  print(c)

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

A = {}
B = []
C = [-1] * (N)

for _ in range(N - 1):
  u, v, w = map(int, input().strip().split(' '))
  if u not in A: A[u] = {}
  if v not in A: A[v] = {}

  for key, val in A[u].items():
    s = val + w
    A[v][key] = s
    A[key][v] = s
    if s % 2 == 1:
      B.append((v, key))

  for key, val in A[v].items():
    s = val + w
    A[u][key] = s
    A[key][u] = s
    if s % 2 == 1:
      B.append((u, key))

  A[u][v] = w
  A[v][u] = w
  if w % 2 == 1:
    B.append((u, v))

for k0, k1 in B:
  del A[k0][k1]
  del A[k1][k0]

k, v = A.popitem()
C[k - 1] = 0
for i in v.keys():
  C[i - 1] = 0
  del A[i]

for i in A.keys():
  C[i - 1] = 1

for i in C:
  print(i)
Problem p02783 (python)

Fixed submission:
h,a = map(int,input().split())
ans = h//a
if h % a == 0:
    print(ans)
else:
    print(ans+1)

Buggy submission (verdict: Runtime Error):
h,n = map(int,input().split())
i = list(map(int,input().split()))
ans = 0
for j in range(n):
    ans+=i[j]
    if ans >= h:
        print("Yes")
        exit()
print("No")
Problem p02854 (python)

Fixed submission:
import sys
n = int(input())
a = list(map(int, input().split()))
tmp=sys.maxsize
s = sum(a)
t = 0
for i in range(n):
    t += a[i]
    tmp = min(tmp,abs(s-t*2))
print(tmp)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
a = list(map(int, input().split()))
tmp=sys.maxsize
s = sum(a)
for i in range(n):
    t += a[i]
    tmp = min(tmp,abs(s-t*2))
print(tmp)
Problem p02981 (python)

Fixed submission:
n,a,b = map(int,input().split())
print(n*a if n*a<b else b)

Buggy submission (verdict: Runtime Error):
n,a,b = map(input().split())
print(n*a if n*a<b else b)
Problem p02936 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

n,q=map(int, input().split())
ab=[]
for _ in range(n):
    ab.append([])
for _ in range(n-1):
    a,b=map(int, input().split())
    ab[a-1].append(b)
px=[0]*n
for _ in range(q):
    p,x=map(int, input().split())    
    px[p-1]+=x

def func(p, now):
    global res
    res[p-1]+=px[p-1]+now
    for i in ab[p-1]:
        func(i, res[p-1])

res=[0]*n

func(1, 0)

print(" ".join(map(str, res)))

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(100000)

n,q=map(int, input().split())
ab=[]
for _ in range(n):
    ab.append([])
for _ in range(n-1):
    a,b=map(int, input().split())
    ab[a-1].append(b)
px=[0]*n
for _ in range(q):
    p,x=map(int, input().split())    
    px[p-1]+=x

def func(p, now):
    global res
    res[p-1]+=px[p-1]+now
    for i in ab[p-1]:
        func(i, res[p-1])

res=[0]*n

func(1, 0)

print(" ".join(map(str, res)))
Problem p02937 (python)

Fixed submission:
import bisect
import sys

sys.setrecursionlimit(1000000)

s=input()
t=input()
dic={}
for v in s:
    dic[v]=True

for u in t:
    if not u in dic:
        print(-1)
        exit()

nex={}
for i, v in enumerate(s+s):
    if not v in nex:
        nex[v]=[i]
    else:
        nex[v].append(i)
#print(s)
#print(t)
#print(nex)
sl=len(s)
tl=len(t)
def func(st, tn, su):
    if tn == tl:
        return su
    #print(st, tn, su, t[tn])
    ind=bisect.bisect_left(nex[t[tn]] ,st+1)
    nm=(nex[t[tn]][ind]-st)
    return func((st+nm)%sl, tn+1, su+nm)


res=func(-1, 0, 0)

print(res)

Buggy submission (verdict: Runtime Error):
import bisect
s=input()
t=input()
dic={}
for v in s:
    dic[v]=True

for u in s:
    if not dic[u]:
        print(-1)
        exit()

nex={}
for i, v in enumerate(s+s):
    if not v in nex:
        nex[v]=[i]
    else:
        nex[v].append(i)
#print(s)
#print(t)
#print(nex)
sl=len(s)
tl=len(t)
def func(st, tn, su):
    #print(st, tn, su)
    if tn == tl:
        return su 
    ind=bisect.bisect_left(nex[t[tn]] ,st)
    nm=(nex[t[tn]][ind]-st)
    return func((st+nm)%sl, tn+1, su+nm)


res=func(-1, 0, 0)

print(res)