Harryxun/stf_run huggingface dataset:
#途中
#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

graph = [set([]) for _ in range(N+1)]
for a,b in AB:
    graph[a].add(b)
    graph[b].add(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
check = [False for _ in range(N+1)]
check[1] = True
#check[i]:i番目の頂点を発見した
#check[i] == True and i in graph[j]ならiはjの親

for p,x in PX:
    counter[p] += x

def cal(graph,counter,edge):
    for e in graph[edge]:
        if not check[e]:
            counter[e] += counter[edge]
            check[edge] = True
            cal(graph,counter,e)

cal(graph,counter,1)

print(str(counter[1]),end="")
for i in range(2,N+1):
    print(" "+str(counter[i]),end="")
print()


### FIXED CODE ###

#全体に同じものを足すときは累積和を考えたい

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]

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

for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
#どちらが親か分からないがとりあえずつながっている
#どちらが親かは後で判断

counter = [0 for _ in range(N+1)]
#counter[i]:i番目の頂点のカウンター
parent = [None for _ in range(N+1)]

for p,x in PX:
    counter[p] += x

def dfs(graph,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

dfs(graph,counter,1)

ans = " ".join(map(str,counter[1:]))
print(ans)
S = list(map(int,input().split())
print("Yes" if len(set(S))==2 else "No")

### FIXED CODE ###

S = list(map(int,input().split()))
print("Yes" if len(set(S))==2 else "No")
a, b = map(int, raw_input().split())
 if (a > b):
    print "a > b"
if (a < b):
    print "a < b"
else:
    print "a == b"

### FIXED CODE ###

a, b = map(int, raw_input().split())
if a < b:
 print "a < b"
elif a > b:
 print "a > b"
else:
 print "a == b"
import itertools

n,m,q=map(int, input().split())  
a=[list(map(int, input().split())) for i in range(m)]
b=[list(map(int, input().split())) for i in range(q)]

x=[[0]*(501) for i in range(501)]

for i in range(m):
    x[a[i][0]][a[i][1]]+=1



for i in range(501):
    x[i] = list(itertools.accumulate(x[i]))
  

for i in range(501):
    x[:,i] = list(itertools.accumulate(x[:,i]))



for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2,v2]
    a2=x[v2,v1-1]
    a3=x[v1-1,v2]
    a4=x[v1-1,v1-1]
    print(a1-a2-a3+a4)


 







### FIXED CODE ###

import itertools
import numpy as np
n,m,q=map(int, input().split())  
a=[list(map(int, input().split())) for i in range(m)]
b=[list(map(int, input().split())) for i in range(q)]

x=[[0]*(501) for i in range(501)]

for i in range(m):
    x[a[i][0]][a[i][1]]+=1



for i in range(501):
    x[i] = list(itertools.accumulate(x[i]))
  
x=np.array(x)
for i in range(501):
    x[:,i] = list(itertools.accumulate(x[:,i]))



for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2,v2]
    a2=x[v2,v1-1]
    a3=x[v1-1,v2]
    a4=x[v1-1,v1-1]
    print(a1-a2-a3+a4)
line = input()

strL = line.split()
X = int(strL[0])
K = int(strL[1])
D = int(strL[2])

mod = X % D
div = int(X / D)

if div > K:
    ans = abs(X - K * D)
elif (K - div) % 2 != 0:
    if mod > 0:
        ans = mod - D
    else:
        ans = mod + D

print(int(abs(ans)))

### FIXED CODE ###

line = input()

strL = line.split()
X = abs(int(strL[0]))
K = int(strL[1])
D = int(strL[2])

mod = X % D
div = int(X / D)

if div > K:
    ans = X - K * D
elif (K - div) % 2 != 0:
    ans = mod - D
else:
    ans = mod

print(abs(int(ans)))
a = input()
a = int(a)

b = input()
b = int(b)

c = a * b

if c % == 2:
  print("Even")
else:
  print("Odd")
    

### FIXED CODE ###

a, b = map(int, input().split())
if (a*b)%2 == 1:
  print("Odd")
else:
  print("Even")
w,h,x,y,r = map(input().split())
print(['No','Yes'][r<=x<=w-r & r<=y<=h-r])


### FIXED CODE ###

w,h,x,y,r = map(int,input().split())
print(['No','Yes'][r<=x<=w-r and r<=y<=h-r])
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
X_sub = []
for i in range(len(X)-1):
    X_sub.append(X[i+1]-X[i])
X_sub.sort()
for i in range(N-1):
    del X_sub[-1]
print(sum(X_sub))

### FIXED CODE ###

N, M = map(int, input().split())
X = list(map(int, input().split()))
if N >=  M:
    print(0)
else:
    X.sort()
    X_sub = []
    for i in range(len(X)-1):
        X_sub.append(X[i+1]-X[i])
    X_sub.sort()
    for i in range(N-1):
        del X_sub[-1]
    print(sum(X_sub))
#n回,m回　　X =n + 2*m  Y = 2*n + m
X,Y = map(int,input().split())
import numpy as np
a = [[1, 2], [2, 1]]
#次に逆行列を求めます。
mod = pow(10,9)+7

b = np.linalg.inv(a)


Z = np.array([[X],[Y]])

n,m=np.dot(b,Z)
p,q = *n,*m

def comb(n,k,p):
    if k==0:
        return 1
    A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)])
    B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)])
    return A*pow(B,p-2,p)%p

if p<0 or q<0:
    print(0)
elif not p == int(p) or not q==int(q):
    print(0)
elif p==0 and q==0:
    print(0)
elif p==0:
    print(1)
elif q==0:
    print(1)
else:
    n = int(p)
    m = int(q)
    ans = comb(n,m,mod)

    print(ans%mod)


### FIXED CODE ###

#n回,m回　　X =n + 2*m  Y = 2*n + m
X,Y = map(int,input().split())
import numpy as np
from functools import reduce
import math 
a = [[1, 2], [2, 1]]
#次に逆行列を求めます。
mod = pow(10,9)+7

b = np.linalg.inv(a)


Z = np.array([[X],[Y]])

n,m=np.dot(b,Z)
p,q = *n,*m


def comb(n,k,p):
    if k==0:
        return 1
    A = reduce(lambda x,y:x*y%p ,[n-k+1+i for i in range(k)])
    B = reduce(lambda x,y:x*y%p ,[i+1 for i in range(k)])
    return A*pow(B,p-2,p)%p


if p<0 or q<0:
    print(0)
elif not abs(p-round(p))<pow(10,-3) or not abs(q-round(q))<pow(10,-3):
    print(0)
elif p==0 and q==0:
    print(0)
elif p==0:
    print(1)
elif q==0:
    print(1)
else:
    n = int(round(p))
    m = int(round(q))
    ans = comb(n+m,m,mod)

    print(ans%mod)
def get_cache(chars, start, end, cache=dict()):
    pair = (start, end)
    block = cache.get(pair)
    if block is not None:
        return block
    else:
        block = chars[start:end]
        cache[pair] = block
        return block


def count_k(chars, previous_start, previous_end):
    skip = len(chars)
    previous_len = previous_end - previous_start
    if previous_end + previous_len < len(chars):
        previous = get_cache(chars, previous_start, previous_end)
        suspicious_end = previous_end + previous_len
        suspicious = get_cache(chars, previous_end, previous_end + previous_len)
        if previous == suspicious:
            skip = suspicious_end

    max_k = 1
    for n in range(previous_end + 1, len(chars)):
        if n == skip:
            continue
        k = count_k(chars, previous_end, n) + 1
        if k == 1:
            continue
        if max_k >= k:
            break
        else:
            max_k = k
    return max_k


s = input()
print(count_k(list(s), 0, 0))

### FIXED CODE ###

s = input()
maximum = [(0, [()])]

s = tuple(s)
for i in range(1, len(s) + 1):
    j = i - 1
    while j >= 0:
        max_count, previous = maximum[j]
        if max_count < 0:
            j -= 1
            continue
        current = s[j:i]
        if any(p != current for p in previous):
            if len(maximum) == i + 1:
                mc, blocks = maximum[i]
                if mc == max_count + 1:
                    blocks.append(current)
                break
            else:
                maximum.append((max_count + 1, [current]))
        j -= 1
    else:
        if len(maximum) != i + 1:
            maximum.append((-1, []))
    assert len(maximum) == i + 1

print(maximum[-1][0])
S = input()
S[3] = '8'
print(S)


### FIXED CODE ###

S = list(input())
S[3] = '8'
print(''.join(S))
a,b,c,x,y=map(int,input().split())
ans=10**18
for i in range(max(x,y)+1):
    price=a*max(0,x-i)+b*max(0,y-i)+s*c*i
    ans = min(ans,price)
print(ans)

### FIXED CODE ###

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

cost1 = A * X + B * Y
cost2 = C * max([X, Y]) * 2

if X > Y:
    cost3 = C * Y * 2 + A * (X - Y)
else:
    cost3 = C * X * 2 + B * (Y - X)

print(min([cost1, cost2, cost3]))
X, Y, Z = int(input().split())

print((X-1)//(Y+Z))

### FIXED CODE ###

X,Y,Z = map(int, input().split())


print((X-Z)//(Z+Y))
n = int(input())

ds = list(map(int, input().split()))
ds.sort()

max_abc = ds[n/2 - 1]
min_arc = ds[n_2]

print(max_abc - min_arc)

### FIXED CODE ###

n = int(input())

ds = list(map(int, input().split()))
ds.sort()

max_abc = ds[int(n/2 - 1)]
min_arc = ds[int(n/2)]

print(min_arc - max_abc)
N = int(input().split()[0])
aa = input().split()
bb = []

for i in range(1, N+1):
    bb.append(aa.index(str(i+1)))

print(*bb)


### FIXED CODE ###

N = int(input().split()[0])
aa = input().split()
bb = [0]*N

for i in range(0, N):
    bb[int(aa[i]) - 1] = i + 1

print(*bb)
N=int(input())
S=list(input())
T=list(input()) 
sum=""
for i in range(N):
  sum+=S[i]
  sum+=T[i]
print(sum)

### FIXED CODE ###

N=int(input())
S,T=input().split()
sum=""
for i in range(N):
  sum+=S[i]
  sum+=T[i]
print(sum)
from __future__ import print_function
range = xrange
input = raw_input
import sys,bisect

from sys  import stdin,stdout

from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right

from math import gcd,ceil,floor,sqrt

from collections import Counter,defaultdict,deque,OrderedDict

dx=[-1,1,0,0]
dy=[0,0,1,-1]


sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 998244353
mod = 10**9+7

def isPrime(n):
    if (n <= 1) :return False
    if (n <= 3) :return True
    if (n%2 == 0 or n%3 == 0):return False
    for i in range(5,ceil(sqrt(n))+1,6):
        if (n%i==0 or n%(i+2)==0):
            return False
    return True

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def CC(d,v,i,l):
    v[i]=True
    stack=[i]
    c=1
    while stack:
        a=stack.pop()
        for i in d[a]:
            if not v[i]:
                stack.append(i)
                v[i]=True
                c+=1
    l.append(c)
    
def solve():
    n,m=mp()
    d={i:[] for i in range(1,n+1)}
    for i in range(m):
        a,b=mp()
        d[a].append(b)
        d[b].append(a)

    v=[False for i in range(n+1)]
    x=[]
    for i in range(1,n+1):
        if not v[i]:
            CC(d,v,i,x)


    x.sort()
    cd=0
    while sum(x)!=0:
        for i in range(len(x)):
            if x[i]>0:
                x[i]-=1
        cd+=1
    pr(cd)
        
        
    
for _ in range(1):
    solve()



### FIXED CODE ###

import sys,bisect

from sys  import stdin,stdout

from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right

from math import gcd,ceil,floor,sqrt

from collections import Counter,defaultdict,deque,OrderedDict

dx=[-1,1,0,0]
dy=[0,0,1,-1]


sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 998244353
mod = 10**9+7

def isPrime(n):
    if (n <= 1) :return False
    if (n <= 3) :return True
    if (n%2 == 0 or n%3 == 0):return False
    for i in range(5,ceil(sqrt(n))+1,6):
        if (n%i==0 or n%(i+2)==0):
            return False
    return True

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def CC(d,v,i,l):
    v[i]=True
    stack=[i]
    c=1
    while stack:
        a=stack.pop()
        for i in d[a]:
            if not v[i]:
                stack.append(i)
                v[i]=True
                c+=1
    l.append(c)
    
def solve():
    n,m=mp()
    d={i:[] for i in range(1,n+1)}
    for i in range(m):
        a,b=mp()
        d[a].append(b)
        d[b].append(a)

    v=[False for i in range(n+1)]
    x=[]
    for i in range(1,n+1):
        if not v[i]:
            CC(d,v,i,x)
           
    pr(max(x))
        
        
    
for _ in range(1):
    solve()
import sys

args = sys.argv

# print(args[0])

x1 = int(args[1])
x2 = int(args[2])

if (x1 * x2) % 2 == 0 :
    print("Even")
else:
    print("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
print("Even" if a*b % 2 == 0 else "Odd")
numpy as np

INPUT_1 = input()

N = int(INPUT_1.split(" ")[0])
M = int(INPUT_1.split(" ")[1])

A = np.empty(N)
B = np.empty(N)

for i in range(N):
    INPUT_AB = input()
    A[i] = int(INPUT_AB.split(" ")[0])
    B[i] = int(INPUT_AB.split(" ")[1])

num_drink = 0
drink_price = 0import

while num_drink < M:
    price = np.amin(A)
    store_index = np.argmin(A)
    num_drink += B[store_index]
    print(num_drink)
    if num_drink >= M:
        num_drink -= B[store_index]
        while num_drink < M:
            num_drink += 1
            drink_price += price
        
    else:
        drink_price += price * B[store_index]
        A = np.delete(A, store_index)
        B = np.delete(B, store_index)

print(drink_price)

### FIXED CODE ###

# 2150 start

import numpy

N,M=map(int, input().split())
price = numpy.empty((N,3))
sumcan = 0
sumprice = 0
lastshop = 0

for i in range(N):
    shop_data = input().split()
    A = int(shop_data[0])
    B = int(shop_data[1])
    price[i,0]= A * B
    price[i,1] = A
    price[i,2] = B

price = price[price[:,1].argsort(),:]

for j in range(M):
    sumcan = sumcan + price[j,2]
    if sumcan < M:
        sumprice = sumprice + price[j,0]
    elif sumcan >= M:
        sumcan = sumcan - price[j,2]
        lastshop = j
        break

sumprice = sumprice + (M - sumcan)*price[lastshop,1]

print(int(sumprice))
import math
a,b = input(),input()
c = int(a+b)
d = math.sqrt(c)
if c / d = d:
  print("Yes")

### FIXED CODE ###

a,b = input().split()
c = int(a + b)
d = []
for i in range(400):
  d.append(i**2)
if c in d:
  print("Yes")
else:
  print("No")
n=str(N)
if n.find(7)!=-1
   print("Yes")
else 
   print("No")

### FIXED CODE ###

n=str(input())
if n.find("7")!= -1:
   print("Yes")
else:
   print("No")
n, k = map(int, input().split())
A = []
for _ in range(n):
    t, d = map(int, input().split())
    A.append((d, t))
A.sort(reverse=True)
X = []
Y = []
st = set()
for d, t in A:
    if t in st:
        X.append(d)
    else:
        Y.append(d)
    st.add(t)
ans = 0
len_y = len(Y)
if len_y >= k:
    a = 0
    b = len_y - 1
    x = 0
    y = sum(Y[:k])
else:
    a = k - len_y
    b = len_y - 1
    x = sum(X[:k - len_y])
    y = sum(Y)
ans = x + y + len_y ** 2
t = ans
for i in range(min(len(X), k - 1)):
    x += X[a]
    a += 1
    y -= Y[b]
    b -= 1
    len_y -= 1
    t = x + y + len_y ** 2
    ans = max(ans, t)
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
A = []
for _ in range(n):
    t, d = map(int, input().split())
    A.append((d, t))
A.sort(reverse=True)
X = []
Y = []
st = set()
for i in range(k):
    d, t = A[i]
    if t in st:
        X.append(d)
    else:
        Y.append(d)
        st.add(t)
x = sum(X)
y = sum(Y)
v = len(Y)
ans = x + y + v ** 2
for i in range(k, n):
    if not X:
        break
    d, t = A[i]
    if t in st:
        continue
    st.add(t)
    x -= X.pop()
    y += d
    v += 1
    ans = max(ans, x + y + v ** 2)
print(ans)
K=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a=int(input())
print(K.index(a))

### FIXED CODE ###

K=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a=int(input())
print(K[a-1])
# 再帰関数で作る木の個数を返す
def dfs(now, end, summary):
    # 終了条件
    if now == end:
        return summary
    # 1つ前の頂点時点で作ることのできる木の個数 *（現在の深さ ^ その深さの頂点の数）で再帰関数
    else:
        return dfs(now + 1, end, summary * (now ** deep[now]))
# 最後に割る数の定数
JOSU = 998244353

# 入力
N = int(input())
D = list(map(int, input().split()))

# 深さをメモするため、Dの最大値 + 1の数の配列を用意
# 例：深さの最大が2なら、0, 1, 2の3つが必要
deep = [0] * (max(D) + 1)

# 各深さの頂点の数を記録
for i in range(N):
    deep[D[i]] += 1

# 深さ0の頂点が1以外なら、木ができないため0を返す
if deep[D[0]] != 1:
    print(0)
# 深さ0の頂点のみなら、1を返す
elif len(deep) == 1:
    print(1)
# それ以外なら各深さの辺のつけ方を計算して返す
else:
    print(dfs(1, len(deep), 1) % JOSU)



### FIXED CODE ###

# 再帰関数の最大再帰回数を変更
import sys
sys.setrecursionlimit(1000000)

# 再帰関数で作る木の個数を返す
def dfs(now, end, summary):
    # 終了条件
    if now == end:
        return summary
    # 1つ前の頂点時点で作ることのできる木の個数 *（１つ前の深さの頂点の数 ^ 現在の深さの頂点の数）で再帰関数
    else:
        return dfs(now + 1, end, summary * (deep[now - 1] ** deep[now]))

# 最後に割る数の定数
JOSU = 998244353

# 入力
N = int(input())
D = list(map(int, input().split()))

# 深さをメモするため、Dの最大値 + 1の数の配列を用意
# 例：深さの最大が2なら、0, 1, 2の3つが必要
deep = [0] * (max(D) + 1)

# 各深さの頂点の数を記録
for i in range(N):

    # 頂点1が深さ0以外なら制約違反
    if i == 0 and D[i] != 0:
        print(0)
        exit()
    # 頂点1以外が深さ0なら制約違反
    elif i > 0 and D[i] == 0:
        print(0)
        exit()

    deep[D[i]] += 1

# 再帰関数で計算
print(dfs(1, len(deep), 1) % JOSU)
K = input()

list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(list[int(K)])

### FIXED CODE ###

K = input()



list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]


print(list[int(K) -1])
# -*- coding: utf-8 -*-

a, b, c = map(int, input().split())
return c - a + b

### FIXED CODE ###

# -*- coding: utf-8 -*-
 
a, b, c = map(int, input().split())
rest = a - b
if c - rest < 0:
  print(0)
else:
  print (c - a + b)
import sys
x = int(sys.argv[1])
print(x**3)


### FIXED CODE ###

x = input()
print(x**3)
import math

def str2list(str):
	result = []
	for value in str.split(' '):
		result.append(int(value))
	return result

def distance1(n, x, y):
	result = 0
	for i in range(n):
		result += abs(x[i] - y[i])
		
	return result
	
def distance2(n, x, y):
	result = 0
	for i in range(n):
		result += (x[i] - y[i]) * (x[i] - y[i])
		
	return math.sqrt(result)
	
def distance3(n, x, y):
	result = 0
	for i in range(n):
		result += math.pow(abs(x[i] - y[i]), 3)
		
	return math.exp(math.log(result)/3)
	
def distanceInf(n, x, y):
	result = 0
	for i in range(n):
		new_result = abs(x[i] - y[i])
		result = new_result if new_result > result else result
		
	return result

n = int(input());
x = str2list(input())
y = str2list(input())

print('%.6f'%distance1(n, x, y))
print('%.6f'%distance2(n, x, y))
print('%.6f'%distance3(n, x, y))
print('%.6f'%distanceInf(n, x, y))

### FIXED CODE ###

import math

def str2list(str):
	result = []
	for value in str.split(' '):
		result.append(int(value))
	return result

def distance1(n, x, y):
	result = 0
	for i in range(n):
		result += abs(x[i] - y[i])
		
	return result
	
def distance2(n, x, y):
	result = 0
	for i in range(n):
		result += (x[i] - y[i]) * (x[i] - y[i])
		
	return math.sqrt(result) if result != 0 else 0
	
def distance3(n, x, y):
	result = 0
	for i in range(n):
		result += math.pow(abs(x[i] - y[i]), 3)
		
	return math.exp(math.log(result)/3) if result != 0 else 0
	
def distanceInf(n, x, y):
	result = 0
	for i in range(n):
		new_result = abs(x[i] - y[i])
		result = new_result if new_result > result else result
		
	return result

n = int(input());
x = str2list(input())
y = str2list(input())

print('%.6f'%distance1(n, x, y))
print('%.6f'%distance2(n, x, y))
print('%.6f'%distance3(n, x, y))
print('%.6f'%distanceInf(n, x, y))
R, C = map(int, input().split())
c = [list(input()) for _ in range(R)]
d = {}
q = [(0, 0, 0)]
d[0, 0] = 0
while q != []:
    (y, x, z) = q.pop(0)
    for v, w in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        t = x + v
        u = y + w
        if t < 0 or t >= C or u < 0 or u >= R:
            continue
        if c[u][t] == '.' and (u, t) not in d:
            q.append((u, t, z + 1))
            d[u, t] = z + 1
ans = R * C - d[R - 1, C - 1] - 1
for i in c:
    for j in i:
        if j == '#':
            ans -= 1
print(ans)

### FIXED CODE ###

R, C = map(int, input().split())
c = [list(input()) for _ in range(R)]
d = {}
q = [(0, 0, 0)]
d[0, 0] = 0
while q != []:
    (y, x, z) = q.pop(0)
    for v, w in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        t = x + v
        u = y + w
        if t < 0 or t >= C or u < 0 or u >= R:
            continue
        if c[u][t] == '.' and (u, t) not in d:
            q.append((u, t, z + 1))
            d[u, t] = z + 1
if (R - 1, C - 1) not in d:
    ans = -1
else:
    ans = R * C - d[R - 1, C - 1] - 1
    for i in c:
        for j in i:
            if j == '#':
                ans -= 1
print(ans)
t = list(input())
t.reverse()

tmptmp = "P"
for i in range(len(t)):
    if i == 0:
        tmp = t[i]
        continue
    if tmp == "?" and tmptmp == "P":
        t[i-1] = "D"
    elif tmp == "?" and tmptmp == "D" and t[i] == "P":
        t[i-1] = "D"
    elif tmp == "?" and tmptmp == "D" and t[i] == "D":
        t[i-1] = "P"
    tmptmp = t[i-1]
    tmp = t[i]

t.reverse()

if t[0] == "?" and t[1] == "D":
    t[0] = "P"
elif t[0] == "?" and t[1] == "P":
    t[0] = "D"

t = "".join(t)
print(t)


### FIXED CODE ###

t = list(input())
t.reverse()

tmptmp = "P"
for i in range(len(t)):
    if i == 0:
        tmp = t[i]
        continue
    if tmp == "?" and tmptmp != "D":
        t[i-1] = "D"
    elif tmp == "?" and tmptmp == "D" and t[i] != "D":
        t[i-1] = "D"
    elif tmp == "?" and tmptmp == "D" and t[i] == "D":
        t[i-1] = "P"
    tmptmp = t[i-1]
    tmp = t[i]

t.reverse()

if len(t) > 1:
    if t[0] == "?" and t[1] == "D":
        t[0] = "P"
    elif t[0] == "?" and t[1] == "P":
        t[0] = "D"

if len(t) == 1:
    t[0] = "D"

t = "".join(t)
print(t)
import sys
input = sys.stdin.readline
from collections import deque
N,M=map(int,input().split())
table=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    table[a].append(b)
    table[b].append(a)
Q=int(input())
X=[[int(i) for i in input().split()] for i in range(Q)]
color=[0]*Q
dp=[[-1]*N for i in range(10)]
for i in range(Q-1,-1,-1):
    v, d, c=X[i]
    v=v-1
    color[i]=c
    dp[d][v]=i

for d in range(9,0,-1):
    for x in range(N):
        for y in table[x]:
            dp[d-1][y]=max(dp[d][x],dp[d-1][y])
for i in range(N):
    s=-1
    for d in range(10):
        s=max(s,dp[d][i])
    if s==-1:
        print(0)
    else:
        print(color[s])




### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque
N,M=map(int,input().split())
table=[[] for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    table[a].append(b)
    table[b].append(a)
Q=int(input())
X=[[int(i) for i in input().split()] for i in range(Q)]
color=[0]*Q
dp=[[-1]*N for i in range(11)]
for i in range(Q-1,-1,-1):
    v, d, c=X[i]
    v=v-1
    color[i]=c
    dp[d][v]=max(dp[d][v],i)

for d in range(10,0,-1):
    for x in range(N):
        for y in table[x]:
            dp[d-1][y]=max(dp[d][x],dp[d-1][y])
for i in range(N):
    s=-1
    for d in range(11):
        s=max(s,dp[d][i])
    if s==-1:
        print(0)
    else:
        print(color[s])
input(x)
print(x*x*x)


### FIXED CODE ###

x = int(input(''))
print(x*x*x)
lis=[]
lis.append(int(input()))
lis.append(int(input()))
lis.append(int(input()))
lis.append(int(input()))
lis.append(int(input()))
ans=0
lis_h=[]
for i in range(5):
        hito=int(str(lis[i])[-1])
        time=lis[i]
        if hito==0:
                ans+=time
        else:
                lis_h.append([hito,time])
lis_h.sort()
ans+=lis_h[0][1]

for i in range(len(lis_h)):
        if i==0:
                continue
        num = (lis_h[i][1]//10) * 10
        if lis_h[i][0] != 0:
                num+=10
        ans+=num

print(ans)

### FIXED CODE ###

lis=[]
lis.append(int(input()))
lis.append(int(input()))
lis.append(int(input()))
lis.append(int(input()))
lis.append(int(input()))
ans=0
lis_h=[]
for i in range(5):
        hito=int(str(lis[i])[-1])
        time=lis[i]
        if hito==0:
                ans+=time
        else:
                lis_h.append([hito,time])
lis_h.sort()

if len(lis_h)==0:
        print(ans)
        exit()
ans+=lis_h[0][1]

for i in range(len(lis_h)):
        if i==0:
                continue
        num = (lis_h[i][1]//10) * 10
        if lis_h[i][0] != 0:
                num+=10
        ans+=num

print(ans)