Harryxun/stf_run huggingface dataset:
counter = 0

def merge(L, R, left, right):
    A=[]
    L.append(float('inf'))
    R.append(float('inf'))

    i,j=(0,0)
    global counter
    for n in range(0,right-left):
        counter = counter+1
        if L[i]<=R[j]:
            A[n]=L[i]
            i=i+1
        else:
            A[n]=R[j]
            j=j+1
    return A

def mergeSort(A, left, right):
    if left+1 < right:
        mid = int((left+right)/2)
        L = mergeSort(A[left:mid],0,mid-left)
        R = mergeSort(A[mid:right],0,right-mid)
        A = merge(L, R, left, right)
    return A

n = int(input())
l = list(map(int,input().split()))
ll = mergeSort(l,0,n)
print(*ll)
print(counter)

### FIXED CODE ###

counter = 0

def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    #print(L)
    #print(R)
    L.append(float('inf'))
    R.append(float('inf'))
    i=j=0
    global counter
    for k in range(left,right):
        counter = counter+1
        if L[i]<=R[j]:
            A[k]=L[i]
            i=i+1
        else:
            A[k]=R[j]
            j=j+1

def mergeSort(A, left, right):
    if left+1<right:
        mid=(left+right)//2
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)

n = int(input())
l = list(map(int,input().split()))
mergeSort(l,0,n)
print(*l)
print(counter)
N = int(input())

s = 1
while N > 26 ** s:
    N -= 26 ** s
    s += 1

ans = ""
N -= 1
for i in range(s):
    ans += chr(ord("a") + ord(N % 26))
    N = N // 26

print(ans[::-1])

### FIXED CODE ###

N = int(input())

s = 1
while N > 26 ** s:
    N -= 26 ** s
    s += 1

ans = ""
N -= 1
for i in range(s)[::-1]:
    a = N // (26 ** i)
    N -= (26 ** i) * a
    ans += chr(ord("a") + a)
    
print(ans)
S = input()
S_len = len(S)
S_list = list(S)
ans = ''

if S_len == 2:
    print(S)

elif S_len == 3:
    S_reverse = sorted(S, reverse=True)
    for i in range(S_len):
        ans += S_reverse[i]
    pr

### FIXED CODE ###

S = input()
S_len = len(S)
S_list = list(S)
ans = ''

if S_len == 2:
    print(S)

elif S_len == 3:
    for i in range(S_len-1, -1, -1):
        ans += S_list[i]
    print(ans)
B = int(input())
C = int(input())
D = int(input())

if A <= B:
    densya = A

else:
    densya = B

if C <= D:
    bus = C

else:
    bus = D

untin = densya + bus

print(untin)

### FIXED CODE ###

A = int(input())
B = int(input())
C = int(input())
D = int(input())

if A <= B:
    densya = A

else:
    densya = B

if C <= D:
    bus = C

else:
    bus = D

untin = densya + bus

print(untin)
s=input()

def hoge(str)
	if(str == ""):
  		return "YES"
	if(str.startWith("dream")):
		return hoge(str.rstrip("dream"))
	if(str.startWith("dreamer")):
		return hoge(str.rstrip("dreamer"))
	if(str.startWith("erase")):
		return hoge(str.rstrip("erase"))
	if(str.startWith("eraser")):
		return hoge(str.rstrip("eraser"))
	return "NO"

print(hoge(s))

### FIXED CODE ###

def main():
    S = input()

    while len(S) >= 5:
        if len(S) >= 7 and S[-7:] == "dreamer":
            S = S[:-7]
            continue

        if len(S) >= 6 and S[-6:] == "eraser":
            S = S[:-6]
            continue

        elif S[-5:] == "dream" or S[-5:] == "erase":
            S = S[:-5]
            continue

        else:
            break

    if len(S) == 0:
        print("YES")
    else:
        print("NO")

main()
n = int(input())
a = int(input()).split()
a.sort()
if a[0] == 0:
  print(0)
  return
ans = 1
for i in range(n):
  ans *= a[i]
  if ans > 10**18:
    print(-1)
    return
print(ans)

### FIXED CODE ###

import sys
n = int(input())
a = list(map(int,input().split()))
a.sort()
if a[0] == 0:
  print(0)
  sys.exit()
ans = 1
for i in range(n):
  ans *= a[i]
  if ans > 10**18:
    print(-1)
    sys.exit()
print(ans)
a,b = map(int,input())
print(a/b)

### FIXED CODE ###

a,b = map(int,input().split())
print(a/b)
A,B,M=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(M)]
ans = []
for i in range(M):
  ans.append(a[xyc[i][0]-1]+a[xyc[i][1]-1]-xyc[i][2])
mi=min(a)+min(b)
print(min(min(ans),mi))

### FIXED CODE ###

A,B,M=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(M)]
ans = []
for i in range(M):
  ans.append(a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2])
mi=min(a)+min(b)
print(min(min(ans),mi))
import math
i=int(raw_input())
print "%.6f %.6f" % (i*i*math.pi,2*i*math.pi)

### FIXED CODE ###

import math
i=float(raw_input())
print "%.6f %.6f" % (i*i*math.pi,2*i*math.pi)
import itertools

N = int(input())
params = []
for i in range(N):
    xyh = [int(n) for n in input().split()]
    params.append(xyh)

for cxi, cyi in itertools.product(range(101), range(101)):
    for k in range(N):
        if params[k][2] > 0:
            hight = params[k][2] + abs(params[k][0] - cxi) + abs(params[k][1] - cyi)

    for i in range(N):
        if params[i][2] != max(h - abs(params[k][0] - cxi) - abs(params[k][1] - cyi), 0)
            break
    
    else:
        Cx = cxi
        Cy = cyi
        H = hight
        print(Cx, Cy, H)

### FIXED CODE ###

N = int(input())
params = []
for i in range(N):
    xyh = [int(n) for n in input().split()]
    params.append(xyh)

for cxi in range(101):
    for cyi in range(101):
        for k in range(N):
            if params[k][2] > 0:
                hight = params[k][2] + abs(params[k][0] - cxi) + abs(params[k][1] - cyi)

        for k in range(N):
            if params[k][2] != max((hight - abs(params[k][0] - cxi) - abs(params[k][1] - cyi)), 0):
                break
        
        else:
            print(cxi, cyi, hight)
n=list(map(int,input()))
s=sum(n)
k=len(n)
print(max(n[0]-1)+9*(k-1),s)

### FIXED CODE ###

n=list(map(int,input()))
s=sum(n)
k=len(n)
print(max((n[0]-1)+9*(k-1),s))
a=int(input())
s=input()
if a>=3200:
  print(s)
else
 print('red')
  


### FIXED CODE ###

a=int(input())
s=input()
if a>=3200:
  print(s)
else :
  print('red')
str = input() # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))

from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(len(num)):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]
l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1,key=lambda d:d[1],reverse=True)


if l0[0][0]!=l1[0][0]:
    print(len(num)-l0[0][1]-l1[0][1])
else:
    s=0
    if l0[0][1]>=l1[0][1]:
        s=l0[0][1]+l1[1][1]
    else:
        s=l0[1][1]+l1[0][1]
    print(len(num)-s)


### FIXED CODE ###

n = int(input()) # sを取得し、strに値を入れる
num= input()
num=list(map(int,num.split()))

from collections import defaultdict

d0=defaultdict(int)
d1=defaultdict(int)
for i in range(n):
    if i%2==0:
        d0[num[i]]+=1
    else:
        d1[num[i]]+=1

l0=[(k,d0[k]) for k in d0]
l1=[(k,d1[k]) for k in d1]

l0=sorted(l0, key=lambda d:d[1],reverse=True)
l1=sorted(l1, key=lambda d:d[1],reverse=True)

l0.append(("wild card",0))
l1.append(("wild card",0))

if l0[0][0]!=l1[0][0]: #文字が同じ場合
    print(len(num)-l0[0][1]-l1[0][1])
elif n==2:
    print(1)
else:
    print(n-max(l0[0][1]+l1[1][1],l0[1][1]+l1[0][1]))
A,B=map(int,input().split())
print(["Possible","Impossible][bool(A*B*(A+B))])

### FIXED CODE ###

A,B=map(int,input().split())
print(["Possible","Impossible"][bool(A*B*(A+B)%3)])
import sys
#import numpy as np
from scipy.special import comb

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M, K = i2nn()
    L = max(M, N)
    dp = [0] * L
    for i in range(1, L):
        dp[i] = dp[i-1] + i
    n = 0
    for i in range(N):
        n += (dp[i] + dp[N-1-i]) * M * M
    for i in range(M):
        n += (dp[i] + dp[M-1-i]) * N * N
    n = int(n / 2)
    r = comb(N*M-2, K-2, exact=True)
    n = n * r % (int(1e+9)+7)
    print(n)

main()


### FIXED CODE ###

import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

MOD = int(1e+9) + 7

def comb(n, k):
    r = 1
    for i in range(n, max(n-k, k), -1):
        r *= i
    for i in range(1, min(n-k, k) + 1, 1):
        r //= i
    return r

class Comb:
    def __init__(self, MAX, MOD):
        MAX += 1
        fac = [0] * MAX
        finv = [0] * MAX
        inv = [0] * MAX
        fac[0] = fac[1] = 1
        finv[0] = finv[1] = 1
        inv[1] = 1
        for i in range(2, MAX):
            fac[i] = fac[i - 1] * i % MOD
            inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD
        self.fac = fac
        self.finv = finv
        self.MOD = MOD
    
    def comb(self, n, k):
        fac = self.fac
        finv = self.finv
        MOD = self.MOD
        if (n < k):
            return 0
        if (n < 0 or k < 0):
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main():
    # 行数, 列数, 駒数
    N, M, K = i2nn()
    # 配置コストの総和 % MOD

    # 例）N, M, K = 2, 2, 2
    # 駒が置ける場所は4箇所: N * M
    # 駒の配置は6通り: comb(4, 2) = comb(N*M, K)
    # K=2 の場合のコスト
    xcost = 0
    for i in range(1, M):
        # iをx座標の差とする
        # x座標のみに注目した場合、差がiとなるのは(M-i)通り
        #   M=4, i=1, => (1,2), (2,3), (3,4) = 3通り
        #   M=4, i=2, => (1,3), (2,4) = 2通り
        #   M=4, i=3, => (1,4) = 1通り
        # さらにy座標の組み合わせは, 左側がN通り, 右側がN通り
        #   (1,2) について M=2 の場合 ((1,1), (2,1)), ((1,1), (2,2)), ((1,2), (2,1)), ((1,2), (2,2))
        xcost = (xcost + i * (M-i) * (N*N)) % MOD
    ycost = 0
    for i in range(1, N):
        ycost = (ycost + i * (N-i) * (M*M)) % MOD
    cost = (xcost + ycost) % MOD
    # K=3 の場合、K=2 の場合のコストを NM-2 倍すればよい
    # 汎用的に考えると、 K=2 の場合のコストを comb(MN-2, K-2) 倍すればよい
    #cost = (cost * comb(M*N-2, K-2)) % MOD
    cost = (cost * Comb(N*M-2, MOD).comb(N*M-2, K-2)) % MOD
    print(cost)

main()
n, m, l = map(int,input().split())
a = [list(map(int, input().split()))for i in range(n)]
b = [list(map(int, input().split()))for j in range(m)]
num = [[0 for i in range(n)]for j in range(l)]
for k in range(n):
    for i in range(l):
        for j in range(m):
            num[k][i] += a[k][j] * b[j][i]
for i in range(n):
    print(" ".join(map(str, num[i])))



### FIXED CODE ###

n, m, l = map(int,input().split())
a = [list(map(int, input().split()))for i in range(n)]
b = [list(map(int, input().split()))for j in range(m)]
num = [[0 for i in range(l)]for j in range(n)]
for k in range(n):
    for i in range(l):
        for j in range(m):
            num[k][i] += a[k][j] * b[j][i]
for i in range(n):
    print(" ".join(map(str, num[i])))
#ABC140_C
N=int(input())
A=[0]*N
B=[]
for _ in range(N-1):
    B.append(int(input()))
A[0]=B[0]

for i in range(1,N):
    A[i]=max(A[i-1],B[i-1],B[i])
print(*A)

### FIXED CODE ###

#ABC140_C
N=int(input())
A=[0]*N
B=[int(i) for i in input().split()]
A[0]=B[0]

for i in range(1,N-1):
    A[i]=min(B[i-1],B[i])
A[N-1]=B[N-2]

print(sum(A))
import math
lst = [int(input()) for _ in range(5)] 

lst1 = []
min1 = 9
num1 = 5

for i, l in enumerate(lst):
    lst1.append(math.ceil(l/10)*10)
    if min1 > l%10 and l%10!=0:
        min1 = l%10
        num1 = i
lst1[num1] = lst[num1]

print(sum(lst1))

### FIXED CODE ###

import math
lst = [int(input()) for _ in range(5)] 

lst1 = []
min1 = 9
num1 = 0

for i, l in enumerate(lst):
    lst1.append(math.ceil(l/10)*10)
    if min1 > l%10 and l%10!=0:
        min1 = l%10
        num1 = i
lst1[num1] = lst[num1]

print(sum(lst1))
import sys
input = sys.stdin.readline


def main():
    X = int(input().rstrip())
    for b in range(64):
        if (X - b ** 5) ** (1 / 5) % 1 == 0:
            A = int((X - b ** 5) ** (1 / 5))
            B = b
            break

    print(A, B)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
 
def main():
    X = int(input().rstrip())
    f = 0
    for a in range(-150, 150):
        for b in range(-150, 150):
            i = a ** 5 - b ** 5
            if i == X:
                print(a, b)
                f = 1
                break
 
        if f:
            break
 
 
if __name__ == '__main__':
    main()
import math
n,x=int(input())
a=list(map(int(input())))
ans=a[0]-x
for i in a:
    ans=math.gcd(ans,a[i]-x)
print(math)

### FIXED CODE ###

from fractions import gcd
n,x=list(map(int, input().split()))
a=list(map(int, input().split()))
ans=a[0]-x
for i in a:
    ans=gcd(ans,abs(i-x))
print(ans)
s=list(str(int(input())))
print('Bad' if s[0]==s[1] or s[1]==s[2] or s[2]==s[3] else 'Good')


### FIXED CODE ###

s=list(str(input()))
print('Bad' if s[0]==s[1] or s[1]==s[2] or s[2]==s[3] else 'Good')
print(input().count("1"))

### FIXED CODE ###

print(input().count("1"))
input()
a = list(map(str, input().split()))
b = list(map(int, input().split()))
if sorted(b) == a:
    print("YES")
else:
    m = 0
    for i in range(len(a)):
        if a[i] in sorted(b)[i]:
            m+=1
    if m==len(a)-2:
        print("YES")
    else:
        print("NO")

### FIXED CODE ###

input()
g = input()
a = list(map(str, g.split()))
b = list(map(int, g.split()))
if sorted(b) == b:
    print("YES")
else:
    m = 0
    for i in range(len(b)):
        if b[i] == sorted(b)[i]:
            m+=1
    if m==len(b)-2:
        print("YES")
    else:
        print("NO")
S,T=map(str,input().split())
print(f"{T}{S}")

### FIXED CODE ###

S,T=map(str,input().split())
print("{}{}".format(T,S))
n,q=list(map(int,input().split()))
s=list(input())
l=[0]*q
r=[0]*q
for i in range(q):
  l[i],r[i]=list(map(int(input().split())))
A=[]
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    A.append(1)
  else:
    A.append(0)
check=[0]+A
check=list(accumulate(check))
for i in range(q):
  print(check[r[i]]-check[l[i]+1])

    
  

### FIXED CODE ###

from itertools import accumulate
n,q=list(map(int,input().split()))
s=list(input())
l=[0]*q
r=[0]*q
for i in range(q):
  l[i],r[i]=list(map(int,input().split()))
A=[]
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    A.append(1)
  else:
    A.append(0)
check=[0]+A+[0]
check=list(accumulate(check))
for i in range(q):
  print(check[r[i]-1]-check[l[i]-1])
a,b,c = map(int, input().split())
sum = 0
result = 0
while b >= a:
    result = c%a
    if result == 0:
        sum += 1
    a += 1
print(sum)



### FIXED CODE ###

a,b = map(int, input().split())
print("%d %d %f"%(a//b,a%b,a/b))
import sys
sys.setrecursionlimit(k:=2*n)
n=int(input())
T=[[]for _ in"_"*k]
for _ in range(n-1):a,b=map(int,input().split());T[a]+=b,;T[b]+=a,
def d(v,p):
 r=0
 for s in T[v]:
  if s!=p:r^=d(s,v)+1
 return r
print("ABloibc e"[d(1,1)<1::2])

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n = int(input())
T = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  T[a].append(b)
  T[b].append(a)
def dfs(v, par=-1):
  res = 0
  for nv in T[v]:
    if nv == par:
      continue
    res ^= dfs(nv, v)+1
  return res
if dfs(0) == 0:
  print("Bob")
else:
  print("Alice")
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.items():
    if count[1] >= 2:
        B.append(count)
B.sort(reverse=True)
if len(B) ==0:
    print(0)
elif len(B) == 1:
    if B[0][1] >= 4:
        print(B[0][0]**2)
else:
    if B[0][1] >= 4:
        print(B[0][0]**2)
    else:
        print(B[0]*B[1])
    

### FIXED CODE ###

import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.items():
    if count[1] >= 2:
        B.append(count)
B.sort(reverse=True)
if len(B) ==0:
    print(0)
elif len(B) == 1:
    if B[0][1] >= 4:
        print(B[0][0]**2)
    else:
        print(0)
else:
    if B[0][1] >= 4:
        print(B[0][0]**2)
    else:
        print(B[0][0]*B[1][0])
x = input()
y = x*x*x
print (y)
print ("\n")


### FIXED CODE ###

x = input()
x = int(x)
print (x*x*x)
X = int(input())
from sympy import primerange, sieve
L = list(sieve.primerange(X, 10**5))
print(L[0])

### FIXED CODE ###

X = int(input())
def price(n):
  if n == 1:
    return False
  for i in range(2, int(n**0.5)+1):
    if n%i == 0:
      return False
  return True

while(1):
  if price(X):
    print(X)
    break
  else:
    X += 1
n = int(input())

s = []
ss = []
for i in range(n)
	s.append(str(input()))
  	ss.append(sorted(str(input())))
  
c = 0
for i in range(n)
	for l in range(i+1,n)
  		if ss[i] == ss[l]:
      		c += 1
print(c)
  

### FIXED CODE ###

n = int(input())

ss = []
for i in range(n):
	ss.append(sorted(str(input())))

sm = sorted(ss)
c = 0
ans = 0
for i in range(n-1):
	if sm[i] == sm[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)
print(48 - input())

### FIXED CODE ###

# coding = SJIS

m = int(input())

ans = 48 - m

print(ans)
X = input()
Y = input()

print((X+Y)/2)

### FIXED CODE ###

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

x = input_data[0]
y = input_data[1]/2

print(int(x+y))
n = int(input())
p = list(map(int, input().split()))

ans = 0

#+2まで考慮してるから、nの数を-2にして調整しろ
for i in range(n):
	if p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]:
		ans = ans + 1

print(ans)

### FIXED CODE ###

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

ans = 0

#+2まで考慮してるから、nの数を-2にして調整しろ
for i in range(n-2):
	if p[i] < p[i + 1] < p[i + 2] or p[i + 2] < p[i + 1] < p[i]:
		ans = ans + 1

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


### FIXED CODE ###

x, y = map(int, input().split())
print(int(x + (y/2)))
import networkx as nx
import itertools 

def majic_power(c):
	graph = nx.DiGraph()
	graph.add_nodes_from(range(10))
	for s,t in itertools.product(range(10), range(10)):
		if s != t:
			graph.add_edge(s,t, weight=c[s][t])
	return [nx.dijkstra_path_length(graph, i, 1) for i in range(10)]

def wall(A, c):
	power = majic_power(c)
	cost = 0
	for i,j in itertools.product(range(H), range(W)):
		if A[i][j] == -1 or A[i][j] == 1:
			pass
		else:
			cost += power[A[i][j]]
	print(cost)

items = list(map(int, input().split()))
H = items[0]
W = items[1]
c = list()
A = list()
for i in range(10):
	c_i = list(map(int, input().split()))
	c.append(c_i)
for i in range(H):
	A_i = list(map(int, input().split()))
	A.append(A_i)

wall(A, c)

### FIXED CODE ###

import itertools 

def wall(A,c,H,W):
    for k in range(10):
        for i,j in itertools.product(range(10), range(10)):
            c[i][j] = min(c[i][j], c[i][k]+c[k][j])

    cost = 0
    for i,j in itertools.product(range(H), range(W)):
        if A[i][j] != -1 and A[i][j] != 1:
            cost += c[A[i][j]][1]
    print(cost)


items = list(map(int, input().split()))
H = items[0]
W = items[1]
c = list()
A = list()
for i in range(10):
	c_i = list(map(int, input().split()))
	c.append(c_i)
for i in range(H):
	A_i = list(map(int, input().split()))
	A.append(A_i)
wall(A,c,H,W)
while(1):
    try:
        a, b = map(str, raw_input().split())
        print int(a)+int(b)
    except ValueError:
        exit

### FIXED CODE ###

while True:
    try:
        print sum(map(int, raw_input().split()))
    except EOFError:
        break
N = input()
a = [input() for i in range(N)]
 
l = map(int, a[1].split())
m = map(int, a[2].split())
 
if a[0] == 1:
  t = l[0] + l[1]
  print(p)
  
else:
  f = a[0]
  t = 0
  for i in range(len(f-1)):
    t = t + l[i]
  t = t + m[f-1] + m[f]
  print(t)

### FIXED CODE ###

import sys
a = []
for line in sys.stdin:
    a.append(int(line))
q = a[0] - a[1]
p = q % a[2]
print(p)
# BFS queue
import queue
import copy

import time
sss = time.time()
H, W = map(int,input().split())
b = [list(input()) for _ in range(H)]
dist = [[10**2 for _ in range(W)] for _ in range(H)]
start = (-1,-1)
qq = queue.Queue()
# start把握
for i in range(H):
    for j in range(W):
        if b[i][j] == '.':
            qq.put((i,j))
far = 0
move = [(-1,0), (0,-1), (1,0), (0,1)]
def BFS(start, bb):
    dist = [[10**2 for _ in range(W)] for _ in range(H)]
    far = 0
    q = queue.Queue()
    q.put(start)
    dist[start[0]][start[1]] = 0
    # BFS
    while 1:
        now = q.get()
        x = now[0]
        y = now[1]
        olddist = dist[x][y]
        bb[x][y] = '#'
        for elem in move:
            dx = elem[0]
            dy = elem[1]
            x+dx = xx
            y+dy = yy
            if xx>=0 and xx<= H-1 and yy>=0 and yy<=W-1:
                if bb[xx][yy] != '#':
                    if dist[xx][yy] > olddist:
                        dist[xx][yy] = olddist + 1
                        far = max([far,olddist+1])
                        q.put((xx,yy))
        if q.empty():
            break
    return far
res = 0
while 1:
    ttt = time.time()
    if sss-ttt >= 1.8:
        break
    now = qq.get()
    res = max([res, BFS(now, copy.deepcopy(b))])
    if qq.empty():
        break
print(res)


### FIXED CODE ###

# BFS queue
import queue
import copy

import time
sss = time.time()
H, W = map(int,input().split())
b = [list(input()) for _ in range(H)]
dist = [[10**9 for _ in range(W)] for _ in range(H)]
start = (-1,-1)
qq = queue.Queue()
l = 0
# start把握
for i in range(H):
    for j in range(W):
        if b[i][j] == '.':
            qq.put((i,j))
            l += 1
if l >= H*W-(H-2):
    print(H+W-2)
    exit()
far = 0
move = [(-1,0), (0,-1), (1,0), (0,1)]
def BFS(start, bb):
    dist = [[10**9 for _ in range(W)] for _ in range(H)]
    far = 0
    q = queue.Queue()
    q.put(start)
    dist[start[0]][start[1]] = 0
    # BFS
    while 1:
        now = q.get()
        x = now[0]
        y = now[1]
        bb[x][y] == '#'
        for elem in move:
            dx = elem[0]
            dy = elem[1]
            if x+dx>=0 and x+dx<= H-1 and y+dy>=0 and y+dy<=W-1 and abs(dx-dy)==1:
                if bb[x+dx][y+dy] != '#':
                    if dist[x+dx][y+dy] > dist[x][y]:
                        dist[x+dx][y+dy] = dist[x][y] + 1
                        if dist[x+dx][y+dy] > far:
                            far = dist[x+dx][y+dy]
                        q.put((x+dx,y+dy))
        if q.empty():
            break
    return far
res = 0
while 1:
    ttt = time.time()
    if ttt-sss >= 1:
        break
    now = qq.get()
    res = max([res, BFS(now, copy.deepcopy(b))])
    if qq.empty():
        break
print(res)