Harryxun/stf_run huggingface dataset:
n, q = map(int, input().split())

edge = [[] for _ in range(n)]

counter = [0] * n

for _ in range(n-1):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

for _ in range(q):
    a, b = map(int, input().split())
    counter[a-1] += b

parent = 0
child = 1
while True:
    while len(edge[parent]) == 0:
        parent += 1
        if parent == n-1:
            break
    if parent == n-1:
        break
    child = edge[parent].pop(0)
    edge[child].pop(0)
    counter[child] += counter[parent]
    

for i in range(n):
    print(counter[i], end=" ")
print("")

### FIXED CODE ###


# n, q = map(int, input().split())

# edge = [[] for _ in range(n)]

# counter = [0] * n

# for _ in range(n-1):
#     a, b = map(int, input().split())
#     edge[a-1].append(b-1)
#     edge[b-1].append(a-1)

# for _ in range(q):
#     a, b = map(int, input().split())
#     counter[a-1] += b

# parent = [0]
# visited = []

# for i in parent:
#     visited.append(i)
#     for v in edge[i]:
#         if v in visited:
#             continue
#         parent.append(v)
#         counter[v] += counter[i]
        
# for i in range(n):
#     print(counter[i], end=" ")
# print("")

import sys
input = sys.stdin.readline
 
N, Q = [int(x) for x in input().split()]
 
edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
 
cost = [0] * N
for _ in range(Q):
    p, x = [int(x) for x in input().split()]
    cost[p - 1] += x
 
next = [0]
s_next = {0}
for i in next:
    for v in edge[i]:
        if v in s_next:
            continue
        s_next.add(v)
        next.append(v)
        cost[v] += cost[i]
 
print(" ".join(map(str, cost)))
n = int(input())
sn=0
for i in range(len(n)):
  sn += n[i]
print("Yes" if n%sn==0 else "No")

### FIXED CODE ###

n = input()
sn=0
for i in range(len(str(n))):
  sn += int(n[i])
print("Yes" if int(n)%sn==0 else "No")
# https://atcoder.jp/contests/abc065/tasks/abc065_b
# B - Trained?
n = int(input().split()[0])

index2number_dict = {}
number2index_dict = {}

for i in range(n):
    a_i = int(input().split()[0])
    index2number_dict[i+1] = a_i
    number2index_dict[a_i] = i+1

# ボタンが光っているときに押すと、
# 今のボタンの光が消える
# 次のボタンが光る
# ボタン2が光っている状態でやめたい
# print(index2number_dict)

start_number = 1
start_index = number2index_dict[start_number]
# print(start_number)
# print(start_index)

step = 0
lighting_number = start_number
lighting_index = start_index
status_list = str(lighting_number)
can_stop = False

while True:
    step += 1
    lighting_number = index2number_dict[lighting_number]
    
    if lighting_number == 2:
        can_stop = True
        break

    status_list += str(lighting_number)

    if len(status_list) % 2 == 0:
        half = len(status_list) // 2
        # print('status(full): {}'.format(status_list))
        # print('status(half): {}'.format(status_list[:half]))

        if status_list == status_list[:half] * 2:
            break

if not can_stop:
    step = -1

# print('===========')
# print(status_list)
print(step)


### FIXED CODE ###

# https://atcoder.jp/contests/abc065/tasks/abc065_b
# B - Trained?
n = int(input().split()[0])

index2number_dict = {}
number2index_dict = {}
button_list = []

for _ in range(n):
    number = int(input().split()[0])
    button_list.append(number)
    

# ボタンが光っているときに押すと、
# 今のボタンの光が消える
# 次のボタンが光る
# ボタン2が光っている状態でやめたい
# print(index2number_dict)

start_index = 1
# print(start_number)
# print(start_index)

step = 0
lighting_index = start_index # 1 - n
status_list = ''
can_stop = False

while True:
    status_list += str(lighting_index)

    lighting_number = button_list[lighting_index - 1]
    lighting_index = lighting_number  # 次のインデックス
    step += 1


    if lighting_index == 2:
        can_stop = True
        break

    if step >= len(button_list):
        break
    # print('i = {}, ai = {}'.format(lighting_index, lighting_number))
    

    # print('Next -> i = {}, a_i = {} '.format(lighting_index, lighting_number))
    

if not can_stop:
    step = -1

# print('===========')
# print(status_list)
print(step)
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))

dic = {}
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    tmp = l[i] + l[j]
    
    index2 = dic.get(tmp, -1)
    
    if index2 == -1
      index2 = bisect.bisect_left(l, tmp)
      dic[tmp] = index2
      
    index1 = dic.get(l[j], -1)
    if index1 == -1:
      index1 = bisect.bisect_left(l, l[j])
      dic[l[j]] = index1     
    
    if l[i] == l[j]:
      d = index2 - index1 - 2
    else:
      d = index2 - index1 - 1
    
    ans += max(d,0)
    
print(ans)

### FIXED CODE ###

import bisect as bs
n = int(input())
l = sorted(list(map(int,input().split())))

count = 0
for i in range(n):
  for j in range(i+1,n):
    index = bs.bisect_left(l,l[i]+l[j])
    count += index - j - 1
    
print(count)
n,k = map(int,input().split())
print(n%abs(n-k))

### FIXED CODE ###

n,k = map(int,input().split())
n %= k
print(min(n,abs(n-k)))
mod=10**9+7
s=input()

b=int(s.replace("?","0"))%13
if b<=5:
    cal=5-b
else:
    cal=18-b
d=[0 for _ in range(13)]
p=[[i*j%13 for i in range(10)] for j in range(13)]
rev=s[::-1]
num=rev.find("?")
if num==-1:
    if cal==0:
        print(1)
    else:
        print(0)
else:
    tmp=10**(i+num+1)%13
    for i in p[tmp]:
        d[i]+=1
    c=rev[num+1:]
    for i,v in enumerate(c):
        #print(i+num+1)
        if v=="?":
            tmp=10**i%13
            t_d=[0 for _ in range(13)]
            #print("i,tmp:",i+num+1,",",tmp)
            for k in range(0,13):
                for j in range(0,10):
                    t_d[(p[tmp][j]+k)%13]+=d[k]
                #print(t_d)
            #for j in range(13):
                #d[j]=t_d[j]
            d=t_d
            #print(t_d)
    #print(d)
    print(d[cal]%mod)
        



### FIXED CODE ###

#%%time
mod=10**9+7
s=input()


#p=[[i*j%13 for i in range(10)] for j in range(13)]
rev=reversed(s)
d=[0 for i in range(13)]
d[0]=1
keep=[0 for _ in range(13)]
mul=1
cal=0
for v in rev:
    #print(i+num+1)
    if v=="?":
        t_d=[0 for _ in range(13)]
        #print("i,tmp:",i+num+1,",",tmp)
        for k in range(0,13):
            for j in range(0,10):
                t_d[(mul*j+k)%13]+=d[k]
            t_d[k]%=mod
        d=t_d
    else:
        cal+=mul*int(v)%13
    mul*=10
    mul%=13
        #print(t_d)
cal%=13
if cal<=5:
    cal=5-cal
else:
    cal=18-cal
print(d[cal]%mod)
#print(d)
#h=d
#print([i%mod for i in h])
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q): l, r = map(int, input().split())
print(t[r-1] - t[l-1])

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
	t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
s=[]
for i in range(h):
    for j in range(w):
        if l[i][j]=='.':
            s.append([i,j])
def solve(s):
    v=[[0 for i in range(w)] for j in range(h)]       
    v[s[0]][s[1]]=1
    mc=0
    q=[[s,0]]
    while len(q):
        p=q.pop(0)
        x=p[0][0]
        y=p[0][1]
        c=p[1]
        k=[[0,1],[0,-1],[1,0],[-1,0]]
        for j in k:
            nx=x+j[0]
            ny=y+j[1]
            if 0<=nx<h and 0<=ny<w and l[nx][ny]=='.' and v[nx][ny]==0:
                v[nx][ny]=1
                q.append([[nx,ny],c+1])
                if mc<=c+1:
                    mc=c+1
                    # ms=[nx,ny]
    return mc
ans=
exit()

v=[[0 for i in range(w)] for j in range(h)]       
v[ms[0]][ms[1]]=1
ans=0
q=[[ms,0]]
while len(q):
    p=q.pop(0)
    x=p[0][0]
    y=p[0][1]
    c=p[1]
    k=[[0,1],[0,-1],[1,0],[-1,0]]
    for j in k:
        nx=x+j[0]
        ny=y+j[1]
        if 0<=nx<h and 0<=ny<w and l[nx][ny]=='.' and v[nx][ny]==0:
            v[nx][ny]=1
            q.append([[nx,ny],c+1])
            ans=max(ans,c+1)
                #ms=[nx,ny]
print(ans)


### FIXED CODE ###

h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
s=[]
for i in range(h):
    for j in range(w):
        if l[i][j]=='.':
            s.append([i,j])
def solve(s):
    v=[[0 for i in range(w)] for j in range(h)]       
    v[s[0]][s[1]]=1
    mc=0
    q=[[s,0]]
    while len(q):
        p=q.pop(0)
        x=p[0][0]
        y=p[0][1]
        c=p[1]
        k=[[0,1],[0,-1],[1,0],[-1,0]]
        for j in k:
            nx=x+j[0]
            ny=y+j[1]
            if 0<=nx<h and 0<=ny<w and l[nx][ny]=='.' and v[nx][ny]==0:
                v[nx][ny]=1
                q.append([[nx,ny],c+1])
                if mc<=c+1:
                    mc=c+1
                    # ms=[nx,ny]
    return mc 
ans=0
for i in s:
    ans=max(ans,solve(i))
print(ans)
exit()

v=[[0 for i in range(w)] for j in range(h)]       
v[ms[0]][ms[1]]=1
ans=0
q=[[ms,0]]
while len(q):
    p=q.pop(0)
    x=p[0][0]
    y=p[0][1]
    c=p[1]
    k=[[0,1],[0,-1],[1,0],[-1,0]]
    for j in k:
        nx=x+j[0]
        ny=y+j[1]
        if 0<=nx<h and 0<=ny<w and l[nx][ny]=='.' and v[nx][ny]==0:
            v[nx][ny]=1
            q.append([[nx,ny],c+1])
            ans=max(ans,c+1)
                #ms=[nx,ny]
print(ans)
import sys
sys.setrecursionlimit(10**10)
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)


def chouhoukei(count, ans, num):
    if count == 4:
        return ans
    else:
        if num >= N:
            return 0
        if A[num] == A[num + 1]:
            return chouhoukei(count + 2, ans * A[num], num + 2)
        else:
            return chouhoukei(count, ans, num + 2)


print(chouhoukei(0, 1, 0))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)


def chouhoukei(count, ans, num):
    if count == 4:
        return ans
    else:
        if num >= N - 1:
            return 0
        if A[num] == A[num + 1]:
            return chouhoukei(count + 2, ans * A[num], num + 2)
        else:
            return chouhoukei(count, ans, num + 1)


print(chouhoukei(0, 1, 0))
s = int(input())
w = int(input())
print("safe" if s > w else "unsafe")

### FIXED CODE ###

num = map(int,input().split())
a = []
for i in num:
    a.append(i)
if a[0]<a[1]:
    print('unsafe')
elif a[0]>a[1]:
    print('safe')
else:
    print('unsafe')
# -*- coding: utf-8 -*-
import numpy as np

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

a = np.array(list(map(int, input().split())))
for i in range(n[0] - 1):
    a = np.vstack((a, list(map(int, input().split()))))

b = np.array(list(map(int, input().split())))
for i in range(n[1] - 1):
    b = np.vstack((b, list(map(int, input().split()))))

ab_sum = np.dot(a, b)
for i in range(n[0]):
    print('{0}'.format(int(ab_sum[i])))



### FIXED CODE ###

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

for i in range(n[0]):
    a.append(list(map(int, input().split())))

for i in range(n[1]):
    b.append(int(input()))

for i in range(n[0]):
    ab_sum = 0
    for j in range(n[1]):
        ab_sum += a[i][j] * b[j]
    print(ab_sum)
N, Q = map(int, input().split())
child_per = {1:0}
for i in range(N-1):
  a, b = map(int, input().split())
  child_per[b] = a
  
c = [0] * (N+1)
for i in range(Q):
  p, x = map(int, input().split())
  c[p] += x

for i in range(1, N+1):
  c[i] += c[child_per[i]]
  print(c[i], '', end='')

### FIXED CODE ###

from collections import deque

def main():
  N, Q = map(int, input().split())
  visited = [False] * (N+1)
  graph = {i:deque() for i in range(N+1)}

  for i in range(N-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

  visited[1] = True

  c = [0] * (N+1)
  for i in range(Q):
    p, x = map(int, input().split())
    c[p] += x
    
  q = [1]
  while q:
    per = q.pop()
    for child in graph[per]:
      if not visited[child]:
        visited[child] = True
        c[child] += c[per]
        q.append(child)

  for i in range(1, N+1):
    print(c[i], '', end='')

if __name__ == '__main__':
  main()
N = int(input())
A_list = list(map(int,input().split()))
A_list.sort(reverse = True)
indx_list = []
for i in range(1,100000,2):
    indx_list.append(i)
insx_list = []
for j in range(0,20):
    insx_list.extend(indx_list[:2 ** j])
mx_cmfrt = 0
reached_list = [A_list[0],A_list[0]]
for j in range(1, len(A_list)):
    cmfrt = min(reached_list[insx_list[j-1]-1],reached_list[insx_list[j-1]])
    reached_list.insert(insx_list[j-1], A_list[j])
    mx_cmfrt += cmfrt
print(mx_cmfrt)

### FIXED CODE ###

N = int(input())
M = 10000 - N
M = str(M)
M = M[-3:]
M = int(M)
print(M)
class dllist:

    def __init__(self):
        self._list = []
        self._fp = 0
        self._bp = 0

    def insert(self, x):
        self._list.append(x)
        self._fp += 1

    def delete(self, x):
        t = self._list[::-1]
        if x in t[:-self._bp]:
            self._list.remove(x)
            self._fp -= 1

    def deleteFirst(self):
        self._list.pop()

    def deleteLast(self):
        self._bp += 1

    def disp(self):
        print(" ".join([str(x) for x in self._list[self._bp:][::-1]]))


if __name__ == '__main__':

    q = dllist()

    n = int(input())

    for _ in range(n):
        inst = input().split()

        if inst[0] == "insert":
            q.insert(int(inst[1]))
        elif inst[0] == "delete":
            q.delete(int(inst[1]))
        elif inst[0] == "deleteFirst":
            q.deleteFirst()
        elif inst[0] == "deleteLast":
            q.deleteLast()

    q.disp()


### FIXED CODE ###

def check(aline):
    pools = []
    leftedge = []

    for i, c in enumerate(aline):
        if c == "\\":
            leftedge.append(i)
        elif c == "_":
            pass
        else:
            if leftedge:
                left = leftedge.pop()
                w = i - left

                while pools and left < pools[-1][0]:
                    w += pools.pop()[1]

                pools.append((left, w))

    return pools


if __name__ == '__main__':

    al = input().strip()
    ps = check(al)

    print(sum([x[1] for x in ps]))
    print(len(ps), *[x[1] for x in ps])
n = int(input())
a = list(map(int, input().split()))
ma = [None]*n
ma[0] = 1
for i in range(n-1):
    ma[i+1] = (ma[i]-a[i])*2
node = a[-1]
ans = node
for i in range(n-1, -1, -1):
    mi = (node+1)//2
    if ma[i]-a[i]<mi:
        print(-1)
        exit()
    node = min(ma[i]-a[i], node) + a[i]
    ans += node
print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
if n==0:
    if a[0]==1:
        print(1)
    else:
        print(-1)
    exit()
ma = [None]*n
ma[0] = 1
for i in range(n-1):
    ma[i+1] = (ma[i]-a[i])*2
node = a[-1]
ans = node
for i in range(n-1, -1, -1):
    mi = (node+1)//2
    if ma[i]-a[i]<mi:
        print(-1)
        exit()
    node = min(ma[i]-a[i], node) + a[i]
    ans += node
print(ans)
n,k=map(int,input())
ans='NO'
if k<=(n+1)//2:
  ans='YES'
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
ans='NO'
if k<=(n+1)//2:
  ans='YES'
print(ans)
import math
n = int(input())
lst = list(map(int,input().split()))

l = lst[0]
g = lst[0]
pair_coprime = True
set_coprime = False
for i in range(1,n):
  if set_coprime == False:
    g = math.gcd(g,lst[i])
    if g == 1:
      set_coprime = True
      
  if pair_coprime == True:
    g_l = math.gcd(l,lst[i])
    if g_l == 1:
      l = l*lst[i]//g_l
    else:
      pair_coprime = False
    
if set_coprime == False:
  print('not coprime')
  
elif pair_coprime == False:
  print('setwize coprime')
else:
  print('pairwize coprime')
  

### FIXED CODE ###

d,t,s = map(int,input().split())
if d/s <= t:
  print('Yes')
else:
  print('No')
n = [int(input()) for i in range(5)]
for i in range(n):
  if n[i] - n[i+1] > 0:
    print("Yay!")
  else:
    print(":(")

### FIXED CODE ###

n = [int(input()) for i in range(6)]
if max(n[0], n[1], n[2], n[3], n[4]) - min(n[0], n[1], n[2], n[3], n[4]) <= n[5]:
  print("Yay!")  
else:
  print(":(")
def main():
    N, Q = map(int, input().split())
    AB = [list(map(int,input().split())) for _ in range(N-1)]
    roots = {}
    for root,leaf in AB:
        roots[leaf] = root

    ans = [0 for _ in range(N)]
    for _ in range(Q):
        p,x = map(int, input().split())
        ans[int(p)-1] += int(x)
    # print(ans)
    for i in range(1,N):
        ans[i] += ans[roots[i+1]-1]
    print(*ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**6)
N, Q = map(int, input().split())
tree = [[] for _ in range(N)]
ans = [0] * N

def dfs(v, p):
    for u in tree[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

def main():

    for _ in range(N-1):
        a, b = map(int,input().split())
        a -= 1
        b -= 1
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(Q):
        p,x = map(int, input().split())
        ans[p-1] += x
    # print(ans)

    dfs(0, -1)
    print(*ans)

if __name__ == "__main__":
    main()
n,k=int(input().split())
l=list(map(int,input().split()))
l1 = sorted(l, reverse=True)
s=0
for i in range(k):
    s+=l1[i]
print(s)

### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
l1 = sorted(l, reverse=True)
s=0
for i in range(k):
    s+=l1[i]
print(s)
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]

w = sum(A)

r = N-w

if r<0:
  print(-1)
else:
  print(r)

### FIXED CODE ###

N, M = map(int,input().split()) 
A = list(map(int,input().split()))

w = sum(A)

r = N-w

if r<0:
  print(-1)
else:
  print(r)
res = 0
a_sort = sorted(a)

for i in range(n):
    if a_sort[i] != a[i]:
        res += 1

if res > 2:
    print("NO")
else:
    print("YES")


### FIXED CODE ###

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

cnt = 0
for i in range(N):
    if i + 1 == p[i]:
        cnt += 1

if cnt >= N - 2:
    print("YES")
else:
    print("NO")
n, k = map(int, input().split())
A = list(map(int, input().split()))
L = [1]
def f(L):
    if A[L[-1]-1] not in L:
        L.append(A[L[-1]-1])
        return f(L)
    else:
        return L
P = f(L)
a = A[P[-1]-1]
j = P.index(a)
r = len(P)
l = r - j
if k <= j:
  print(P[k])
else:
  print(P[j + (k-j)%l])
  


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n, k = map(int, input().split())
A = list(map(int, input().split()))
L = [1]
S = {1}

def f(L, S):
    last = L[-1]-1
    if A[last] not in S:
        L.append(A[last])
        S |= {A[last]}
        return f(L, S)
    else:
        return L
P = f(L, S)
a = A[P[-1]-1]
j = P.index(a)
r = len(P)
l = r - j

if k+1 <= j:
    print(P[k])
else:
    print(P[j+(k-j)%l])
class Graph:
    def __init__(self,n,side):
        self.side = side
        self.neighbor = [set() for i in range(n+1)]
        self.visited = [False]*(n+1)
        self.product()
        self.group =[0]*n
    def product(self):
        for a,b in self.side:
            self.neighbor[a].add(b)
            self.neighbor[b].add(a)
    def dfs(self,x,a):
        self.group[a] += 1
        self.visited[x] = True
        for i in self.neighbor[x]:
            if self.visited[i]:continue
            self.dfs(i,a)
    def all_dfs(self):
        a = 0
        for i in range(1,n+1):
            if not self.visited[i]:
                self.dfs(i,a)
                a += 1

n,m = map(int,input().split())
side = list(tuple(map(int,input().split()))for i in range(m))
graph1 = Graph(n,side)
graph1.all_dfs()
print(max(graph1.group))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)

class Graph:
    def __init__(self,n,side):
        self.side = side
        self.neighbor = [set() for i in range(n+1)]
        self.visited = [False]*(n+1)
        self.group =[0]*n
        self.product()
    def product(self):
        for a,b in self.side:
            self.neighbor[a].add(b)
            self.neighbor[b].add(a)
    def dfs(self,x,a):
        self.group[a] += 1
        self.visited[x] = True
        for i in self.neighbor[x]:
            if self.visited[i]:continue
            self.dfs(i,a)
    def all_dfs(self):
        a = 0
        for i in range(1,n+1):
            if not self.visited[i]:
                self.dfs(i,a)
                a += 1

n,m = map(int,input().split())
side = list(tuple(map(int,input().split()))for i in range(m))
graph1 = Graph(n,side)
graph1.all_dfs()
print(max(graph1.group))
import numpy as np
import math

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

ans = 0
for n in range(1,N+1):
    p = np.log2(K/n)
    p = math.ceil(p)
    
    if p < 0:
        p=0
    
    ans_temp = (1/N)*(1/2)**p
    ans+=ans_temp
    
print(ans)

### FIXED CODE ###

import numpy as np
import math
 
N,K=list(map(int,input().split()))
 
ans = 0
for n in range(1,N+1):
    p = np.log2(K/n)
    p = math.ceil(p)
    
    if p < 0:
        p=0
    
    ans_temp = (1/N)*(1/2)**p
    ans+=ans_temp
    
print(ans)
# coding: utf-8

odd = raw_input()
even = raw_input()

res = ""
for (o, e) in zip(odd, even):
    res = res + o + e

print res if len(odd) - len(even) == 0 else res + odd[-1]


### FIXED CODE ###

o, e = input(), input() + " "
for x, y in zip(o, e):
  print(x + y, end="")
from scipy.special import comb

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

print(comb(n, 2, exact=True) + comb(m, 2, exact=True))


### FIXED CODE ###

from math import factorial

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

if n > 2 and m > 2:
    print(
        factorial(n) // (factorial(n - 2) * factorial(2))
        + factorial(m) // (factorial(m - 2) * factorial(2))
    )
elif n < 2 and m < 2:
    print(0)
elif n < 2:
    print(factorial(m) // (factorial(m - 2) * factorial(2)))
elif m < 2:
    print(factorial(n) // (factorial(n - 2) * factorial(2)))
# coding: utf-8
# Your code here!
N, K = map(int,input().split())

link = [[] for i in range(N)]
link[0] = [i for i in range(1,N)]
for i in range(1,N):
    link[i].append(0)
    
from scipy.special import comb
if N == 2 and K == 0:
    print(1)
    print("1 2")
elif N == 2 and K == 1:
    print(-1)
elif comb(N-1,2) < K:
    print(-1)
else:
    maxnum = comb(N-1,2)
    for i in range(1,N):
        for j in range(1,N):
            if i < j:
                if maxnum != K:
                    link[i].append(j)
                    link[j].append(i)
                    maxnum -= 1
                else:
                    continue
    print(sum([len(l) for l in link])//2)
    for i in range(N):
        for j in link[i]:
            if i < j:
                print(i+1, j+1)

                
        
    


### FIXED CODE ###

# coding: utf-8
# Your code here!
N, K = map(int,input().split())

link = [[] for i in range(N)]
link[0] = [i for i in range(1,N)]
for i in range(1,N):
    link[i].append(0)

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if N == 2 and K == 0:
    print(1)
    print("1 2")
elif N == 2 and K == 1:
    print(-1)
elif comb(N-1,2) < K:
    print(-1)
else:
    maxnum = comb(N-1,2)
    for i in range(1,N):
        for j in range(1,N):
            if i < j:
                if maxnum != K:
                    link[i].append(j)
                    link[j].append(i)
                    maxnum -= 1
                else:
                    continue
    print(sum([len(l) for l in link])//2)
    for i in range(N):
        for j in link[i]:
            if i < j:
                print(i+1, j+1)