Harryxun/stf_run huggingface dataset:
n = int(input())
a = [int(input()) for _ in range(n)]
input()
m = [int(input()) for _ in range(n)]

aa = [0 for _ in range(n**2)]
for i in range(n):
    t = 2**i
    for j in range(n**2):
        if (j//t)%2:
            aa[j] += a[i]
aa = set(aa)

for k in m:
    if k in aa:
        print('yes')
    else:
        print('no')

### FIXED CODE ###

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

n2 = 2**n
aa = [0 for _ in range(n2)]
for i in range(n):
    t = 2**i
    for j in range(n2):
        if (j//t)%2:
            aa[j] += a[i]

for k in m:
    if k in aa:
        print('yes')
    else:
        print('no')
# -*- coding: utf-8 -*-


def qui(l):
    num = len(l)
    if num <= 1:
        return l
    piv = 0
    piv2 = len(l)-1
    piv3 = int(len(l)/2)
    if (l[piv] > l[piv2]) and (l[piv2] > l[piv3]):
        piv = piv2
    elif (l[piv] > l[piv3]) and (l[piv3] > l[piv2]):
        piv = piv3
    elif (l[piv] < l[piv2]) and (l[piv2] < l[piv3]):
        piv = piv2
    elif (l[piv] < l[piv3]) and (l[piv3] < l[piv2]):
        piv = piv3
    else:
        pass
    mini = []
    maxi = []

    for i in range(0,len(l)):
        if i == piv:
            continue
        if l[piv] > l[i]:
            mini.append(l[i])
        elif l[piv] <= l[i]:
            maxi.append(l[i])
    return qui(mini) + [l[piv]] + qui(maxi)

input()
list1 = list(map(lambda x: int(x), input().split(" ")))
result = qui(list1)

print(' '.join(map(str, result)))

### FIXED CODE ###

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

import random
def qui(l):
    num = len(l)
    if num <= 1:
        return l
    piv = random.randrange(0,len(l))
    piv2 = random.randrange(0,len(l))
    piv3 = random.randrange(0,len(l))
    if (l[piv] > l[piv2]) and (l[piv2] > l[piv3]):
        piv = piv2
    elif (l[piv] > l[piv3]) and (l[piv3] > l[piv2]):
        piv = piv3
    elif (l[piv] < l[piv2]) and (l[piv2] < l[piv3]):
        piv = piv2
    elif (l[piv] < l[piv3]) and (l[piv3] < l[piv2]):
        piv = piv3
    else:
        pass
    mini = []
    middlei = []
    maxi = []

    for i in range(0,len(l)):
        if l[i] == l[piv]:
            middlei.append(l[i])
        elif l[piv] > l[i]:
            mini.append(l[i])
        elif l[piv] <= l[i]:
            maxi.append(l[i])
    mini = qui(mini)
    maxi = qui(maxi)
    return mini+ middlei+maxi
input()
list1 = input().split(" ")
for i in range(0, len(list1)):
    list1[i] = int(list1[i])

result = qui(list1)

print(' '.join(map(str, result)))
N = int(iput())
if N < 100:
    ans = '0' + str(N) + 'ABC'
else:
    ans = str(N) + 'ABC'
print(ans)


### FIXED CODE ###

N = int(input())
if N < 100:
    ans = 'ABC' + '0' + str(N)
else:
    ans = 'ABC' + str(N)
print(ans)
for _ in range(3):
  A += list(map(int,input().split()))
N = int(input())
B = [int(input()) for _ in range(N)]
C = [0]*9
for i in B:
  if i in A:
    x = A.index(i)
    C[x] = 1
if C[0]*C[1]*C[2] == 1 or C[3]*C[4]*C[5]==1 or C[6]*C[7]*C[8] ==1 or C[0]*C[3]*C[6] ==1 or C[1]*C[4]*C[7]==1 or C[2]*C[5]*C[8] ==1 or C[0]*C[4]*C[8] ==1 or C[2]*C[4]*C[6] ==1:
  print("Yes")
else:
  print("No")
  

### FIXED CODE ###

A = []
for _ in range(3):
  A += list(map(int,input().split()))
N = int(input())
B = [int(input()) for _ in range(N)]
C = [0]*9
for i in B:
  if i in A:
    x = A.index(i)
    C[x] = 1
if C[0]*C[1]*C[2] == 1 or C[3]*C[4]*C[5]==1 or C[6]*C[7]*C[8] ==1 or C[0]*C[3]*C[6] ==1 or C[1]*C[4]*C[7]==1 or C[2]*C[5]*C[8] ==1 or C[0]*C[4]*C[8] ==1 or C[2]*C[4]*C[6] ==1:
  print("Yes")
else:
  print("No")
from math import factorial
L = [0]
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
    L.append(L[-1] + A[i])
L.sort()
ind = list(set(L))
for i in ind:
    n = L.count(i)
    if n > 1:
        cnt += factorial(n) / factorial(2) / factorial(n - 2)
print(int(cnt))

### FIXED CODE ###

from math import factorial as f
L = [0]
N = int(input())
A = list(map(int, input().split()))
cnt = 0
dic = {}
dic[0] = 1
for i in range(N):
    n = L[-1] + A[i]
    L.append(n)
    dic.setdefault(n, 0)
    dic[n] += 1
for key in dic.keys():
    if dic[key] > 1:
        cnt += f(dic[key]) // f(2) // f(dic[key] - 2)
print(int(cnt))
from math import gcd

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

lcm = 1
for a in A:
    lcm = lcm * a // gcd(lcm, a)


ans = 0
for a in A:
    # フェルマーの小定理
    ans += lcm * pow(a, MOD-2, MOD)
    ans %= MOD


print(ans)

### FIXED CODE ###

from fractions import gcd


def main():
        
    N = int(input())
    A = list(map(int, input().split())) 
    MOD = 10**9 + 7


    l = 1

    for a in A:
        l = l * a // gcd(l, a)


    ans = 0
    for a in A:
        ans += (l // a)
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()
import itertools
n,m,q=map(int,input().split())
abcd=[None]*q
for i in range(q):
    abcd[i]=list(map(int,input().split()))
num=0
for l in list(map(list, itertools.combinations(list(range(1,m+1))*m, n))):
    num_ = 0
    for x in abcd:
        if l[x[1]-1]-l[x[0]-1] == x[2]:
            num_ += x[3]
    num = max(num ,num_)
print(num)


### FIXED CODE ###

a,b,n=map(int, input().split())
if n < b:
    print((a*n)//b - a*(n//b))
else:
    print((a*(b-1))//b - a*((b-1)//b))
K=int(K)
if len(S)<=K:
    print(S)
else:
    print(S[:K]+"...")

### FIXED CODE ###

K=input()
S=input()
K=int(K)
if len(S)<=K:
    print(S)
else:
    print(S[:K]+"...")
import sys
n=int(input())
for i in range(1,10):
  x = n //i
  if n % i == 0 and 0 < x < 10:
    print('Yes')
 	sys.exit()
print('No')

### FIXED CODE ###

import sys
n=int(input())
for i in range(1,10):
  x = n //i
  if n % i == 0 and 0 < x < 10:
    print('Yes')
    sys.exit()
print('No')
x=input().split()

for i in range(3):
  y[i]=int(x[i])

y=[0]*3
ans=(y[2]-(y[0]-y[1]))

if ans>0:
  print(ans)
  
elif ans<0:
    print(0)

### FIXED CODE ###

x=input().split()

y=[0]*3

for i in range(3):
  y[i]=int(x[i])

ans=(y[2]-(y[0]-y[1]))

if ans>0:
  print(ans)
  
elif ans<=0:
  print(0)
x,n = map(int,input().split())
p = list(map(int,input().split()))
t = abs(min(p)-x)+1
u = min(p)-1
for i in range(min(x-1,min(p)-1),max(x+1,max(p)+2)):
	if not( i in p ):
		if abs(i-x)<t:
			t = abs(i-x)
			u = i
		elif  abs(i-x)==t:
			if i < u:
				u = i
print(u)

### FIXED CODE ###

x,n = map(int,input().split())
if n == 0:
	print(x)
else:
	p = list(map(int,input().split()))
	t = abs(min(p)-x)+1
	u = min(p)-1
	for i in range(min(x-1,min(p)-1),max(x+1,max(p)+2)):
		if not( i in p ):
			if abs(i-x)<t:
				t = abs(i-x)
				u = i
			elif  abs(i-x)==t:
				if i < u:
					u = i
	print(u)
A, B, X = map(int, input().split())
print("YES" A+B <= X else "NO")

### FIXED CODE ###

A, B, X = map(int, input().split())
print("YES" if A <= X <= A+B else "NO")
w = input()

for i in range(ord('a'),ord('z')+1):
  if w.count(chr(i))%2==1:
    print('No')
    break()
else: print('Yes')


### FIXED CODE ###

w = input()
 
for i in range(ord('a'),ord('z')+1):
  if w.count(chr(i))%2==1:
    print('No')
    break
else: print('Yes')
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    left = 1
    right = N if N%2 == 0 else N-1
    count = 0
    if N%2 == 0:
        raise Exception
        while count < M:
            if right-left == N//2:
                left += 1
                right -= 1
                continue
            print(left,right)
            left += 1
            right -= 1
            count += 1
    else:
        while count < M:
            print(left,right)
            left += 1
            right -= 1
            count += 1
    return


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
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    left = 1
    right = N if N%2 == 0 else N-1
    count = 0
    if N%2 == 0:
        p = set()
        while count < M:
            if right-left == N//2 or N-(right-left) in p:
                left += 1
                continue
            print(left,right)
            p.add(right-left)
            left += 1
            right -= 1
            count += 1
    else:
        while count < M:
            print(left,right)
            left += 1
            right -= 1
            count += 1
    return


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
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()
n = int(stdin.readline().rstrip())
d = stdin.readline().rstrip().split()
res = 0
count1 = 0
for el1 in d:
    count2 = 0
    for el2 in d:
        if (count2 > count1):
            res += int(el1) * int(el2)
        count2 += 1
    count1 += 1

print(res)

### FIXED CODE ###

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import copy

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''

n = int(stdin.readline().rstrip())
d = stdin.readline().rstrip().split()
res = 0
count1 = 0
for el1 in d:
    count2 = 0
    for el2 in d:
        if (count2 > count1):
            res += int(el1) * int(el2)
        count2 += 1
    count1 += 1

print(res)
def solve():
    N, A, B = map(int, input().split())
    if A + B == 0:
        print(0)
        exit(0)

    n_times = N // (A+B)
    amari = N % (A+B)
    cnt = 0
    if amari != 0:
        S = 'b' * A + 'r' * B
        S = S[:min(amari, len(S))]

        for ball in S:
            if ball == 'b':
                cnt += 1
    
    print(n_times * A + cnt)

if __name__ == '__main__':
    solve()

### FIXED CODE ###

def solve():
    N, A, B = map(int, input().split())

    n_times = N // (A+B)
    amari = N % (A+B)

    cnt = 0
    if A <= amari:
        cnt = A
    else:
        cnt = amari
    
    print(n_times * A + cnt)

if __name__ == '__main__':
    solve()
import math
import collections
import fractions
import itertools
import functools
import operator

def ncr(n, r):
    if n < r: return 0
    r = min(r, n-r)
    if r == 0:
        return 1
    numer = functools.reduce(operator.mul, range(n, n-r, -1), 1)
    denom = functools.reduce(operator.mul, range(1, r+1), 1)
    return numer / denom

def solve():
    n, k = map(int, input().split())
    for i in range(1,k+1):
        ans = (ncr(k-1, i-1) * ncr(n-k+1, i)) % (10**9+7)
        print(ans)
    return 0

if __name__ == "__main__":
    solve()


### FIXED CODE ###

import math
import collections
import fractions
import itertools
import functools
import operator

def ncr(n, r):
    if n < r: return 0
    r = min(r, n-r)
    if r == 0:
        return 1
    numer = functools.reduce(operator.mul, range(n, n-r, -1), 1)
    denom = functools.reduce(operator.mul, range(1, r+1), 1)
    return numer // denom % (10 ** 9 + 7)

def solve():
    n, k = map(int, input().split())
    for i in range(1,k+1):
        ans = (ncr(k-1, i-1) * ncr(n-k+1, i)) % (10**9+7)
        print(int(ans))
    return 0

if __name__ == "__main__":
    solve()
S = input()

if S[0] = S[1] and S[2] = S[3]
or S[0] = S[2] and S[1] = S[3]
or S[0] = S[3] and S[1] = S[2]:
  print(Yes)
else:
  print(No)

### FIXED CODE ###

S = input()

if S[0] == S[1] == S[2] == S[3]:
  print('No')
elif S[0] == S[1] and S[2] == S[3]:
  print('Yes')
elif S[0] == S[2] and S[1] == S[3]:
  print('Yes')
elif S[0] == S[3] and S[1] == S[2]:
  print('Yes')
else:
  print('No')
from fractions import gcd

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

rs, ls = [0], [0]
for i in range(n-1):
  rs.append(gcd(rs[i], a[i]))
  ls.append(gcd(ls[i], a[-i-1]))

print(max(gcd(r, l) for r, l in zip(rs, ls[::-1])))

### FIXED CODE ###

a, b, t = map(int, input().split())
print(int(((t + 0.5) // a) * b))
import sys

argv=sys.argv

#print(argv)

x=int(argv[1])
a=int(argv[2])

if(x<a):
    print(0)
else:
    print(10)


### FIXED CODE ###

import sys

#argv=sys.argv

#print(argv)

argv=input()
argv1,argv2=argv.split(" ")


x=int(argv1)
a=int(argv2)

if(x<a):
    print(0)
else:
    print(10)
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*(N+1)
B[0]=1
kaisuu=1
C=[-1]*(N+1)
C[0]=0
roo=0
rooa=0
while kaisuu>=0:
 B[kaisuu]=A[B[kaisuu-1]-1]
 if C[B[kaisuu]-1]>=0:
  roo=kaisuu-C[B[kaisuu]-1]
  rooa=C[B[kaisuu]-1]
  break
 else:
  C[B[kaisuu]-1]=kaisuu
  kaisuu+=1
if K<=rooa:
 print(lst[K])
else:
 d= (K-rooa)%roo
 print(B[rooa+d])

### FIXED CODE ###

N,K=map(int,input().split())
T=str(bin(K))
S=len(T)-2
A = list(map(int,input().split()))
lst=[[0 for e in range(N+1)] for f in range(S)]
for i in range(1,N+1):
 lst[0][i]=A[i-1]
for j in range(1,S):
 for i in range(1,N+1):
  lst[j][i]=lst[j-1][lst[j-1][i]]
ans=[[e for e in range(N+1)] for f in range(S+1)]
for k in range(S):
 if int(T[k+2])==1:
  for l in range(1,N+1):
   ans[k+1][l]=lst[S-1-k][ans[k][l]]
 else:
  for l in range(1,N+1):
   ans[k+1][l]=ans[k][l]
print(ans[S][1])
N = input().split()

i = 0
while True:

    if i ** 2 > N:
        print ((i-1)**2)
        break

### FIXED CODE ###


N = int(input())

i = 0
while True:

    if i ** 2 > N:
        print ((i-1)**2)
        break

    i += 1
a, b, c = map(int, input().solit())
capacity = a - b
answer = c - capacity
if answer < 0:
  answer = 0
print(answer)

### FIXED CODE ###

a, b, c = map(int, input().split())
capacity = a - b
if c > capacity:
    answer = c - capacity
else:
    answer = 0
    
print(answer)
from collections import Counter
n = int(input())
v = list(map(int,input().split()))
even = Counter(v[::2]).most_common(2)
odd = Counter(n[1::2]).most_common(2)
if even[0][0] != odd[0][0]:
    ans =  n - even[0][1] - odd[0][1]
else:
    if len(even) == 1:
        ans = n//2
    else:
        ans =  n - max(even[0][1] + odd[1][1],even[1][1],odd[0][1])
print(ans)


### FIXED CODE ###

from collections import Counter
n = int(input())
v = list(map(int,input().split()))
even = Counter(v[::2]).most_common(2)
odd = Counter(v[1::2]).most_common(2)

if even[0][0] != odd[0][0]:
    ans =  n - even[0][1] - odd[0][1]
else:
    if len(even) == 1 or len(odd)==1:#単一の要素からなる場合ex.)1111
        ans = n//2
    else:
        ans =  n - max(even[0][1] + odd[1][1],even[1][1]+odd[0][1])
print(ans)
N = int(input())
S, T = map(str, input().split())
S = S.split('')
T = T.split('')

for i in range(N):
  ans = []
  ans.append(S[i])
  ans.append(T[i])
print(''.join(ans))

### FIXED CODE ###

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

for i in range(N):
  ans = []
  for j in range(N):
    ans.append(S[j])
    ans.append(T[j])
print(''.join(ans))
N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
L = N*M//gcd(N,M)
res = ['!']*(L+100)
cnt1 = 0
for s in S:
    res[cnt1*L//N] = s
    cnt1 += 1
cnt2 = 0
for t in T:
    if res[cnt2*L//M] == '!' or res[cnt2*L//M] == t:
        res[cnt2*L//M] = t
        cnt2 += 1
    else:
        print(-1)
        exit()
print(L) 

### FIXED CODE ###

N,M = map(int,input().split())
S = input()
T = input()
from fractions import gcd
G = gcd(N,M)
if S[::N//G] == T[::M//G]:
    print(N*M//G)
else:
    print(-1)
x = int(input())
ans = []
for i in range(2, x):
    for l in range(2, x):
        if i ** l <= x:
            ans.append(i ** l)
        if i ** l > x:
            break

print(ans[len(ans)-1])



### FIXED CODE ###

x = int(input())
ans = []
for i in range(1, x+2):
    for l in range(2, x+2):
        if i ** l <= x:
            ans.append(i ** l)
        if i ** l > x:
            break
            

ans.sort()
print(ans[len(ans)-1])
S = input().split()
if S[0] != S[1] != S[2]:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

if sorted(input()) == ["a", "b", "c"]:
    print("Yes")
else:
    print("No")
S = input()
S.sort()
flag = True
if S[0] != S[1]:
  flag = False
if S[2] != S[3]:
  flag = False
if flag == True:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

N = input()
S = sorted(N)
flag = True
if S[0] != S[1]:
  flag = False
if S[2] != S[3]:
  flag = False
if S[1] == S[2]:
  flag = False
if flag == True:
  print("Yes")
else:
  print("No")
import sys
for line in sys.stdin:
    a,b = line.split()
    a,b = int(a),int(b)
    print '%d %d %5.6f' %(a/b, a%b, 1.0*a/b)

### FIXED CODE ###

a, b = map(int, raw_input().split())
print '%d %d %.12f' %(a/b, a%b, 1.0*a/b)
import sys
n = int(input())
a = list(map(int, input().split()))

def prime_decomposition(n):
    i = 2
    table = []
    while i**2 <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1: table.append(n)
    return set(table)

pri_0 = prime_decomposition(a[0])
pri_1 = prime_decomposition(a[1])

if len(pri_0&pri_1):
    for i in range(2, n):
        res = prime_decomposition(a[i])
        ans &= res
        if not ans:
            print('setwise coprime')
            sys.exit()
    print('not coprime')

else:
    ans = pri_0 | pri_1
    for i in range(2, n):
        res = prime_decomposition(a[i])
        for i in res:
            if i in ans:
                print('setwise coprime')
                sys.exit()
        ans |= res
    print('pairwise coprime')

### FIXED CODE ###

import sys
n = int(input())
a = list(map(int, input().split()))

def prime_decomposition(n):
    i = 2
    table = []
    while i**2 <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1: table.append(n)
    return set(table)

pri_0 = prime_decomposition(a[0])
pri_1 = prime_decomposition(a[1])
ans = pri_0&pri_1

if len(ans):
    for i in range(2, n):
        res = prime_decomposition(a[i])
        ans &= res
        if not ans:
            print('setwise coprime')
            sys.exit()
    print('not coprime')

else:
    ans = pri_0 | pri_1
    for i in range(2, n):
        res = prime_decomposition(a[i])
        for i in res:
            if i in ans:
                print('setwise coprime')
                sys.exit()
        ans |= res
    print('pairwise coprime')
import math
n,k = map(int,input().split())
p = list(map(int,input().split()))
max_array = sum(p[0:k])
a = math.inf
u = max_array
for i in range(k, n):
    u = u + p[i]-p[i-k]
    max_array = max(max_array, u)
print((max_array+k) / 2)
print("test")


### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
max_array = sum(p[0:k])
u = max_array
for i in range(k, n):
    u = u + p[i]-p[i-k]
    max_array = max(max_array, u)
print((max_array+k) / 2)
s = input()
t = input()
ans=0,cnt=0
for check in s:
    if t[cnt] == check:
        cnt+=1
    else:
        ans+=1
        cnt+=1
print(ans)

### FIXED CODE ###

s = input()
t = input()
ans=0
cnt=0
for check in s:
    if t[cnt] == check:
        cnt+=1
    else:
        ans+=1
        cnt+=1
print(ans)
n=int(input())
h=list(map(int,input().split()))
ans=0
while h!=[0]*n:
  b=(h[0]!=0)+0
  for i in range(n):
    if b==1 and h[i]==0:ans+=1;b=0
    if h[i]!=0:h-=1;b=1
  if b==1:ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
ans=0
while h!=[0]*n:
  b=(h[0]!=0)+0
  for i in range(n):
    if b==1 and h[i]==0:ans+=1;b=0
    if h[i]!=0:h[i]-=1;b=1
  if b==1:ans+=1
print(ans)
N,X,T = input(int()).split()


if N % X != 0:
  A = ((N // X) + 1 ) * T
else:
  A = (N/X) * T
print(int(A))

### FIXED CODE ###

N,X,T = input().split()

N = int(N)
X = int(X)
T = int(T)

if N % X != 0:
  A = ((N // X) + 1 ) * T
else:
  A = (N/X) * T
print(int(A))
a,b=map(int,inout().split())
if a>=0:
    print("Positive" if a!=0 else "Zero")
if a<0 and b>0:
    print("Zero")
if b<=0:
    if b==0:
        print("Zero")
    else:
        if (a-b+1)%2==0:
            print("Positive")
        else:
            print("Negative")

### FIXED CODE ###

a,b=map(int,input().split())
if a>=0:
    print("Positive" if a!=0 else "Zero")
if a<0 and b>0:
    print("Zero")
if b<=0:
    if b==0:
        print("Zero")
    else:
        if (a-b+1)%2==0:
            print("Positive")
        else:
            print("Negative")
n = input()
A = list(map(int, input().split()))
flags = [0] * 8
count = 0
for a in A:
  if a < 3200:
    flags[a // 400] += True
  else:
    counts += 1
print(sum(flags), sum(flags) + count)

### FIXED CODE ###

n = input()
A = list(map(int, input().split()))
flags = [False] * 8
count = 0
for a in A:
  if a < 3200:
    flags[a // 400] = True
  else:
    count += 1
print(max(sum(flags), 1), sum(flags) + count)
moves = [(0, -1), (0, 1), (-1, 0), (1, 0)]
 
 
def search(dataset):
    min_time = 0
    mouse = 1
    gx, gy = get_start(dataset)
    for i in xrange(N):
        gx, gy, min_time_tmp = bfs(dataset, (gx, gy), mouse)
        mouse += 1
        min_time += min_time_tmp
    print(min_time)
 
 
def bfs(dataset, start, mouse):
    INF = 10000000
    min_time = [[INF for j in range(W)] for i in range(H)]
    min_time[start[0]][start[1]] = 0
    queue = [start]
 
    while len(queue) != 0:
        dx, dy = queue.pop(0)
        for i, j in moves:
            nx = dx + i
            ny = dy + j
            if 0 <= nx < H and 0 <= ny < W and dataset[nx][ny] != 'X' and min_time[nx][ny] == INF:
                cell = dataset[nx][ny]
            else:
                continue
            if type(cell) is int:
                if mouse == int(cell):
                    min_time[nx][ny] = min_time[dx][dy] + 1
                    return nx, ny, min_time[nx][ny]
            min_time[nx][ny] = min_time[dx][dy] + 1
            queue.append((nx, ny))
 
 
def get_start(dataset):
    for i in range(H):
        rows = dataset[i]
        for j in range(W):
            cell = rows[j]
            if cell == 'S':
                return i, j
 
 
dataset = []
while True:
    line = input().rstrip().split()
    if len(line) == 3:
        H, W, N = map(int, line)
    else:
        row = []
        for e in line[0]:
            if e.isdigit():
                row.append(int(e))
            else:
                row.append(e)
        dataset.append(row)
    if len(dataset) == H:
        search(dataset)
        break

### FIXED CODE ###

def bfs(field,H,W,start_x,start_y,tmp_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * W for i in range(H)]
    min_path[start_y][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
                min_path[ny][nx] = min_path[current[1]][current[0]] + 1
                if field[ny][nx] == tmp_N:
                    return nx,ny,min_path[ny][nx]
                else:
                    que.append([nx,ny])

def getField():
    matrix = []
    first = input().strip()
    H,W,N = map(int,first.split())
    for i in range(H):
        row = list(input().strip())
        for j in range(W):
            if row[j].isdigit():
                row[j] = int(row[j])
        matrix.append(row)
    return matrix,H,W,N

def getStart(field):
    for y in range(len(field)):
        for x in range(len(field[0])):
            if field[y][x] == "S":
                return x,y

def main():
    matrix,H,W,N = getField()
    sx,sy = getStart(matrix)
    distance = 0
    tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,1)
    distance += tmp_dist
    tmps = [tmp_x,tmp_y]
    for k in range(N-1):
        tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+2)
        distance += tmp_dist
        tmps = [tmp_x,tmp_y]
    print(distance)

if __name__=='__main__':
    main()