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

Fixed submission:
a = int(input().split()[0])
alle = []
counter = 0
output = []
for i in range(a):
	p = input().split()
	p = [int(j)%2 for j in p]
	for j in range(len(p) - 1):
		if p[j] % 2 == 1:
			output.append([i + 1, j + 1, i + 1, j + 2])
			counter += 1
			p[j + 1] += 1
	alle.append(p[-1])
	
for i in range(a - 1):
	if alle[i] % 2 == 1:
		output.append([i + 1, len(p),  i + 2, len(p)])
		counter += 1
		alle[i + 1]  += 1
		
print (counter)
for i in output:
	print (i[0],i[1],i[2],i[3])

Buggy submission (verdict: Runtime Error):
a = int(input().split()[0])
alle = []
counter = 0
output = []
for i in range(a):
	p = input().split()
	p = [int(j)%2 for j in p]
	for j in range(len(p) - 1):
		if p[j] % 2 == 1:
			output.append([i + 1, j + 1, i + 1, j + 2])
			counter += 1
			p[j + 1] += 1
		alle.append(p[-1])
	
for i in range(a - 1):
	if alle[i] % 2 == 1:
		output.append([i + 1, 1,  i + 2, 1])
		counter += 1
		alle[i + 1] = alle[i] + 1
		
print (counter)
for i in output:
	print (i[0],i[1],i[2],i[3])

Buggy submission (verdict: Runtime Error):
a = int(input().split()[0])
alle = []
counter = 0
output = []
for i in range(a):
	p = input().split()
	p = [int(j)%2 for j in p]
	if len(p) >= 1:
		for j in range(len(p) - 1):
			if p[j] % 2 == 1:
				output.append([i + 1, j + 1, i + 1, j + 2])
				counter += 1
				p[j + 1] += 1
		alle.append(p[-1])
	else:
		alle.append(p)
	
for i in range(a - 1):
	if (len(p) > 1):
		if alle[i] % 2 == 1:
			output.append([i + 1, len(p[0]),  i + 2, len(p[0])])
			counter += 1
			alle[i + 1] = alle[i] + 1
	else:
		if alle[i] % 2 == 1:
			output.append([i + 1, 1,  i + 2, 1])
			counter += 1
			alle[i + 1] = alle[i] + 1
		
print (counter)
for i in output:
	print (i[0],i[1],i[2],i[3])

Buggy submission (verdict: Runtime Error):
a = int(input().split()[0])
alle = []
counter = 0
output = []
for i in range(a):
	p = input().split()
	p = [int(j)%2 for j in p]
	if len(p) >= 1:
		for j in range(len(p) - 1):
			if p[j] % 2 == 1:
				output.append([i + 1, j + 1, i + 1, j + 2])
				counter += 1
				p[j + 1] += 1
		alle.append(p[-1])
	else:
		alle.append(p)
	
for i in range(a - 1):
	if (len(p) > 1):
		if alle[i] % 2 == 1:
			output.append([i + 1, len(p[0]),  i + 2, len(p[0])])
			counter += 1
			alle[i + 1] = alle[i] + 1
	else:
		if alle[i] % 2 == 1:
			output.append([i + 1, 1,  i + 2, 1])
			counter += 1
			alle[i + 1] = alle[i] + 1
		
print (counter)
for i in output:
	print (i[0],i[1],i[2],i[3])

Buggy submission (verdict: Runtime Error):
a = int(input().split()[0])
alle = []
counter = 0
output = []
for i in range(a):
	p = input().split()
	p = [int(j)%2 for j in p]
	for j in range(len(p) - 1):
		if p[j] % 2 == 1:
			output.append([i + 1, j + 1, i + 1, j + 2])
			counter += 1
			p[j + 1] += 1
	alle.append(p[-1])
	
for i in range(a - 1):
	if alle[i] % 2 == 1:
		output.append([i + 1, len(p[0]),  i + 2, len(p[0])])
		counter += 1
		alle[i + 1] = alle[i] + 1
		
print (counter)
for i in output:
	print (i[0],i[1],i[2],i[3])
Problem p03266 (python)

Fixed submission:
a = [int(i) for i in input().split()]
 
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	if a[0]%a[1] < a[1] // 2:
		print ((a[0]//a[1])**3 + ((a[0]//a[1])**3))
	else:
		print ((1 + a[0]//a[1])**3 + ((a[0]//a[1])**3))

Buggy submission (verdict: Runtime Error):
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	if a[0]%a[1] < a[1] // 2:
		print ((a[0]//a[1])**3 + ((a[0]//a[1])**3))
	else:
		print ((1 + a[0]//a[1])**3 + ((a[0]//a[1])**3))

Buggy submission (verdict: Runtime Error):
from math import ceil
a = [int(i) for i in input().split()]
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	print (math.ceil(a[0]/(a[1]))**3 + ((a[0]//a[1])**3))
Problem p03280 (python)

Fixed submission:
a = input().split()
m = int(a[0])
n = int(a[1])
 
print(m*n - m - n +1)

Buggy submission (verdict: Runtime Error):
a = input()
m = int(a[0])
n = int(a[1])

print(m*n - m - n +1)
Problem p03284 (python)

Fixed submission:
a = input().split(' ')
m = int(a[0])
n = int(a[1])

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

Buggy submission (verdict: Runtime Error):
a = input().split()
n = int(a[0])
m = int(a[1])

a = input().split(' ')
a = [int(i) for i in a]

summatrix = [[0 for i in range(n)] for i in range(n)]
output = 0

for i in range(n):
	for j in range(i, n):
		if i != 0:
			summatrix[i][j] = (summatrix[i - 1][j - 1]%m + a[i]%m + a[j]%m)%m
		if i == 0 and j == 0:
			summatrix[0][0] = a[0] %m
		else:
			summatrix[i][j] = (summatrix[i][j - 1]%m + a[j]%m)% m
		if summatrix[i][j] == 0:
			output += 1
		
print (output)
Problem p03351 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
ans = 0
if abs(a-c) <= d: 
    ans = 1
if abs(a-b) <= d and abs(b-c) <= d: 
    ans = 1
if ans == 1:
    print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
ans = 0
if abs(a-c) <= d: 
    ans = 1
if abs(a-b) <= d && abs(b-c) <= d: 
    ans = 1
if ans == 1:
    print("Yes")
else
	print("No")
Problem p03359 (python)

Fixed submission:
x, y = map(int, input().split())
ans = x - 1
if x <= y: 
    ans = ans + 1
print(ans)

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split())
ans = x - 1
if x <= y: 
    ans++
print(ans)
Problem p03145 (python)

Fixed submission:
AB, BC, CA = map(int, input().split())

a = int(AB * BC / 2)

print(str(a))

Buggy submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        if(a[i] / 2 != 0):
        	ans = int(a[i] / 2)
        else:
            ans = 0
        if ans in a:
            print(i + 2)
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(i + 2)
            break
        a.append(anss)

    i += 1

Buggy submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        if(a[i] / 2 != 0):
        	ans = int(a[i] / 2)
        else:
            ans = 0
        if ans in a:
            print(str(i + 2))
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(str(i + 2))
            break
        a.append(anss)

    i += 1

Buggy submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        ans = int(a[i] / 2)
        if ans in a:
            print(str(i + 2))
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(str(i + 2))
            break
        a.append(anss)

    i += 1

Buggy submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        ans = int(a[i] / 2)
        if ans in a:
            print(str(i + 2))
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(str(i + 2))
            break
        a.append(anss)

    i += 1

Buggy submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        ans = int(a[i] / 2)
        if ans in a:
            print(str(i + 2))
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(str(i + 2))
            break
        a.append(anss)

    i += 1
    
print(a)
Problem p03598 (python)

Fixed submission:
n=int(input())
k=int(input())
a=0
for x in [int(i) for i in input().split()]:
    a+=min(x,abs(k-x))
print(a*2)

Buggy submission (verdict: Runtime Error):
n=int(input())
k=int(input())
a=0
for i in range(n):
  x=int(input())
  a+=min(x,abs(k-x))
print(a*2)
Problem p02642 (python)

Fixed submission:
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
mx = max(A)+1
B = [0]*(mx)
dic = defaultdict(int)
for a in A:
  dic[a] += 1

A = sorted(list(set(A)))
ans = 0
for a in A:
  if B[a] == 0:
    if dic[a] == 1:
      ans += 1
  for i in range(a, mx, a):
    B[i] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
"""D問題"""
from collections import defaultdict
import sympy
N = int(input())

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = set(table)
  return table

A = list(map(int, input().split()))
A.sort()
dic = defaultdict(int)
for a in A:
  dic[a] += 1
A = set(A)

for a in A:
  if a == 1:
    print(0)
    exit()
B = {}
for a in A:
  B[a] = set(sympy.divisors(a))

s = set()
ans = 0

for a in A:
  s = A - set([a])
  if len(s) == 0:
    continue
  if len(B[a] & s) == 0:
    if dic[a] == 1:
      ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
"""D問題"""
from collections import defaultdict
import sympy
N = int(input())

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = set(table)
  return table

A = list(map(int, input().split()))
A.sort()
dic = defaultdict(int)
for a in A:
  dic[a] += 1
A = set(A)

for a in A:
  if a == 1:
    print(0)
    exit()
B = {}
for a in A:
  B[a] = set(sympy.divisors(a))

s = set()
ans = 0

for a in A:
  s = A - set([a])
  if len(s) == 0:
    continue
  if len(B[a] & s) == 0:
    if dic[a] == 1:
      ans += 1

print(ans)
Problem p02690 (python)

Fixed submission:
x = int(input())
ans = []
for i in range(-120, 120):
  for j in range(-120, 120):
    if pow(i, 5) - pow(j, 5) == x:
      ans += [[i, j]]
ans = list(map(str, ans[0]))
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
x = int(input())
ans = []
for i in range(-105, 105):
  for j in range(-105, 105):
    if pow(i, 5) - pow(j, 5) == x:
      ans += [[i, j]]
ans = list(map(str, ans[0]))
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
 = int(input())
ans = []
for i in range(-105, 105):
  for j in range(-105, 105):
    if pow(i, 5) - pow(j, 5) == x:
      ans += [[i, j]]
ans = list(map(str, ans[0]))
print(" ".join(ans))
Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

p = p[:x]
q = q[:y]
a = p + q + r 
a = sorted(a, reverse=True)
print(sum(a[:(x+y)]))

Buggy submission (verdict: Runtime Error):
, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)

p = p[:x]
q = q[:y]
a = p + q + r 
a = sorted(a, reverse=True)
print(sum(a[:x+y]))

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)
ans = 0
ans += sum(p[:x])
ans += sum(q[:y])
pq = p[:x] + q[:y]
pq = sorted(pq)
if a+b >= c:
  for i in range(c):
    if pq[i] < r[i]:
      ans = ans - pq[i] + r[i]
  print(ans)
else:
  for i in range(c-a-b):
    ans += r[i]
  print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted(list(map(int, input().split())), reverse=True)
r = sorted(list(map(int, input().split())), reverse=True)
dp = defaultdict(int)
dq = defaultdict(int)
dr = defaultdict(int)
ans = 0
ans += sum(p[:x])
ans += sum(q[:y])
pq = p[:x] + q[:y]
pq = sorted(pq)
for i in range(c):
  if pq[i] < r[i]:
    ans = ans - pq[i] + r[i]
print(ans)
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
for i in range(0, 1000):
  i = str(i)
  flag = True
  if len(i) != N:
    continue
  for s, c in sc:
    #print(i, s, len(i))
    if len(list(i)) < s:
      flag = False
      break
    if i[s-1] != str(c):
      flag = False
      break
  if flag:
    print(i)
    exit()

print(-1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

if n == 1:
  for i in range(10):
    i = str(i)
    for s, c in sc:
      if i == str(c):
        flag = True 
      else:
        flag = False
        break 
    if flag:
      print(''.join(i))
      exit()

for i in range(10**(n-1), 1000):
  i = list(str(i))
  flag = False
  for s,c in sc:
    if i[s-1] == str(c):
      flag = True
    else:
      flag = False
      break
  if flag:
    print(''.join(i))
    exit()

print('-1')

Buggy submission (verdict: Runtime Error):
if n == 1:
  for i in range(10):
    i = str(i)
    for s, c in sc:
      if i == str(c):
        flag = True 
      else:
        flag = False
        break 
    if flag:
      print(''.join(i))
      exit()

for i in range(10**(n-1), 1000):
  i = list(str(i))
  flag = False
  for s,c in sc:
    if i[s-1] == str(c):
      flag = True
    else:
      flag = False
      break
  if flag:
    print(''.join(i))
    exit()

print('-1')
Problem p02784 (python)

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

if sum(A) >= H:
  print('Yes')
else:
  print('No')

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

if sum(A) >= H:
  print('Yes')
else:
Problem p02804 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
B = A[:][::-1]

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9+7
def COMinit():
  #N_C_kのN
  for i in range(2, 10**5+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


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

COMinit()

comb = {}
for i in range(K-1, N):
  comb[(i, K-1)] = COM(i, K-1)

ans = 0
for i in range(K-1, N):
  ans += A[i] * comb[(i, K-1)]
  ans %= Mod
for i in range(K-1, N):
  ans -= B[i] * comb[(i, K-1)]
  ans %= Mod
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
B = A[:][::-1]

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9+7
def COMinit():
  #N_C_kのN
  for i in range(2, 10**5+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


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

COMinit()

comb = {}
for i in range(K-1, N):
  comb[(i, K-1)] = COM(i, K-1)

ans = 0
for i in range(K-1, N):
  ans += A[i] * comb[(i, K-1)]
  ans %= p 
for i in range(K-1, N):
  ans -= B[i] * comb[(i, K-1)]
  ans %= p
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
B = A[:][::-1]

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
Mod = 10**9+7
def COMinit():
  #N_C_kのN
  for i in range(2, 10**5+10):
    fac.append(fac[-1]*i%Mod)
    inv.append((-inv[Mod%i] * (Mod//i)) % Mod)
    finv.append(finv[-1] * inv[-1] % Mod)


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

COMinit()

comb = {}
for i in range(K-1, N):
  comb[(i, K-1)] = COM(i, K-1, p)

ans = 0
for i in range(K-1, N):
  ans += A[i] * comb[(i, K-1)]
  ans %= p 
for i in range(K-1, N):
  ans -= B[i] * comb[(i, K-1)]
  ans %= p
print(ans)
Problem p02843 (python)

Fixed submission:
x = int(input())
n = x // 100 + 10
for i1 in range(n+1):
  for i2 in range(n+1-i1+1):
    for i3 in range(n+1-i1-i2+1):
      for i4 in range(n+1-i1-i2-i3+1):
        for i5 in range(n+1-i1-i2-i3-i4+1):
          for i6 in range(n+1-i1-i2-i3-i4-i5+1):
            if 100*i1+101*i2+102*i3+103*i4+104*i5+105*i6 == x:
              if i1<=1000000 and i2<=1000000 and i3<=1000000 and i4<=1000000 and i5<=1000000 and i6<=1000000:
                print(1)
                exit()
print(0)

Buggy submission (verdict: Runtime Error):
x = int(input())
dic = {0: 100, 1:101, 2:102, 3:103, 4:104, 5:105}
global ans
ans = 0
def dfs(i, v):
  global ans
  if v == x:
    ans = 1
    return

  if v > x:
    return
  
  for k in range(6):
    dfs(k, v+dic[k])

  return 

dfs(0, 0)
if ans == 1:
  print(1)
else:
  print(0)
Problem p02882 (python)

Fixed submission:
import math
a, b, x = map(int, input().split())
y = a*a*b - x
if y == 0:
  print(0)
  exit()

if (a*a*b/2 < x):
  print(90-math.degrees(math.atan((a**3)/(2*y))))
else:
  print(90-math.degrees(math.atan((2*x)/(a* b**2))))

Buggy submission (verdict: Runtime Error):
import math
a, b, x = map(int, input().split())
y = a*a*b - x

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

Fixed submission:
import fractions
import math
from collections import Counter
a, b = map(int, input().split())
n = fractions.gcd(a, b)

prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(n))+1):
  while n % i == 0:
    n /= i
    prime_count[i] += 1
if n > 1:
  prime_count[int(n)] += 1

print(len(prime_count)+1)

Buggy submission (verdict: Runtime Error):
import math
from collections import Counter
A, B = map(int, input().split())
C = math.gcd(A, B)

prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(C))+1):
  while C % i == 0:
    C /= i
    prime_count[i] += 1
if C > 1:
  prime_count[int(C)] += 1

print(len(prime_count)+1)

Buggy submission (verdict: Runtime Error):
import math
from collections import Counter
a, b = map(int, input().split())
n = math.gcd(a, b)

prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(n))+1):
  while n % i == 0:
    n /= i
    prime_count[i] += 1
if n > 1:
  prime_count[int(n)] += 1

print(len(prime_count)+1)

Buggy submission (verdict: Runtime Error):

import math
from collections import Counter
a, b = map(int, input().split())
n = math.gcd(a, b)

prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(n))+1):
  while n % i == 0:
    n /= i
    prime_count[i] += 1
if n > 1:
  prime_count[int(n)] += 1

print(len(prime_count)+1)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.buffer.readline
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
  a, b = map(lambda x:int(x)-1, input().split())
  graph[a] += [b]
  graph[b] += [a]


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

def dfs(u, pre, c):
  for v in graph[u]:
    if v != pre:
      cnt[v] += cnt[u]
      dfs(v, u, cnt[v])

dfs(0, -1, cnt[0])
print(*cnt)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
ab = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)]
px = [list(map(lambda x:int(x)-1, input().split())) for _ in range(Q)]
graph = [[] for _ in range(N)]
for a, b in ab:
  graph[a] += [b]
dist = [0 for _ in range(N)]
for p, x in px:
  dist[p] += x+1

def dfs(u, pre):
  for v in graph[u]:
    if v != pre:
      dist[v] += dist[u]
      dfs(v, u)

  return 

dfs(0, -1)
dist = list(map(str, dist))
print(" ".join(dist))

Buggy submission (verdict: Runtime Error):
def dfs(v, p, ad_list, count):
  for u in ad_list[v]:
    if u != p:
      count[u] += count[v]
      dfs(u, v, ad_list, count)

def main():
  n, q = map(int, input().split())
  ab = tuple(tuple((map(lambda x: int(x)-1, input().split())) for _ in range(n-1)))
  px = tuple(tuple(map(int, input().split())) for _ in range(q))

  ad_list = [[] for _ in range(n)]
  for a, b in ab:
    ad_list[a] += [b]
    ad_list[b] += [a]

  count = [0 for _ in range(n)]
  for p, x in px:
    count[p-1] += x

  dfs(0, -1, ad_list, count)

  print(*count)

if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]
ad_list = [[] for _ in range(n)]
for a, b in ab:
  ad_list[a-1].append(b)
count = [0 for _ in range(n)]

def dfs(v, x):
  count[v] += x
  if len(ad_list[v]) == 0:
    return 0
  else:
    for ad_v in ad_list[v]:
      dfs(ad_v-1, x)
    return 0

for p, x in px:
  dfs(p-1, x)
print(*count)
Problem p02937 (python)

Fixed submission:
import bisect
s = list(input())
t = list(input())
n = len(s)
m = len(t)
alphabet = [[] for _ in range(26)]
for i in range(n):
  alphabet[ord(s[i])-ord('a')] += [i] 
loop = 0
pre = -1
for i in range(m):
  c = ord(t[i]) - ord('a')
  if len(alphabet[c]) == 0:
    print(-1)
    exit()
  idx = bisect.bisect_left(alphabet[c], pre+1)
  if idx == len(alphabet[c]):
    loop += 1
    pre = alphabet[c][0]
  else:
    pre = alphabet[c][idx]

print(pre + loop * n + 1)

Buggy submission (verdict: Runtime Error):
import bisect
s = list(input())
t = list(input())
n = len(s)
m = len(t)
alphabet = [[] for _ in range(26)]
for i in range(n):
  alphabet[ord(s[i])-ord('a')+1] += [i] 

loop = 0
pre = -1
for i in range(m):
  c = ord(t[i]) - ord('a') + 1
  if len(alphabet[c]) == 0:
    print(-1)
    exit()
  idx = bisect.bisect_left(alphabet[c], pre+1)
  if idx == len(alphabet[c]):
    loop += 1
    pre = alphabet[c][0]
  else:
    pre = alphabet[c][idx]

print(pre + loop * n + 1)

Buggy submission (verdict: Runtime Error):
import bisect
s = list(input())
t = list(input())
n = len(s)
m = len(t)
alphabet = [[] for _ in range(26)]
for i in range(n):
  alphabet[ord(s[i])-ord('a')+1] += [i] 

loop = 0
pre = -1
for i in range(m):
  c = ord(t[i]) - ord('a') + 1
  idx = bisect.bisect_left(alphabet[c], pre+1)
  if idx == len(alphabet[c]):
    loop += 1
    pre = alphabet[c][0]
  else:
    pre = alphabet[c][idx]

print(pre + loop * n + 1)
Problem p03014 (python)

Fixed submission:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

L = [[0 for _ in range(w)] for _ in range(h)]
R = [[0 for _ in range(w)] for _ in range(h)]
D = [[0 for _ in range(w)] for _ in range(h)]
U = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        L[i][j] = 1
      else:
        L[i][j] = L[i][j-1]+1     
      if i == 0:
        D[i][j] = 1
      else:
        D[i][j] = D[i-1][j]+1
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
  for j in range(w-1, -1, -1):
    if s[i][j] == '.':
      if j == w-1:
        R[i][j] = 1
      else:
        R[i][j] = R[i][j+1]+1

for i in range(h-1, -1, -1):
  for j in range(w):
    if s[i][j] == '.':
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
moves = [[0,1], [0,-1],[1,0], [-1,0]]

def bfs(b, a):
  light = [[0 for _ in range(w)] for _ in range(h)]
  q = deque([(b, a, (0, 1, 2, 3))])
  ans = 0
  while q:
    y, x, direction= q.popleft()
    light[y][x] = 1
    ans += 1
    
    for i in direction:
      next_y = y + moves[i][0]
      next_x = x + moves[i][1]
      if 0 <= next_y < h and 0 <= next_x < w and s[next_y][next_x] == '.' and light[next_y][next_x] == 0:
        q.append([next_y, next_x, [i]])
  return ans
bfs(2, 5)
final_ans = 0
for i in range(h):
  for j in range(w):
    final_ans = max(final_ans, bfs(i, j))

print(final_ans)