Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self,n):
        self.n = n
        self.parents = [-1] * n

    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]    

def main():
    N, K, L = map(int, input().split())
    road = UnionFind(N)
    train = UnionFind(N)
    for _ in range(K):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        road.union(p,q)
    for _ in range(L):
        r, s = map(int, input().split())
        r -= 1
        s -= 1
        train.union(r,s)

    ans = [0] * N
    for i in range(N):
        a = set(road.members(i))
        b = set(train.members(i))
        ans[i] = len(list(a & b))

    print(*ans)




if __name__ == "__main__":
    main()

Fixed submission:
from collections import defaultdict
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self,n):
        self.n = n
        self.parents = [-1] * n

    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]    

def main():
    N, K, L = map(int, input().split())
    road = UnionFind(N)
    train = UnionFind(N)
    for _ in range(K):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        road.union(p,q)
    for _ in range(L):
        r, s = map(int, input().split())
        r -= 1
        s -= 1
        train.union(r,s)

    d = defaultdict(int)
    for i in range(N):
        a = road.find(i)
        b = train.find(i)
        d[(a,b)] += 1

    ans = [0] * N

    for i in range(N):
        a = road.find(i)
        b = train.find(i)
        ans[i] = d[(a,b)]
    print(*ans)




if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split())
A = list(map(int, input().split()))

max_bef = 0
cnt = 0
A_min = A[0]

for i in range(1,N):
    tmp = A[i] - A_min
    if max_bef < tmp:
        max_bef = tmp
        cnt = 1
    if max_bef == tmp:
        cnt += 1
    a_min = min(a_min, a[i])

print(cnt)


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

max_bef = 0
cnt = 0
A_min = A[0]

for i in range(1,N):
    tmp = A[i] - A_min
    if max_bef < tmp:
        max_bef = tmp
        cnt = 0
    if max_bef == tmp:
        cnt += 1
    A_min = min(A_min, A[i])

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N, T = map(int, input().split())
A = list(map(int, input().split()))

max_bef = 0
cnt = 0

for i in range(1,N):
    tmp = A[i] - min(A[:i])
    if max_bef < tmp:
        max_bef = tmp
        cnt = 0
    if max_bef == tmp:
        cnt += 1

print(cnt)


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

max_bef = 0
cnt = 0
A_min = A[0]

for i in range(1,N):
    tmp = A[i] - A_min
    if max_bef < tmp:
        max_bef = tmp
        cnt = 0
    if max_bef == tmp:
        cnt += 1
    A_min = min(A_min, A[i])

print(cnt)
Buggy python submission (verdict: Runtime Error):
def main():
    S = list(input())
    K = int(input())
    L = len(S)
    for i in range(L):
        if ord('z') - ord(S[i]) + 1 <= K:
            K -= ord('z') - ord(S[i]) + 1
            S[i] = 'a'

    if K > 0:
        S[-1] = chr(ord(S[-1]) + K)

    print(''.join(S))




if __name__ == "__main__":
    main()

Fixed submission:
def main():
    S = input()
    K = int(input())
    ans = ""
    for i, s in enumerate(S):
        tmp = ord(s) - ord('a')
        if i == len(S) - 1:
            ans += chr((tmp + K) % 26 + ord('a'))
        elif s == 'a':
            ans += s
        elif 26 - tmp <= K:
            ans += 'a'
            K -= 26 - tmp
        else:
            ans += s

    print(ans)
            


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    K = int(input())
    ans = ""
    for i, s in enumerate(S):
        tmp = ord(s) - ord('a')
        if i == len(S) - 1:
            ans += chr((tmp + K) % 26 + ord('a'))
        elif s == 'a':
            ans += s
        elif 26 - tmp <= K:
            ans += 'a'
            K -= 26 - tmp
        else:
            ans += s

    print(ans)
            


if __name__ == "__main__":
    main()

Fixed submission:
def main():
    S = input()
    K = int(input())
    ans = ""
    for i, s in enumerate(S):
        tmp = ord(s) - ord('a')
        if i == len(S) - 1:
            ans += chr((tmp + K) % 26 + ord('a'))
        elif s == 'a':
            ans += s
        elif 26 - tmp <= K:
            ans += 'a'
            K -= 26 - tmp
        else:
            ans += s

    print(ans)
            


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
;

Fixed submission:
a,b,c=map(int,input().split())
print("YES") if b-a==c-b else print("NO")

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split)
print("YES")if b-a==c-b else print("YES")

Fixed submission:
a,b,c=map(int,input().split())
print("YES") if b-a==c-b else print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

f = [{} for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    f[a][b] = True
    f[b][a] = True

for i in range(N):
    koho = set()
    for k in f[i].keys():
        for ff in f[k].keys():
            if not(ff in f[i]):
                koho.add(ff)
    for k in koho:
        f[i][k] = True

ans = 0
zumi = set()
for i in range(N):
    if i in zumi:
        continue

    koho = set()
    ans += 1
    for j in range(N):
        if j in koho or j in zumi:
            continue
        for k in koho:
            if j in f[k]:
                break
        else:
            koho.add(j)
            zumi.add(j)
print(ans)


Fixed submission:
import sys


def input():
    return sys.stdin.readline()[:-1]


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a, b)

ans = 0
for i in range(N):
    ans = max(ans, uf.size(i))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ans = 0
for i in range(1, N+1):
    for j in range(i, N+1, i):
        ans += j
print(ans)


Fixed submission:
N = int(input())

ans = 0
for i in range(1, N+1):
    tmp = i*(N//i)
    ans += (N//i)*(tmp+i)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

zumi = [-1]*(2*(10**5))
ima = 1
for i in range(K):
    # 行ったことある町を通る＝ループする
    if ima in zumi:
        zumi[i] = ima
        break
    # 同じ町へテレポートしている
    if ima == A[ima-1]:
        print(ima)
        exit(0)
    zumi[i] = ima
    ima = A[ima-1]
else:
    print(ima)
    exit(0)

loop_e = zumi.index(-1)
loop_s = zumi.index(zumi[loop_e-1])
zan_loop = K-loop_s
loop = zumi[loop_s:loop_e-1]
amari = zan_loop % (len(loop))
print(loop[amari])


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

zumi_hash = {}
zumi = [-1]*(2*(10**5))
ima = 1
for i in range(K):
    # 行ったことある町を通る＝ループする
    if ima in zumi_hash:
        zumi[i] = ima
        break
    # 同じ町へテレポートしている
    if ima == A[ima-1]:
        print(ima)
        exit(0)
    zumi_hash[ima] = True
    zumi[i] = ima
    ima = A[ima-1]
else:
    print(ima)
    exit(0)

loop_e = zumi.index(-1)
loop_s = zumi.index(zumi[loop_e-1])
zan_loop = K-loop_s
loop = zumi[loop_s:loop_e-1]
amari = zan_loop % (len(loop))
print(loop[amari])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

zumi = []
ima = 1
for i in range(K):
    # 行ったことある町を通る＝ループする
    if ima in zumi:
        zumi.append(ima)
        break
    # 同じ町へテレポートしている
    if ima == A[ima-1]:
        print(ima)
        exit(0)
    zumi.append(ima)
    ima = A[ima-1]
else:
    print(ima)
    exit(0)

loop_s = zumi.index(zumi[-1])
zan_loop = K-loop_s
loop = zumi[loop_s:-1]
amari = zan_loop % (len(zumi)-loop_s-1)
print(loop[amari])


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

zumi_hash = {}
zumi = [-1]*(2*(10**5))
ima = 1
for i in range(K):
    # 行ったことある町を通る＝ループする
    if ima in zumi_hash:
        zumi[i] = ima
        break
    # 同じ町へテレポートしている
    if ima == A[ima-1]:
        print(ima)
        exit(0)
    zumi_hash[ima] = True
    zumi[i] = ima
    ima = A[ima-1]
else:
    print(ima)
    exit(0)

loop_e = zumi.index(-1)
loop_s = zumi.index(zumi[loop_e-1])
zan_loop = K-loop_s
loop = zumi[loop_s:loop_e-1]
amari = zan_loop % (len(loop))
print(loop[amari])
Buggy python submission (verdict: Runtime Error):
import math

A, B, N = map(int, input().split())

ans = 0
if N == max(A, B, N):
    ans = math.floor((A*N)/B)-A*(N//B)
else:
    if N <= 1000000:
        for x in range(1, N+1):
            tmp = math.floor((A*x)/B)-A*(x//B)
            ans = max(ans, tmp)
    else:
        for x in range(1, 300000):
            tmp = math.floor((A*x)/B)-A*(x//B)
            ans = max(ans, tmp)

        base = N//2-150000
        for x in range(base, base+300000):
            tmp = math.floor((A*x)/B)-A*(x//B)
            ans = max(ans, tmp)

        for x in range(N-300000, N+1):
            tmp = math.floor((A*x/B))-A*(x//B)
            ans = max(ans, tmp)
print(int(ans))


Fixed submission:
K = int(input())
A, B = map(int, input().split())

for i in range(A, B+1):
    if i % K == 0:
        print('OK')
        exit(0)
print('NG')
Buggy python submission (verdict: Runtime Error):
import math

A, B, N = map(int, input().split())
x = max(B-1, N)
print(math.floor((A*x)/B)-A*(x//B)

Fixed submission:
import math

A, B, N = map(int, input().split())
x = min(B-1, N)
print(math.floor((A*x)/B)-A*(x//B))
Buggy python submission (verdict: Time Limit Exceeded):
import math

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

balls = [0]*n
for a in A:
    balls[a-1] += 1

tei = math.factorial(2)
ball_permu = [0]*n
ball_permu_target = [0]*n
fac = [-1]*n
for i in range(n):
    if balls[i] < 2:
        ball_permu[i] = 0
    else:
        if fac[balls[i]-1] == -1:
            ball_permu[i] = math.factorial(balls[i])//(math.factorial(balls[i]-2)*tei)
            fac[balls[i]-1] = ball_permu[i]
        else:
            ball_permu[i]=fac[balls[i]-1]

    ball = balls[i]-1
    if ball < 2:
        ball_permu_target[i] = 0
    else:
        if fac[ball-1] == -1:
            ball_permu_target[i] = math.factorial(ball)//(math.factorial(ball-2)*tei)
            fac[ball-1] = ball_permu_target[i]
        else:
            ball_permu_target[i]=fac[ball-1]

ball_sum = sum(ball_permu)
for a in A:
    ans = ball_sum-ball_permu[a-1]+ball_permu_target[a-1]
    print(ans)


Fixed submission:
from collections import Counter

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

C = Counter(A)
a_sum = 0
for i in C.values():
    a_sum += i*(i-1)//2

for a in A:
    k = C[a]
    print(a_sum-(k*(k-1)//2)+((k-1)*(k-2)//2))

Buggy python submission (verdict: Time Limit Exceeded):
import math

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

balls = [0]*n
for a in A:
    balls[a-1] += 1

tei = math.factorial(2)
ball_permu = [0]*n
ball_permu_target = [0]*n
for i in range(n):
    if balls[i] < 2:
        ball_permu[i] = 0
    else:
        ball_permu[i] = math.factorial(
            balls[i])//(math.factorial(balls[i]-2)*tei)

    ball = balls[i]-1
    if ball < 2:
        ball_permu_target[i] = 0
    else:
        ball_permu_target[i] = math.factorial(
            ball)//(math.factorial(ball-2)*tei)

ball_sum = sum(ball_permu)
# print(balls)
# print(ball_permu)
# print(ball_permu_target)
for a in A:
    ans = ball_sum-ball_permu[a-1]+ball_permu_target[a-1]
    print(ans)


Fixed submission:
from collections import Counter

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

C = Counter(A)
a_sum = 0
for i in C.values():
    a_sum += i*(i-1)//2

for a in A:
    k = C[a]
    print(a_sum-(k*(k-1)//2)+((k-1)*(k-2)//2))
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())

ans = 0
while True:
    if n >= a:
        n -= a
        ans += a
    else:
        ans += n
        break

    if n >= b:
        n -= b
    else:
        break
print(ans)


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

ans = n//(a+b)*a
amari = n-(a+b)*(n//(a+b))
ans += min(amari, a)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
sl = []
s_count = []

for i in range(n):
    s = input()
    if not(s in sl):
        sl.append(s)
        s_count.append(1)
    else:
        index = sl.index(s)
        s_count[index] += 1

ans = []
s_max = max(s_count)
for i in range(len(s_count)):
    if s_count[i] == s_max:
        ans.append(sl[i])

ans.sort()
for a in ans:
    print(a)


Fixed submission:
n = int(input())
sl = {}

for i in range(n):
    s = input()
    if not(s in sl):
        sl[s] = 0
    else:
        sl[s] += 1

ans = []
s_max = max(sl.values())
for key in sl:
    if sl[key] == s_max:
        ans.append(key)

ans.sort()
for a in ans:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
P = list(map(int, input().split()))

me = []
for p in P:
    me.append((p * (p + 1) / 2) / p)

ans = 0
for i in range(n-k+1):
    ans = max(ans, sum(me[i:i+k]))
print(ans)


Fixed submission:
n, k = map(int, input().split())
pl = list(map(int, input().split()))

ave_pl = []
for i, p in enumerate(pl):
    p_sum = p*(p+1)/2
    if i == 0:
        ave_pl.append(p_sum/p)
    else:
        ave_pl.append(ave_pl[i-1]+(p_sum/p))

ans = 0
if n == k:
    print(ave_pl[-1])
else:
    for i in range(k-1, n):
        if i == 0:
            ans = max(ans, ave_pl[i])
        else:
            ans = max(ans, ave_pl[i]-ave_pl[i-k])
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
pl = list(map(int, input().split()))

ave_pl = []
for i, p in enumerate(pl):
    p_sum = p*(p+1)/2
    ave_pl.append(p_sum/p)

ans = 0
for i in range(n-k+1):
    ans = max(ans, sum(ave_pl[i:i+k]))

print(ans)


Fixed submission:
n, k = map(int, input().split())
pl = list(map(int, input().split()))

ave_pl = []
for i, p in enumerate(pl):
    p_sum = p*(p+1)/2
    if i == 0:
        ave_pl.append(p_sum/p)
    else:
        ave_pl.append(ave_pl[i-1]+(p_sum/p))

ans = 0
if n == k:
    print(ave_pl[-1])
else:
    for i in range(k-1, n):
        if i == 0:
            ans = max(ans, ave_pl[i])
        else:
            ans = max(ans, ave_pl[i]-ave_pl[i-k])
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))

ret = 0
for i in range(1, n+1):
    if p[i-1] == min(p[:i]):
        ret += 1

print(ret)


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

ret = 1
min_num = p[0]
for i in range(1, n):
    if min_num > p[i]:
        ret += 1
        min_num = p[i]

print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

ans = 0
for i in range(1000):
    p = str(i).zfill(3)
    p_index = 0
    for j in range(n):
        if p[p_index] == s[j]:
            p_index += 1
            if p_index == 3:
                break
    if p_index == 3:
        ans += 1

print(ans)


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

ans = 0
# 000 ～　999 がsから作成できるか確認していく
for i in range(1000):
    p = str(i).zfill(3)

    s_index_100 = s.find(p[2])
    if s_index_100 == -1:
        continue

    s_index_10 = s.find(p[1], s_index_100+1)
    if s_index_10 == -1:
        continue

    s_index_1 = s.find(p[0], s_index_10+1)
    if s_index_1 == -1:
        continue
    ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    ans = 1
    N = int(input())
    s = input()
    ans = 0
    for i in range(1000):
        t = str(i).zfill(3)
        t_index = 0 
        for s_index in range(N):
            if s[s_index] == t[t_index]:
                t_index += 1
                if t_index == 3:
                    break
        if t_index == 3:
            ans += 1
    print(ans)
solve()

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

ans = 0
# 000 ～　999 がsから作成できるか確認していく
for i in range(1000):
    p = str(i).zfill(3)

    s_index_100 = s.find(p[2])
    if s_index_100 == -1:
        continue

    s_index_10 = s.find(p[1], s_index_100+1)
    if s_index_10 == -1:
        continue

    s_index_1 = s.find(p[0], s_index_10+1)
    if s_index_1 == -1:
        continue
    ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

ans = 0
for i in range(1000):
    p = str(i).zfill(3)
    p_index = 0
    for j in range(n):
        if p[p_index] == s[j]:
            p_index += 1
        if p_index == 3:
            break
    if p_index == 3:
        ans += 1

print(ans)


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

ans = 0
# 000 ～　999 がsから作成できるか確認していく
for i in range(1000):
    p = str(i).zfill(3)

    s_index_100 = s.find(p[2])
    if s_index_100 == -1:
        continue

    s_index_10 = s.find(p[1], s_index_100+1)
    if s_index_10 == -1:
        continue

    s_index_1 = s.find(p[0], s_index_10+1)
    if s_index_1 == -1:
        continue
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
r=list(input())
print(r*r)

Fixed submission:
r = int(input())
print(r*r)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int, input().split()))

# 各数値が何個あるか
C = [0]*(2100)
for l in L:
    C[l] += 1

# 累積和を作成する
S = [0]
for i in range(2100):
    S.append(S[i]+C[i])

ans = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue

        left = abs(L[i]-L[j])+1
        right = L[i]+L[j]
        tmp = S[right]-S[left]

        if left <= L[i] <= right:
            tmp -= 1
        if left <= L[j] <= right:
            tmp -= 1
        ans += max(0, tmp)

print(ans//6)


Fixed submission:
import bisect

N = int(input())
L = list(map(int, input().split()))

L.sort()
ans = 0
for i in range(N-1):
    for j in range(i+1, N-1):
        idx = bisect.bisect_left(L, L[i]+L[j])
        ans += max(0, idx-j-1)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

# S単体で必要な置換数を求める
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5)
cnt = int(cnt+0.5)

# Sを接続した時に必要な置換数を求める
s3 = S*3
cnt_1 = 0
for i in range((len(s3)*3)-1):
    if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5)
cnt_1 = int(cnt_1+0.5)

# 単体と接続時に必要な置換数の合計を求める
ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K
print(ans)


Fixed submission:
S = input()
K = int(input())

# S単体で必要な置換数を求める
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5)
cnt = int(cnt+0.5)

# Sを接続した時に必要な置換数を求める
s3 = S*3
cnt_1 = 0
for i in range(len(s3)-1):
    if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5)
cnt_1 = int(cnt_1+0.5)

# 単体と接続時に必要な置換数の合計を求める
ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 6)


def dfs(now, prev=-1):
    for next in tree[now]:
        # 1個前のノードを参照した時はcontinue
        if next == prev:
            continue

        # 現在のポイントを次のノードへ加算して累積和をとる
        point[next] += point[now]

        # 次のノードへ
        dfs(next, now)


N, Q = map(int, input().split())
tree = [[] for _ in range(N)]
point = [0]*N

# 木構造を2次元配列で表現。要素Xのノードからつながっているノード番号が格納される。
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

# 各ノードのポイントを求める
for _ in range(Q):
    p, x = map(int, input().split())
    point[p-1] += x

dfs(0)
print(*point)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)


def input():
    return sys.stdin.readline()[:-1]


def dfs(now, prev=-1):
    for next in tree[now]:
        # 1個前のノードを参照した時はcontinue
        if next == prev:
            continue

        # 現在のポイントを次のノードへ加算して累積和をとる
        point[next] += point[now]

        # 次のノードへ
        dfs(next, now)


N, Q = map(int, input().split())
tree = [[] for _ in range(N)]
point = [0]*N

# 木構造を2次元配列で表現。要素Xのノードからつながっているノード番号が格納される。
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

# 各ノードのポイントを求める
for _ in range(Q):
    p, x = map(int, input().split())
    point[p-1] += x

dfs(0)
print(*point)
Buggy python submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
AB = [[] for i in range(10*5+1)]

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

hq = []
heapq.heapify(hq)

ans = 0
for i in range(1, M+1):
    for a in AB[i]:
        heapq.heappush(hq, a)

    if len(hq) > 0:
        ans += abs(heapq.heappop(hq))

print(ans)


Fixed submission:
import heapq

N, M = map(int, input().split())
AB = [[] for i in range(10**5+1)]

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

hq = []
heapq.heapify(hq)

ans = 0
for i in range(1, M+1):
    for b in AB[i]:
        heapq.heappush(hq, b)

    if len(hq) > 0:
        ans += -heapq.heappop(hq)

print(ans)