Harryxun/stf_run huggingface dataset:
#ABC138D
def main():
    import sys
    N, Q = map(int, sys.stdin.readline().split())
    ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N-1)]
    px = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]
    
    edge = [[] for _ in range(N)]
    #有向グラフ
    for row in ab:
        edge[row[0]-1].append(row[1]-1)
    #print(edge)
    point_list = [0 for i in range(N)]
    for row in px:
        point_list[row[0]-1] += row[1]
    #print(point_list)
    
    sys.setrecursionlimit(1000)
    visited = [-1 for _ in range(N)]
    visited[0] = 0
    def dfs(p):
        for c in edge[p]:
            if visited[c]==-1:
                visited[c]=0
                point_list[c] +=point_list[p]
                dfs(c)
            
    
    dfs(0)
    #print(visited)
    print(point_list)
        



if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(1000000)

n,q = map(int, input().split())
a_b = [list(map(int, sys.stdin.readline().split())) for _ in range(n-1)]
p_x = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

v = [deque([]) for i in range(n)]
for e in a_b:
    v[e[0]-1]+=[e[1]-1]
    v[e[1]-1]+=[e[0]-1]
score = [0 for i in range(n)]
for e in p_x:
    score[e[0]-1]+=e[1]
def dfs(p, bp=-1):
    while v[p]:
        c =v[p].popleft()
        if c ==bp:
            continue
        #print(p, c, bp)
        score[c]+=score[p]
        dfs(c, bp=p)
visited = [0]                
dfs(0)
print(*score)
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)] # a_0...a_(M-1)

def f(x): # フィボナッチ数列
    if x == 0:
        return(1)
    elif x == 1:
        return(1)
    elif x == 2:
        return(2)
    else:
        return(f(x-1) + f(x-2))

ans = 0
MOD = 10**9 + 7

for i in range(M+1): # iは0からM
    if i == 0:
        ans += f((a[0]-1) - 0) % MOD # 0段目からa_0-1段目に上る(その後a_0段目を飛ばしてa_0+1段目に上る)
    elif i == M:
        ans *= f(N - (a[M-1] + 1)) % MOD # a_M-1段目からN段目に上る
    else: # iは1からM-1
        stair = (a[i] - 1) - (a[i-1] + 1) # 登る段数
        if stair >= 0:
            ans *= f(stair) % MOD # a_(i-1)+1段目からa_i-1段目に上る(その後a_i段目を飛ばしてa_i+1段目に上る)
        else:
            ans = 0
            break

print(ans % MOD)

### FIXED CODE ###

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)] # a_0...a_(M-1)

def f(x):
    a, b = 1, 1
    if x == 0:
        return a
    elif x == 1:
        return b
    else:
        for i in range(x-1):
            a, b = b, a + b
        return b
"""
# 再帰だとTLEとかREとかになるよ
def f(x): # フィボナッチ数列
    if x == 0:
        return(1)
    elif x == 1:
        return(1)
    else:
        return(f(x-1) + f(x-2))
"""

ans = 0
MOD = 10**9 + 7

if M == 0:
    ans += f(N) % MOD
    print(ans)
else:
    ans += f((a[0]-1) - 0) % MOD # 0段目からa_0-1段目に上る(その後a_0段目を飛ばしてa_0+1段目に上る)
    for i in range(1, M): # iは1からM-1
        stair = (a[i] - 1) - (a[i-1] + 1) # 登る段数
        if stair >= 0:
            ans *= f(stair) % MOD # a_(i-1)+1段目からa_i-1段目に上る(その後a_i段目を飛ばしてa_i+1段目に上る)
        else:
            ans = 0
            break
    ans *= f(N - (a[M-1] + 1)) % MOD # a_M-1段目からN段目に上る
    print(ans % MOD)
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

k=int(input())
n=len(input())
ans=0
for i in range(k,-1,-1):
  ans=(ans+cmb(k+n,i)*pow(25,i,mod))%mod
print(ans)

### FIXED CODE ###

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

k=int(input())
n=len(input())
ans=0
for i in range(k,-1,-1):
  ans=(ans+cmb(k+n,i)*pow(25,i,mod))%mod
print(ans)
N = input()
input_data = [input() for i in range(N)]

num = 0
#while input_data[num] > 0 :
#	print("Case","{0}:".format(num+1),"{1}".format(input_data[num]))
#	num+=1

### FIXED CODE ###

input_data = []
while 1:
	n = int(input())
	if n == 0:
		break
	input_data.append(n)
n=0
for i in input_data:
	print("Case {}:".format(n+1),"{}".format(input_data[n]))
	n+=1
n = list(map(int, input().split()))
for i in range(3):
  if n[i] == 7:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

n = list(input())
n = list(map(int, n))
if 7 in n:
    print('Yes')
else:
    print('No')
import math
def gcd(a,b):
    if a == 0 or b == 0:
        return max(a,b)
    else:
        return math.gcd(a,b)


N = int(input())
A = [int(i) for i in input().split()]

L = [0]
R = [0]
for i in range(N):
    L.append(gcd(L[-1],A[i]))
    R = [gcd(R[0],A[N-1-i])] + R
M = [gcd(i,j) for i,j in zip(L[:-1],R[1:])]
print(max(M))

### FIXED CODE ###

from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
gcda = [A[0]]
gcdb = [A[-1]]
for i in range(N-2):
    gcda.append(gcd(gcda[-1],A[i+1]))
    gcdb.append(gcd(gcdb[-1],A[-(i+2)]))
gcdb.reverse()
GC = [gcdb[0]]
for i in range(N-2):
    GC.append(gcd(gcda[i],gcdb[i+1]))
else:
    GC.append(gcda[-1])
print(max(GC))
from collections import*
c=Counter.most_common
n=int(input())
n_l =[int(input()) for i in range(n)]
m=int(input())
m_l =[int(input()) for i in range(m)]
d=n_l.c()[0][1]-m_l.c()[-1][1]
if d <=0:print(0)
else:print(d)

### FIXED CODE ###

n=int(input())
nl=[input() for i in range(n)]
m=int(input())
ml=[input() for i in range(m)]
nsl=list(set(nl))
mx=0
for x in range(len(nsl)):
	d=nl.count(nsl[x])-ml.count(nsl[x])
	if d>mx:mx=d
print(max(0,mx))
a,b=list(map(int, input().split()))
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def md(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def coprime(a, b):
    return gcd(a, b) == 1

c = md(gcd(a,b))
c.sort()
if len(c)== 1:
    print(1)
else:
    count = 1
    d = c[0]
    for i in c[1:]:
        if coprime(d, i):
            d = d*i
            count += 1
        else:
            continue

print(count)

### FIXED CODE ###

a,b=list(map(int, input().split()))
def gcd(a,b):
    while b:
        a, b = b, a%b
    return a

def md(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def coprime(a, b):
    return gcd(a, b) == 1

c = md(gcd(a,b))
c.sort()
if len(c)== 1:
    count = 1
else:
    count = 1
    d = c[0]
    for i in c[1:]:
        if coprime(d, i):
            d = d*i
            count += 1
        else:
            continue

print(count)
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def check(node_hash_list, edge_color_hash, next_node, node, color):
    if node > next_node:
        edge_color_hash[str(next_node) + " " + str(node)] = color
    else:
        edge_color_hash[str(node) + " " + str(next_node)] = color
    new_color = 1
    max_color = color
    if next_node in node_hash_list:
        for new_next_node in node_hash_list[next_node]:
            if color == new_color:
                new_color += 1
            if max_color < new_color:
                max_color = new_color
            temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
            new_color += 1
            if max_color < temp_color:
                max_color = temp_color
    return max_color
n = int(input())
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    node_hash_list[a].append(b)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    edge_color_hash[str(next_node) + " " + str(node)] = color
    new_color = 1
    max_color = color
    for new_next_node in node_hash_list[next_node]:
        if new_next_node == node:
            continue
        if color == new_color:
            new_color += 1
        if max_color < new_color:
            max_color = new_color
        temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
        new_color += 1
        if max_color < temp_color:
            max_color = temp_color
    return max_color
n = int(input())
sys.setrecursionlimit(n * 10)
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    if b not in node_hash_list:
        node_hash_list[b] = []
    node_hash_list[a].append(b)
    node_hash_list[b].append(a)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])
# -*- config: utg-8 -*-

n = int(input())
s = [input() for i in range(n)]

sort_list = []

for i in s:
	str_sort_list = sorted(i)
	new_str = ''.join(str_sort_list)
	sort_list.append(new_str)

count = 0
for i in sort_list[:]:
  hoge = sort_list.pop(0)
  chohuku_count = sort_list.count(hoge)
  
  count += chohuku_count
  

print(count)

### FIXED CODE ###

# -*- config: utg-8 -*-

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

a = i[0]
b = i[1]

wa = a + b
sa = a- b
seki = a * b

print(max(wa,sa,seki))
A,B = map(int,input().split())
print(A*B)

### FIXED CODE ###

A,B = map(float,input().split())
a = round(B*100)
b = int(A)
print(a*b//100)
# -*- coding: utf-8 -*-

s = list(input())
line = []
for w in s:
    if w == '0':
        line.append(w)
    elif w == '1':
        line.append(w)
    elif w == 'B':
        line.pop()

for n in line:
    print('{0}'.format(n), end='')

### FIXED CODE ###

# -*- coding: utf-8 -*-

s = list(input())
line = []
for w in s:
    if w == '0':
        line.append(w)
    elif w == '1':
        line.append(w)
    elif w == 'B' and line:
        line.pop()

for n in line:
    print('{0}'.format(n), end='')
n,T=map(int, input().split())

x=[]

for i in range(n):
    c,t=map(int, input().split())
    if t<=T:
        x.append((i+1,c))
        
x.sort(key=lambda tup: tup[1])

print(x[0][0])

### FIXED CODE ###

N,T=map(int,input().split())
c=[]
mn=1001
for i in range(N):
    cost,time=map(int,input().split())
    if time<=T:
        c.append(cost)
for i in c:
    if i<=mn:
        mn=i
if len(c)==0:
    print('TLE')
else:
    print(mn)
N,M=map(int,input().split())
G=[[] for _ in range(N)]
for _ in  range(M):
    xi,yi=map(int,input().split())
    G[xi-1].append(yi-1)

dp=[-1]*(N+1) #各ノードを始点とした時の最長経路

def rec(v):
    if dp[v]!=-1:
        return dp[v]
    
    res=0

    for nv in G[v]:
        res=max(res,rec(nv)+1)
    
    dp[v]=res
    return res

ans=0
for v in range(N):
    ans=max(ans,rec(v))
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5+100)

N,M=map(int,input().split())
G=[[] for _ in range(N)]
for _ in  range(M):
    xi,yi=map(int,input().split())
    G[xi-1].append(yi-1)

dp=[-1]*N #各ノードを始点とした時の最長経路

def rec(v):
    if dp[v]!=-1:
        return dp[v]
    
    res=0

    for nv in G[v]:
        res=max(res,rec(nv)+1)
    
    dp[v]=res
    return res

ans=0
for v in range(N):
    ans=max(ans,rec(v))
print(ans)
a = int(inpu())
b = int(inpu())
c = int(inpu())
x = int(inpu())
res = 0
for i in range(a):
  for j in range(b):
    for k in range(c):
      total = i * 500 + j * 100 + c * 50
      if total == x:
        res += 1

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
x = int(input())
res = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      total = i*500 + j*100 + k*50
      if total == x:
        res += 1
print(res)
import sys

#+++++
		
def main():
	n, k = map(int, input().split())
	aal = list(map(int, input().split()))
	
	sss = [0]*(n+1)
	si=0
	for i, a in enumerate(aal):
		si+=a-1
		sss[i+1]=si%k
	
	count=0
	mkl=[0]*k
	for j in range(n+1):
		sj=sss[j]
		for i in range(j-1, max(-1, j-k), -1):
			si=sss[i]
			pa((j,i,sj, si, (sj - si) % k))
			if (sj - si) % k == 0:
				#pa((i,j))
				count+=1
	
	print(count)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

### FIXED CODE ###

import sys
from collections import defaultdict

#+++++
		
def main():
	n, k = map(int, input().split())
	aal = list(map(int, input().split()))
	
	sss = [0]*(n+1)
	si=0
	for i, a in enumerate(aal):
		si+=a-1
		sss[i+1]=si%k
	
	count=0
	mkl_dict=defaultdict(lambda :0)
	for j in range(n+1):
		sj=sss[j]
		if j-k >= 0:
			mkl_dict[sss[j-k]]-=1
		count += mkl_dict[sj]
		mkl_dict[sj] += 1
			
	print(count)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
from itertools import product
n = int(input())
if n%2 == 0:
  print(n,n,n//2)
else:
  for h,l in product(range(2,3501),repeat=2):
    m = n*h*l
    c = 4*h*l - n*(h+l)
    if c >= 0 and m%c == 0:
      w = m//c
      break
  print(h,l,w)

### FIXED CODE ###

from itertools import product
n = int(input())
if n%2 == 0:
  print(n,n,n//2)
else:
  for h,l in product(range(max(2, n//4),3501),repeat=2):
    m = n*h*l
    c = 4*h*l - n*(h+l)
    if c > 0 and m%c == 0:
      w = m//c
      break
  print(h,l,w)
n = int(input())
heigt = list(map(int, input().split()))

cost = [0] * n
cost[0] = 0
cost[1] = abs(heigt[1] - heigt[0])
cost[2] = abs(heigt[2] - heigt[0])

for i in range(3,n):
    cost[i] = min(cost[i-1] + abs(heigt[i] - heigt[i-1]),cost[i-2] + abs(heigt[i] - heigt[i-2]))

print(cost[n-1])

### FIXED CODE ###

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

cost = [0] * n
cost[0] = 0
cost[1] = abs(heigt[1] - heigt[0])
if n == 2:
    print(cost[1])
else:
    cost[2] = abs(heigt[2] - heigt[0])
    if n == 3:
        print(cost[2])
    else:
        for i in range(3,n):
            cost[i] = min(cost[i-1] + abs(heigt[i] - heigt[i-1]),cost[i-2] + abs(heigt[i] - heigt[i-2]))

        print(cost[n-1])
#!/usr/bin/env python3
import sys
import math

def solve(N: int, A: "List[int]"):
    res = A[0]
    for a in A[1:]:
        res = math.gcd(res,a)
    print(res)

# Generated by 1.1.4 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
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math

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

def solve(N: int, A: "List[int]"):
    res = A[0]
    B = A[1:]
    for a in B:
        res = gcd(res,a)

    print(res)

# Generated by 1.1.4 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
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
A,B,C=map(int,raw_input().split())
if B/A>C
print C
else:
  print B/A 

### FIXED CODE ###

A,B,C=map(int,raw_input().split())
if B/A>C:
    print C
else:
    print B/A
import time
from collections import deque
tstart=time.time()
N=int(input())
M=(N*(N-1))//2
D=dict()
tmp=0
X=[(0,0) for i in range(M)]
G=[[] for i in range(M)]
for i in range(1,N+1):
    for j in range(1,N+1):
        if i<j:
            D[(i,j)]=tmp
            X[tmp]=(i,j)
            tmp+=1
A=[[int(j) for j in input().split()] for i in range(N)]
for i in range(N):
    for j in range(N-2):
        p1=D[(i+1,A[i][j])] if i+1<A[i][j] else D[(A[i][j],i+1)]
        p2=D[(i+1,A[i][j+1])] if i+1<A[i][j+1] else D[(A[i][j+1],i+1)]
        G[p1].append(p2)
K=[0 for i in range(M)]
for i in range(M):
    for p in G[i]:
        K[p]+=1
q=deque(i for i in range(M) if K[i]==0)
res=[]
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in G[v1]:
        K[v2]-=1
        if K[v2]==0:
            q.append(v2)
#print(D)
#print(res)
if len(res)<M:
    print(-1)
    exit()
def isok(x,y):
    a,b=X[x]
    c,d=X[y]
    if len({a,b,c,d})<4:
        return False
    else:
        return True
invres=[0 for i in range(M)]
for i in range(M):
    invres[res[i]]=i
#print(invres)
Y=[0 for i in range(M)]
for i in res:
    for j in G[i]:
        Y[invres[j]]=max(Y[invres[j]],invres[i]+1)
#print(Y)
dp=[0 for i in range(M)]
dp[0]=1
for i in range(1,M):
    flag=0
    for j in range(Y[i],i):
        if isok(res[i],res[j]):
            flag=1
            break
    if flag==0:
        dp[i]=dp[i-1]+1
    else:
        dp[i]=dp[i-1]
tfin=time.time()
if tfin-tstart<1:
    print([0,0][3])
print(dp[-1])


### FIXED CODE ###

from collections import deque
N=int(input())
M=(N*(N-1))//2
D=dict()
tmp=0
X=[(0,0) for i in range(M)]
G=[[] for i in range(M)]
for i in range(1,N+1):
    for j in range(1,N+1):
        if i<j:
            D[(i,j)]=tmp
            X[tmp]=(i,j)
            tmp+=1
A=[[int(j) for j in input().split()] for i in range(N)]
for i in range(N):
    for j in range(N-2):
        p1=D[(i+1,A[i][j])] if i+1<A[i][j] else D[(A[i][j],i+1)]
        p2=D[(i+1,A[i][j+1])] if i+1<A[i][j+1] else D[(A[i][j+1],i+1)]
        G[p1].append(p2)
K=[0 for i in range(M)]
for i in range(M):
    for p in G[i]:
        K[p]+=1
q=deque(i for i in range(M) if K[i]==0)
res=[]
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in G[v1]:
        K[v2]-=1
        if K[v2]==0:
            q.append(v2)
#print(D)
#print(res)
if len(res)<M:
    print(-1)
    exit()
ans=[0 for i in range(M)]
ans[res[-1]]=1
for i in res[:-1][::-1]:
    if len(G[i])==0:
        ans[i]=1
    else:
        for j in G[i]:
            ans[i]=max(ans[i],ans[j]+1)
print(max(ans))
import math

if __name__ == "__main__":
    A, B = input().split()
    A = int(A)
    B = int(B)
    ret = (A * B) // math.gcd(A, B)
    print(ret)


### FIXED CODE ###

import fractions

if __name__ == "__main__":
    A, B = input().split()
    A = int(A)
    B = int(B)
    ret = (A * B) // fractions.gcd(A, B)
    print(ret)
A = input()
B = input()
x = 0
for i in range(3):
  if a(i) == b(i):
    x += 1
print(x)

### FIXED CODE ###

A = input()
B = input()
x = 0
for i in range(3):
  if A[i] == B[i]:
    x += 1
print(x)
# -*- coding: utf-8 -*-

# input
s = input()

# solve
for i in range(len(s)):
    if s[i] == 'A':
        a = i
        break

for i in reversed(range(len(s))):
    if s[i] == 'Z':
        z = i
        break

# output
print(z - a + 1)


### FIXED CODE ###

x=int(input())
if 1200>x:
  print("ABC")
  
else:
  print("ARC")
H,W = map(int,input().split())
C = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]


inf = 10**9+7

point = [inf] * 10


for i in range(10):
    tmp = 0
    for j in range(10):
        tmp += C[i][j]
        point[i] = min(point[i],tmp+C[j][1])
        
ans = 0
for i in range(H):
    for j in range(W):
        if H[i][j] != -1:
            ans += point[H[i][j]]
            
print(ans)

### FIXED CODE ###

H,W = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

N  = 10
d = c
for k  in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])

ans = 0
for aa in A:
    for a in aa:
        if a!=-1:
           ans += d[a][1]
           
print(ans)
N = int(input())

if N == 0:
    print(2)
elif N == 1:
    print(1)
    exit()

L0 = 2; L1 = 1
for _ in range(N-2):
    L2 = L1 + L0
    L1, L0 = L2, L1
print(L2)    


### FIXED CODE ###

N = int(input())

if N == 0:
    print(2)
elif N == 1:
    print(1)
    exit()

L0 = 2; L1 = 1
for _ in range(2, N+1):
    L2 = L1 + L0
    L1, L0 = L2, L1
print(L2)
N, M = map(int, input().split())
Hi = list(map(int,input().split(" ")))
path = [list() for _ in range(M+1)]

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

goodT = 0
T = range(M)

for i, p in zip(T, path):
    good = 1
    if p == []:
        goodT += good
    else:
        for t in p:
            if Hi[i] <= Hi[t]:
                good = 0
        goodT +=good
        
print (goodT)

### FIXED CODE ###

N, M = map(int, input().split())
Hi = list(map(int,input().split(" ")))
#path = [list() for _ in range(M+1)]

Tallest = [0]*N

for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    Tallest[a] = max(Tallest[a], Hi[b])
    Tallest[b] = max(Tallest[b], Hi[a])

goodT = 0

for i in range(N):
    if Hi[i]>Tallest[i]:
        goodT +=1
    
print (goodT)
from collections import namedtuple

Point = namedtuple('Point', ('x', 'y', 'h'))

def main():
    n = int(input())
    points = [read_point() for _ in range(n)]
    print(*solve(points))

def solve(points):
    for x in range(0, 101 + 1):
        for y in range(0, 100 + 1):
            h = points[0].h + abs(points[0].x - x) + abs(points[0].y - y)
            for p in points[1:]:
                h2 = p.h + abs(p.x - x) + abs(p.y - y)
                if (p.h > 0 and h2 != h) or h2 > h:
                    break
            else:
                return Point(x, y, h)

def read_point():
    x, y, h = map(int, input().split())
    return Point(x, y, h)

main()


### FIXED CODE ###

from collections import namedtuple

Point = namedtuple('Point', ('x', 'y', 'h'))

def main():
    n = int(input())
    points = [read_point() for _ in range(n)]
    print(*solve(points))

def solve(points):
    for p in points:
        if p.h != 0:
            base = p
            break

    for x in range(0, 101 + 1):
        for y in range(0, 100 + 1):
            h = base.h + abs(base.x - x) + abs(base.y - y)
            for p in points:
                ph = max(h - abs(x - p.x) - abs(y - p.y), 0)
                if ph != p.h:
                    break
            else:
                return Point(x, y, h)

def read_point():
    x, y, h = map(int, input().split())
    return Point(x, y, h)

main()
n, k = map(int, input().split())
list_H = [int(input()) for _ in range(n)]

list_H.sort()
ans = []

for i in range(n-k+1):
    ans.append(list_H[i+2]-list_H[i])

print(min(ans))

### FIXED CODE ###

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

list_H.sort()
ans = []

for i in range(n-k+1):
    ans.append(list_H[i+k-1]-list_H[i])

print(min(ans))