Harryxun/stf_run huggingface dataset:
n, q = map(int, input().split(' '))
inf = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split(' '))
    inf[a-1].append(b-1)
    inf[b-1].append(a-1)
score = [0 for _ in range(n)]
visit = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split(' '))
    score[p-1] += x
def addp(num):
    if all(visit[x] == 1 for x in inf[num]):
        return 0
    visit[num] = 1
    for i in inf[num]:
        if visit[i] == 1:
            continue
        else:
            score[i] += score[num]
            addp(i)
    return 0
addp(0)
print(*score)

### FIXED CODE ###

def main():
    n, q = map(int, input().split(' '))
    import sys
    from collections import deque
    sys.setrecursionlimit(10**7)

    visit = [True for _ in range(n)]
    point = [0 for _ in range(n)]
    dic = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split(' '))
        dic[a-1].append(b-1)
        dic[b-1].append(a-1)
    for _ in range(q):
        p, x = map(int, input().split(' '))
        point[p-1] += x
    next_visit = deque()
    next_visit.append(0)
    visit[0] = False
    counter = 1
    while counter < n:
        t = next_visit.pop()
        for s in dic[t]:
            if visit[s]:
                point[s] += point[t]
                visit[s] = False
                counter += 1
                next_visit.append(s)
    print(*point)
if __name__ == '__main__':
    main()
n = int(input())
a = 9
for i in range(a+1):
  for j in range(a+1):
    if i*j == n:
      print('Yes')
      exit()
Print('No')

### FIXED CODE ###

n = int(input())
for i in range(9):
  for j in range(9):
    if (i+1)*(j+1) == n:
      print('Yes')
      exit()
print('No')
N,M=map(int,input().split())
a = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
j = 0
dp[0] = 1
mod = 10**9+7
for i in range(1, N+1):
    if i == a[j]:
        j += 1
        j = min(M-1, j)
    elif i == 1:
        dp[i] = 1
    else:
        dp[i] = (dp[i-1]+dp[i-2]) % mod
print(dp[N])

### FIXED CODE ###

N,M=map(int,input().split())
a = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
j = 0
dp[0] = 1
mod = 10**9+7
for i in range(1, N+1):
    if j < M and i == a[j]:
        j += 1
    elif i == 1:
        dp[i] = 1
    else:
        dp[i] = (dp[i-1]+dp[i-2]) % mod
print(dp[N])
from collections import Counter
N, K = map(int, raw_input().split())
C = sorted(Counter(raw_input()[0] for _ in xrange(N)).values())
a = C.pop()
b = sum(C)
for i in xrange(a, 0, -1):
    if b/i >= K-1:
        print i
        break
else:
    print 0

### FIXED CODE ###

N, A, B=map(int, raw_input().split())
print sum(not(A<=int(raw_input())<B) for _ in range(N))
import sys
param=input().split()
menseki=int(param[0])*int(param[1])
nagasa=int(param[0])*2+int(param[1])*2
print(menseki nagasa)

### FIXED CODE ###

import sys
param=input().split()
menseki=int(param[0])*int(param[1])
nagasa=int(param[0])*2+int(param[1])*2
print(menseki,nagasa)
n = int(input())
s = [list(map(int, input().split())) for i in range(n)]

for cx in range(101):
    for cy in range(101):
        flag_success = 0
        for _n in range(n):
            if s[_n][2] != 0:
                H = s[_n][2] + abs(s[_n][0] - cx) + abs(s[_n][1] - cy)
                if _n == 0:
                    H0 = H
                else:
                    if H != H0:
                        flag_success = 1 # miss break
            if _n == n-1:
                print(cx, cy, H)
                flag_success = 2 # sucess break

            if flag_success == 1 or flag_success == 2:
                break

        if flag_success == 2:
            break
    if flag_success == 2:
        break


### FIXED CODE ###

n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]

xyh.sort(key=lambda x:x[2], reverse=True)
for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        H = abs(x - cx) + abs(y - cy) + h
        f = True

        for i in range(1, n):
            x, y, h = xyh[i]
            h2 = max(0, H - abs(x - cx) - abs(y - cy))
            if h != h2:
                f = False
                break

        if f:
            ans = (cx, cy, H)

print(ans[0], ans[1], ans[2])
a=list(map(int,input().split()))
if n%2==0:
    b=sorted(a)
    i=0
    while i<len(b):
        if not (b[i]==b[i+1] or b[i+2]==b[i]+2):
            print(0)
            exit()
        i+=2
    print((2**(len(b)//2))%(10**9+7))
else:
    b=sorted(a)
    if len(b)>1:
        if b[1]==0:
            print(0)
            exit()
    if b[0]!=0:
        print(0)
        exit()
    else:
        i=1
        while i<len(b):
            if not (b[i]==b[i+1] or b[i+2]==b[i]+2):
                print(0)
                exit()
            i+=2
        print(2**(len(b)//2)%(10**9+7))



### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
if n%2==0:
    b=sorted(a)
    i=0
    while i<len(b):
        if not (b[i]==b[i+1] or b[i+2]==b[i]+2):
            print(0)
            exit()
        i+=2
    print((2**(len(b)//2))%(10**9+7))
else:
    b=sorted(a)
    if len(b)>1:
        if b[1]==0:
            print(0)
            exit()
    if b[0]!=0:
        print(0)
        exit()
    else:
        i=1
        while i<len(b):
            if not (b[i]==b[i+1] or b[i+2]==b[i]+2):
                print(0)
                exit()
            i+=2
        print(2**(len(b)//2)%(10**9+7))
import functools  # Python3 
N,M = map(int,input().split())
x, y, z = [0] * N, [0] * N, [0] * N
for i in range(N):
	x[i], y[i], z[i] = map(int,input().split())

# N, M = 5, 3
# x = [1, -4, 7, -10, 13]
# y = [-2, 5, -8, 11, -14]
# z = [3, -6, -9, -12, 15]
ppp = [ x[i]+y[i]+z[i] for i in range(N)]
pmp = [ x[i]-y[i]+z[i] for i in range(N)]
ppm = [ x[i]+y[i]-z[i] for i in range(N)]
pmm = [ x[i]-y[i]-z[i] for i in range(N)]
mpp = [-x[i]+y[i]+z[i] for i in range(N)]
mpm = [-x[i]+y[i]-z[i] for i in range(N)]
mmp = [-x[i]-y[i]+z[i] for i in range(N)]
mmm = [-x[i]-y[i]-z[i] for i in range(N)]

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	cur = functools.reduce(lambda x,y: x+y,filter(lambda t: t >= 0,lis))
	if cur > MAX:
		MAX = cur
print(MAX)


### FIXED CODE ###

import functools  # Python3 
N,M = map(int,input().split())
x, y, z = [0] * N, [0] * N, [0] * N
for i in range(N):
	x[i], y[i], z[i] = map(int,input().split())

if M==0:
	print(0)
	exit()

ppp = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]+z[i] for i in range(N)])[-M:])
pmp = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]+z[i] for i in range(N)])[-M:])
ppm = functools.reduce(lambda x,y: x+y,sorted([ x[i]+y[i]-z[i] for i in range(N)])[-M:])
pmm = functools.reduce(lambda x,y: x+y,sorted([ x[i]-y[i]-z[i] for i in range(N)])[-M:])
mpp = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]+z[i] for i in range(N)])[-M:])
mpm = functools.reduce(lambda x,y: x+y,sorted([-x[i]+y[i]-z[i] for i in range(N)])[-M:])
mmp = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]+z[i] for i in range(N)])[-M:])
mmm = functools.reduce(lambda x,y: x+y,sorted([-x[i]-y[i]-z[i] for i in range(N)])[-M:])

MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
	if lis  > MAX:
		MAX = lis
print(MAX)
n, m, c = map(int, input().split()
B = list(map(int, input().split()))
A = [list(map(int, input().split()))for i in range(n)]
cnt = 0
for i in range(n):
  total = 0
  for j in range(m):
    total += b[j] * a[i][j]
  total += c
  if total > 0:
    cnt += 1
print(cnt)


### FIXED CODE ###

n,m,c=map(int,input().split())
B=list(map(int,input().split()))
A=[list(map(int, input().split()))for i in range(n)]
cnt = 0
for i in range(n):
  total = 0
  for j in range(m):
    total += B[j] * A[i][j]
  total += c
  if total > 0:
    cnt += 1
print(cnt)
import math

# print('input >>')
D, G = map(int, (input().split()))
pc = []
for _ in range(D):
    p, c = map(int, (input().split()))
    pc.append((p, c))

point = 0
ans = []

def dfs(i, count, point):
    # Gまで到達したかどうか確かめる
    if point >= G:
        ans.append(count)
        return
    # 途中まで解いてGまで届くかどうか試す
    if point + (i + 1) * 100 * (pc[i][0] - 1) >= G:
        count += math.ceil((G - point) / ((i + 1) * 100))
        point += math.ceil((G - point) / ((i + 1) * 100)) * (i + 1) * 100
        ans.append(count)
    if i == 0:
        return
    # 完全に解く
    dfs(i-1, count+pc[i][0], point + (i+1)*100 * pc[i][0] + pc[i][1])
    # 完全に解かない
    dfs(i-1, count, point)

dfs(D-1,0,0)

# print('----------output----------')
print(min(ans))

### FIXED CODE ###

import math

# print('input >>')
D, G = map(int, (input().split()))
pc = []
for _ in range(D):
    p, c = map(int, (input().split()))
    pc.append((p, c))

point = 0
ans = []

def dfs(i, count, point):
    # Gまで到達したかどうか確かめる
    c_ = count
    if point >= G:
        ans.append(count)
        return
    # 途中まで解いてGまで届くかどうか試す
    if point + (i + 1) * 100 * (pc[i][0] - 1) >= G:
        count += math.ceil((G - point) / ((i + 1) * 100))
        ans.append(count)
    # 全部解いてGまで届くかどうか試す
    elif point + (i + 1) * 100 * pc[i][0] + pc[i][1] >= G:
        count += pc[i][0]
        ans.append(count)
    if i == 0:
        return
    # 完全に解く
    dfs(i-1, c_+pc[i][0], point + (i+1)*100 * pc[i][0] + pc[i][1])
    # 完全に解かない
    dfs(i-1, c_, point)

dfs(D-1,0,0)

# print('----------output----------')
print(min(ans))
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]"):
    a = sorted(A, reverse=True)
    bsum = 0
    p = []
    for day in range(M, -1, -1):

        rem = []

        for i, a_ in enumerate(a):
            if a_[0]==day:
                p.append(a_)
                rem.append(i)
            else:
                [a.pop(k) for k in rem] # 遅いかも
        
        # print("day : {}, a:{}, p:{}".format(day, a, p))
        if len(p)>0:
            p = sorted(p, key = lambda x : x[1], reverse=True)
            bsum += p[0][1]
            p.pop(0)
        

    print(bsum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = []

    for i in range(N):
        A.append((M-int(next(tokens)),int(next(tokens))))
    solve(N, M, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
from collections import deque
import heapq

def solve(N: int, M: int, A: "List[int]"):
    a = sorted(A, reverse=False)
    a = deque(a)
    # ai(day) bi(reward)
    b_cands = []
    heapq.heapify(b_cands)

    ans = 0
    for M in range(M+1):
        while (len(a)!=0) and (a[0][0]==M):
            heapq.heappush(b_cands, -a.popleft()[1])
            # print(b_cands)
        if len(b_cands)>0:
            ans -= heapq.heappop(b_cands)

    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = []

    for i in range(N):
        A.append((int(next(tokens)),int(next(tokens))))
    solve(N, M, A)

if __name__ == '__main__':
    main()
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

MOD = 10**9 + 7
N, K = map(int, read().split())

is_prime = np.zeros(K + 1, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, K + 1, 2):
    if p * p >= K:
        break
    if is_prime[p]:
        is_prime[p * p:: p + p] = 0
primes = np.where(is_prime)[0]


A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for p in primes.tolist():
    for i in range(N // p + 1):
        A[i] -= A[i * p]

answer = sum(i * x for i, x in enumerate(A))
print(answer % MOD)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9 + 7

N, K = map(int, read().split())

A = [0] * (K + 1)
for d in range(1, K + 1):
    A[d] = pow(K // d, N, MOD)

for d in range(K, 0, -1):
    for i in range(2, K // d + 1):
        A[d] -= A[d * i]

answer = sum(d * x for d, x in enumerate(A))
print(answer % MOD)
a = input()

if RRR in a:
  print(3)
elif RR in a:
  print(2)
elif R in a:
  print(1)
else:
  print(0)

### FIXED CODE ###

a = input()

if 'RRR' in a:
  print(3)
elif 'RR' in a:
  print(2)
elif 'R' in a:
  print(1)
else:
  print(0)
import bisect

n,k= map(int,input().split())
x = [int(i) for i in input().split()]

idx = bisect.bisect_left(x,0)
"""
if x[idx] == 0:
    x.insert(idx,0)
"""

ans = 10**100

if x[idx] == 0 and idx - k + 1 >= 0:
    ans = min(ans,ans)

print(ans)
exit()

for i in range(k+1):
    #print(idx-i,idx+k-1-i)
    if i == 0 and idx+k-1 < n:
        ans = min(ans, x[idx+k-1])
    elif idx - i < 0 or idx+k-1-i >= n:
        continue
    else:
        ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])
        ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])

print(ans)

### FIXED CODE ###

import bisect

n,k= map(int,input().split())
x = [int(i) for i in input().split()]

idx = bisect.bisect_left(x,0)
"""
if x[idx] == 0:
    x.insert(idx,0)
"""
ans = 10**100


for i in range(k+1):
    #print(idx-i,idx+k-1-i)
    if i == 0 and idx+k-1 < n:
        ans = min(ans, x[idx+k-1])
    elif idx - i < 0 or idx+k-1-i >= n:
        continue
    else:
        ans = min(ans, - 2*x[idx-i] + x[idx+k-1-i])
        ans = min(ans, - x[idx-i] + 2*x[idx+k-1-i])

if idx == n:
    ans = -x[-k]

print(ans)
import numpy as np
import math
import functools


# 2数を受け取って最小公倍数を返す関数
def lcm(a, b):
    y = a * b / math.gcd(a, b)
    return int(y)


# 可変引数を受け取って最小公倍数を返す関数
def lcm_2(vals):
    return functools.reduce(lcm, vals)


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

a = np.array(list(map(int, input().split())))
lcm = lcm_2(a)

half_lcm = lcm / 2
ans = 0
flg = False
while True:
    if not sum((half_lcm * 2) % a):
        flg = True
        break

    half_lcm += lcm
    if half_lcm > m:
        break

if flg:
    ans = (m - half_lcm) // lcm + 1

print(int(ans))


### FIXED CODE ###

import functools
import sys

n, m = map(int, input().split())
a = list(map(lambda x: x // 2, map(int, input().split())))

# A[0]を素因数分解して2で割り切れる回数を数える
div = 0

a_0 = a[0]
while a_0 % 2 == 0:
    a_0 /= 2
    div += 1

# print("count = " + str(div))#

# Aのすべての整数がA[0]と同じ回数2で割り切れるか調べる
for i in range(1, len(a)):
    div2 = 0
    tmp_a = a[i]
    while tmp_a % 2 == 0:
        tmp_a /= 2
        div2 += 1
    # print("A[" + str(i) + "] count = " + str(div2))#
    if div2 != div:
        print("0")
        sys.exit()


def gcd(x, y):
    if x == 0:
        return y

    return gcd(y % x, x)


def least_common_multiple(iter):
    '''
    最小公倍数を返す
    '''
    lcm = lambda x, y: x * y // gcd(x, y)
    return functools.reduce(lcm, iter)


lc = least_common_multiple(a)
ans = 0
a = 1

ans = m // lc
if ans == 0:
    print(0)
    sys.exit()
if ans % 2 == 0:
    print(ans // 2)
else:
    print(ans // 2 + 1)
import math

class common_function():
    """
        1. よく使いそうで予め用意しておいた変数をまとめた
        2. よく使いそうな関数群をまとめた
    """
    def lcm(self, x:int, y:int):
        """
            最小公倍数を返すメソッド
            math をインポートする
        """
        return (x * y) // math.gcd(x, y)
        

def main():
    common = common_function()
    N, M = map(int, input().split())
    S = input()
    T = input()
    lengthX = common.lcm(N, M)
    XdivS = lengthX//N
    XdivT = lengthX//M
    X = ['0'] * lengthX
    for i in range(N):
        j = XdivS*i
        X[j] = S[i]
    
    for i in range(M):
        j = XdivT*i
        if X[j] == '0':
            continue
        if X[j] != T[i]:
            print(-1)
            return
    print(lengthX)

if __name__ == "__main__":
    main()







### FIXED CODE ###

import math

class common_function():
    """
        1. よく使いそうで予め用意しておいた変数をまとめた
        2. よく使いそうな関数群をまとめた
    """
    def lcm(self, x:int, y:int):
        """
            最小公倍数を返すメソッド
            math をインポートする
        """
        return (x * y) // math.gcd(x, y)
        

def main():
    common = common_function()
    N, M = map(int, input().split())
    S = input()
    T = input()
    lengthX = common.lcm(N, M)
    XdivS = lengthX//N
    XdivT = lengthX//M
    X = []
    for i in range(N):
        j = XdivS*i
        X.append((j, S[i]))
    X.sort(key=lambda x: x[0], reverse=True)
    
    k, x = X.pop()
    for i in range(M):
        j = XdivT*i
        for a in range(lengthX):
            if len(X) == 0:
                break
            if k < j:
                k, x = X.pop()
            else:
                break
        if k == j:
            if x != T[i]:
                print(-1)
                return
    print(lengthX)

if __name__ == "__main__":
    main()
N = int(input())
sum = 0 
while(N != 0):
    sum += (N%10)
    N /= 10
if sum % 9 == 0:
    print('Yes')
else: print('No')

### FIXED CODE ###

N = int(input())
sumN = sum(int(digit) for digit in str(N))
if sumN%9 == 0:
    print("Yes")
else:
    print("No")
A, B = map( int, input().split() )
if A > B :
   print( "Alice" )
elseif A < B :
   print( "Bob" )
else : 
   print( "Draw" )

### FIXED CODE ###

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

if A == 1 :
   A = 14
if B == 1 :
   B = 14

if A > B :
   print( "Alice" )
elif A < B :
   print( "Bob" )
else : 
   print( "Draw" )
H,W = map(int,input().split())
S = [input() for i in range(H)]

dxy = [(0,1),(1,0),(0,-1),(-1,0)]
from collections import deque
ans = 0
for y in range(H):
    for x in range(W):
        if S[y][x] == '#': continue
        dist = [[0]*W for i in range(H)]
        visited = [[0]*W for i in range(H)]
        visited[y][x] = 1
        q = deque([(x,y)])
        while q:
            x,y = q.popleft()
            for dx,dy in dxy:
                nx,ny = x+dx,y+dy
                if not 0 <= nx < W: continue
                if not 0 <= ny < H: continue
                if visited[ny][nx]: continue
                if S[ny][nx] == '#': continue
                visited[ny][nx] = 1
                dist[ny][nx] = dist[y][x] + 1
                q.append((nx,ny))
        
        for i in range(H):
            ans = max(ans, dist[i])

print(ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

def main():
    H,W = map(int, input().split())

    S = ["" for _ in range(H)]
    for i in range(H):
        S[i] = input()

    INF = float("inf")
    N = H*W
    dp = [[INF for _ in range(N)] for _ in range(N)]

    for i in range(H):
        for j in range(W):
            
            if j != W-1 and S[i][j] == "." and S[i][j+1] == ".":
                dp[(W*i)+j][(W*i)+j+1] = 1
                dp[(W*i)+j+1][(W*i)+j] = 1

            if i != H-1 and S[i][j] == "." and S[i+1][j] == ".":

                dp[(W*i)+j][(W*(i+1))+j] = 1
                dp[(W*(i+1))+j][(W*i)+j] = 1
        
            dp[(W*i)+j][(W*i)+j] = 0


    N = H*W
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

    ans = 0
    for i in range(N):
        for j in range(N):
            if dp[i][j] != INF:
                ans = max(ans, dp[i][j])
    
    print(ans)

if __name__ == "__main__":
    main()
n=int(input())
X=[]
L=[]
A=[]
B=[]
for _ in range(n):
    x,l=map(int,input().split())
    X.append(x)
    L.append(l)
    A.append(x-l)
    B.append(x+l)
k = zip(L,X,A,B)
k = sorted(k, key=lambda x:(x[1], x[2]))
c=1
ans=[]
ans.append((k[0][2],k[0][3]))
for i in range(1,n):
    x=(k[i][2],k[i][3])
    if judge(x,ans):
        ans.append(x)
        c+=1
print(c)

### FIXED CODE ###

n=int(input())
itv=[]
for _ in range(n):
    x,l=map(int,input().split())
    itv.append((x+l,x-l))
itv.sort()
ass = 0
tt = -float("inf")
for i in range(n):
    if tt <= itv[i][1]:
        ass += 1
        tt = itv[i][0]
print(ass)
x,y=map(int,input())
print(x+y/2)

### FIXED CODE ###

x,y=map(int,input().split())
print(int(x+y/2))
s = input()
k = int(input())

s_list = []
times = 0
flow = 0


print(s.count(s[len(s)-1]))

for i in range(len(s)):
    s_list.append(s[i])


while True:
    if s_list[flow] == s_list[flow + 1]:
        times += 1
        flow += 2
    elif s_list[flow] != s_list[flow + 1]:
        flow += 1

    if flow >= len(s) - 1:
        break

if s.count(s[len(s)-1]) % 2 == 1 :
    if s[0] == s[len(s)-1]:
        times += 1



print(times*k)



### FIXED CODE ###

s = list(input())
k = int(input())
S = s.copy()
S_3 =s.copy()
cnt = 0
cnt_2 = 0
cnt_3 = 0


for i in range(1, len(s)):
    if s[i-1] == s[i]:
        cnt += 1
        s[i] = "A"

# --------------------------

for i in range(len(s)):
    S.append(S[i])

for i in range(1, len(S)):
    if S[i-1] == S[i]:
        cnt_2 += 1
        S[i] = "A"

# if k == 1:
#     print(cnt)
# else:
#     print(cnt + (cnt_2 - cnt) * (k-1))

# ---------------------------------------

for i in range(len(S)):
    S_3.append(S_3[i])

for i in range(1, len(S_3)):
    if S_3[i-1] == S_3[i]:
        cnt_3 += 1
        S_3[i] = "A"

# --------------------------------------

if k == 1:
    print(cnt)
elif k == 2:
    print(cnt_2)
elif k == 3:
    print(cnt_3)
elif cnt_2 - cnt == cnt_3 - cnt_2:
    print(cnt + (cnt_2 - cnt) * (k-1))
else:
    if k % 2 == 0:
        print(int(cnt + (cnt_2 - cnt) * (k / 2) + (cnt_3 - cnt_2) * (k / 2 - 1)))
    else:
        print(int(cnt + (cnt_2 - cnt) * ((k - 1) / 2) + (cnt_3 - cnt_2) * ((k - 1) / 2)))
N_str, q_str = raw_input().spilit()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in N:
    t = raw_input().spilit()
    A.append(t[0],int(t[1]))

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append([name, time])
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)

### FIXED CODE ###

N_str, q_str = raw_input().split()
N = int(N_str)
q = int (q_str)
A =[]
B =[]
total =0

for i in range(N):
    t = raw_input().split()
    A.append([t[0],int(t[1])])

while A:
    name, time = A.pop(0)
    if time <= q:
        total += time
        B.append(name+" "+ str(total))
       
    else:
        time -= q
        total += q
        A.append([name, time])

print '\n'.join(B)
s = input()
if s[6] >= 5:
    print('TBD')
else:
    print('Heisei')

### FIXED CODE ###

a,b,c = map(int,input().split('/'))
if a > 2019 or a == 2019 and b >= 5:
    print('TBD')
else:
    print('Heisei')
n,k=map(int,input().split())
ans=[0]*10**5
for i in range(n):
    a,b=map(int,input().split())
    ans[a]+=b
    
v=0
for i in range(k):
    v+=ans[i]
    if ans[i]==0:
        i-=1
    if v>=k:
        a=i
        break
    
print(a)

### FIXED CODE ###

n,k=map(int,input().split())
ans=[0]*(10**5+1)
for i in range(n):
    a,b=map(int,input().split())
    ans[a]+=b
    
v=0
for i in range(k):
    v+=ans[i]
    if ans[i]==0:
        i-=1
    if v>=k:
        a=i
        break
    
print(a)