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

Fixed submission:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: (x * y) // math.gcd(x, y)
lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    T = [ii() for _ in range(N)]

    ret = lcm(T[0], T[1]) if len(T) > 1 else T[0]
    for t in T:
        ret = lcm(ret, t)
    print(ret)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: (x * y) // math.gcd(x, y)
lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    T = [ii() for _ in range(N)]

    ret = lcm(T[0], T[1])
    for t in T:
        ret = lcm(ret, t)
    print(ret)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    T = [ii() for _ in range(N)]

    ret = lcm(T[0], T[1])
    for t in T:
        ret = lcm(ret, t)
    print(ret)


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

Fixed submission:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    o, t, f = 0, 0, 0
    for a in A:
        if a % 4 == 0:
            f += 1
        elif a % 2 == 0:
            t += 1
        else:
            o += 1
    if t > 0:
        o += 1
    print('Yes' if o <= f + 1 else 'No')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = sorted(il())

    cnt = 0
    for n in range(N):
        if A[n] % 4 == 0:
            cnt += 1
        elif A[n] % 2 == 0 and A[n + 1] % 2 == 0:
            cnt += 0.5
    print('YES' if N // 2 <= int(cnt + 0.5) else 'NO')


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

Fixed submission:
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    *A, = iss()
    *B, = iss()
    *C, = iss()
    tmp = "a"

    while True:
        if tmp == 'a' and len(A) == 0:
            print('A')
            exit()
        elif tmp == 'b' and len(B) == 0:
            print('B')
            exit()
        elif tmp == 'c' and len(C) == 0:
            print('C')
            exit()

        if tmp == 'a':
            tmp = A.pop(0)
        elif tmp == 'b':
            tmp = B.pop(0)
        elif tmp == 'c':
            tmp = C.pop(0)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    *A, = iss()
    *B, = iss()
    *C, = iss()
    tmp = "a"

    while True:
        if tmp == "a" and len(A) == 0:
            print('A')
            exit()
        if tmp == "b" and len(B) == 0:
            print('B')
            exit()
        if tmp == "c" and len(C) == 0:
            print('C')
            exit()

        if tmp == 'a':
            tmp = A.pop(0)
        if tmp == 'b':
            tmp = B.pop(0)
        if tmp == 'c':
            tmp = C.pop(0)


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

Fixed submission:
a,b,c,d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)

temp1 = a*c
temp2 = a*d
temp3 = b*c
temp4 = b*d

answer = max(temp1,temp2,temp3,temp4)

print(answer)

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

if a >= 0 and b >= 0 and c >= 0 and d >= 0:
  answer = b*d

elif a <0 and b<0 and c <0 and d <0:
  answer = a*c

elif a < 0 and c < 0 and b >= 0 and d >= 0:
  temp1 = -a
  temp2 = -c
  temp3 = max(temp1,b)
  temp4 = max(temp2,d)
  answer = temp3*temp4

print(answer)
Problem p02582 (python)

Fixed submission:
a = str(input())

if a[0] == 'R' and a[1] == 'R' and a[2] == 'R':
  print(3)
elif a[1] == 'R' and a[2] == 'R' and a[0] != 'R':
  print(2)
elif a[0] == 'R' and a[1] == 'R' and a[2] != 'R':
  print(2)
elif 'R' not in a:
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
a = input()
count = 0

for i in range(len(a)):
  if i = 'R':
    count += 1

print(count)
Problem p02584 (python)

Fixed submission:
x,k,d = map(int, input().split())
lists = []
x = abs(x)

step = int(x/d) 

if step >= k:
  answer = x - k * d
elif step < k:
  k_left = k - int(step)
  if k_left % 2 == 0:
    answer = x % d
  if k_left % 2 == 1:
    answer = abs(x - step * d - d)

print(answer)

Buggy submission (verdict: Runtime Error):
x,k,d = map(int, input().split())
lists = []
i = 1
 

if k*d <= x:
  answer = x - k*d
else:
  while i * d <= x and i <= d:
    minx = abs(i*d-x)
    if (k-i) % 2 == 0:
      answer = abs(minx)
    if (k-i) % 2 == 1:
      answer = min(abs(minx-d),abs(minx+d))
    i += 1

print(answer)

Buggy submission (verdict: Runtime Error):
x,k,d = map(int, input().split())
lists = []
i = 1
 

if k*d <= x:
  answer = x - k*d
else:
  while i * d <= x and i <= d:
    minx = min(abs(i*d), (i * d - x))
    if (k-i) % 2 == 0:
      answer = abs(minx)
    if (k-i) % 2 == 1:
      answer = abs(min(abs(minx-d), abs(minx+d)))
    i += 1

print(answer)

Buggy submission (verdict: Runtime Error):
x,k,d = map(int, input().split())
lists = []
i = 1
 

if k*d <= x:
  answer = x - k*d
else:
  while i * d <= x and i <= d:
    if i % 2 == 0:
      answer = abs(x - i * d)
    if i % 2 == 1:
      answer = abs(i*d)
    i += 1



print(answer)

Buggy submission (verdict: Runtime Error):
x,k,d = map(int, input().split())
lists = []
i = 0
 

if k*d <= x:
  answer = x - k*d
else:
  while i * d <= x and i <= d:
    answer = min(abs(i*d-x),i*d+x)
    i += 1


print(answer)

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

def moving(x,k,d):
  if k == 0:
    return x
  
  x = min(abs(x-d), abs(x+d))
  return moving(x,k - 1, d)

answer = moving(x,k,d)
print(answer)

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

def moving(x,k,d):
  if k == 0:
    return x
  
  x = min(abs(x-d), abs(x+d))
  return moving(x,k - 1, d)

answer = moving(x,k,d)
print(answer)
Problem p03043 (python)

Fixed submission:
import collections, math, bisect
from fractions import Fraction

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()


N, K = ints()

oneprob = Fraction(1, N)
ans = 0
for i in range(1, N+1):
    if i>=K:
        break
        
    doubling_amounts = math.ceil(math.log2(K/i))
    ans+=Fraction(1,2)**doubling_amounts

ans*=oneprob

if N>=K:
    ans+=Fraction(N-K+1, N)

print("{:.20f}".format(float(ans)))

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Buggy submission (verdict: Runtime Error):
import collections, math, bisect
from fractions import Fraction

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()


N, K = ints()

oneprob = Fraction(1, N)
ans = 0
for i in range(1, N+1):
    if i>=K:
        break
        
    doubling_amounts = math.ceil(math.log2(K/i))
    ans+=Fraction(1,2)**doubling_amounts

ans*=oneprob

if N>K:
    ans+=Fraction(N-K+1, N)

print("{:.20f}".format(float(ans)))

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Buggy submission (verdict: Runtime Error):
import collections, math, bisect
from decimal import *

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]

if local:
    start=time.time()

getcontext().prec = 15

N, K = ints()

oneprob = 1/N
ans = 0
for i in range(1, N+1):
    if i>=K:
        break
        
    doubling_amounts = math.ceil(math.log2(K/i))
    ans+=0.5**doubling_amounts

ans*=oneprob

if N>K:
    ans+=(N-K) / N

print(ans)

if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")
Problem p03044 (python)

Fixed submission:
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


if local:
    start=time.time()

N = int(inp())

connection = [dict() for i in range(N)]

for i in range(1, N):
    u,v,w = ints()

    connection[u-1][v-1] = w
    connection[v-1][u-1] = w

colors = ["0"]*N
visited = set()

stck = [(0,0)]
visited.add(0)

while len(stck)>0:
    vertex, cur_dist = stck.pop(-1)

    if cur_dist%2==0:
        colors[vertex] = "0"
    else:
        colors[vertex] = "1"

    for nextVertex in connection[vertex]:
        if nextVertex not in visited:
            visited.add(nextVertex)
            stck.append((nextVertex, cur_dist+connection[vertex][nextVertex]))

for c in colors:
    print(c)


if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Buggy submission (verdict: Runtime Error):
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


def dfs(vertex, colors, visited, cur_dist, connection):
    if cur_dist%2==0:
        colors[vertex] = "0"
    else:
        colors[vertex] = "1"

    visited.add(vertex)

    for nextVertex in connection[vertex]:
        if nextVertex not in visited:
            dfs(nextVertex, colors, visited, cur_dist+connection[vertex][nextVertex], connection)
    

if local:
    start=time.time()

N = int(inp())

connection = [dict() for i in range(N)]

for i in range(1, N):
    u,v,w = ints()

    connection[u-1][v-1] = w
    connection[v-1][u-1] = w

colors = ["0"]*N
visited = set()
dfs(0, colors, visited, 0, connection)

for c in colors:
    print(c)


if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Buggy submission (verdict: Runtime Error):
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


def dfs(vertex, colors, visited, cur_dist, connection):
    if cur_dist%2==0:
        colors[vertex] = "0"
    else:
        colors[vertex] = "1"

    visited.add(vertex)

    for nextVertex in connection[vertex]:
        if nextVertex not in visited:
            dfs(nextVertex, colors, visited, cur_dist+connection[vertex][nextVertex], connection)
    

if local:
    start=time.time()

N = int(inp())

connection = [dict() for i in range(N)]

for i in range(1, N):
    u,v,w = ints()

    connection[u-1][v-1] = w
    connection[v-1][u-1] = w

colors = ["0"]*N
visited = set()
dfs(0, colors, visited, 0, connection)

for c in colors:
    print(c)


if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")
Problem p02602 (python)

Fixed submission:
from collections import deque

n, k = map(int, input().split())
a = list(map(int, input().split()))
queue = deque()
for i in range(n):
    if i <= k - 1:
        queue.append(a[i])
    elif i >= k:
        x = queue.popleft()
        if x < a[i]:
            print("Yes")
        else:
            print("No")
        queue.append(a[i])

Buggy submission (verdict: Runtime Error):
from collections import deque

n, k = map(int, input().split())
a = list(map(int, input().split()))
queue = deque()
for i in range(n):
    if i < k - 1:
        queue.append(a[i])
    elif i >= k:
        x = queue.popleft()
        if x < a[i]:
            print("Yes")
        else:
            print("No")
        queue.append(a[i])
Problem p02678 (python)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
data = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    data[a - 1].append(b - 1)
    data[b - 1].append(a - 1)

ans = [0] * (n - 1)

def bfs(i, queue, p):
    while len(queue) > 0:
        x = queue.popleft()
        pre = p.popleft()
        for j in range(len(x)):
            if ans[x[j] - 1] == 0 and x[j] != 0:
                ans[x[j] - 1] = pre + 1
                queue.append(data[x[j]])
                p.append(x[j])

queue = deque()
pre = deque()
pre.append(0)
queue.append(data[0])
bfs(0, queue, pre)

if 0 not in ans:
    print("Yes")
    for i in range(len(ans)):
        print(ans[i])
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
data = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    data[a - 1].append(b - 1)
    data[b - 1].append(a - 1)

ans = [0] * (n - 1)

def bfs(i, queue, p):
    if len(queue) == 0:
        return 
    while len(queue) > 0:
        x = queue.pop(0)
        pre = p.pop(0)
        for j in range(len(x)):
            if ans[x[j] - 1] == 0 and x[j] != 0:
                ans[x[j] - 1] = pre + 1
                queue.append(data[x[j]])
                p.append(x[j])
        bfs(x[j], queue, p)

queue = []
pre = [0]
queue.append(data[0])
bfs(0, queue, pre)

if 0 not in ans:
    print("Yes")
    for i in range(len(ans)):
        print(ans[i])
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
data = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    data[a - 1].append(b - 1)
    data[b - 1].append(a - 1)

ans = [0] * (n - 1)

def bfs(i, queue, p):
    q = []
    if len(queue) == 0:
        return 
    while len(queue) > 0:
        x = queue.pop(0)
        pre = p.pop(0)
        for j in range(len(x)):
            if ans[x[j] - 1] == 0 and x[j] != 0:
                ans[x[j] - 1] = pre + 1
                q.append(data[x[j]])
                p.append(x[j])
        bfs(x[j], q, p)

queue = []
pre = [0]
queue.append(data[0])
bfs(0, queue, pre)

if 0 not in ans:
    print("Yes")
    for i in range(len(ans)):
        print(ans[i])
else:
    print("No")
Problem p02796 (python)

Fixed submission:
n = int(input())
data = []
for i in range(n):
    x, l = map(int, input().split())
    data.append([x, l])
data = sorted(data, key = lambda x: x[0] + x[1])
ans = 0
pre = -(10 ** 10)
for i in range(n):
    if data[i][0] - data[i][1] >= pre:
        ans += 1
        pre = data[i][0] + data[i][1]

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
data = []
for i in range(n):
    x, l = map(int, input().split())
    data.append([x, l])
data = sorted(data, key = lambda x: x[0])
i = 1
while 1:
    if data[i][0] - data[i][1] < data[i - 1][0] + data[i - 1][1]:
        del data[i]
    else:
        i += 1
    if i >= len(data) - 1:
        break
print(len(data))

Buggy submission (verdict: Runtime Error):
n = int(input())
data = []
for i in range(n):
    x, l = map(int, input().split())
    data.append([x, l])
data = sorted(data, key = lambda x: x[0])
i = 0
while 1:
    if data[i][0] + data[i][1] > data[i + 1][0] - data[i + 1][1]:
        del data[i + 1]
    else:
        i += 1
    if i >= len(data) - 1:
        break
print(len(data))
Problem p02837 (python)

Fixed submission:
n = int(input())

xy = [[] * n for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        xy[i].append((x, y))

ans = 0
def judge(f):
    for i in range(n):
        if flag[i] == 1:
            for j in xy[i]:
                if f[j[0] - 1] != j[1]:
                    return False
        
    return True

for i in range(2 ** n):
    flag = [0] * n
    for j in range(n):
        if i >> j & 1:
            flag[j] = 1
    if judge(flag):
        ans = max(ans, sum(flag))
print(ans)

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

xy = [[] * n for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        xy[i].append((x, y))

ans = 0
def judge(f):
    for i in range(n):
        if flag[i] == 1:
            for j in xy[i]:
                if f[j[0] - 1] != j[1]:
                    return False
        
    return True

for i in range(2 ** n):
    flag = [0] * n
    for j in range(n):
        if i >> j & 1:
            flag[j] = 1
    if judge(flag):
        ans = max(ans, sum(flag))
print(ans)
Problem p02900 (python)

Fixed submission:
from math import gcd
from copy import copy
a, b = map(int, input().split())

def div(x):
    ret = []
    for i in range(1, int(x ** 0.5) + 1):
        if x % i == 0:
            ret.append(i)
            ret.append(x // i)
    
    return ret

def judge_prime(x):
    cnt = 0
    for i in range(1, int(x ** 0.5) + 1):
        if x % i == 0:
            cnt += 1
        if cnt >= 2:
            return False
    return True

div_a = div(a)
div_b = div(b)

data = list(set(div_a) & set(div_b))

ans = 0
for x in data:
    if judge_prime(x):
        ans += 1
print(ans)

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

a, b = map(int, input().split())
data = []
for i in range(1, int(min(a, b) ** 0.5) + 1):
    if a % i == 0 and b % i == 0:
        data.append(i)
        if b % (a // i) == 0:
            data.append(a // i)
        if a % (b // i) == 0:
            data.append(b // i)
data = list(set(data)).sort()
for i in range(len(data)):
    j = i + 1
    while j < len(data):
        if gcd(data[i], data[j]) != 1:
            del data[j]
        else:
            j += 1
print(len(data))
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
n, q = map(int, input().split())
cnt = [0] * n
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

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

def dfs(cur, par):
    for chi in tree[cur]:
        if chi == par:
            continue
        cnt[chi] += cnt[cur]
        dfs(chi, cur)
dfs(0, -1)
print(*cnt)

Buggy submission (verdict: Runtime Error):
"""
import sys
sys.setrecursionlimit(10 ** 6)
"""
n, q = map(int, input().split())
cnt = [0] * n
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

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

def dfs(cur, par):
    for chi in tree[cur]:
        if chi == par:
            continue
        cnt[chi] += cnt[cur]
        dfs(chi, cur)
dfs(0, -1)
print(*cnt)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
cnt = [0] * n
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

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

def dfs(cur, par):
    for chi in tree[cur]:
        if chi == par:
            continue
        cnt[chi] += cnt[cur]
        dfs(chi, cur)
dfs(0, -1)
print(*cnt)