Harryxun/stf_run huggingface dataset:
from collections import deque
H, W = map(int, input().split())
CY, CX = map(lambda x: int(x)-1, input().split())
DY, DX = map(lambda x: int(x)-1, input().split())

gridgraph = [input() for _ in range(H)]
q = deque()
q.append([CY, CX])
# 更新されるなら追加
adjacent = [[1, 0], [0, 1], [-1, 0], [0, -1]]
INF = float("inf")
distant = [[INF]*W for _ in range(H)]
distant[CY][CX] = 0
visited = set()
while len(q):
    cy, cx = q.popleft()
    if (cy, cx) in visited:
        continue
    visited.add((cy, cx))
    for dy, dx in adjacent:
        ny, nx = cy+dy, cx+dx
        if ny < 0 or ny >= H or nx < 0 or nx >= W:
            continue
        if gridgraph[ny][nx] == "." and distant[ny][nx] > distant[cy][cx]:
            distant[ny][nx] = distant[cy][cx]
            q.appendleft([ny, nx])
    for i in range(-2, 3, 1):
        for j in range(-2, 3, 1):
            target_y, target_x = cy+i, cx+j
            if target_y < 0 or target_y >= H or target_x < 0 or target_x >= W:
                continue
            if gridgraph[target_y][target_x] == "." and distant[target_y][target_x] > distant[cy][cx]+1:
                distant[target_y][target_x] = distant[cy][cx]+1
                q.append([target_y, target_x])
if distant[DY][DX] == INF:
    print(-1)
else:
    print(distant[DY][DX])


### FIXED CODE ###

H, W, M = map(int, input().split())
row = [0]*H  # 行
column = [0]*W  # 列

target = set()
for _ in range(M):
    # h行, w列に爆破対象がある
    h, w = map(lambda x: int(x)-1, input().split())
    row[h] += 1
    column[w] += 1
    target.add((h, w))

max_row_value = max(row)
max_column_value = max(column)
max_row_idx = []
max_column_idx = []

for i in range(H):
    if row[i] == max_row_value:
        max_row_idx.append(i)
for j in range(W):
    if column[j] == max_column_value:
        max_column_idx.append(j)

# なければ出力して即終了
# print(max_row_idx)
# print(max_column_idx)
# print(target)
for r in max_row_idx:
    for c in max_column_idx:
        if (r, c) not in target:
            # この式がFalseになるのは，(r, c)に爆発対象があるときのみ，それはたかだか10**5回程度
            # 必ず上記の条件式がTrueになるときがくる
            # (r, c) in targetがTrueになるのは10**5回程度なので！
            print(max_row_value+max_column_value)
            exit()

print(max_row_value+max_column_value-1)
S=input()
    T=input()
    a=0
    for i in range(3):
        if S[i]==T[i]:
            a+=1
    print(a)

### FIXED CODE ###

S=input()
T=input()
a=0
for i in range(3):
    if S[i]==T[i]:
            a+=1
print(a)
K, N = map(int, input().split())
lst = list(map(int, input().split()))

dist = lst[-1]-lst[0]
for i in range(N-1):
    dist = min(dist, K-lst[i+1]+lst[i])
print(dist)

### FIXED CODE ###

S = input()
if S[2]==S[3] and S[4]==S[5]:
  print("Yes")
else:
  print("No")
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())) for i in range(n))
i = 0
while k > 0:
    k -= a[i][1]
    i += 1
print(a[i][0])

### FIXED CODE ###

n,k = map(int,input().split())
a = sorted(list(map(int,input().split())) for i in range(n))
i = 0
while k > 0:
    k -= a[i][1]
    i += 1
print(a[i-1][0])
N, M = map(int, input().split())  #頂点, 辺
g = [[] for _ in range(M)]  #iはjと繋がっている
for i in range(M):
    u, v = map(int, input().split())
    if u > v:
        u, v = v, u
    g[u-1].append(v-1)
    g[v-1].append(u-1)

is_checked = [False] * N

def dfs(i):
    cnt = 0
    is_checked[i] = True
    for j in g[i]:
        if not(is_checked[j]):
            dfs(j)
        if not(False in is_checked):
            cnt += 1
    return cnt
            
ans = dfs(0)
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())  #頂点, 辺
g = [[] for _ in range(N)]  #iはjと繋がっている
for _ in range(M):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

#1度通った頂点をTrueにする
is_checked = [False] * N

import sys
sys.setrecursionlimit(10 ** 8)
def dfs(i):
    cnt = 0
    is_checked[i] = True
    if not(False in is_checked):
        return 1
    else:
        for j in g[i]:
            if not(is_checked[j]):
                cnt += dfs(j)
                is_checked[j] = False
        return cnt
            
ans = dfs(0)
print(ans)
a, b, c = map(int, input().split())
if a == b:
    if b != c:
    print("Yes")
elif b == c:
    if c != a:
    print("Yes")
elif c == a:
    if a != b:
        print("Yes")
else:
    print("No")

### FIXED CODE ###

a, b, c = map(int, input().split())
if a == b and b != c:
        print("Yes")
elif b == c and c != a:
        print("Yes")
elif c == a and a != b:
        print("Yes")
else:
    print("No")
a, b, c = map(int,input().split())
R = int(|a-b|)
E = int(|a-c|)
if R > E:
 print("B")
else:
 print("A")

### FIXED CODE ###

a, b, c =map(int,input().split())
import math
if abs(a-b) > abs(a-c):
 print("B")
else:
 print("A")
print(sum(list(int(input()))))

### FIXED CODE ###

print(sum([int(i) for i in list(input())]))
from collections import deque

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

tmp = [0 for _ in range(N + 1)]

now = 0

if 1 not in A:
    tmp[1] = 1
    
else:
    now += 1
    
if N >= 2:
    if 2 not in A:
        tmp[2] = tmp[1] + 1
    
    else:
        now += 1

if now == M:
    now -= 1

for i in range(3, N+1):
    
    if i != A[now]:
        tmp[i] = tmp[i-1] + tmp[i-2] 
        
    else:
        if now < M - 1:
            now += 1
        

    
print(tmp[-1]%(10**9+7))




### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

tmp = [0 for _ in range(N + 1)]

now = 0
if 1 not in A:
    tmp[1] = 1
    
else:
    now += 1
    
if (2 not in A) and N >= 2:
    tmp[2] = tmp[1] + 1
    
else:
    now += 1

for i in range(3, N+1):
    
    try:
        if i != A[now]:
            tmp[i] = tmp[i-1] + tmp[i-2] 
            
        else:
            now += 1
        
    except:
        tmp[i] = tmp[i-1] + tmp[i-2] 

    
print(tmp[-1]%(10**9+7))
import sys
from bisect import bisect_left, bisect_right


class RangeUpdateTree:
    def __init__(self, n, initial=-1, sentinel=-2):
        n2 = 1 << n.bit_length()
        self.n = n2
        self.offset = n2
        self.data = [initial] * (n2 << 1)
        self.sentinel = sentinel

    def update(self, a, b, x):
        stack = [(1, 0, self.n)]
        while stack:
            i, l, r = stack.pop()
            if a <= l and r <= b:
                self.data[i] = x
                continue
            y = self.data[i]
            j = i << 1
            if y != self.sentinel:
                self.data[i] = self.sentinel
                self.data[j] = self.data[j + 1] = y
            m = (l + r) // 2
            if a < m:
                stack.append((j, l, m))
            if m < b:
                stack.append((j + 1, m, r))

    def aggregate(self):
        stack = [1]
        ans = 0
        while stack:
            i = stack.pop()
            if self.data[i] != self.sentinel:
                ans += self.data[i] * (self.n >> i.bit_length() - 1)
                continue
            i <<= 1
            stack.append(i)
            stack.append(i + 1)
        return ans

    def debug_print(self):
        i = 1
        while i <= self.offset:
            print(self.data[i:2 * i])
            i <<= 1


n, q = list(map(int, input().split()))
lines = sys.stdin.readlines()
kkk = []
for line in lines[:n]:
    s, t, x = list(map(int, line.split()))
    kkk.append((x, s, t))
kkk.sort(reverse=True)
ddd = [int(line) for line in lines[n:]]
rut = RangeUpdateTree(q)
for x, s, t in kkk:
    ss = bisect_left(ddd, s - x)
    tt = bisect_left(ddd, t - x)
    # print(x, s, t, s - x, t - x, ss, tt)
    rut.update(ss, tt, x)
data = rut.data[rut.offset:]
# rut.debug_print()
print('\n'.join(map(str, data[:q])))


### FIXED CODE ###

import sys
from bisect import bisect_left

n, q = map(int, input().split())
lines = sys.stdin.readlines()
kkk = []
for line in lines[:n]:
    s, t, x = map(int, line.split())
    kkk.append((x, s, t))
kkk.sort()
ddd = list(map(int, lines[n:]))

ans = [-1] * q
skip = [-1] * q
for x, s, t in kkk:
    ss = bisect_left(ddd, s - x)
    tt = bisect_left(ddd, t - x)
    while ss < tt:
        if skip[ss] == -1:
            ans[ss] = x
            skip[ss] = tt
            ss += 1
        else:
            ss = skip[ss]
print('\n'.join(map(str, ans)))
# A - Darker and Darker
import numpy as np

H,W = map(int,input().split())
h,w = np.arange(H,dtype=int),np.arange(W,dtype=int)
A = [list(input()) for _ in range(H)]

queue = []
new_queue = []

for i in h:
    for j in w:
        if A[i][j]=='#':
            queue.append((i,j))
            
def darker(i,j):
    if (i in h) and (j in w) and A[i][j]=='.':
        A[i][j]='#'
        new_queue.append((int(i),int(j)))

ans = 0

while True:
    new_queue = []
    for i,j in queue:
        darker(i-1,j)
        darker(i+1,j)
        darker(i,j-1)
        darker(i,j+1)
    if new_queue==[]:
        break
    ans += 1
    queue = new_queue 

print(ans)

### FIXED CODE ###

# A - Darker and Darker
from collections import deque

H,W = map(int,input().split())
B = [[-1] * W for _ in range(H)]

queue = deque([])

for i in range(H):
    A = input()
    for j in range(W):
        if A[j]=='#':
            B[i][j] = 0
            queue.append((i,j))

ans = 0

while queue:
    I,J = queue.popleft()
    for di,dj in ((-1,0),(1,0),(0,-1),(0,1)):
        i,j = I+di,J+dj
        if 0<=i<H and 0<=j<W:
            if B[i][j]<0:
                B[i][j] = B[I][J]+1
                ans = max(ans,B[i][j])
                queue.append((i,j))

print(ans)
s=input()
op=[0]*3
for i in range(2):
    a=calc(s[0],s[1],i)
    for j in range(2):
        b=calc(a,s[2],j)
        for k in range(2):
            c=calc(b,s[3],k)
            if c==7:
                ret=[i,j,k]               
for i in range(3):
    if ret[i]==0:
        ret[i]="+"
    else:
        ret[i]="-"
for i in range(3):
    print(s[i]+ret[i],sep="",end="")
print(s[3]+"=7")


### FIXED CODE ###

def calc(a,b,f):
    a=int(a)
    b=int(b)
    if f==0:
        return a+b
    else:
        return a-b

s=input()
op=[0]*3
for i in range(2):
    a=calc(s[0],s[1],i)
    for j in range(2):
        b=calc(a,s[2],j)
        for k in range(2):
            c=calc(b,s[3],k)
            if c==7:
                ret=[i,j,k]               
for i in range(3):
    if ret[i]==0:
        ret[i]="+"
    else:
        ret[i]="-"
for i in range(3):
    print(s[i]+ret[i],sep="",end="")
print(s[3]+"=7")
S = input()
L=len(S)
longest=0
for i in range(L):
  for j in range(i+1):
    DUP=S[j:i]
    DUP=DUP.replace("A","#")
    DUP=DUP.replace("T","#")
    DUP=DUP.replace("G","#")
    DUP=DUP.replace("C","#")
    count=0
    for a in range(len(DUP)):
      if DUP[a]=="#":
        count+=1
      else:
        break
    else:
      longest=max(longest,count)
print(longest)
S = input()
L=len(S)
longest=0
for i in range(L):
  for j in range(i+1):
    DUP=S[j:i+1]
    DUP=DUP.replace("A","#")
    DUP=DUP.replace("T","#")
    DUP=DUP.replace("G","#")
    DUP=DUP.replace("C","#")
    count=0
    for a in range(len(DUP)):
      if DUP[a]=="#":
        count+=1
      else:
        break
    else:
      longest=max(longest,count)
print(longest)


### FIXED CODE ###

IN=input()
print("A"if IN=="T" else "C" if IN=="G" else "T" if IN=="A" else "G")
N, Q = map(int, input().split())
2 S = input()
3 t = [0] * (N + 1)
4 for i in range(N):
5     t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
6 for i in range(Q):
7     l, r = map(int, input().split())
8     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, a = map(int, input().split)

if h%a == 0:
  print((int)h/a)
else:
  print((int)(h/a)+1)

### FIXED CODE ###

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

if h%a == 0:
  print((int)(h/a))
else:
  print((int)(h/a)+1)
l=raw_input().split()
for i in range(len(l)):
 print(f"Case{i+1}: {l[i]}")

### FIXED CODE ###

import sys
i=1
for e in sys.stdin:
 if'0\n'==e:break
 print(f'Case {i}: {e[:-1]}');i+=1
import numpy as np
x = np.arange(int(input()))
print(np.sum(x))

### FIXED CODE ###

n=int(input())
n-=1
print(n*(n+1)//2)
a = int(input())
l = list(map(int,input().split()))

le,ri = 0,sum(l)
ans = 10**10
for i in range(len(l)-1):
    le += l[i]
    ri -= l[i]
    ans = min(ans,abs(le-ri))
else:
    print(min(ans))

### FIXED CODE ###

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

le,ri = 0,sum(l)
ans = []
for i in range(len(l)-1):
    le += l[i]
    ri -= l[i]
    ans.append(abs(le-ri))
else:
    print(min(ans))
def main():
    n,m = [int(v) for v in input().split()]
    groups = []
    g = [-1]*(n+1)
    for _ in range(m):
        a,b = [int(v) for v in input().split()]
        if g[a]!=-1 and g[b]!=-1:
            if g[a]==g[b]: continue
            gb = g[b]
            for no in groups[gb]:
                g[no] = g[a]
            groups[gb] = {}
        elif g[a]!=-1:
            g[b] = g[a]
            groups[g[a]].append(b)
        elif g[b]!=-1:
            g[a] = g[b]
            groups[g[b]].append(a)
        else:
            g[a] = g[b] = len(groups)
            groups.append([a,b])
    # print(groups, g)
    ans = max([len(v) for v in groups])
    print(ans)

main()

### FIXED CODE ###

def main():
    n,m = [int(v) for v in input().split()]
    if m==0:
        print(1)
        return
    
    g = [set() for _ in range(n+1)]
    seen = [False] * (n+1)
    for _ in range(m):
        a,b = [int(v) for v in input().split()]
        g[a].add(b)
        g[b].add(a)

    ans = 0
    for i in range(1,n+1):
        if seen[i]: continue
        stack = set([i])
        l = 0
        while len(stack)>0:
            no = stack.pop()
            seen[no] = True
            l += 1
            for nn in g[no]:
                if not seen[nn]:
                    stack.add(nn)
        ans = max(ans, l)

    # print(groups, g)
    print(ans)

main()
from itertools import permutations 
inf=10**9
n, m, r1 = map(int, input().split())
r=list(map(int, input().split()))
abc=[list(map(int, input().split())) for _ in range(m)]
d=[[inf]*n for i in range(n)]
for ai, bi, ci in abc:
    d[ai-1][bi-1]=ci
    d[bi-1][ai-1]=ci
for k in range(n):
    for i in range(n-1):
        for j in range(i, n):
            d[i][j]=min(d[i][j], d[i][k]+d[k][j])
            d[j][i]=d[i][j]
p=list(permutations(r))
ans=inf
for pi in p:
    res=0
    for i in range(r1-1):
        res+=d[pi[i]-1][pi[I+1]-1]
    if ans>res:
        ans=res
print(ans)

### FIXED CODE ###

from itertools import permutations
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
E = [list(map(int, input().split())) for _ in range(M)]
INF = 10 ** 9
d = [[INF for j in range(N)] for i in range(N)]
for i, j, c in E:
    d[i - 1][j - 1] = c
    d[j - 1][i - 1] = c
for k in range(N):
    for i in range(N - 1):
        for j in range(i, N):
            dk = d[i][k] + d[k][j]
            if d[i][j] > dk:
                d[i][j] = dk
                d[j][i] = dk
ans = 10 ** 9
for ri in permutations(r):
    x = 0
    for i in range(R - 1):
        x += d[ri[i] - 1][ri[i + 1] - 1]
    if ans > x:
        ans = x
print(ans)
w, h, x, y = input().split()
w, h, x, y = int(w), int(h), int(x), int(y)
if (x==0) or (y==0) or (x==w/2) or (y==h/2) or (x==w) or (y==h):
    if (x==w/2) and (y==h/2):
        print(w*h/2, 1)
    else:
        print(w*h/2, 0)
else:
    if (x < w/2) and (y < h/2):
        p = (h-y)/(w-x)
        x_pos = (p*x-y)/p
        print((w-x_pos)*h/2, 0)
    elif (x > w/2) and (y < h/2):
        p = (h-y)/-x
        x_pos = (p*x-y)/p
        print(x_pos*h/2, 0)
    elif (x < w/2) and (y > h/2):
        p = -y/(w-x)
        x_pos = (h-y+p*x)/p
        print((w-x_pos)*h/2, 0)
    elif (x > w/2) and (y > h/2):
        p = y/x
        x_pos = (h-y+p*x)/p
        print(x_pos*h/2, 0)

### FIXED CODE ###

x, a = input().split()
if x < a:
    print(0)
else:
    print(10)
from collections import defaultdict

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

odd = defaultdict(int)
even = defaultdict(int)

nodd = 0
neven = 0
for ix in range(1, n+1):
    if ix & 1:
        odd[v[ix-1]] += 1
        nodd += 1
    else:
        even[v[ix-1]] += 1
        neven += 1

odd_sorted = sorted(odd.items(), key=lambda x: x[1], reverse=True)
even_sorted = sorted(even.items(), key=lambda x: x[1], reverse=True)

odd_top = odd_sorted[0]
even_top = even_sorted[0]

# solve

ans = 0

if odd_top[0] == even_top[0]:

    if len(odd) == len(even) == 1:
        ans = nodd
    else:
        if len(odd) == 1:
            ans += nodd - odd_top[1]
            ans += neven - even_sorted[1][1]

        elif len(even) == 1:
            ans += nodd - odd_sorted[1][1]
            ans += neven - even_top[1]

        else:
            odd_sec = odd_sorted[1]
            even_sec = even_sorted[1]

            # use others
            if nodd_sec[1] < neven_sec[1]:
                # use nodd_sec
                ans += nodd - odd_sec[1]
                ans += neven - even_top[1]
            else:
                ans += nodd - odd_top[1]
                ans += neven - even_sec[1]
else:
    ans += nodd - odd_top[1]
    ans += neven - even_top[1]

# print("odd_top", odd_top)
# print("even_top", even_top)
print(ans)

### FIXED CODE ###

from collections import Counter
 
n = int(input())
v_array = list(map(int,input().split()))
 
v_odd = v_array[0::2]
v_even = v_array[1::2]
 
v_odd_common = Counter(v_odd).most_common()
v_even_common = Counter(v_even).most_common()
 
v_odd_common.append((0,0))
v_even_common.append((0,0))
 
if v_odd_common[0] != v_even_common[0]:
    print(n-v_odd_common[0][1]-v_even_common[0][1])
else:
    print(min(n-v_odd_common[0][1]-v_even_common[1][1],n-v_odd_common[1][1]-v_even_common[0][1]))
N, K = map(int, input().split())
x = list(map(int, input().split()))

plus = [i for i in x if i >= 0]
minus = [i for i in x if i <= 0]
ans = (x[-1] - x[0])*2
if len(plus) >= K:
    ans = plus[K-1]
if len(minus) >= K:
    ans = min(ans, minus[-K])
for i in range(1, min(len(plus), len(minus))):
    tmp = plus[K-1-i] - (minus[-i])*2
    ans = min(tmp, ans)

    tmp = plus[K-1-i]*2 - minus[-i]
    ans = min(tmp, ans)

print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
x = list(map(int, input().split()))
import bisect
id = bisect.bisect_left(x,0)
ans=10**10
if id == N:
  print(abs(x[N-K]))
  exit(0)
for i in range(max(0,(K+id)-N),min(id+1,K)):
  right = x[K+id-1-i]
  left=0
  if i>0:
    left =x[id-i]
  tmp=min(abs(left)*2+right,right*2+abs(left)) 
  ans=min(tmp,ans)
print(ans)
n = int(input())
h = list(map(int, input().split()))

dp = [float("inf")] * n
dp[0] = 0
dp[1] = abs(h[2] - h[1])

for i in range(1, n ):
    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i] + abs(h[i] - h[i - 2]))

print(dp[n-1])

### FIXED CODE ###

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

dp = [float("inf")] * n
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i]-h[i - 1]), dp[i - 2] + abs(h[i]-h[i - 2]))

print(dp[n - 1])
import numpy as np

class DP():
    def __init__(self):
        pass
    
    def chmin(self, a, b):
        if a>b:
            return b
        else:
            return a
        
    def chmax(self):
        if a<b:
            return b
        else:
            return a
        
N = int(input())
cost_list = list(map(int, input().split()))
# cost_list = [2, 9, 4, 5, 1, 6, 10]

dpfun = DP()
dp = (np.ones(7) * np.inf)
# " 初期条件 "
dp[0] = 0

for i in range(1, N, 1):
    if i==1:    
        dp[i] = dpfun.chmin(dp[i], dp[i-1] + abs(cost_list[i] - cost_list[i-1]))
    else:
        dp[i] = dpfun.chmin(dp[i], dp[i-1] + abs(cost_list[i] - cost_list[i-1]))
        dp[i] = dpfun.chmin(dp[i], dp[i-2] + abs(cost_list[i] - cost_list[i-2]))
print(int(dp[-1]))

### FIXED CODE ###

"""
A - Frog 1
"""
class DP():
    def __init__(self):
        pass
    
    def chmin(self, a, b):
        if a>b:
            return b
        else:
            return a
        
    def chmax(self):
        if a<b:
            return b
        else:
            return a
        
N = int(input())
# K = int(input())
cost_list = list(map(int, input().split()))
# cost_list = [2, 9, 4, 5, 1, 6, 10]
# N = len(cost_list)
K = 2

dpfun = DP()
# dp = np.ones(N) * np.inf
INF = 2**60
dp = [INF]*N
" 初期条件 "
dp[0] = 0

for i in range(1, N, 1):
    if i==1:    
        dp[i] = dpfun.chmin(dp[i], dp[i-1] + abs(cost_list[i] - cost_list[i-1]))
    else:
        for j in range(1, K+1, 1):
            dp[i] = dpfun.chmin(dp[i], dp[i-j] + abs(cost_list[i] - cost_list[i-j]))
print(int(dp[-1]))
from Queue import Queue

n, q = [ int( val ) for val in input( ).split( " " ) ]
names = Queue( )
times = Queue( )
for i in range( n ):
	name, time = input( ).split( " " )
	names.put( name )
	times.put( int( time ) )
 
qsum = 0
output = []
while not times.empty( ):
	name = names.get( )
	time = times.get( )
	if time <= q:
		qsum += time
		output.append( "{:s} {:d}".format( name, qsum ) )
	else:
		times.put( time - q )
		names.put( name )
		qsum += q

print( "\n".join( output ) )

### FIXED CODE ###

from collections import deque

n, q = [ int( val ) for val in input( ).split( " " ) ]
processes = deque( )
for i in range( n ):
    name, time = input( ).split( " " )
    processes.append( ( name, int( time ) ) )
  
qsum = 0
output = []
while len( processes ):
    process = processes.popleft( )
    if process[1] <= q:
        qsum += process[1]
        output.append( "{:s} {:d}".format( process[0], qsum ) )
    else:
        processes.append( ( process[0], process[1]- q ) )
        qsum += q
 
print( "\n".join( output ) )
from collections import defaultdict
N, Q = map(int, input().split())

parent = [None] * N
child = defaultdict(list)
counter = [0] * N
pcounter = [0] * N

for i in range(N-1):
    a, b = map(int, input().split())
    parent[b-1] = a-1
    child[a-1].append(b-1)
for i in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x

def propagate(node, acc):
    pcounter[node] = counter[node] + acc
    for c in child[node]:
        propagate(c, pcounter[node])

propagate(0, 0)
print(*pcounter, sep=' ')


### FIXED CODE ###

import sys
from collections import defaultdict
sys.setrecursionlimit(100000)
N, Q = map(int, input().split())

neighbor = defaultdict(list)
counter = [0] * N
pcounter = [None] * N
depth = {0: 0}

for i in range(N-1):
    a, b = map(int, input().split())
    a_deper, b_deeper = False, False
    if a in depth and b not in depth:
        depth[b] = depth[a] + 1
    if b in depth and a not in depth:
        depth[a] = depth[b] + 1
    if a in depth and b in depth:
        if depth[a] < depth[b]:
            neighbor[a-1].append(b-1)
        else:
            neighbor[b-1].append(a-1)
    else:
            neighbor[a-1].append(b-1)
            neighbor[b-1].append(a-1)

for i in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x

def solve():
    stack = [(0, None)]
    while stack:
        (node, parent) = stack.pop()
        pcounter[node] = counter[node]
        if parent is not None:
            pcounter[node] += pcounter[parent]
        for c in neighbor[node]:
            if pcounter[c] is None:
                stack.append((c, node))

solve()
print(*pcounter, sep=' ')
a,b,t = list(map(int,input().split()))
printf(t//a * b)

### FIXED CODE ###

a,b,t = list(map(int, input().split()))
c = t // a
print(c*b)