Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
readline = sys.stdin.buffer.readline

a,b,c = map(int,readline().split())
array = np.array([a,b,c],dtype="float64")
if np.sqrt(a)+np.sqrt(b) < np.sqrt(c):
    print("Yes")
else:
    print("No")

Fixed submission:
import sys
readline = sys.stdin.buffer.readline

n = int(readline())

alphabets = [chr(ord('a') + x) for x in range(26)]

def dfs(s,i):
    if len(s)==n:
        print("".join(s))
    else:
        t = min(len(set(s))+1,len(s)+1)
        for i in range(t):
            dfs(s+[alphabets[i]],i)

dfs([],0)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
s = readline().rstrip().decode('utf-8')
k = int(readline())
n = len(s)
"""
0の場所を固定してやる。
その時、9**(0以外が入る桁の数)が答え。
"""

from math import factorial

def permutations_count(n,r):
    """順列nPr"""
    return factorial(n) // factorial(n-r)

def combinations_count(n,r):
    """組み合わせnCr"""
    return factorial(n) // (factorial(n-r)*factorial(r))
if k == 1:
    i = 1
    ans = 0
    while True:
        if n == i:
            ans += int(s[0])
            break
        else:
            ans += 9
        i += 1
    print(ans)
    exit()

ans = 0
for i in range(1,n+1): #n+1桁
    if i < k:
        continue
    elif i == k:
        ans += 9**i
    else:
        ans += 9*(9**(k-1)*combinations_count(i-1,k-1)) #9は一番上の桁で、9通りが確定.kは1つ使っているのでk-1通りi桁からk-1個の並び

#現在、n桁(長さの桁)の9999...までの通りをカウントしてある。
#ここから、上位3桁に着目して、そこまでの分を引いてやる
if k == 2:
    point2 = int(s[:2]) #10~99までありえる
    delay = 0
    if point2 == 99:
        print(ans)
        exit()
    for i in range(point2,100):
        if not "0" in str(i):
            delay += 1
        else:
            delay += 9*(n-2)
    print(ans-delay)
else:
    point3 = int(s[:3])
    delay = 0
        if point3 == 999:
        print(ans)
        exit()
    for i in range(point3,1000):
        if not "0" in str(i):
            delay += 1
        else:
            if s[1:3] == "00":
                delay += 81*combinations_count(n-3,2)
            else:
                delay += 9*(n-3)
    print(ans-delay)




Fixed submission:
#ABC154-E Almost Everywhere Zero

#桁DP

"""
問題：
n以下の0以外の数字の数が丁度k個である整数の個数を求めよ。

解法：
桁DP
以下の条件があったら桁DPを疑うべし
・桁に関している
・制約が大きい
・整数nがある範囲を動くときの、〜〜〜の最大値を求めよ
・整数nがある範囲を動くときの、〜〜〜という条件を満たすものは何通りあるか←今回はコッチ

考え方：
桁DPでは上位桁から条件を絞っていって、下位桁にクエリを出すという再帰方法で解く。この時、何回もこの再帰をやっていると
下位桁が全く同じ条件になることが出現するので、それをメモ化、呼び出しして動的に解く。
そのためのdpテーブルは３次元で、各階層に対応するのは以下のようなデータ。

dp[i][j][k] = (上から)i桁まで見た,j個Kを使った,k=0:制約ありk=1:自由     の時の条件を満たす場合の個数(value)

問題により多少dpテーブルの内容や順番は異なるが、i桁目まで見た、と、自由度kについての制約は必ずテーブルの中に入る。
もうひとつ、今回で言えばjのテーブルは、kをいくつ使ったか、全桁の合計がD以下であるみたいな問題はいま合計はいくらか
みたいなデータになる。
"""

n = input() #桁DPの場合、nはstr型で取る
m = len(n)
K = int(input()) #DPテーブルのkとかぶって紛らわしいので、大文字にする

dp = [[[0]*2 for j in range(4)] for i in range(105)]
dp[0][0][0] = 1
for i in range(m): #m=桁数
    for j in range(4): #0以外の数はj回使っている
        for k in range(2): #制約,自由の2通り(制約がかかってから気にするんじゃなくて、
            #最初から全桁に制約がかかってるもんだと思って全部計算する)
            nd = int(n[i]) #その桁の数字(制約ありの時に使う)
            for d in range(10): #下位桁に対して10回(0~9まで)まわす
                ni = i+1 #下位桁に
                nj = j #0以外を使った回数はj回
                nk = k #制約か自由か
                if d != 0: nj += 1 #その桁を0だと仮定して場合、現在までの0の個数+=1
                if nj > K: continue #0の個数がKを超えていたら条件を満たさない
                if k == 0: #制約ありの場合
                    if d > nd:continue #その桁の制約を超えていたら飛ばす
                    if d < nd:nk = 1 #逆にd未満ならば、下位桁は自由になるので、k=1:自由にしてやる
                #この下位桁に対するforループを全て満たした時、dpテーブルを更新
                dp[ni][nj][nk] += dp[i][j][k]

ans = dp[m][K][0] + dp[m][K][1] #制約ありでもなしでも良いので、両方足す

print(ans)
Buggy python submission (verdict: Runtime Error):
import math,bisect
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,d,a = map(int,readline().split())
lst1 = [list(map(int,readline().split())) for i in range(n)]
lst1.sort()

#####segfunc######
def segfunc(x,y):
    return x+y

def init(init_val): #渡されたリストでsegを初期化
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x): #segの要素kをxに変更(セグ木全体の更新)
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q): #区間[p,q)での、segfuncに準じた値を返す
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
"""
最小値のセグ木 → 10**9　(最小値の更新に影響しないため)
　　和のセグ木 → 0
　　積のセグ木 → 1
　　gcdのセグ木 → 0　(gcdを更新しない値は0)
"""
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num


#process
x = []
for i in lst1:
    x.append(i[0])


ans = 0

for i in range(n):
    k = bisect.bisect_left(x,lst1[i][0]-2*d) #手前側にあるダメージ量を確認

    r = query(k,i) #kからiまでの合計ダメージを取得

    if lst1[i][1] > r:
        if (lst1[i][1]-r)/a%1==0:
            need = (lst1[i][1]-r)//a
        else:
            need = (lst1[i][1]-r)//a+1
        ans += need
        update(i,need*a)

print(ans)


Fixed submission:
#n = int(input())
h,a = map(int,input().split())
#lst1 = list(map(int,input().split()))
import math
print(math.ceil(h/a))
Buggy python submission (verdict: Runtime Error):
import testcase
n = 10**4
lst1 = list(map(int,testcase.integers(10**4,1,10**5+1).split()))
mod = 10**9+7

import math
#リスト l の最大公約数
def lcmlist(l):
    a = l[0]
    for i in range(len(l)):
        a = int(a)
        a = a*l[i]//math.gcd(a,l[i])
    return int(a)

g = lcmlist(lst1)
ans = 0
for i in range(n):
    ans += g//lst1[i]
print(ans%mod)

Fixed submission:
n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7
 
def GCD(a,b):
    if b == 0:
        return a
    else:
        return GCD(b,a%b)
def LCM(a,b):
    return (a//GCD(a,b)*b)

l = 1
for i in lst1:
    l = LCM(l,i)

ans = 0
for i in range(n):
    ans += l//lst1[i]
 
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7
 
def GCD(a,b):
    if b == 0:
        return a
    else:
        return GCD(b,a%b)
def LCM(a,b):
    return (a//GCD(a,b)*b)

l = 1
for i in lst1:
    l = LCM(l,i)

ans = 0
for i in range(n):
    ans += l//lst1[i]
 
print(ans%mod)

Fixed submission:
n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7
 
def GCD(a,b):
    if b == 0:
        return a
    else:
        return GCD(b,a%b)
def LCM(a,b):
    return (a//GCD(a,b)*b)

l = 1
for i in lst1:
    l = LCM(l,i)

ans = 0
for i in range(n):
    ans += l//lst1[i]
 
print(ans%mod)

Buggy python submission (verdict: Runtime Error):
n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7

import fractions as math
#リスト l の最大公約数
def lcmlist(l):
    a = l[0]
    for i in range(len(l)):
        a = int(a)
        a = a*l[i]/math.gcd(a,l[i])
    return int(a)

g = lcmlist(lst1)
ans = 0
for i in range(n):
    ans += g//lst1[i]%mod

print(ans%mod)




Fixed submission:
n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7
 
def GCD(a,b):
    if b == 0:
        return a
    else:
        return GCD(b,a%b)
def LCM(a,b):
    return (a//GCD(a,b)*b)

l = 1
for i in lst1:
    l = LCM(l,i)

ans = 0
for i in range(n):
    ans += l//lst1[i]
 
print(ans%mod)

Buggy python submission (verdict: Runtime Error):
n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7

import math
#リスト l の最大公約数
def lcmlist(l):
    a = l[0]
    for i in range(len(l)):
        a = int(a)
        a = a*l[i]/math.gcd(a,l[i])
    return int(a)

g = lcmlist(lst1)
ans = 0
for i in range(n):
    ans += g//lst1[i]%mod

print(ans%mod)

Fixed submission:
n = int(input())
lst1 = list(map(int,input().split()))
mod = 10**9+7
 
def GCD(a,b):
    if b == 0:
        return a
    else:
        return GCD(b,a%b)
def LCM(a,b):
    return (a//GCD(a,b)*b)

l = 1
for i in lst1:
    l = LCM(l,i)

ans = 0
for i in range(n):
    ans += l//lst1[i]
 
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
from collections import deque
import testcase
H,W = map(int,input().split())
lst1 = [list(list(input())) for i in range(H)]

def dfs(maze,visited, sh, sw):
    a = 0
    stack = deque([[sh, sw]])
    visited[sh][sw] = 0
    while stack:
        h, w = stack.popleft()
        print(visited)
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): #4近傍について探索
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
               new_w < 0 or new_w >= W: #リスト外でないならelif条件へ
                continue
            elif maze[new_h][new_w] != "#" and \
                visited[new_h][new_w] == 0: #行ったことがないかつ、壁でないなら
                visited[new_h][new_w] = visited[h][w]+1
                stack.append([new_h, new_w])
    a = 0
    for s in range(H):
        for x in range(W):
            a = max(a,visited[s][x])
    return a

ans = 0

for i in range(H):
    for q in range(W):
        visited = [[0]*W for _ in range(H)]
        if lst1[i][q] == ".":
            ans = max(ans,dfs(lst1,visited,i,q))
print(ans)


Fixed submission:
from collections import deque
H,W = map(int,input().split())
lst1 = [list(list(input())) for i in range(H)]

def dfs(maze,visited, sh, sw):
    a = 0
    stack = deque([[sh, sw]])
    visited[sh][sw] = 1
    while stack:
        h, w = stack.popleft()
        #print(visited)
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): #4近傍について探索
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
               new_w < 0 or new_w >= W: #リスト外でないならelif条件へ
                continue
            elif maze[new_h][new_w] != "#" and \
                visited[new_h][new_w] == 0: #行ったことがないかつ、壁でないなら
                visited[new_h][new_w] = visited[h][w]+1
                stack.append([new_h, new_w])
    a = 0
    for s in range(H):
        for x in range(W):
            a = max(a,visited[s][x])
    return a

ans = 0

for i in range(H):
    for q in range(W):
        visited = [[0]*W for _ in range(H)]
        if lst1[i][q] == ".":
            ans = max(ans,dfs(lst1,visited,i,q))
print(ans-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
k = 10
ans = 0


if n%2!=0:
	print(0)
    exit()

def k_change():
    global k
    k = k*5


def func(n):
    global ans,k
    #print(k)
    if n < k:
        print(ans)
        exit()
    ans += n//k
    k_change()
    func(n)

func(n)

Fixed submission:
n = int(input())
k = 10
ans = 0


if n%2!=0:
	print(0)
	exit()

def k_change():
	global k
	k = k*5


def func(n):
	global ans,k
	#print(k)
	if n < k:
		print(ans)
		exit()
	ans += n//k
	k_change()
	func(n)

func(n)
Buggy python submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())
 
maxint = 10**9
 
def dn(p):
    plist = list(str(p))
    return len(plist) #nの桁数d(n)が帰る

def nibuntansaku(l,u):
    c = (l+u)//2 #切り捨て
    if c <= (x-b*dn(c))/a: #条件を満たす(つまり、)
        return c,u
    else:
        return l,c





#上限(大きい)
n_upper = math.ceil((x-b*1)/a)
#下限(小さい)
n_lower = math.floor((x-b*10)/a)


if n_upper < 1 : #最小条件ですでに1未満の場合は0を出力
    print(0)
    exit()

while True:
    if abs(n_upper-n_lower) <= 1:
        break 
    n_lower,n_upper = nibuntansaku(n_lower,n_upper)

if n_upper+1 <= (x-b*dn(n_upper+1))/a:
    ans = n_upper+1

elif n_upper <= (x-b*dn(n_upper))/a:
    ans = n_upper
else:
    ans = n_lower

print(min(ans,maxint))

Fixed submission:
s = input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
n = int(input()) #n文字サイクルさせる
s = list(input().split()) #元の文字列(全て大文字)
list1 = []
for i in range(s):
    number = (ord(s[i]) + n - ord("A")) %26 + ord("A")
    list1.append(chr(number))

print("".join(list1))

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

list1 = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

mods = 26
list2 = []
for i in s:
    a = (list1.index(i) +n)%mods
    list2.append(list1[a])

print("".join(list2))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
count = 0
f0,f1 = -1,-1
for ans in range(1000):
  f0,f1 = -1,-1
  ans_str = "{0:03d}".format(ans)
  for i in range(n):
    if s[i] == ans_str[0]:
      f0 = i
      break
  if f0 == -1:
    continue
  for j in range(f0+1,n):
    if s[j] == ans_str[1]:
      f1 = j
      break
  if f1 == -1:
    continue
  for k in range(f1+1,n):
    if s[k] == ans_str[2]:
      count += 1
      break

print(count)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
AB = [list(map(int,readline().split())) for i in range(N-1)]

graph = [[] for _ in range(N+1)] #隣接リスト
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

#親のノードに子を入れてくdfs
stack = [1]
parent = [0]*(N+1)
order = []
while stack:
    x = stack.pop()
    order.append(x)
    for i in graph[x]:
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)

#各子の色を決めていく。
color = [-1]*(N+1)
for x in order:
    ng = color[x]
    c = 1
    for y in graph[x]:
        if parent[x] == y:
            continue
        if c == ng:
            c += 1
        color[y] = c
        c += 1

ans = []
for a,b in AB:
    if parent[a] == b: #子の頂点の色を入れる
        ans.append(color[a])
    else:
        ans.append(color[b])

print(max(ans))
for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
#sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
s = list(input())
s.reverse()
list1 = []
def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(str(n-mass))
    return
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(str(i))
      maze(mass+i,times+1)
      return
    elif i == 1:
      print("-1")
      exit()
  return

a = maze(0,0)
list1.reverse()
print(" ".join(list1))

Fixed submission:
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m = map(int,input().split())
s = list(input())
s.reverse()
list1 = []
def maze(mass,times): #今いるマス、現状の手数
  if mass+m >= n:
    list1.append(str(n-mass))
    return
  for i in range(m,0,-1):
    if s[mass+i] == "0":
      list1.append(str(i))
      maze(mass+i,times+1)
      return
    elif i == 1:
      print("-1")
      exit()
  return

a = maze(0,0)
list1.reverse()
print(" ".join(list1))
Buggy python submission (verdict: Runtime Error):
h,w,k = map(int,input().split())
list1 = [list(input()) for i in range(h)]
import numpy as np
list2 = np.zeros((h,w),np.uint8)
numcount = 1
berrycount = 0
flag = 0
for i in range(h):
    flag = 0
    if not "#" in list1[i]:
        if numcount == 1:
            for j in range(w):
                list2[i][j] = numcount
            numcount -= 1
        else:
            numcount -= 1
            for j in range(w):
                list2[i][j] = numcount
        flag = 1

    if not flag:        
        for j in range(w):
            
            if list1[i][j] == ".":
                list2[i][j] = numcount
            else:
                if berrycount == 0:
                    berrycount += 1
                    list2[i][j] = numcount
                else:
                    berrycount += 1
                    numcount += 1
                    list2[i][j] = numcount
    berrycount = 0
    numcount += 1

for i in range(h):
    print(" ".join(map(str,list2[i])))

Fixed submission:
h,w,k = map(int,input().split())
list1 = [list(input()) for i in range(h)]
import numpy as np
list2 = np.zeros((h,w),np.uint32) #list2に0の配列を用意
numcount = 1 #切り分けたケーキにふる番号
berrycount = 0 #1列に何回目のいちごが現れたか
flag = 0 #1列にいちごが一個も無かったときのフラグ
que = [] #その時の列をqueに入れてく
for i in range(h):
    flag = 0
    if not "#" in list1[i]: #いちごが乗ってない列
        flag = 1
        numcount -= 1
        que.append(i)
    if not flag: #いちごが乗ってる例
        for j in range(w):    
            if list1[i][j] == ".":
                list2[i][j] = numcount
            else:
                if berrycount == 0: #いちごが出現するのが1回目なら、特に気にせず番号をつける
                    berrycount += 1
                    list2[i][j] = numcount
                else: #2回目以降なら、振り分ける番号を+1する
                    berrycount += 1
                    numcount += 1
                    list2[i][j] = numcount
    berrycount = 0 #いちごリセット
    numcount += 1 #振り分け番号を+1

meme = 0 
"""
1列目から何列もいちごが現れないとき、
初めていちごが現れる列を探索し、その列の数字を1列目~にコピーする。
それ以外(普通に列の途中でいちごのない列が出現したとき)
は、一つ前の列を参照してコピーする
"""
for i in que:
    if i == 0:
        for j in range(1,h):
            if "#" in list1[j]:
                meme = j
                break
        list2[i] = list2[meme]
    else:
        list2[i] = list2[i-1]
for i in range(h):
    for j in range(w):
        list2[i][j] = int(list2[i][j])
for i in range(h):
    print(" ".join(map(str,list2[i])))
Buggy python submission (verdict: Runtime Error):
import bisect
#input
n = int(input())
list1 = list(map(int,input().split()))
list1.sort()

cout = 0 #最終的な三角形の個数

for i in range(n-2): #リストから三角形が作れなくなるまでループ
	o = list1[i] #1辺を確定、そのままリストから消去
	for j in range(i+1,n-1): #残りの二辺のループ(iで使っている次の値から)
		p = list1[j] #２辺目を確定

		b = o+p -1 #昇順にソートしてあるので、c<a+b条件のみ計算

		d = bisect.bisect_right(list1[j+1:],b) #３辺目を確定
		
		cout += d

print(cout)

Fixed submission:
a,b = map(int,input().split())
if a <= b*2:
    print(0)
else:
    print(a-b*2)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import copy
n= int(input())
a = input()
list1 = list(map(int,a.split()))
list1_1 = copy.deepcopy(list1)
heapq.heapify(list1)
list2 = []
for i in range(n):
    list2.append(list1_1.index(heapq.heappop(list1))+1)

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

Fixed submission:

n= int(input())
a = input()
list1 = list(map(int,a.split()))
list2 = [0]*n
for i in range(n):
    list2[list1[i]-1] = i+1

print(" ".join(map(str,list2)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = input()
list1 = list(map(int,a.split()))

list2 = []
list2.append(list1[0])
for i in range(n):
    list2.append(min(list1[(n-1)-i:]))
print(sum(list2))

Fixed submission:
n = int(input())
list1 = list(map(int,input().split()))
cout = list1[-1]
min_int = list1[-1]
for i in range(n-3,-1,-1):
    cout += min(list1[i:i+2])

cout += list1[0]

print(cout)
Buggy python submission (verdict: Time Limit Exceeded):
n= int(input())
cout,cout2 = 0,0
for i in range(n-1):
        cout += 1
        cout2 += cout
print(cout2)
        

Fixed submission:
n= int(input()) -1
cout = (n*(2+n-1))//2
print(cout)
Buggy python submission (verdict: Runtime Error):
m,d = int(input().split())
f = []
d1,d10,cout = 0,0,0
for i in range(m):
  for j in range(d):
    if d+1 >= 10:
      f = list(str(d+1))
      d10 = int(f[0])
      d1 = int(f[1])
    if d1*d10 == i+1:
      cout += 1
print(cout)
      


Fixed submission:
m,d = map(int,input().split())
f = []
d1,d10,cout = 0,0,0
for i in range(m):
  for j in range(d):
    if j+1 >= 10:
      f = list(str(j+1))
      d10 = int(f[0])
      d1 = int(f[1])
    if d1 >=2 and d10 >= 2:
      if d1*d10 == i+1:
        cout += 1
  d10,d1 = 0,0
print(cout)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,readline().split())
ki = [[] for _ in range(n)]

for i in range(n-1):
    a,b = map(int,readline().split())
    a,b = a-1,b-1
    ki[a].append(b)
    ki[b].append(a)

count = [0]*n
for j in range(q):
    p,x = map(int,readline().split())
    p -= 1
    count[p] += x

queue = deque([[0,count[0]]])
already = [0]
while queue:
    x,q = queue.pop()
    already.append(x)
    for i in ki[x]:
        if not i in already:
            count[i] += q
            queue.append([i,count[i]])
        


print(*count)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,Q = map(int,readline().split())
AB = [list(map(int,readline().split())) for i in range(N-1)]

graph = [[] for _ in range(N+1)] #隣接リスト
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

#親のノードに子を入れてくdfs
stack = [1]
parent = [0]*(N+1)
order = []
while stack:
    x = stack.pop()
    order.append(x)
    for i in graph[x]:
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)

query = [0]*(N+1)

for i in range(Q):
    p,x = map(int,readline().split())
    query[p] += x

#全ての親についての累積和を取る。
#この時、親方向に逆流しないように注意。
for x in order:
    a = query[x]
    for y in graph[x]:
        if y == parent[x]: #逆流防止弁
            continue
        query[y] += a

print(*query[1:])
Buggy python submission (verdict: Runtime Error):

    #ABC138-E Strings of Impurity
"""
sの好きなだけのループに対する部分文字列tを求める
tにあってsにない文字がある時点でno
そうでないならば必ず達成可能で、
tに対してループを回し(i)、
sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex
にする。
そのようなindexがないならば、j=0とし、またはじめから回す。
"""
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
t = readline().rstrip().decode('utf-8')
s_s = set(list(s))
t_s = set(list(t))
flag = 1 if s_s & t_s == t_s else 0

if not flag:
    raise Exception
"""    print(-1)
    exit()
"""
#2進数で、
lst1 = [[] for _ in range(26)]
kijun = ord("a")
for idx,i in enumerate(s):
    lst1[ord(i)-kijun].append(idx)

i = 0
roop = 0
count = 0
while True:
    if i >= len(t):
        print(roop*len(s)+count+1) #countは0-indexedの為
        break
    now = ord(t[i])-kijun
    res = bisect.bisect_left(lst1[now],count)
    if res == len(lst1[now]):
        roop += 1
        count = 0
        res = bisect.bisect_left(lst1[now],count)
        count = lst1[now][res]
    else:
        count = lst1[now][res]
    i += 1
    

Fixed submission:
#ABC138-E Strings of Impurity
"""
sの好きなだけのループに対する部分文字列tを求める
tにあってsにない文字がある時点でno
そうでないならば必ず達成可能で、
tに対してループを回し(i)、
sのj文字目に関して、それより後に初めて出てくるt[i+1]の場所をindexで返し,i+=1,j=そのindex
にする。
そのようなindexがないならば、j=0とし、またはじめから回す。
"""
import sys
import bisect
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
t = readline().rstrip().decode('utf-8')
s_s = set(list(s))
t_s = set(list(t))
flag = 1 if s_s & t_s == t_s else 0

if not flag:
    print(-1)
    exit()

#2進数で、
lst1 = [[] for _ in range(26)]
kijun = ord("a")
for idx,i in enumerate(s):
    lst1[ord(i)-kijun].append(idx)

i = 0
roop = 0
count = 0
while True:
    if i >= len(t):
        print(roop*len(s)+count) #countは0-indexedの為
        break
    now = ord(t[i])-kijun
    res = bisect.bisect_left(lst1[now],count)
    if res == len(lst1[now]):
        roop += 1
        count = 0
        res = bisect.bisect_left(lst1[now],count)
        count = lst1[now][res]+1 #その次の文字から
    else:
        count = lst1[now][res]+1
    i += 1
Buggy python submission (verdict: Runtime Error):
from functools import lru_cache

n = int(input())
list1 = [''.join(sorted(input())) for i in range(n)]
dict1 = dict()
cout = 0
@lru_cache(maxsize = None)
def func(s):
	if s == 2:
		return 1 #2個の場合は1パターン
	return s-1 + func(s-1)

for i in range(n):
	if list1[i] in dict1:
		dict1[list1[i]] += 1
	else:
		dict1[list1[i]] = 1

for i in dict1:
	if dict1[i] != 1:
		cout += func(dict1[i])

print(cout)


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