Harryxun/stf_run huggingface dataset:
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log,floor
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a,b,c,d = MAP()

print(max(a*c,a*d,b*c,b*d))

### FIXED CODE ###

# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log,floor
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a,b,c,d = MAP()

print(max(a*c,a*d,b*c,b*d))
#素因数分解
def Prime_Factorization(N):
    if N<0:
        R=[[-1,1]]
    else:
        R=[]

    N=abs(N)
    k=2
    while k*k<=N:
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])
        k+=1

    if N!=1:
        R.append([N,1])
    if not R:
        R.append([N,1])

    return R
#================================================
from math import gcd
N=int(input())
A=list(map(int,input().split()))

#Pairwise?
P=set()
F=True
for a in A:
    K=Prime_Factorization(a)
    for (p,_) in K:
        if p in P:
            F=False
            break
        else:
            P.add(p)

    if not F:
        break

if F:
    print("pairwise coprime")
    exit()

#Setwise?
g=A[0]
for a in A:
    g=gcd(g,a)

if g==1:
    print(1/0)
    print("setwise coprime")
else:
    print("not coprime")


### FIXED CODE ###

#素因数分解
def Prime_Factorization(N):
    if N<0:
        R=[[-1,1]]
    else:
        R=[]

    N=abs(N)
    k=2
    while k*k<=N:
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])
        k+=1

    if N!=1:
        R.append([N,1])
    if not R:
        R.append([N,1])

    return R
#================================================
from math import gcd
N=int(input())
A=list(map(int,input().split()))

#Pairwise?
P=set()
F=True
for a in A:
    K=Prime_Factorization(a)
    for (p,_) in K:
        if p in P and p!=1:
            F=False
            break
        else:
            P.add(p)

    if not F:
        break

if F:
    print("pairwise coprime")
    exit()

#Setwise?
g=A[0]
for a in A:
    g=gcd(g,a)

if g==1:
    print("setwise coprime")
else:
    print("not coprime")
S = input()

b = 0

ans = []

for i in s:
  if (i == 'A' or i == 'G' or i == 'C' or i == 'T'):
    b += 1
  else:
    ans.append(b)
    b = 0

print(max(ans))   

### FIXED CODE ###

S = list(input())

b = 0

ans = [0]

for n, i in enumerate(S, 1):
  if (i == 'A' or i == 'G' or i == 'C' or i == 'T'):
    b += 1
  else:
    b = 0
  ans.append(b)
print(max(ans))
n=int(input())

a = list(input().split())
a = [int(i) for i in a]
ans=1

if len(a) % 2 == 1: 
  for i in range(1, int(len(a)/2)+2):
    if ans > 10**18 or ans == 0:
      break
    if a[i-1] == 1:
      continue
    if i == int(len(a)/i) + 1:
      ans = ans*a[i-1]
    else:
      ans = ans*a[i-1]*a[-1*i]
    
else:
  for i in range(0, int(len(a)/2)):
    if ans > 10**18 or ans == 0:
      break
    if a[i-1] == 1:
      continue
    ans = ans*a[i]*a[-1 - i]
    

if ans > 10**18:
  print('-1')
else:
  print(ans)


### FIXED CODE ###

a, b = [int(i)  for i in input().split()]

print(a*b)
n, k = map(int,input().split())
a = list(map(int,input().split()))

ans = 0
b = [1]
for i in range(k):
  if a[b[-1] - 1] in b:
    c = a[b[-1] - 1]
    break
  b.append(a[b[-1] - 1])

d = b[:b.index(c)]
b = b[b.index(c):]

k = k - len(d) - k // len(b) * len(b)
#print(d,b,k)
ans = b[k]
print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!
n,k = map(int,input().split())

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

b = [1 for i in range(n)]


now = 0
next = a[now] - 1
c = []
for i in range(n):
    if b[next] == 0:
        d = c[:c.index(next)]
        e = c[c.index(next):]
        #print(d,e)
        break
    #print(now)
    b[now] = 0
    c.append(now)
    next = a[now] - 1
    #print(" ",next)
    now = next

if k >= len(d):
    k = k - len(d)
    k = k % len(e)
    print(e[k]+1)

else:
    print(d[k]+1)
a,b,k = map(int,input().split(" "))
c = []
for i in range(1,max(a,b)):
  if a % i == 0 and b % i == 0:
    c.append(i)
c.sort(reverse=True)
print(c[k-1])

### FIXED CODE ###

a,b,k = map(int,input().split(" "))
c = [1]
for i in range(1,max(a,b)+1):
  if a % i == 0 and b % i == 0 and i!=1:
    c.append(i)
c.sort(reverse=True)
print(c[k-1])
import sys
a = []
for l in sys.stdin:
    a.append(int(l))
a = a[1:]
print(len(set(a)))

### FIXED CODE ###

from sys import stdin
import numpy as np
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(len(set(np.array(data).reshape(-1,))))
# from math import gcd, sqrt
# import fractions
import math


def is_prime(n):
    flag = True
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            flag = False
            return

    if flag:
        return n


def make_divisors(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 main():
    a, b = map(int, input().split())
    coms = make_divisors(math.gcd(a, b))
    ans = [is_prime(i) for i in coms]
    ans2 = [a for a in ans if a is not None]
    print(len(ans2))


if __name__ == "__main__":
    main()


### FIXED CODE ###

# from math import gcd, sqrt
import fractions
import math


def is_prime(n):
    flag = True
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            flag = False
            return

    if flag:
        return n


def make_divisors(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 main():
    a, b = map(int, input().split())
    coms = make_divisors(fractions.gcd(a, b))
    ans = [is_prime(i) for i in coms]
    ans2 = [a for a in ans if a is not None]
    print(len(ans2))


if __name__ == "__main__":
    main()
# -*- coding: utf-8 -*-

D = int(input())
c = list(map(int, input().split()))
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))
s4 = list(map(int, input().split()))
s5 = list(map(int, input().split()))
t1 = int(input())
t2 = int(input())
t3 = int(input())
t4 = int(input())
t5 = int(input())

t = [0] * 26

ans = 0

# 1日目
ans = ans + s1[t1 - 1]
for i in range(26):
    if (t1 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t1 - 1) == i:
        t[i] = 0
print(ans)

# 2日目
ans = ans + s2[t2 - 1]
for i in range(26):
    if (t2 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t2 - 1) == i:
        t[i] = 0
print(ans)

# 3日目
ans = ans + s3[t3 - 1]
for i in range(26):
    if (t3 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t3 - 1) == i:
        t[i] = 0
print(ans)

# 4日目
ans = ans + s4[t4 - 1]
for i in range(26):
    if (t4 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t4 - 1) == i:
        t[i] = 0
print(ans)

# 5日目
ans = ans + s5[t5 - 1]
for i in range(26):
    if (t5 - 1) != i:
        t[i] = t[i] + 1
        ans = ans - (c[i] * t[i])
    elif (t5 - 1) == i:
        t[i] = 0
print(ans)

### FIXED CODE ###

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

D = int(input())
c = list(map(int, input().split()))
s = []
t = []

for i in range(D):
    s.append(list(map(int, input().split())))

for i in range(D):
    t.append(int(input()) - 1)

last = [0] * 26

ans = 0

for i in range(D):
    ans = ans + s[i][t[i]]
    for j in range(26):
        if t[i] != j:
            last[j] += 1
            ans = ans - (c[j] * last[j])
        elif t[i] == j:
            last[j] = 0
    print(ans)
from collections import Counter

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

v1 = v[::2]
v2 = v[1::2]

counter1 = Counter(v1)
x1 = counter1.most_common()[0:2]
counter2 = Counter(v2)
x2 = counter2.most_common()[0:2]

n = n//2
ans = 0
if x1[0][0] == x2[0][0]:
    if x1[0][1] > x2[0][1]:
        ans = (n - x1[0][1]) + (n - x2[1][1])
    else:
        ans =  (n - x2[0][1]) + (n - x1[1][1])
else:
    ans = (n - x1[0][1]) + (n - x2[0][1])
print(ans)

### FIXED CODE ###

from collections import Counter

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

v1 = v[::2]
v2 = v[1::2]

counter1 = dict(Counter(v1))
counter2 = dict(Counter(v2))
x1 = max(counter1, key=counter1.get)
x2 = max(counter2, key=counter2.get)
x1_c = counter1[x1]
x2_c = counter2[x2]
del counter1[x1]
del counter2[x2]
y1_c = 0
y2_c = 0
if len(counter1) != 0:
    y1_c = max(counter1.values())
if len(counter2) != 0:
    y2_c = max(counter2.values())

n = n//2
ans = 0
if x1 == x2:
    ans = min((n - x1_c) + (n - y2_c), (n - y1_c) + (n - x2_c))
    """
    if x1_c > x2_c:
        ans = (n - x1_c) + (n - y2_c)
    else:
        ans =  (n - y1_c) + (n - x2_c)
    """
else:
    ans = (n - x1_c) + (n - x2_c)

print(ans)
from math import factorial
N = int(input())
P = {}
ans = 0
def counter(s):
    ret = [0]*26
    for ss in s:
        ret[ord(ss)-ord('a')] += 1
    return tuple(ret)
for _ in range(N):
    s = input()
    c = counter(s)
    if not c in P.keys():
        P[c] = 1
    else:
        P[c] += 1
for v in P.values():
    ans += factorial(v) / factorial(2) / factorial(v-2)
print(int(ans))


### FIXED CODE ###

from math import factorial
N = int(input())
P = {}
ans = 0
def counter(s):
    ret = [0]*26
    for ss in s:
        ret[ord(ss)-ord('a')] += 1
    return tuple(ret)
for _ in range(N):
    s = input()
    c = counter(s)
    if not c in P.keys():
        P[c] = 1
    else:
        P[c] += 1
for v in P.values():
    if v > 1:
        ans += factorial(v) // factorial(2) // factorial(v-2)
print(ans)
x = int(input());

for i in range(x + 1, 10**5 + 1):
  for k in range(1, i):
    if i % k != 0: #割り切れない
      continue;
    else: #割り切れた
      break;
  else:
    continue;
  break;
  
print(i)
      

### FIXED CODE ###

x = int(input());

for i in range(x, 10**6):
  for k in range(2, i):
    if i % k != 0: #割り切れない
      continue;
    else: #割り切れた
      break;
  else:
    break;
  
print(i)
import math

A, B, K = map(int, input().split())

gcd = int(math.gcd(A, B))

com_div = []
count = 1
while count <= gcd:
    if gcd % count == 0:
        gcd = int(gcd / count)
        com_div.append(gcd)
        com_div.append(count)
    count += 1

com_div.sort(reverse=True)
print(com_div[K-1])


### FIXED CODE ###

A, B, K = map(int, input().split())

if A >= B:
    L, S = A, B
if A < B:
    L, S = B, A

while L%S != 0:
    tmp = L;
    L = S;
    S = tmp%S;

gcd = int(S)

if gcd == 1:
    print(1)
    exit()

com_div = []
com_div.append(gcd)
for i in range(1,gcd):
    if gcd % i == 0:
        com_div.append(i)

com_div.sort(reverse=True)
print(com_div[K-1])
N,M=map(int,input().split())
K=10**9+7
"""la=[]
for i in range(M):
    la.append(int(input()))"""
ldp=[0 for i in range(N)]
for i in range(M):
    a=int(input())
    ldp[a-1]=-1
if ldp[0]!=-1:
    ldp[0]=1
    #if ldp[1]!=-1:
    #    ldp[1]=1
if ldp[1]!=-1:
    ldp[1]+=1
    if ldp[0]!=-1:
        ldp[1]+=1
for i in range(2,N):
    if ldp[i]!=-1:
        if ldp[i-1]!=-1:
            ldp[i]=(ldp[i]+ldp[i-1])%K
        if ldp[i-2]!=-1:
            ldp[i]=(ldp[i]+ldp[i-2])%K
#print(ldp)
print(ldp[N-1])


### FIXED CODE ###

N,M=map(int,input().split())
K=10**9+7
"""la=[]
for i in range(M):
    la.append(int(input()))"""
ldp=[0 for i in range(N)]
for i in range(M):
    a=int(input())
    ldp[a-1]=-1
if ldp[0]!=-1:
    ldp[0]=1
    #if ldp[1]!=-1:
    #    ldp[1]=1
#if N>=1:


if N>=2:
    if ldp[1]!=-1:
        ldp[1]+=1
        if ldp[0]!=-1:
            ldp[1]+=1
    for i in range(2,N):
        if ldp[i]!=-1:
            if ldp[i-1]!=-1:
                ldp[i]=(ldp[i]+ldp[i-1])%K
            if ldp[i-2]!=-1:
                ldp[i]=(ldp[i]+ldp[i-2])%K
#print(ldp)
print(ldp[N-1])
n = int(input())
    b = False
    i=1
    while i<=9:
        j=1
        while j<=i:
            if j*i==n:
                print('Yes')
                b = True
                break
            j+=1
        i+=1
    if b==False:
        print('No')

### FIXED CODE ###

A, B = input().split(" ")
A = int(A)
B = int(B)
if A>=1 and A<=9 and B>=1 and B<=9:
    r = A*B
    print(r)
else:
    print(-1)
a, b = map(int, input().split())

c = a - 2b

if c > 0:
  print(c)
  
else:
  print(0)

### FIXED CODE ###

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

c = a - 2 * b

print(c if c > 0 else 0)
N, M = map(int, input().split())
sc = [map(int, input().split()) for _ in range(M)]
s, c = [list(i) for i in zip(*sc)]

def isOK(num):
    l = len(str(num))
    if l != N:
        return False
    for i in range(M):
        if str(num)[s[i]-1] != str(c[i]):
            return False

    return True

ans = -1

for i in range(1000):
    if isOK(i):
        ans = i
        break

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
if M:
    sc = [map(int, input().split()) for _ in range(M)]
    s, c = [list(i) for i in zip(*sc)]

    def isOK(num):
        str_num = str(num)
        l = len(str_num)
        if l != N:
            return False
        for i in range(M):
            if str_num[s[i]-1] != str(c[i]):
                return False

        return True

    ans = -1

    for i in range(10**N):
        if isOK(i):
            ans = i
            break

    print(ans)
else:
    print(10**(N-1) if N != 1 else 0)
n,k=map(int,input().split())
l=reversed(sorted(list(map(int,input().split()))))
sum=0
for i in range(k):
    sum+=l[i]
print(sum)

### FIXED CODE ###

n,k=map(int,input().split())
l=sorted(list(map(int,input().split())))[::-1]
sum=0
for i in range(k):
    sum+=l[i]
print(sum)
import itertools
import math


D, G = map(int, input().split())

P     = [None] * D
C     = [None] * D
count = [None] * D
score = [None] * D

for i in range(D):
    p, c          = map(int, input().split())
    P[i]          = p
    C[i]          = c
    count[i]      = list(range(p+1))
    score[i]      = [100 * (i+1) * j for j in range(p+1)]
    score[i][-1] += c

answer = math.inf

for is_complete in itertools.product([True, False], repeat=D):
    score_tmp  = 0
    count_tmp  = 0
    score_tmp += sum([score[i][-1] for i in range(D) if is_complete[i]])
    count_tmp += sum([count[i][-1] for i in range(D) if is_complete[i]])
    while score_tmp < G:
        for i in list(range(D))[::-1]:
            if is_complete[i] == False:
                if (G - score_tmp) % (100 * (i+1)) == 0:
                    count_add  = min((G - score_tmp) // (100 * (i+1)),     P[i] - 1)
                else:
                    count_add  = min((G - score_tmp) // (100 * (i+1)) + 1, P[i] - 1)
                score_add      = 100 * (i+1) * count_add
                count_tmp     += count_add
                score_tmp     += score_add
            if score_tmp >= G:
                break
    if score_tmp >= G:
        answer = min(answer, count_tmp)

print(answer)


### FIXED CODE ###

import itertools


D, G = map(int, input().split())

P     = [None] * D
C     = [None] * D
count = [None] * D
score = [None] * D

for i in range(D):
    p, c          = map(int, input().split())
    P[i]          = p
    C[i]          = c
    count[i]      = list(range(p+1))
    score[i]      = [100 * (i+1) * j for j in range(p+1)]
    score[i][-1] += c

answer = sum(P)

for is_complete in itertools.product([True, False], repeat=D):
    score_tmp  = 0
    count_tmp  = 0
    score_tmp += sum([score[i][-1] for i in range(D) if is_complete[i]])
    count_tmp += sum([count[i][-1] for i in range(D) if is_complete[i]])
    if score_tmp < G:
        for i in list(range(D))[::-1]:
            if is_complete[i] == False:
                if (G - score_tmp) % (100 * (i+1)) == 0:
                    count_add  = min((G - score_tmp) // (100 * (i+1)),     P[i] - 1)
                else:
                    count_add  = min((G - score_tmp) // (100 * (i+1)) + 1, P[i] - 1)
                score_add      = 100 * (i+1) * count_add
                count_tmp     += count_add
                score_tmp     += score_add
            if score_tmp >= G:
                break
    if score_tmp >= G:
        answer = min(answer, count_tmp)

print(answer)
import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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

#N = int(input())
#s = [input() for i in range(N)]
#M = int(input())
#t = [input() for i in range(M)]
# print(s)
# print(t)

h, w = map(int, input().split())
if (w == 1) or(h == 1):
    print(1)
    exit()

sum = 0

sum += (math.ceil(w/2))*(math.ceil(h/2))  # 切り上げ
sum += (math.floor(w/2))*(math.floor(h/2))  # 切り捨て

print(sum)


### FIXED CODE ###

import math
import string


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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

x = int(input())
a = [1]
for i in range(2, 1001):
    for j in range(2, 10):
        a.append(i**j)
aa = sorted(set(a))
# print(aa)
b = []
for i in range(len(aa)):
    if aa[i] <= x:
        b.append(aa[i])
print(max(b))
a = int(print())
if a%2 ==0:print(a)
else:print(2*a)


### FIXED CODE ###

a = input()
a = int(a)
if a%2 ==0:print(a)
else:print(2*a)
N = int(input())
number = []
    for A in range(1,10)
    for B in range(1,10)
    number.append(A*B)
if N in number :
  print("Yes")
else :
  print("No")

### FIXED CODE ###

N = int(input())
number = []
for a in range(1,10):
    for b in range(1,10):
        number.append(b*a)
if N in number :
    print("Yes")
else :
    print("No")
n = input()

INFTY = 10000000

color = [0 for i in xrange(n)]
M = [[0 for i in xrange(n)] for i in xrange(n)]
d = [INFTY for i in xrange(n)]
p = [-1 for i in xrange(n)]

def MST():
  d[0] = 0

  while True:
    cost = INFTY
    for i in xrange(n):
      if color[i] != 1 and d[i] < cost:
        cost = d[i]
        u = i

    if cost == INFTY:
      break
    color[u] = 2

    for v in xrange(n):
      if color[v] != 2 and M[u][v] != INFTY:
        if M[u][v] < d[v]:
          d[v] = M[u][v]
          p[v] = u
          color[v] = 1:

  sum = 0
  for i in xrange(n):
    if p[i] != -1:
      sum += M[i][p[i]] 
  return sum

for i in xrange(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] == -1:
     M[i][j] = INFTY
   else:
     M[i][j] = G[n]

print MST()

### FIXED CODE ###

n = input()

INFTY = 10000000

color = [0 for i in xrange(n)]
M = [[INFTY for i in xrange(n)] for i in xrange(n)]
d = [INFTY for i in xrange(n)]
p = [-1 for i in xrange(n)]

def MST():
  d[0] = 0

  while True:
    cost = INFTY
    for i in xrange(n):
      if color[i] != 2 and d[i] < cost:
        cost = d[i]
        u = i

    if cost == INFTY:
      break
    
    color[u] = 2

    for v in xrange(n):
      if color[v] != 2 and M[u][v] != INFTY and M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u
        color[v] = 1

  sum = 0
  for i in xrange(n):
    if p[i] != -1:
      sum += M[i][p[i]]
  return sum

for i in xrange(n):
  G = map(int, raw_input().split())
  for j in range(n):
   if G[j] != -1:
     M[i][j] = G[j]

print MST()
s=input()
t=input()
for c in range(3):
    if s[c]!=t[2-c]:
        print("NO")
        sys.exit()
print("YES");


### FIXED CODE ###

import sys
s=input()
t=input()
for c in range(3):
    if s[c]!=t[2-c]:
        print("NO")
        sys.exit(0)
print("YES");
import queue

# directions
x_dir = [0, 1, 0, -1]
y_dir = [1, 0, -1, 0]


# initialization visited maps
def init_visited_maps(h, w):
    return [[True for i in range(w)] for j in range(h)]


# bfs algorithm
def bfs(h, w, cheese, maps, sx, sy, moves):
    que = queue.Queue()
    que.put((moves, sx, sy))

    visited = init_visited_maps(h, w)
    visited[sy][sx] = False

    while que.qsize() > 0:
        c_moves, c_x, c_y = que.get()
        if maps[c_y][c_x] == cheese:
            return (c_moves, c_x, c_y)

        for i in range(4):
            n_x = c_x + x_dir[i]
            n_y = c_y + y_dir[i]

            if(0 <= n_x < w and 0 <= n_y < h and visited[n_y][n_x] and maps[n_y][n_x] != 'X'):
                que.put((c_moves+1, n_x, n_y))
                visited[n_y][n_x] = False

    return (-1, -1, -1)


# simulate mouse
def simulate(h, w, n, maps, sx, sy):
    moves = 0
    x, y = sx, sy

    for i in range(1, n+1, 1):
        moves, x, y = bfs(h, w, str(i), maps, x, y, moves)

    return str(moves)


# main function
def main():
    str = (input()).split()

    H = int(str[0])
    W = int(str[1])
    N = int(str[2])

    maps = []
    sx, sy = 0, 0
    for i in range(H):
        maps.append(input())
        for j in range(W):
            if maps[i][j] == 'S':
                sx, sy = j, i

    print(simulate(H, W, N, maps, sx, sy))


if __name__ == '__main__':
    main()

### FIXED CODE ###

# directions
x_dir = [0, 1, 0, -1]
y_dir = [1, 0, -1, 0]

# map info
visited = []
maps = []

# bfs algorithm
def bfs(h, w, cheese, sx, sy, moves):
    que = [(moves, sx, sy)]

    for i in range(h):
        for j in range(w):
            visited[i][j] = (maps[i][j] != 'X')

    visited[sy][sx] = False

    while len(que) > 0:
        c_moves, c_x, c_y = que.pop(0)
        if maps[c_y][c_x] == cheese:
            return (c_moves, c_x, c_y)

        for i in range(4):
            n_x = c_x + x_dir[i]
            n_y = c_y + y_dir[i]

            if(0 <= n_x < w and 0 <= n_y < h and visited[n_y][n_x]):
                que.append((c_moves+1, n_x, n_y))
                visited[n_y][n_x] = False

    return (-1, -1, -1)

# main function
if __name__ == '__main__':
    inputs = (input()).split()

    H = int(inputs[0])
    W = int(inputs[1])
    N = int(inputs[2])

    visited = [[True for i in range(W)] for j in range(H)]
    maps = ["" for i in range(H)]

    x, y = 0, 0
    for i in range(H):
        maps[i] = input()
        for j in range(W):
            if maps[i][j] == 'S':
                x, y = j, i

    moves = 0
    for i in range(1, N+1, 1):
        moves, x, y = bfs(H, W, str(i), x, y, moves)

    print(str(moves))