Harryxun/stf_run huggingface dataset:
r = int(input())
g = int(input())

print(r+2g)

### FIXED CODE ###

r = int(input())
g = int(input())

print(2*g-r)
t=input()
s=[0]*len(t)
for i in range(len(t)):
  
  if t[i]=='?':
    if i==0:
      if t[i+1]=='D':s[i]='P'
      else:s[i]='D'
      
    if i==len(t)-1:s[i]='D'
    
    if t[i-1]=='P':s[i]='D'
    elif t[i+1]=='P':s[i]='D'
    else:s[i]='P'
  else:s[i]=t[i]
print(''.join(s))

### FIXED CODE ###

t=input()
s=[0]*len(t)

for i in range(len(t)):
  
    if t[i]=='?':
        if i==0:
            if len(t)>=2:
                if t[i+1]=='D':
                    s[i]='P'
                else:
                    s[i]='D'
            else:s[i]='D'
      
      
        elif i==len(t)-1:
            s[i]='D'
        
    
        else:
            if s[i-1]=='P':s[i]='D'
            elif t[i+1]=='P':s[i]='D'
            else:s[i]='P'

    elif t[i]=='D' or t[i]=='P':s[i]=t[i]
    else:continue
#print(s)
print(''.join(s))
H, W = map(int, input().spilit())

hal = [H//3, H//3+1]

ans = float("inf")

for ha in hal:
    Sa = ha * W
    
    ## 横に分割
    hb = (H - ha)//2
    hc = H - ha - hb
    Sb = hb * W
    Sc = hc * W
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
    
    ## 縦に分割
    wb = W//2
    wc = W - wb
    Sb = (H - ha) * wb
    Sc = (H - ha) * wc
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))

wal = [W//3, W//3+1]

for wa in wal:
    Sa = H * wa
    
    ## 横に分割
    hb = H//2
    hc = H - hb
    Sb = hb * (W - wa)
    Sc = hc * (W - wb)
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
    
    ## 縦に分割
    wb = (W - wa)//2
    wc = W - wa - wb
    Sb = H * wb
    Sc = H * wc
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))

print(ans)


### FIXED CODE ###


H, W = map(int, input().split())

ans = min(H, W)

for h in range(H // 3, H // 3 + 3):
    w = W // 2
    s1 = h*W
    s2 = (H-h)*w
    s3 = (H-h)*(W-w)
    ans = min(ans, max(s1,s2,s3) - min(s1,s2,s3))

for w in range(W // 3, W // 3 + 3):
    h = H // 2
    s1 = w*H
    s2 = (W-w)*h
    s3 = (W-w)*(H-h)
    ans = min(ans, max(s1,s2,s3) - min(s1,s2,s3))
    
if H % 3 == 0 or W % 3 == 0:
    ans = 0
    
print(ans)
N,M = map(int,input().split())
ab =[list(map(int,input().split())) for i in range(M)]
dist = [INF]*(N)
for i in range(M):
    if ab[i][0] == 1:
        dist[ab[i][1]-1] = 1
for i in range(M):
    if ab[i][1] == N:
        if dist[ab[i][0]-1] <= 1:
            print("POSSIBLE")
            exit()
        else:
            continue
print("IMPOSSIBLE")

### FIXED CODE ###

INF = float("inf")


N,M = map(int,input().split())
ab =[list(map(int,input().split())) for i in range(M)]
dist = [INF]*(N)
for i in range(M):
    if ab[i][0] == 1:
        dist[ab[i][1]-1] = 1
for i in range(M):
    if ab[i][1] == N:
        if dist[ab[i][0]-1] <= 1:
            print("POSSIBLE")
            exit()
        else:
            continue
print("IMPOSSIBLE")
h,w=map(int,input().split())

A=[]
for i in range(h):
    A.append(list(map(int,input().split())))

C=[]
ha=0
s=1
a=0
b=0
for i in range(h*w):
    if A[a][b]%2==1 :
        ha=(ha+1)%2
    if ha==1:
        if b+s<w and b+s>=0 :
            C.append([a,b,a,b+s])
        elif a<h :
            C.append([a,b,a+1,b])
    if ha==0 :
        aa=len(C)

    if b+s<w and b+s>=0 :
        b+=s
    else:
        a+=1
        s = -s

        
print(aa)

for i in range(aa):
    print(str(C[i][0]+1)+" "+str(C[i][1]+1)+" "+str(C[i][2]+1)+" "+str(C[i][3]+1))

    
    


### FIXED CODE ###

h,w=map(int,input().split())

A=[]
for i in range(h):
    A.append(list(map(int,input().split())))

if h==1 and w==1 :
    print(0)
else:


    aa=0
    C=[]
    ha=0
    s=1
    a=0
    b=0
    for i in range(h*w):
        if A[a][b]%2==1 :
            ha=(ha+1)%2
        if ha==1:
            if b+s<w and b+s>=0 :
                C.append([a,b,a,b+s])
            elif a<h :
                C.append([a,b,a+1,b])
        if ha==0 :
            aa=len(C)

        if b+s<w and b+s>=0 :
            b+=s
        else:
            a+=1
            s = -s

            
    print(aa)

    for i in range(aa):
        print(str(C[i][0]+1)+" "+str(C[i][1]+1)+" "+str(C[i][2]+1)+" "+str(C[i][3]+1))
H=int(input())

H_list=[]
while H > 1:
    if H % 2 != 0:
        H=H-1
    H_list.append(H)
        
    H = H//2
    
H_list.sort()

ans_list=[]
for h in H_list:
    if h == 2:
        ans = 3
    else :
        ans = 2*ans+1
    ans_list.append(ans)
    
print(ans)

### FIXED CODE ###

H=int(input())

if H == 1:
  ans=1
  
H_list=[]
while H > 1:
    if H % 2 != 0:
        H=H-1
    H_list.append(H)
        
    H = H//2
    
H_list.sort()
 
ans_list=[]
for h in H_list:
    if h == 2:
        ans = 3
    else :
        ans = 2*ans+1
    ans_list.append(ans)
    
print(ans)
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    #print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    print(0)
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))


### FIXED CODE ###

s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[i]!=t[i] and s[i]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    #print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    #print(0)
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))
A, P = map(int, input().split())
print((3*A+P)//2)Ｖ

### FIXED CODE ###

A, P = map(int, input().split())
print((3*A+P)//2)
N = int(input())
ab = [list(map(int, input().split())) for _ in range(N-1)]
edge = [[] for _ in range(N)]
for a, b in ab:
    a, b = a-1, b-1
    edge[a].append(b)

next_list = []
now_list = [0]
colors = [0] * N
colors[0] = 1
color_list = set()
now_color = 2
while len(now_list) > 0:
    if not 1 in color_list:
        now_color = 1
    color_list = set()
    for v in now_list:
        for nextv in edge[v]:
            if v == nextv:
                continue
            colors[nextv] = now_color
            color_list.add(now_color)
            now_color += 1
            next_list.append(nextv)
    
    now_list = list(next_list)
    next_list = []
            
print('\n'.join(colors))

### FIXED CODE ###

class ColorMgmt:
    from heapq import heappop, heappush
    def __init__(self, n):
        self.colors_hash = [set() for _ in range(n)]
        self.next_colors = [1] * n
    
    def set_color(self, v, c):
        self.colors_hash[v].add(c)
        while self.next_colors[v] in self.colors_hash[v]:
            self.next_colors[v] += 1
    
    def get_color(self, v):
        return self.next_colors[v]


N = int(input())
ab = [list(map(int, input().split())) for _ in range(N-1)]
edge = [[] for _ in range(N)]
edge_cnt = [0] * N
for idx, (a, b) in enumerate(ab):
    a, b = a-1, b-1
    edge[a].append([b, a, 0, idx])
    edge_cnt[a] += 1
    edge_cnt[b] += 1
K = max(edge_cnt)

next_list = []
now_list = [0]
color_mgmt = ColorMgmt(N)
while len(now_list) > 0:
    for v in now_list:
        for idx, nextv in enumerate(edge[v]):
            if v == nextv[0]:
                continue
            colors1 = color_mgmt.get_color(nextv[1])
            colors2 = color_mgmt.get_color(nextv[0])
            color = max(colors1, colors2)
            color_mgmt.set_color(nextv[1], color)
            color_mgmt.set_color(nextv[0], color)
            edge[v][idx][2] = color
            next_list.append(nextv[0])
    
    now_list = list(next_list)
    next_list = []

ret = []
for edges in edge:
    for e in edges:
        ret.append(e)
ret.sort(key=lambda x:x[3])
print(K)
for r in ret:
    print(r[2])
import collections

n, q = map(int, input().split())
edge = collections.deque([tuple(map(int, input().split())) for _ in range(n - 1)])
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
flag = [False] * n
flag[0] = True
while len(edge) != 0:
    a, b = edge.popleft()
    a, b = a - 1, b - 1
    if flag[a] or flag[b]:
        edge.append((a, b))
        continue
    if flag[a]:
        tree[a].append(b)
    else:
        tree[b].append(b)

p = [0] * n
for x, y in query:
    p[x - 1] += y
counter = [0] * n

que = collections.deque([0])
while len(que) != 0:
    i = que.popleft()
    counter[i] += p[i]
    for j in tree[i]:
        counter[j] = counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

### FIXED CODE ###

import collections

n, q = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n - 1)]
counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p - 1] += x

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
s=list(map(int,list(input())))
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
def f(lrc):
  l1,r1,c1,x1=lrc[0]
  for l2,r2,c2,x2 in lrc[1:]:
    l1,r1=max(max(l1,l2)-min(r1,r2),0),r1+r2
    if r1%2!=l1%2:l1+=1
    c1+=c2
    x1+=x2
  return [l1,r1,c1,x1]
def dfs(root,node):
  lrcx=[]
  for mode in edge[node]:
    if root!=mode:
      lrcx.append(dfs(node,mode))
  if len(lrcx)==0:
    return [s[node]]*4
  l,r,c,x=f(lrcx)
  c+=s[node]
  return [l+c,r+c,c,x+c]
anss=[]
for i in range(n):
  l,r,c,x=dfs(-1,i)
  if l==c:
    anss.append(x-c)
if len(anss)==0:print(-1)
else:print(min(anss)//2)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
n=int(input())
s=list(map(int,list(input()[:-1])))
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
def f(lrc):
  l1,r1,c1,x1=lrc[0]
  for l2,r2,c2,x2 in lrc[1:]:
    l1,r1=max(max(l1,l2)-min(r1,r2),0),r1+r2
    if r1%2!=l1%2:l1+=1
    c1+=c2
    x1+=x2
  return [l1,r1,c1,x1]
def dfs(root,node):
  lrcx=[]
  for mode in edge[node]:
    if root!=mode:
      lrcx.append(dfs(node,mode))
  if len(lrcx)==0:
    return [s[node]]*4
  l,r,c,x=f(lrcx)
  c+=s[node]
  return [l+c,r+c,c,x+c]
anss=[]
for i in range(n):
  l,r,c,x=dfs(-1,i)
  if l==c:
    anss.append(x-c)
if len(anss)==0:print(-1)
else:print(min(anss)//2)
N,b,r = input().split()
if(b==0 and r == 0):
  print(0)
else :
  set = N/(b+r)
  surplus = N%(b+r)
  Numbe_of_Blue = set * b + b
  print(Numbe_of_Blue)


### FIXED CODE ###

N,b,r = map(int,input().split())
if(b == 0 and r == 0):
  print(0)
elif (b ==0):
  print(0)
else :
  sets = N//(b+r)
  surplus = N%(b+r)
  if(surplus - b > 0):
    residue = b
  elif(surplus - b < 0):
    residue = surplus  
  Number_of_Blue = sets * b + residue
  print(Number_of_Blue)
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

ans = 0

a = -(-N//K)
r = N%K
T2 = T + 'x'*r

li = []
for i in range(K):
    st = ''
    for j in range(a):
        c = T2[j*K + i]
        if st == '':
            st += c
        elif st[0] == c:
            st += c
        else:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S
            st = c
        if j == a-1:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S

print(ans)

### FIXED CODE ###

N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

ans = 0

a = -(-N//K)
r = N%K
T2 = T + 'x'*(K - r)

li = []
for i in range(K):
    st = ''
    for j in range(a):
        c = T2[j*K + i]
        if st == '':
            st += c
        elif st[0] == c:
            st += c
        else:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S
            st = c
        if j == a-1:
            li.append(st)
            if st[0] == 'r':
                ans += -(-len(st)//2)*P
            elif st[0] == 's':
                ans += -(-len(st)//2)*R
            elif st[0] == 'p':
                ans += -(-len(st)//2)*S

print(ans)
import math
N,K = map(int,input().split())
P=list(map(int,input().split()))


maxnum=0
index=0
num=0
for i in range(len(P)):
    num+=P[i]
    if maxnum<num:
        maxnum=num
        index=i




    if i>=K-1:
        num-=P[i-(K-1)]


List=[]
for i in range(K):
    x1=P[index-i]
    sumx1=sum([j for j in range(1,x1+1)])


    sumx1=sumx1/x1
    List.append(sumx1)


print(sum(List))


### FIXED CODE ###

import math
N,K = map(int,input().split())
P=list(map(int,input().split()))


maxnum=0
index=0
num=0
for i in range(len(P)):
    num+=P[i]
    if maxnum<num:
        maxnum=num
        index=i




    if i>=K-1:
        num-=P[i-(K-1)]


List=[]
for i in range(K):
    x1=P[index-i]

    sumx1=(1+x1)/2
    List.append(sumx1)


print(sum(List))
x, y = input(), input()
if x < y: print('<')
if x == y: print('=')
if x > y: print('>')

### FIXED CODE ###

x, y = input().split()
if x < y: print('<')
if x == y: print('=')
if x > y: print('>')
cards = [[False] * 14 for i in range(4)]
n = int(input())
for i in range(n):
    suit, rank = input().split()
    r = int(rank)
    if suit == "S":
        s == 0
    elif suit == "H":
        s == 1
    elif suit == "C":
        s == 2
    else:
        s == 3
    cards[s][r] = True

name = ["S", "H", "C", "D"]
for s in range(4):
    for r in range(1, 14):
        if cards[s][r]:
            print(name[s], r)

### FIXED CODE ###

cards = [[False] * 14 for i in range(4)]
n = int(input())
for i in range(n):
    suit, rank = input().split()
    r = int(rank)
    if suit == "S":
        s = 0
    elif suit == "H":
        s = 1
    elif suit == "C":
        s = 2
    else:
        s = 3
    cards[s][r] = True

name = ["S", "H", "C", "D"]
for s in range(4):
    for r in range(1, 14):
        if not cards[s][r]:
            print(name[s], r)
n = int( input())
a = list ( map( int, input().split()))

def swap(a,i,j):
  c = a[i]
  d = a[j]
  if a[i]>a[j]:
    a[j] = c
    a[i] = d
  return a

for i in range (int(n/2)+1):
  for j in range (i+1,n):
    swap(a,i,j)
    
print(a[int(n/2)+1]-a[int(n/2)])


  

### FIXED CODE ###

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

a.sort()
k = int(n/2)    
print(a[k]-a[k-1])
n, k = map(int, input().split())
s = str(input())

if s[0] == "1":
    s_first = 1
else:
    s_first = 0

S_count = []
t = 1
for i in range(n-1):
    if s[i] == s[i+1]:
        t += 1
    else:
        S_count.append(t)
        t = 1
S_count.append(t)

t = len(S_count)
ans_list = []
if n-2*k <= 0:
    print(len(s))
else:    
    if s_first == 1:
        for i in range(t-2*k):
            ans_list.append(sum(S_count[i:i+2*k+1]))
    else:
        for i in range(t-2*k):
            ans_list.append(sum(S_count[i:i+2*k]))
    print(S_count)
    print(ans_list)
    ans = max(ans_list)
    print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
s = input()

key = [0]
for i in range(1, n):
  if s[i] != s[i-1]:
    key.append(i)
key.append(n)

m, r = 0, len(key)-1
ans = 0
while True:
  if m == 0 and s[0] == "0":
    p = m+2*k
    if ans < key[min([p, r])] - key[m]:
      ans = key[min([p, r])] - key[m]
    m += 1
  else:
    p = m+2*k+1
    if ans < key[min([p, r])] - key[m]:
      ans = key[min([p, r])] - key[m]
    m += 2
  if p >= r:
    break

print(ans)
N,Q = map(int,input().split())
P = [1]*(N+1)
for i in range(N):
    a,b = map(int,input().split())
    P[b] = a
C = [0]*(N+1)
for i in range(Q):
    p,x = map(int,input().split())
    C[p] = x
for i in range(2,N):
    q = P[i]
    C[i] += C[q]
C.pop(0)
print(*C)


### FIXED CODE ###

N,Q = map(int,input().split())
G = [[]for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
C = [0]*(N)
for i in range(Q):
    p,x = map(int,input().split())
    C[p-1] += x
from collections import deque
d=deque()
d.append(0)
t = [False]*(N)
t[0] = True
while d:
    a = d.popleft()
    for b in G[a]:
        if not t[b]:
            t[b] = True
            d.append(b)
            C[b] += C[a]
print(*C)
n=int(input())
s=str(input().split())
p=int(input().split())
li=[]
for i in range(0,n):
  li.append((i+1,s[i],p[i]))

new_li=sorted(li,key=lambda x:x[1])

new2_li=sorted(new_li,key=lambda x:x[2] , reverse=True)

for j in range(0,n):
  print(new2_li[j][0])


### FIXED CODE ###

n=int(input())

li=[]

for i in range(0,n):
  s,p=input().split()
  p=int(p)
  li.append((i+1,s,p))


new_li=sorted(li,key=lambda x:x[2] , reverse=True)
new2_li=sorted(new_li,key=lambda x:x[1])


for j in range(0,n):
  print(new2_li[j][0])
import math
from collections import Counter
def f(a,b):
    return math.factorial(a) // (math.factorial(a - b) * math.factorial(b))

n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
c=Counter(v)
count=0
if a==1 or v[0]==v[a-1]:
    for i in range(a,min(b,c[v[0]])+1):
        count+=f(min(b,c[v[0]]),i)
    print(v[0])
    print(count)
else: 
    print(sum(v[:a])/a)
    print(f(c[v[a]],a-c[v[0]]))

### FIXED CODE ###

import math
def f(a,b):
    return math.factorial(a) // (math.factorial(a - b) * math.factorial(b))

n,a,b=map(int, input().split())
v=list(map(int, input().split()))
v.sort(reverse=True)
c=0
if v[0]==v[a-1]:
    for i in range(a,min(b,v.count(v[0]))+1):
        c+=f(v.count(v[a-1]),i)
    print(sum(v[:a])/a)
    print(c)
else: 
    print(sum(v[:a])/a)
    print(f(v.count(v[a-1]),v[:a].count(v[a-1])) )
# https://atcoder.jp/contests/abc138/tasks/abc138_d

from collections import deque
from collections import defaultdict
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, q = input_int_list()
    cnt = [0] * (n + 1)  # 1-indexed
    tree = defaultdict(list)

    for _ in range(n - 1):
        a, b = input_int_list()
        tree[a].append(b)
        tree[b].append(a)

    # 遅延評価をする
    for _ in range(q):
        p, x = input_int_list()
        cnt[p] += x

    # 遅延評価（DFS）
    def tree_walk(root, add):
        cnt[root] += add
        for node in tree[root]:
            if node not in visited:
                visited.add(node)
                tree_walk(node, cnt[root])

    visited = set([1])
    # ルート(1)から結果を評価する
    tree_walk(1, 0)

    print(*cnt[1:])
    return


if __name__ == "__main__":
    main()


### FIXED CODE ###

# https://atcoder.jp/contests/abc138/tasks/abc138_d

from collections import defaultdict
import sys
sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, q = input_int_list()
    cnt = [0] * (n + 1)  # 1-indexed
    tree = defaultdict(list)

    for _ in range(n - 1):
        a, b = input_int_list()
        tree[a].append(b)
        tree[b].append(a)

    # 遅延評価をする O(q)
    for _ in range(q):
        p, x = input_int_list()
        cnt[p] += x

    # 遅延評価（DFS）O(n)
    stack = [(1, 0)]
    visited = set([1])
    while stack:
        e, add = stack.pop()
        cnt[e] += add
        for node in tree[e]:
            if node not in visited:
                visited.add(node)
                stack.append((node, cnt[e]))

    print(" ".join([str(i) for i in cnt[1:]]))
    return


if __name__ == "__main__":
    main()
d = int(input())
if d = 25:
  print('Christmas')
elif d = 24:
  print('Christmas Eve')
elif d = 23:
  print('Christmas Eve Eve')
else d = 22:
  print('Christmas Eve Eve Eve')

### FIXED CODE ###

d = int(input())
if d == 25:
  print('Christmas')
elif d == 24:
  print('Christmas Eve')
elif d == 23:
  print('Christmas Eve Eve')
else:
  print('Christmas Eve Eve Eve')
n = list(map(int,input().split))
if n.count(5) = 2 and n.count(7) = 1:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

n = list(map (int, input().split()))
if n.count(int (5)) == 2 and n.count(int (7)) == 1:
  print("YES")
else:
  print("NO")
def dfs_v(u):
  color[u] = 1
  d[u] = ++t
  for v in range(n):
    if M[u][v] == 0 and color[v] == 0:
      dfs_v(v)
  color[u] = 2
  f[u] = ++t

def dfs():
  color[0 for i in range(n)]
  t = 0
  for u in range(n):
    dfs_v(u)
  for u in range(n):
    print "%d %d %d" %(u+1, d[u], f[u])

n = input()

M[0 for i in range(n)]0 for j in range(n)]

for i in range(n):
  u, k = map(int, raw_input().split())
  for j in range(n):
   v = input()
   M[u][v] = 1

dfs()
    

### FIXED CODE ###

n = int(raw_input())
 
d = [0 for i in range(n)]
f = [0 for i in range(n)]
G = [0 for i in range(n)]
M = [[0 for i in range(n)] for j in range(n)]
col = [0 for i in range(n)]
t = [0]
 
def DFS_visit(u):
    col[u] = 1
    t[0] += 1
    d[u] = t[0]
    for v in range(n):
        if M[u][v] == 1 and col[v] == 0:
            DFS_visit(v)
    col[u] = 2
    t[0] += 1
    f[u] = t[0]
 
def DFS():
    for u in range(n):
        if col[u] == 0:
            DFS_visit(u)
    for u in range(n):
        print'{0} {1} {2}'.format(u+1, d[u], f[u])
     
for i in range(n):
    X = map(int, raw_input().split())
    for j in range(X[1]):
        M[X[0]-1][X[2+j]-1] = 1
 
DFS()
import sys


def next_round(now, diff, N):
    if now + diff <= N:
        return now + diff
    else:
        return now + diff - N


def main():
    # N=10, M=4
    # 1 2
    # 3 5
    # 6 9
    # 10 4
    input = sys.stdin.buffer.readline
    N, M = map(int, input().split())
    unused = set(range(1, N + 1))
    diff = 1
    i = 1
    count = 0
    while count < M:
        left = i
        right = next_round(i, diff, N)
        unused.remove(left)
        unused.remove(right)
        print(left, right)
        count += 1
        diff += 1
        i = next_round(right, 1, N)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys


def main():
    input = sys.stdin.buffer.readline
    N, M = map(int, input().split())
    skip = (N // 2) // 2 + 1 if N % 2 == 0 else None
    count = 0
    left, right = 0, N + 1
    while count < M:
        left += 1
        if left == skip:
            continue
        right -= 1
        print(left, right)
        count += 1


if __name__ == '__main__':
    main()