Harryxun/stf_run huggingface dataset:
if K<N//2+1:
    for i in range(K):
        flag=0
        old=S[0]
        reverse=[]

        for j in range(1,N):
    #         print(j,old,S[j])
            if S[j]!=old:
                reverse.append(j)
                old=S[j]

            if len(reverse)==2:

                for k in range(reverse[0],reverse[1]):

                    if S[k]=='R':
                        S[k]='L'
                    else:
                        S[k]='R'
                break

        if len(reverse)==1:
                 for k in range(reverse[0],N):
                    if S[k]=='R':
                        S[k]='L'
                    else:
                        S[k]='R'
    old='aaa'
    ans=0
    for s in S:
        if old==s:
            ans+=1
        old=s
    print(ans)
else:
    print(N)

### FIXED CODE ###

N,K=map(int,input().split())
S=list(input())

old='X'
count=0
for i,s in enumerate(S):
    if s==old:
        count+=1

    old=s
print(min(count+2*K,N-1))
c=input("").split(" ")
a=int(c[0])

e=100*int(c[0][0])+int(c[0][1])*10+int(c[0][2])

d=int(int(a*e)/100)
print(d)

### FIXED CODE ###

c=input("").split(" ")
a=int(c[0])

e=100*int(c[1][0])+10*int(c[1][2])+int(c[1][3])

d=int(a*e)
s=str(d)
if (len(s)<3):
    f="0"
else:
    f=s[:len(s)-2]

print(f)
cnt = int(input())
in_str = [int(i) for i in input().split()]
in_str.sort()
print(in_str[cnt//2+1] - in_str[cnt // 2])

### FIXED CODE ###

cnt = int(input())
in_str = [int(i) for i in input().split()]
in_str.sort()
#print("in_str[cnt // 2-1]",in_str[cnt // 2-1])
#print("in_str[cnt//2]",in_str[cnt//2])
print(in_str[cnt//2] - in_str[cnt // 2-1])
n=int(input())
a=list(map(int,input().split()))
pl = [0]*(n+5)

for i in range(n):
    num = a[i]
    pl[num-1] += 1
    pl[num+2] -= 1

for i in range(1,n):
    pl[i] += pl[i-1]

print(max(pl))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
pl = [0]*100005

for i in range(n):
    num = a[i]
    pl[num-1 + 2] += 1
    pl[num+2 + 2] -= 1

for i in range(1,100004):
    pl[i] += pl[i-1]

print(max(pl))
import sys


def main():
    
    def walk(p, c):
        if visited[p]:
            return
        visited[p] = True
        cnt[p] += c
        for n in tree[p]:
            walk(n, cnt[p])

    sys.setrecursionlimit(200000)
    rl = sys.stdin.readline

    n, q = [int(x) for x in rl().split()]

    tree = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        a, b = [int(x) for x in rl().split()]
        tree[a].append(b)
        tree[b].append(a)

    cnt = [0] * (n + 1)
    for _ in range(q):
        p, x = [int(x) for x in rl().split()]
        cnt[p] += x

    visited = [False] * (n + 1)
    walk(1, 0)

    print(*cnt[1:])


main()


### FIXED CODE ###

from sys import stdin, setrecursionlimit

setrecursionlimit(1000000)


def main():
    def read_tree(n):
        parents = [0 for _ in range(n + 1)]
        for _ in range(n - 1):
            a, b = [int(x) for x in input().split()]
            parents[b] = a
        return parents

    n, q = [int(x) for x in input().split()]

    parents = read_tree(n)
    cnt = [0] * (n + 1)

    for _ in range(q):
        p, x = [int(x) for x in input().split()]
        cnt[p] += x
    
    for i in range(1, n + 1):
        cnt[i] += cnt[parents[i]]

    for i in range(1, n + 1):
        print(cnt[i], end=" ")


main()
n,m,x = map(int,input().split())
a = list(map(int,input().split()))

for i in range(m):
    if a[i] > x:
        break
    y = i+1
for i in range(m):
    if a[-1-i] < x:
        break
    z = i+1
print(min([m-y,m-z]))

### FIXED CODE ###

n,m,x = map(int,input().split())
a = list(map(int,input().split()))
y = 0
z = 0
for i in range(m):
    if a[i] > x:
        break
    y = i+1
for i in range(m):
    if a[-1-i] < x:
        break
    z = i+1
print(min([m-y,m-z]))
m = 10 ** 9 + 7
f = [1]

for i in range(10 ** 5 + 5):
    f.append(f[-1] * (i + 1) % m)

def nCr(n,r,mod = m):
    return f[n] * pow(f[r],m - 2,m) * pow(f[n-r],m - 2,m) % m

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

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

a.sort()

ans = 0
for i in range(n - k + 1):
    ans += (a[-1-i] - a[i]) * nCr(n - 1 - i,k - 1)
    ans %= m

print(ans)


### FIXED CODE ###

from collections import deque

def bfs(loc):
    global tem_ans
    d = [[float('inf')] * w for i in range(h)]
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    que = deque([])
    que.append(loc)
    d[loc[0]][loc[1]] = 0
    while que:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] == '.' and d[nx][ny] == float('inf'):
                d[nx][ny] = d[p[0]][p[1]] + 1
                que.append([nx,ny])
                if tem_ans < d[nx][ny]:
                    tem_ans = d[nx][ny]
    return tem_ans

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

maze = [list(input()) for i in range(h)]


ans = 0
tem_ans = 0

loc = []
for i in range(h):
    for j in range(w):
        if maze[i][j] != '#':
            loc = [i,j]
        else:
            continue
        ans = max(ans,bfs(loc))

print(ans)
N, K = map(int, input().split(' '))
h = [int(val) for val in input().split(' ')]
if len(h) == 0:
    return 0
dp = [0] + [float('inf')]*(len(h)-1)
for i in range(1, len(h)):
    dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
print(dp[-1])


### FIXED CODE ###

import numpy as np

N, K = map(int, input().split(' '))
h = np.array(list(map(int, input().split(' '))))
dp = np.zeros(len(h), dtype=int)
for i in range(1, len(h)):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + np.abs(h[i] - h[start:i]))
print(dp[-1])
a,b,c = map(int, raw_input().split)

count=0
for x in range(a,b+1):
    if  c%x == 0:
     print(str(count += 1) + x)
       
  

### FIXED CODE ###

a,b,c = map(int, raw_input().split())

count=0
for x in range(a,b+1):
    if  c%x == 0:
       count += 1
print(count)
n = int(input())
l = list(map(int, input().split()))
dic = {}
count = 0

for i in range(n):
  dic.setdefault(l[i],0)
  dic[l[i]] += 1
#print(dic)
for x,y in dic.items():
  if x <= y:
    count += y - x
  else:
    count += y
print(count)


### FIXED CODE ###

import math
a,b = map(int,input().split())
print(math.ceil((a+b)/2))
s=input()
        
ngram=[]
for i in range(4,len(s)):
    for j in range(len(s)-i+1):

ans=0
for i in range(len(ngram)):
    if int(ngram[i])%2019==0:
        ans+=1
print(ans)

### FIXED CODE ###

s=input()
l=len(s)
amari=[0]*2019
amari[0]=1

d=0
digi=1

for c in s[::-1]:
    d=(int(c)*digi + d)%2019
    amari[d]+=1
    digi=(digi*10)%2019

ans=0
for i in amari:
    ans+=i*(i-1)//2
print(ans)
n = int(input())

g = [[] for _ in range(n)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    g[u - 1].append((v - 1, w))
    g[v - 1].append((u - 1, w))

color = [-1] * n
dist = [0] * n

def dfs(v):
    for next_v in g[v]:
        if color[next_v[0]] == -1 and next_v[1] != 0:
            dist[next_v[0]] = dist[v] + next_v[1]
            color[next_v[0]] = dist[next_v[0]] % 2
            dfs(next_v[0])

# 0を始点として各点までの距離を求める
dfs(0)

for c in color:
    print(c)

### FIXED CODE ###

n = int(input())

g = [[] for _ in range(n)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    g[u - 1].append((v - 1, w))
    g[v - 1].append((u - 1, w))

color = [-1] * n
dist = [0] * n

import queue
def dfs(v):
    color[v] = dist[v] % 2
    q = queue.LifoQueue()
    q.put(v)

    while not q.empty():
        vv = q.get()
        for next_v in g[vv]:
            if color[next_v[0]] == -1 and next_v[1] != 0:
                dist[next_v[0]] = dist[vv] + next_v[1]
                color[next_v[0]] = dist[next_v[0]] % 2
                q.put(next_v[0])

# 0を始点として各点までの距離を求める
dfs(0)

for c in color:
    print(c)
a = int(input())
b = int(input())
print(a * b)

### FIXED CODE ###

a,b = map(int,input().split())
print(a * b)
R=input()
G=input()
print(G*2-R)

### FIXED CODE ###

R=int(input())
G=int(input())
print(G*2-R)
import math
def lcm_base(x, y):
    return int((x * y) / math.gcd(x, y))
def lcm_list(numbers):
    answer=numbers[0]
    for number in numbers:
        answer=lcm_base(answer,number)
    return answer
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
while a[0]%2==0:
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=int(a[i]/2)
        else:
            b=1
            break
if b==1:
    print(0)
else:
    # amc=lcm_list(a)
    print(int((m+amc)/(2*amc)))



### FIXED CODE ###

import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
nm=list(map(int, input().split()))
a=list(map(int, input().split()))
n=nm[0]
m=nm[1]
b=0
c=a[0]
dnum=0
while c%2==0:
    dnum+=1
    c=c//2
for i in range(len(a)):
    c=a[i]
    dnum1=0
    while c%2==0:
        dnum1+=1
        c=c//2
    #print(dnum)
    if dnum1!=dnum:
        b=1
        break

#print(a)
if b==1:
    print(0)
else:
    for i in range(len(a)):
        a[i]=a[i]//2
    #print(a)
    amc=lcm_list(a)
    #print(amc)
    # version3.5にてgcdがfractionsからmathに移動した
    print(int((m+amc)/(2*amc)))
#! -*- coding:utf-8 -*-
def gcd(a, b):
    if b == 0: return int(a)
    return int(gcd(int(b), int(a % b)))
 
def lcm(c, d):
    return int(int(c * d) / int(gcd(c, d)))

n = int(input())
k = []
for i in range(n):
    k.append(int(input()))

p = lcm(k[0],k[1])
for i in range(n):
    p = lcm(p,k[i])
print(int(p))


### FIXED CODE ###

#! -*- coding:utf-8 -*-
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
k = []
for i in range(n):
    k.append(int(input()))

if n == 1:
    print(k[0])
else:
    p = lcm(k[0],k[1])
    for i in range(n):
        p = lcm(p,k[i])
    print(int(p))
>>> a,b,c=map(int,input().split())
if a<c and c<b:
 print("Yes")
elif b<c and c<a:
 print("Yes")
else:
 print("No")

### FIXED CODE ###

a,b,c=map(int,input().split())
if a<b:
	if a<c and c<b:
		print("Yes")
	else:
		print("No")
elif b<a:
	if b<c and c<a:
		 print("Yes")
	else:
		 print("No")
else:
	 print("No")
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

S = sys.stdin.readline().rstrip()
K = int(sys.stdin.readline())


def prune(it):
    hist = set()
    ret = []
    for s, l in it:
        if s not in hist:
            hist.add(s)
        if len(hist) > K:
            break
        ret.append((s, l))
    return ret


collections = prune(sorted([(c, L) for L, c in enumerate(S)]))
for size in range(1, len(S)):
    threshold, _ = collections[-1]
    for s, left in collections:
        r = left + size + 1
        if len(s) == size and r <= len(S):
            t = S[left:r]
            if t <= threshold:
                collections.append((t, left))
    collections = prune(sorted(collections))

strings = list(set([s for s, _ in collections]))
strings.sort()
print(strings[K - 1])


### FIXED CODE ###

import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

S = sys.stdin.readline().rstrip()
K = int(sys.stdin.readline())

s = set()
for k in range(1, K + 1):
    for i in range(len(S)):
        s.add(S[i:i + k])

s = list(sorted(list(s)))
print(s[K - 1])
n = int(input())
a = list(int(input()) for _ in range(n))

num = max(a)
try:
    num2 = max([k for k in a if k != num])
except:
    pass
for i in range(n):
    if a[i] < num:
        print(num)
    else:
        print(num2)

### FIXED CODE ###

n = int(input())
a = list(int(input()) for _ in range(n))

max_list = sorted(a,reverse=True)[:2]
num = max_list[0]
num2 = max_list[1]

for i in range(n):
    if a[i] < num:
        print(num)
    else:
        print(num2)
N = int(input())
d = list(map(int,input().split()))

sd = sorted(d)
low = sd[N/2-1]
up = sd[N/2]
num = up - low
print(num)

### FIXED CODE ###

N = int(input())
d = list(map(int,input().split()))

sd = sorted(d)
low = sd[N//2-1]
up = sd[N//2]
num = up - low
print(num)
D = int(input())

if D==25:
  print("Christmas")
  elif D==24:
    print("Christmas Eve")
    elif D==23:
      print("Christmas Eve Eve")
      else D==22:
        print("Christmas Eve Eve Eve")

### FIXED CODE ###

D = int(input())

if D == 25:
  print("Christmas")
elif D == 24:
  print("Christmas Eve")
elif D == 23:
  print("Christmas Eve Eve")
else:
  print("Christmas Eve Eve Eve")
def subarraySum(nums, k):
  count = total = 0
  cache = collections.defaultdict(int)
  cache[0] = 1
  for num in nums:
    total += num
    count += cache[total - k]
    cache[total] += 1
    return count
A = input()
nums = list(map(int,input().split()))
k = 0
print(subarraySum(nums, 0))

### FIXED CODE ###

import collections
def subarraySum(nums, k):
    count = total = 0
    cache = collections.defaultdict(int)
    cache[0] = 1
    for num in nums:
        total += num
        count += cache[total - k]
        cache[total] += 1
    return count
A = input()
nums = list(map(int,input().split()))
k = 0
print(subarraySum(nums, 0))
# import math
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np


# k,x = map(int, input().split())

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
m = [i + 1 for i in range(n)]
c = 0
for i in permutations(m):
    c += 1
    # print(i)
    if list(i) == p:
        a = c
    if list(i) == q:
        b = c
print(abs(a - b))


### FIXED CODE ###

# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

k,x = map(int, input().split())
# n = int(input())
# a = list(map(int,input().split()))
ans = 'No'
if 500 * k >= x : ans = 'Yes'
print(ans)
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()


q = queue.Queue()

for i in range(1,9):
	q.put(i)

n = readInt()

for i in range(1,100000):
	a = str(q.get())
	if a[-1]!=0:
		q.put(int(a+str(int(a[-1])-1)))
	q.put(int(a+str(str(int(a[-1])))))
	if a[-1]!=9:
		q.put(int(a+str(int(a[-1])+1)))	
	if i==n:
		print(q.get())
		break

### FIXED CODE ###

def jud(n1,n2):
	if abs(n1-int(str(n2)[0]))<=1:
		return 1
	else:
		return 0

rnrn = [[1,2,3,4,5,6,7,8,9],[10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,98,99]]

for div in range(1,10):
	rnrn.append([])
	for i in range(len(rnrn[div])):
		y = str(rnrn[div][i])
		x = int(y[-1])
		if x-1!=-1:
			rnrn[div+1].append(int(y+str(x-1)))
		rnrn[div+1].append(int(y+str(x)))
		if x+1!=10:
			rnrn[div+1].append(int(y+str(x+1)))
		
rnrn2 = []
for i in range(len(rnrn)):
	rnrn2.extend(rnrn[i])

print(rnrn2[int(input())-1])
A,B,K = map(int, input().split(" "))

def check(A,B,K):
    if A > 0:
        if K-A >= 0:
            K = K-A
            A = 0
        else:
            A = A-K
            return (A,B)
    
    if B > 0:
        if B-K >= 0:
            return (A,B-K)
        else:
            return (A,0)

ans = check(A,B,K)
print(ans[0],ans[1])
            
        

### FIXED CODE ###


A,B,K = [int(i) for i in input().split(" ")]

def check(A,B,K):
    if A > 0:
        if A > K:
            A-=K
            K = 0
        else:
            result = K-A
            A = 0
            K = result
    if B > 0:
        if B > K:
            B-=K
        else:
            B = 0
    return "{0} {1}".format(A,B)

print(check(A,B,K))
import bisect

N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
T.sort()
ans=0
i=0

if T[0]+K>=T[-1]:
  print(1)
else:
  while True:
    if i==N-1:
      ans+=1
      break
    i=bisect.bisect_right(T,T[i]+K)
    print(T,i)
    ans+=1
  print(ans)

### FIXED CODE ###

import bisect
import sys

N,C,K=map(int,input().split())
T=[int(input()) for _ in range(N)]
T.sort()
ans=0
i=0

if T[0]+K>=T[-1]:
  if N%C==0:
    print(N//C)
  else:
    print(N//C+1)
  sys.exit()
else:
  while True:
    t=bisect.bisect_right(T,T[i]+K)
    if t-i>C:
      i+=C
    else:
      i=t
    ans+=1
    if i==N-1:
      ans+=1
      break
    if i>N-1:
      i=N-1
      break
print(ans)
import math
n=input()
a=map(int,input().split())

a.sort()

print(a[-1]-a[0])


### FIXED CODE ###

import math

n=input()
a=sorted(map(int,input().split()))


print(a[-1]-a[0])
import sys
sys.setrecursionlimit(10000)
n,m=map(int,input().split())
bra=[set() for _ in range(m)]
for i in range(m):
    a,b=map(int,input().split())
    bra[a-1].add(b-1)
    bra[b-1].add(a-1)

visit=[1]+[0]*(n-1)
#print(bra)
cnt=[]
def dfs(a,visit):
    if visit==[1]*n:
        cnt.append(1)
        return 
    else:
        for e in bra[a]:
            if visit[e]==0:
                visit[e]=1
#                print(visit)
                dfs(e,visit)
                visit[e]=0   
dfs(0,visit)
print(sum(cnt))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000)
n,m=map(int,input().split())
bra=[set() for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    bra[a-1].add(b-1)
    bra[b-1].add(a-1)

visit=[1]+[0]*(n-1)
#print(bra)
cnt=[]
def dfs(a,visit):
    if visit==[1]*n:
        cnt.append(1)
        return 
    for e in bra[a]:
        if visit[e]==0:
            visit[e]=1
#            print(visit)
            dfs(e,visit)
            visit[e]=0  
    return 
dfs(0,visit)
print(len(cnt))
import numpy as np 
N = int(input())
A =list(map(int, input().strip().split()))
Ap = np.abs(A)
i = 0
m = 0
s = 0
M = 0
while i <= N - 1:
    if A[i] < 0:
        m += 1
    i += 1
if m % 2 == 0:
    M = np.sum(Ap)
if m % 2 == 1:
    while s <= N - 1:
        M1 = np.sum(Ap) - 2 * Ap[s]
        if M1 >= M:
            M = M1
        s += 1
print(M)

### FIXED CODE ###

A, B, T = list(map(int, input().strip().split()))
i = 1
X = 0
while A * i < T + 0.5:
  X = X + B
  i += 1
else:
  print(X)
list = list(map(int, input().split()))

amount = 0
count = 0

while amount < list[1]:
    count += 1
    amount = count * (list[0] - 1) + 1 

print(count)


### FIXED CODE ###

predict = list(input())
result = list(input())

count = 0

for i in range(len(predict)):
    if predict[i] == result[i]:
        count += 1

print(count)
n,k= map(int , input().split())

p=list(map(int,input().split()))
p.sort()
ans =0
for i in range(k):
	ans+= p[i]
print(ans)

### FIXED CODE ###

a = input()
 
if a == a.upper():
	print('A')
else:
	print('a')
SSR
SSR

### FIXED CODE ###

S = input()
T = input()

ans = 0
for i in range(3):
    ans += 1 if S[i] == T[i] else 0

print(ans)
n = input()
ans = “”
for a in n:
  if a == “1”:
    ans  = ans + “9”
  else:
    ans = ans + “1”
print(ans)

### FIXED CODE ###

n = input()
ans = ''
for a in n:
  if a == '1':
    ans  = ans + '9'
  else:
    ans = ans + '1'
print(ans)
n =input()

for i in range(n):
	if n[i] == '9':
		n[i] = '1'
	else:
		n[i] = '9'
print(n)

### FIXED CODE ###

n =input()

n = n.replace('9','0')
n = n.replace('1','9')
n = n.replace('0','1')
print(n)
a = str(input())

count = 0
if a[0] = "1":
  count += 1
if a[1] = "1":
  count += 1
if a[2] = "1":
  count += 1

print(count)

### FIXED CODE ###

a = input()
a = str(a)

count = 0
if a[0] == "1":
  count += 1
if a[1] == "1":
  count += 1
if a[2] == "1":
  count += 1

print(count)
a = input()
b = []
for z in a:
  b.apppend(z)
if b[2]==b[3]:
  if b[4]==b[5]:
    print("Yes")
  else:
    print("No")
else:
  print("No")
  

### FIXED CODE ###

a = input()
b = []
for z in a:
  b.append(z)
if b[2]==b[3]:
  if b[4]==b[5]:
    print("Yes")
  else:
    print("No")
else:
  print("No")
# 最大公約数
def gcd(m, n):
    temp = 0
    while(m % n != 0):
        temp = n
        n = m % n
        m = temp
    return n


N = int(input())
T = [int(input()) for _ in range(N)]
ans = 0
for i in range(len(T)):
    if ans == 0:
        ans = T[i]
    else:
        ans = int((ans * T[i]) / gcd(ans, T[i]))
print(ans)


### FIXED CODE ###

# 最大公約数
def gcd(m, n):
    while(n != 0):
        temp = n
        n = m % n
        m = temp
    return m


N = int(input())
T = [int(input()) for _ in range(N)]
ans = 0
for i in range(len(T)):
    if ans == 0:
        ans = T[i]
    else:
        ans = ans // gcd(ans, T[i]) * T[i]
print(ans)
print(int(input())*2)print(int(input())*2)

### FIXED CODE ###

r=int(input())

print(r**2)
A, B, C, D = map(int,input())

ab = A + B
cd = C + D

if ab == cd:
    print('Balanced')
elif ab > cd:
    print('Left')
else:
    print('Right')

### FIXED CODE ###

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

ab = A + B
cd = C + D

if ab == cd:
    print('Balanced')
elif ab > cd:
    print('Left')
else:
    print('Right')
h,w = map(int,input().split())
c = [[int(i) for i in input().split()] for _ in range(10)]
A = {i:0 for i in range(10)}
for _ in range(h):
  for i in input().split():
    A[int(i)] += 1
    

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

ans = 0
for i in range(10):
  ans += c[i][1] * A[i]
print(ans)




### FIXED CODE ###

h,w = map(int,input().split())
c = [[int(i) for i in input().split()] for _ in range(10)]
A = {i:0 for i in range(10)}
for _ in range(h):
  for i in input().split():
    if i != '-1':
      A[int(i)] += 1
    

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

ans = 0
for i in range(10):
  ans += c[i][1] * A[i]
print(ans)
n,m,k=map(int,input().split())
friend=[0]*n
stock=[[] for i in range(n)]
ter=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    stock[a-1].append(b-1)
    stock[b-1].append(a-1)
    friend[a-1]+=1
    friend[b-1]+=1
def dfs(i,k):
    for next_i in stock[i]:
        if ter[next_i]==0:
            ter[next_i]=k
            dfs(next_i,k)
total=0
for i in range(n):
    if ter[i]==0:
        total+=1
        dfs(i,total)
ans=[0]*n
size=[0]*(total+1)
for i in range(1,total+1):
    size[i]=ter.count(i)
for i in range(n):
    ans[i]=size[ter[i]]-friend[i]-1
for i in range(k):
    c,d=map(int,input().split())
    if ter[c-1]==ter[d-1]:
        ans[c-1]-=1
        ans[d-1]-=1
for i in range(n):
    print(ans[i])


### FIXED CODE ###

class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parent=[i for i in range(n)]
        self.rank=[1]*n#木の高さ
        self.size=[1]*n#size[i]はiを根とするグループのサイズ

    def find(self,x):#ｘの根（親）を返す
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.find(self.parent[x])#経路圧縮
            return self.parent[x]

    def unite(self,x,y):#ｘ、ｙの集合の統合
        x=self.find(x)
        y=self.find(y)
        if x!=y:
            if self.rank[x]<self.rank[y]:#ランクの比較
                self.parent[x]=y
                self.size[y]+=self.size[x]
            else:
                self.parent[y]=x
                self.size[x]+=self.size[y]
                if self.rank[x]==self.rank[y]:
                    self.rank[x]+=1
    def group_size(self,x):#ｘが属する集合の大きさ
        return self.size[self.find(x)]
    def is_same(self,x,y):#ｘ、ｙが同じ集合に属するかを判定する
        return self.find(x)==self.find(y)

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

uf=UnionFind(n)
ans = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    uf.unite(a-1,b-1)
    ans[a - 1] -= 1
    ans[b - 1] -= 1
for i in range(k):
    c, d = map(int, input().split())
    if uf.is_same(c-1,d-1):
        ans[c-1]-=1
        ans[d-1]-=1

for i in range(n):
    ans[i]+=uf.group_size(i)-1
    print(ans[i])