Harryxun/stf_run huggingface dataset:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())
  
n,m,k=input2()
A=input_array()
B=input_array()

ca=0
cb=0
count=0
SUM=0
for i in range(n+m):
	if ca >= n:
		SUM+=B[cb]
		cb+=1
	elif cb >= m:
		SUM+=A[ca]
		ca+=1
	elif A[ca]<=B[cb]:
		SUM+=A[ca]
		ca+=1
	else:
		SUM+=B[cb]
		cb+=1

	if SUM >k:
		break
	else:
		count+=1
print(count)

### FIXED CODE ###

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,m,k=input2()
A=input_array()
B=input_array()
acc_A=[0]
acc_B=[0]

for i in range(n):
	acc_A.append(A[i]+acc_A[i])
for i in range(m):
	acc_B.append(B[i]+acc_B[i])

ans=0
tmp_m=m
for i in range(n+1):
	if acc_A[i]>k:
		break
	for j in range(tmp_m,-1,-1):
		if acc_B[j]<=k-acc_A[i]:
			ans=max(i+j,ans)
			tmp_m=j #探索開始地点の更新
			break
print(ans)
from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        break

dist = [[INF] * W for _ in range(W)]
dist[Si][Sj] = 0


ans = INF

Q = deque([(Si, Sj)])
while Q:
    i, j = Q.popleft()

    ans = min(
        1 + (i + K - 1) // K,
        1 + (j + K - 1) // K,
        1 + (H - 1 - i + K - 1) // K,
        1 + (W - 1 - j + K - 1) // K
    )

    if dist[i][j] == K:
        continue

    distance = dist[i][j] + 1

    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + di, j + dj

        if not (0 <= ni < H or 0 <= nj < W) and A[ni][nj] == "#":
            continue

        if dist[ni][nj] > distance:
            dist[ni][nj] = distance
            Q.append((ni, nj))

print(ans)


### FIXED CODE ###

from collections import deque

INF = float("inf")

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

Si, Sj = (0, 0)
for i, a in enumerate(A):
    if "S" in a:
        Si, Sj = (i, a.index("S"))
        break

dist = [[INF] * W for _ in range(H)]
dist[Si][Sj] = 0


ans = INF

Q = deque([(Si, Sj)])
while Q:
    i, j = Q.popleft()

    ans = min(
        ans,
        1 + (i + K - 1) // K,
        1 + (j + K - 1) // K,
        1 + (H - 1 - i + K - 1) // K,
        1 + (W - 1 - j + K - 1) // K
    )

    if dist[i][j] == K:
        continue

    distance = dist[i][j] + 1

    for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ni, nj = i + di, j + dj

        if not (0 <= ni < H and 0 <= nj < W and A[ni][nj] == "."):
            continue

        A[ni][nj] = "#"

        if dist[ni][nj] > distance:
            dist[ni][nj] = distance
            Q.append((ni, nj))

print(ans)
def s(way):
    global w
    global wc

    for i in way:
        c[i] = 1
        if wc[i] == 0:
            wc[i] =1
            for j in w[i]:
                c[j]=1
                s(w[j])


n,m = map(int,input().split())
a = [0 for i in range(m)]
b = [0 for i in range(m)]
w = [[] for i in range(n)]
wc = [0 for i in range(n)]
c = [0 for i in range(n)]
for i in range(m):
    a[i],b[i] = map(int,input().split())
    w[a[i]-1].append(b[i]-1)
    w[b[i]-1].append(a[i]-1)
ans =-1
for i in range(n):
    if c[i] == 0:
        c[i] = 1
        wc[i] = 1
        ans += 1
        s(w[i])

print(ans)

### FIXED CODE ###


from collections import deque

d = deque()
n,m = map(int,input().split())

w = [[] for i in range(n)]
c = [0 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    w[a-1].append(b-1)
    w[b-1].append(a-1)
ans =-1
for i in range(n):
    if c[i] == 0:
        c[i] = 1
        ans += 1
        d.append(i)
        while d:
            x = d.pop()
            for i in w[x]:
                if c[i] == 0:
                    c[i] = 1
                    d.append(i)

print(ans)
from collections import defaultdict
class UnionFind(object):
  def __init__(self,n=1):
    self.par = [i for i in range(n)]
    self.rank = [0 for _ in range(n)]
    self.size = [1 for _ in range(n)]


  def find(self,x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] ==  self.find(self.par[x])
      return self.par[x]

  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)
    if x != y :
      if self.rank[x] <self.rank[y]:
        x,y = y,x
      if self.rank[x] == self.rank[y]:
        self.rank[x] += 1
      self.par[y] = x
      self.size[x] +=self.size[y]

  def is_same(self,x,y):
    return self.find(x)==self.find(y)
  
  def get_size(self,x):
    x = self.find(x)
    return self.size[x]

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

# 道路のUnionFind
uf1 = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    uf1.union(p - 1, q - 1)
 
# 鉄道のUnionFind
uf2 = UnionFind(N)
for i in range(L):
    r, s = map(int, input().split())
    uf2.union(r - 1, s - 1)
 
# 道路と鉄道の連結の組み合わせ（根のペアのカウント）
c = defaultdict(int)
for i in range(N):
    c[(uf1.find(i), uf2.find(i))] += 1
ans = ""

# 回答を出力
for i in range(N):
    ans += str(c[(uf1.find(i), uf2.find(i))]) + " "
print(ans)

### FIXED CODE ###

from collections import defaultdict
class UnionFind(object):
  def __init__(self,n=1):
    self.par = [i for i in range(n)]
    self.rank = [0 for _ in range(n)]
    self.size = [1 for _ in range(n)]


  def find(self,x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] =  self.find(self.par[x])
      return self.par[x]

  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)
    if x != y :
      if self.rank[x] <self.rank[y]:
        x,y = y,x
      if self.rank[x] == self.rank[y]:
        self.rank[x] += 1
      self.par[y] = x
      self.size[x] +=self.size[y]

  def is_same(self,x,y):
    return self.find(x)==self.find(y)
  
  def get_size(self,x):
    x = self.find(x)
    return self.size[x]

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

# 道路のUnionFind
uf1 = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    uf1.union(p - 1, q - 1)
 
# 鉄道のUnionFind
uf2 = UnionFind(N)
for i in range(L):
    r, s = map(int, input().split())
    uf2.union(r - 1, s - 1)
 
# 道路と鉄道の連結の組み合わせ（根のペアのカウント）
c = defaultdict(int)
for i in range(N):
    c[(uf1.find(i), uf2.find(i))] += 1
ans = ""

# 回答を出力
for i in range(N):
    ans += str(c[(uf1.find(i), uf2.find(i))]) + " "
print(ans)
n = int(input())
h = [None] + list(map(int, input().split('')))

dp = [None for _ in range(n+1)]
for i in range(1,n+1):
  if i == 1:
    dp[i] = 0
  elif i ==2:
    dp[i] = abs(h[2] - h[1])
  else:
    dp[i] = min(
      dp[i-1] + abs(h[k] - h[k-1]),
      dp[i-2] + abs(h[k] - h[k-2])
    )
print(dp[i])

### FIXED CODE ###

n = int(input())
h = [None] + list(map(int, input().split()))

dp = [None for _ in range(n+1)]
for k in range(1,n+1):
  if k == 1:
    dp[k] = 0
  elif k == 2:
    dp[k] = abs(h[2] - h[1])
  else:
    dp[k] = min(
      dp[k-1] + abs(h[k] - h[k-1]),
      dp[k-2] + abs(h[k] - h[k-2])
    )
print(dp[k])
N,K=map(int,input().split())
p = list(map(int,input().split()))
ans = 0

p.sort()
for i in range(K+1):
  ans += p[i]
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
p = list(map(int,input().split()))
ans = 0

p.sort()
for i in range(K):
  ans += p[i]
print(ans)
S = input()

if S = "AAA":
  print("No")
elif S = "BBB":
  print("No")
else:
  print("Yes")

### FIXED CODE ###

S = input()
 
if S == "AAA":
    print("No")
elif S == "BBB":
    print("No")
else:
    print("Yes")
n=int(input())
d=dict()
if n==1:
  print(1)
else:
  for i in range(2,n+1):
    for j in range(2,i+1):
      if i%j==0:
        if j not in d:
          d[i]=1
        else:
          d[i]+=1
  ans=1
  for i in d.values():
    ans*=i+1
  print(ans)

### FIXED CODE ###

n=int(input())
d=dict()
for i in range(1,n+1):
  for j in range(1,i+1):
    if j==1:
      continue
    while i%j==0:
      if j not in d:
        d[j]=1
      else:
        d[j]+=1
      i//=j
ans=1
for i in d.values():
  ans*=i+1
print(ans%1000000007)
x = raw_input()
print int(x**3)

### FIXED CODE ###

x = raw_input()
print int(x)**3
class Node:
    def __init__(self, i):
        self.index = i
        self.val = -1
        self.nodes = []
        self.link = 0

    def __lt__(self, other):
        # self < other
        return self.link < other.link

def width_search(node):
    if node.val == -1:
        node.val = c.pop(0)
        for child in sorted(node.nodes):
            width_search(child)

N = int(input())

nodes = [Node(i) for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    node_a = nodes[a-1]
    node_b = nodes[b-1]
    if node_a not in node_b.nodes:
        node_b.nodes.append(node_a)
        node_b.link += 1
    if node_b not in node_a.nodes:
        node_a.nodes.append(node_b)
        node_a.link += 1

c = list(map(int, input().split()))
c = sorted(c, reverse=True)

max_c = 0
sum_c = 0
for tmp in c:
    sum_c += tmp
    max_c = max(max_c, tmp)

width_search(max(nodes))

print(sum_c - max_c)
for i in range(N-1):
    print(nodes[i].val, end=" ")
print(nodes[-1].val)


### FIXED CODE ###

from collections import deque

class Node:
    def __init__(self):
        self.val = -1
        self.link = []

def main():
    N = int(input())
    nodes = [Node() for i in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1; b -= 1;
        nodes[a].link.append(nodes[b])
        nodes[b].link.append(nodes[a])
    c = list(map(int, input().split()))
    c = sorted(c, reverse=True)
    count = 0
    q = deque()
    q.append(nodes[0])
    while len(q) > 0:
        node = q.popleft()
        node.val = c[count]
        count += 1
        for next in node.link:
            if next.val == -1:
                q.append(next)
    print(sum(c) - c[0])
    for i in range(N):
        print(nodes[i].val, end="")
        if i != N-1:
            print(" ",end="")
        else:
            print()

if __name__ == "__main__":
    main()
,B,C = map(int,input().split())

List_one = [0]*B
List_one = list(map(int,input().split()))

List_one.append(C)
#LIst_one = List_one + [C]
#print (List_one)

List_one.sort()# List_two=List_one.sort()としたらNoneを返してしまう。
#print(List_one)

x = List_one.index(C)

if x>=B-x:
    print(B-x)
else:
    print(x)


### FIXED CODE ###

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

List_one = [0]*B
List_one = list(map(int,input().split()))

List_one.append(C)
#LIst_one = List_one + [C]
#print (List_one)

List_one.sort()# List_two=List_one.sort()としたらNoneを返してしまう。
#print(List_one)

x = List_one.index(C)

if x>=B-x:
    print(B-x)
else:
    print(x)
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m,q = list(map(int, input().split()))
s = [None]*n
for i in range(n):
    s[i] = list(map(int, input()))
e1 = [[0]*(m) for _ in range(n-1)]
e2 = [[0]*(m-1) for _ in range(n)]
for i in range(n):
    for j in range(m):
        if i<n-1 and s[i][j]==s[i+1][j]==1:
            e1[i][j] = 1
        if j<m-1 and s[i][j]==s[i][j+1]==1:
            e2[i][j] = 1
def cumsum2(v):
    # v: h*wの2次元リスト
    h,w = len(v), len(v[0])
    ans = [[0]*(w+1) for _ in range(h+1)]
    for i in range(1,h+1):
        for j in range(1,w+1):
            ans[i][j] = ans[i-1][j] + ans[i][j-1] - ans[i-1][j-1] + v[i-1][j-1]
    return ans
s = cumsum2(s)
e1 = cumsum2(e1)
e2 = cumsum2(e2)
ans = [None]*q
for i in range(q):
    x1,y1,x2,y2 = map(lambda x: int(x)-1, input().split())
    val = s[x2+1][y2+1] - s[x1][y2+1] - s[x2+1][y1] + s[x1][y1]
    val2 = e1[x2][y2+1] - e1[x2][y1] - e1[x1][y2+1] + e1[x1][y1]
    val3 = e2[x2+1][y2] - e2[x2+1][y1] - e2[x1][y2] + e2[x1][y1]
    ans[i] = val - (val2+val3)
write("\n".join(map(str, ans)))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m,q = list(map(int, input().split()))
s = [None]*n
for i in range(n):
    s[i] = list(map(int, input()))
e1 = [[0]*(m) for _ in range(n-1)]
e2 = [[0]*(m-1) for _ in range(n)]
for i in range(n):
    for j in range(m):
        if i<n-1 and s[i][j]==s[i+1][j]==1:
            e1[i][j] = 1
        if j<m-1 and s[i][j]==s[i][j+1]==1:
            e2[i][j] = 1
def cumsum2(v):
    # v: h*wの2次元リスト
    h,w = len(v), len(v[0])
    v.insert(0, [0]*w)
    for l in v:
        l.insert(0, 0)
    for i in range(1,h+1):
        for j in range(1,w+1):
            v[i][j] = v[i-1][j] + v[i][j-1] - v[i-1][j-1] + v[i][j]
    return v
s = cumsum2(s)
if e1:
    e1 = cumsum2(e1)
if e2:
    e2 = cumsum2(e2)
ans = [None]*q
for i in range(q):
    x1,y1,x2,y2 = map(lambda x: int(x)-1, input().split())
    val = s[x2+1][y2+1] - s[x1][y2+1] - s[x2+1][y1] + s[x1][y1]
    if e1:
        val2 = e1[x2][y2+1] - e1[x2][y1] - e1[x1][y2+1] + e1[x1][y1]
    else:
        val2 = 0
    if e2:
        val3 = e2[x2+1][y2] - e2[x2+1][y1] - e2[x1][y2] + e2[x1][y1]
    else:
        val3 = 0
    ans[i] = val - (val2+val3)
write("\n".join(map(str, ans)))
n = int(input())
ab = [[int(item) for item in input().split()] for _ in range(n-1)]
c = [int(item) for item in input().split()]
c.sort()
c.reverse()
sum_score = sum(c[1:])

edge = [[] for _ in range(n)]
score = [0] * n

for a, b in ab:
    a-=1; b-=1
    edge[a].append(b)
    edge[b].append(a)

it = 0
def dfs(f ,n):
    global it
    score[n] = c[it]
    it += 1
    for item in edge[n]:
        if item == f:
            continue
        dfs(n, item)
    return True

dfs(-1, 0)
print(sum_score)
print(" ".join([str(item) for item in score]))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

n = int(input())
ab = [[int(item) for item in input().split()] for _ in range(n-1)]
c = [int(item) for item in input().split()]
c.sort()
c.reverse()
sum_score = sum(c[1:])

edge = [[] for _ in range(n)]
score = [0] * n

for a, b in ab:
    a-=1; b-=1
    edge[a].append(b)
    edge[b].append(a)

it = 0
def dfs(f ,n):
    global it
    score[n] = c[it]
    it += 1
    for item in edge[n]:
        if item == f:
            continue
        dfs(n, item)
    return True

dfs(-1, 0)
print(sum_score)
print(" ".join([str(item) for item in score]))
N,A = input().split()

if (N / 500) >=1  and (N % 500) >= A:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

N = int(input())
A = int(input())

if N%500 <= A:
  print("Yes")
else:
  print("No")
X = int(input())

sum = 0
for i in range(1, N):
    sum += i
    if sum >= X:
        break

print(i)

### FIXED CODE ###

X = int(input())

sum = 0
for i in range(1, 10**9+1):
    sum += i
    if sum >= X:
        break

print(i)
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2

while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0
try:
    for q in range(n-1,-1,-1):

        while p<n and a[q]+a[p]<=md:
            p+=1

        if p==n: break
        cnt+=n-p
        ans+=a[q]*(n-p)*2

except IndexError:
    b=1
    while True:
        b+=1

ans+=(m-cnt)*md
print(ans)


### FIXED CODE ###

import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2
md=(r+l)//2
while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
    except:
        b=1
        while True:
            b+=1

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)
#prepare
L = []
Q = []

#input
W, H, N, = map(int,raw_input().split())
for i in range(N):
    L.append(map(int,raw_input().split()))
x1=0
x2=W
y1=0
y2=H

#calculate
Q = [row[2] for row in L]


for k in range(N):
    if Q[k] == 1:
        x1 = max(x1,L[k][0])
    elif Q[k] == 2:
        x2 = min(x2,L[k][0])
    elif Q[k] == 3:
        y1 = max(y1,L[k][1])
    elif Q[k] == 4:
        y2 = min(y2,L[k][1])

print(max(0,x2-x1) * max(0,y2-y1))

### FIXED CODE ###

W, H, N = map(int, input().split())
array = [list(map(int, input().split())) for i in range(N)]

xmin = 0
xmax = W
ymin = 0
ymax = H
for i in range(N):

    if array[i][2] == 1:
        xmin = max(xmin, array[i][0])
    elif array[i][2] == 2:
        xmax = min(xmax, array[i][0])
    elif array[i][2] == 3:
        ymin = max(ymin, array[i][1])
    elif array[i][2] == 4:
        ymax = min(ymax, array[i][1])
area = (xmax-xmin)*(ymax-ymin)
if area <= 0 or xmax < xmin or ymax < ymin:
    print(0)
else:
    print(area)
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
h = logging.FileHandler("logtest.log")
logger.addHandler(h)

N, Q = map(int, input().split())
s = input()

Query = []
for i in range(Q):
    Query.append(input().split())
logger.info("Query: {}".format(Query))

# left: 左に落ちるゴーレム
# right: 右に落ちるゴーレム
#  N-right-left: 生き残るゴーレム
left, right = 0, N - 1
logger.info("left: {}, right: {}".format(left, right))

# 二分探索
for ch, way in reversed(Query):
    if way == "L":
        if ch == s[left]:
            left += 1
        if right < N - 1 and ch == s[right + 1]:
            right = min(right + 1, N - 1)
    else:
        if left > 0 and ch == s[left - 1]:
            left = max(left - 1, 0)
        if ch == s[right]:
            right -= 1
print(max(0, right - left + 1))


### FIXED CODE ###

# N, Q = map(int, input().split())
import sys

input = sys.stdin.readline

N, Q = tuple(map(int, input().split()))
s = input()

Query = [input().split() for i in range(Q)]

left, right = 0, N - 1

for t, d in reversed(Query):
    if d == "L":
        if t == s[left]:
            left += 1
        if right < N - 1 and t == s[right + 1]:
            right = min(right + 1, N - 1)
    else:
        if left > 0 and t == s[left - 1]:
            left = max(left - 1, 0)
        if t == s[right]:
            right -= 1
print(max(right - left + 1, 0))
n = int(raw_input())
print(n ** 3)

### FIXED CODE ###

n = int(input())
print(n ** 3)
s = list(map(int, input().split()))
print(s[0].upper()+s[1].upper()+s[2].upper())

### FIXED CODE ###

s = list(input().split())
print(s[0][0].upper()+s[1][0].upper()+s[2][0].upper())
import collections

n = int(input())
s = [input() for i in range(n)]
w = ""

if n == 1:
    r = sorted(collections.Counter(s[0]))
    for k, v in r.items():
        w += k * r[k]
    print(w)
    exit()
a = collections.Counter(s[0])
b = collections.Counter(s[1])
res = a & b
if n <= 2:
    for k in sorted(res):
        w += k * res[k]
    print(w)
else:
    for i in s[2:]:
        res = res & collections.Counter(i)
    if not res:
        print("")
    for k in sorted(res):
        w += k * res[k]
    print(w)

### FIXED CODE ###

import collections

n = int(input())
s = [input() for i in range(n)]
w = ""
if n == 1:
    r = collections.Counter(s[0])
    for k in sorted(r):
        w += k * r[k]
    print(w)
    exit()
a = collections.Counter(s[0])
b = collections.Counter(s[1])
res = a & b
if n <= 2:
    for k in sorted(res):
        w += k * res[k]
    print(w)
else:
    for i in s[2:]:
        res = res & collections.Counter(i)
    if not res:
        print("")
    for k in sorted(res):
        w += k * res[k]
    print(w)
a,b,h=map(int, input().split())

N = (a+b)*h/2

print(N)


### FIXED CODE ###

a = int(input())
b = int(input())
h = int(input())
print((a+b)*h//2)
n = list(input())
if int(n[0]) == 7:
	print("Yes")
else:
	if int(n[1]) == 7:
    	print("Yes")
    else:
		if int(n[2]) == 7:
			print("Yes")
        else:
        print("No")
      

### FIXED CODE ###

n = list(input())
if int(n[0]) == 7:
    print("Yes")
else:
    if int(n[1]) == 7:
        print("Yes")
    else:
        if int(n[2]) == 7:
            print("Yes")
        else:
            print("No")
# 4 3
# 1 2
# 2 3
# 2 4
# 2 10
# 1 100
# 3 1

n, q = list(map(int, input().split(" ")))
a = []
b = []
for i in range(n-1):
    j, k = list(map(int, input().split(" ")))
    a.append(j)
    b.append(k)

p = []
x = []
for i in range(q):
    j, k = list(map(int, input().split(" ")))
    p.append(j)
    x.append(k)


class Node:
    def __init__(self, id):
        self.id = id
        self.counter = 0
        self.linked = []

    def add_node(self, node):
        self.linked.append(node)

    def add_count(self, count):
        self.counter += count
        for i in self.linked:
            i.add_count(count)

# make node
tree = []
for i in range(n):
    tree.append(Node(i))

for j, k in zip(a, b):
    tree[j-1].add_node(tree[k-1])

for j, k in zip(p, x):
    tree[j-1].add_count(k)

m = []
for i in tree:
    m.append(i.counter)

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



### FIXED CODE ###

n, q = list(map(int, input().split(" ")))
a = []
b = []
tree = []

class Node:
    def __init__(self, id):
        self.id = id
        self.counter = 0
        self.linked = []

    def add_node(self, node):
        self.linked.append(node)

    def add_count(self, count):
        self.counter += count

# make node
for i in range(n):
    tree.append(Node(i))

# add node
for i in range(n-1):
    j, k = list(map(int, input().split(" ")))
    tree[j-1].add_node(tree[k-1])

# add count
for i in range(q):
    j, k = list(map(int, input().split(" ")))
    tree[j-1].add_count(k)

# traverse
for i in tree:
    for j in i.linked:
        j.counter += i.counter

m = []
for i in tree:
    m.append(i.counter)

print(" ".join(map(str, m)))
import math
a, b = map(int, input().split())
print(math.gcd(a, b))

### FIXED CODE ###

import fractions as fr
a, b = map(int, input().split())
res = int(a*b / fr.gcd(a, b))
print(res)