Harryxun/stf_run huggingface dataset:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    INF = 10**18
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    n,ma,mb = LI()
    med = [LI() for _ in range(n)]
    h1 = []
    h2 = []

    for i in range(2 ** (n//2)):
        b = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n//2):
            if i & b:
                a,b,c = med[j]
                ta += a
                tb += b
                tc += c
            b <<= 1
        dif = ta * mb - tb * ma
        h1.append((dif,tc))

    for i in range(2 ** (n//2)):
        b = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n//2,n):
            if i & b:
                a,b,c = med[j]
                ta += a
                tb += b
                tc += c
            b <<= 1
        dif = tb * ma - ta * mb
        h2.append((dif,tc))

    h1.sort()
    h2.sort()
    i = 0
    ans = INF
    for h,c in h1:
        while h2[i][0] < h:
            i += 1
            if i >= len(h2): break
        if h == h2[i][0] and (h != 0 and h2[i][0] != 0):
            ans = min(ans,c+h2[i][1])
    if ans < INF:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    INF = 10**5
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    n,ma,mb = LI()
    med = [LI() for _ in range(n)]
    h1 = [INF] * 10000

    for i in range(1,2 ** (n//2)):
        bit = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n//2):
            if i & bit:
                a,b,c = med[j]
                ta += a
                tb += b
                tc += c
            bit <<= 1
        dif = ta * mb - tb * ma
        if h1[dif] > tc: h1[dif] = tc

    ans = h1[0]

    for i in range(1,2 ** (n - n//2)):
        bit = 1
        ta = 0
        tb = 0
        tc = 0
        for j in range(n - n//2):
            if i & bit:
                a,b,c = med[j+n//2]
                ta += a
                tb += b
                tc += c
            bit <<= 1
        dif = tb * ma - ta * mb
        if dif == 0:
            ans = min(ans,tc)
        else:
            ans = min(ans,h1[dif]+tc)

    if ans < INF:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()
import math
n = input()

def koch(n, p1_x, p2_x, p1_y, p2_y):
  if n == 0:
    return
  
  %p1, p2 ?????? s, t, u ????¨????

  s_x = (2*p1_x + p2_x) / 3
  s_y = (2*p1_y + p2_y) / 3
  t_x = (p1_x + 2*p2_x) / 3
  t_y = (p1_y + 2*p2_y) / 3

  u_x = (t_x - s_x)/2 - (t_y - s_y) * sqrt(3)/2 + s_x
  u_y = (t_x - s_x) * sqrt(3)/2 + (t_y - s_y)/2 + s_y

  koch(n-1, p1_x, s_x, p1_y, s_y)
  print s_x, s_y
  koch(n-1, s_x, u_x, s_y, u_y)
  print u_x, u_y
  koch(n-1, u_x, t_x, u_y, t_y)
  print t_x, t_y
  koch(n-1, t_x, p2_x, t_y, p2_y)

p1_x = 0.0
p1_y = 0.0
p2_x = 100.0
p2_y = 0.0

print p1_x, p1_y
koch(n, 0, 100, 0, 0)
print p2_x, p2_y

### FIXED CODE ###

import math
n = int(input())
 
def koch(n, p1_x, p2_x, p1_y, p2_y):
  if n == 0:
    return
 
  s_x = (2*p1_x + p2_x) / 3
  s_y = (2*p1_y + p2_y) / 3
  t_x = (p1_x + 2*p2_x) / 3
  t_y = (p1_y + 2*p2_y) / 3
 
  u_x = (t_x - s_x)/2 - (t_y - s_y) * math.sqrt(3)/2 + s_x
  u_y = (t_x - s_x) * math.sqrt(3)/2 + (t_y - s_y)/2 + s_y
 
  koch(n-1, p1_x, s_x, p1_y, s_y)
  print (s_x, s_y)
  koch(n-1, s_x, u_x, s_y, u_y)
  print (u_x, u_y)
  koch(n-1, u_x, t_x, u_y, t_y)
  print (t_x, t_y)
  koch(n-1, t_x, p2_x, t_y, p2_y)
 
p1_x = 0.0
p1_y = 0.0
p2_x = 100.0
p2_y = 0.0
 
print (p1_x, p1_y)
koch(n, 0, 100, 0, 0)
print (p2_x, p2_y)
A = int(input())
B = int(input())

list_ans = [A+B, A-B, A*B]

print(max(list_ans))

### FIXED CODE ###

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

list_ans = [A+B, A-B, A*B]

print(max(list_ans))
import sys
input = sys.stdin.readline
S = list(map(int, list(input())[: -1]))
K = int(input())
x = 0
for i in range(len(S)):
  if S[i] == 1: x += 1
  else: break
if S[0] == 1:
  if K == x: print(1)
  else: print(S[x])
else: print(S[0])

### FIXED CODE ###

import sys
input = sys.stdin.readline
S = list(map(int, list(input())[: -1]))
K = int(input())
x = 0
for i in range(len(S)):
  if S[i] == 1: x += 1
  else: break
if K <= x: print(1)
else: print(S[x])
a,b = map(int, input().split())
if (a>b):
????????print("a > b")
elif (a<b):
????????print("a < b")
elif (a==b):
????????print("a == b")

### FIXED CODE ###

a, b = map(int, input().split())
if (a > b):
	print("a > b")
elif (a < b):
	print("a < b")
elif (a == b):
	print("a == b")
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    A = sorted(il(), reverse=True)

    ret = 0
    for i in range(N):
        for j in range(i + 1, N):
            if A[i] % A[j] == 0:
                break
        else:
            if A[j] not in A[:i]:
                ret += 1
    print(ret)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    A = il()
    A.sort()

    already = set()
    cnt = collections.Counter(A)
    mx = max(A)
    ret = 0
    for a in A:
        if a in already: continue
        if cnt[a] == 1:
            ret += 1

        i = 1
        while a * i <= mx:
            already.add(a * i)
            i += 1
    print(ret)


if __name__ == '__main__':
    main()
n, k, c = map(int, input().split())
s = list(input())
cnt = s.count('o')
os = [i for i,x in enumerate(s) if x=='o']

from collections import deque

q = deque(os.copy())
_q1 = q.popleft()
m = k-1
l = [_q1]
if m > 0:
    while q:
        _q2 = q.popleft()
        if _q2 - _q1 > c:
            l.append(_q2)
            _q1 = _q2
            m -= 1
            if m == 0:
                q = deque([])
        else:
            pass

q = deque(os.copy())
_q2 = q.pop()
m = k-1
r = [_q2]
if m > 0:
    while q:
        _q1 = q.pop()
        if _q2 - _q1 > c:
            r.append(_q1)
            _q2 = _q1
            m -= 1
            if m == 0:
                q = deque([])
        else:
            pass

r = list(reversed(r))

ans = 0
for _l, _r in zip(l, r):
    if _l == _r:
        print(str(_l+1))
        ans = 1

if ans == 0:
    print()


### FIXED CODE ###

n, k, c = map(int, input().split())
s = list(input())
# cnt = s.count('o')
os = [i for i,x in enumerate(s) if x=='o']

from collections import deque

q = deque(os.copy())
_q1 = q.popleft()
m = k-1
l = [_q1]
if m > 0:
    while q:
        _q2 = q.popleft()
        if _q2 - _q1 > c:
            l.append(_q2)
            _q1 = _q2
            m -= 1
            if m == 0:
                q = deque([])
        else:
            pass

q = deque(os.copy())
_q2 = q.pop()
m = k-1
r = [_q2]
if m > 0:
    while q:
        _q1 = q.pop()
        if _q2 - _q1 > c:
            r.append(_q1)
            _q2 = _q1
            m -= 1
            if m == 0:
                q = deque([])
        else:
            pass

r = list(reversed(r))

ans = 0
for _l, _r in zip(l, r):
    if _l == _r:
        print(str(_l+1))
        ans = 1

if ans == 0:
    print()
from itertools import product

X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

if X * Y * Z > 3000:
    X = 3000
    Y = 3000
    Z = 3000

a1 = []
mXY = min(X,Y)
for i, j in product(A[0:mXY], B[0:mXY]):
    a1.append(i + j)
a1.sort(reverse=True)

ans_list = []
for i, j in product(a1[0:min(mXY,Z)], C[0:min(mXY,Z)]):
    ans_list.append(i + j)

ans_list.sort(reverse=True)

for i in range(K):
    print(ans_list[i])


### FIXED CODE ###

from itertools import product

X, Y, Z, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

a = []
count = 0
for i in range(X):
    for j in range(Y):
        if (i+1)*(j+1) > K:
            break
        for k in range(Z):
            if (i+1)*(j+1)*(k+1) > K:
                break
            a.append(A[i] + B[j] + C[k])

a.sort(reverse=True)

for i in range(K):
    print(a[i])
A,B = map(int,input().split())
import math
d = math.gcd(A,B)
print(A*B//d)

### FIXED CODE ###

A,B = map(int,input().split())
import fractions
d = fractions.gcd(A,B)
print(A*B//d)
a=int(input())
print(a.count("1"))

### FIXED CODE ###

a=input()
print(a.count("1"))
while True:
??????????x, y = [int(i) for i in input().split()]
????
??????????if x == y == 0:
??????????????????break
????
??????????if x > y:
??????????????????x, y = y, x
????
??????????print(x,y)

### FIXED CODE ###

a, b, c = [int(i) for i in input().split()]
count = 0
for x in range(a, b+1):
    if c % x == 0:
        count += 1
print(count)
import math

def comb(a, b):
	return int(math.factorial(a) / math.factorial(b) / math.factorial(a-b))

if __name__ == '__main__':
	n = int(input())
	a = [int(x) for x in input().split(' ')]

	sa = sorted(a)

	oldcmb = -float('inf')
	oldi, oldj = (-1, -1)
	i, j = (-1, -1)
	for i in range(n):
		for j in range(n):
			if i == j or i < j:
				break
			cmb = comb(sa[i], sa[j])
			# print('old:{} new:{}[{}][{}]'.format(oldcmb, cmb, i, j))
			if cmb > oldcmb:
				oldcmb = cmb
				oldi, oldj = (i, j)
		if j == n-1:
			break

	print('{} {}'.format(sa[oldi], sa[oldj]))
	# print('{}:{} {}:{}'.format(oldi, sa[oldi], oldj, sa[oldj]))

### FIXED CODE ###

if __name__ == '__main__':
	a,b,x = map(int, input().split(' '))
	if x - a < b and x >= a:
		print('YES')
	else:
		print('NO')
a,b,c = map(int,input().split())
if(b+c >= a):
print(b+c-a)
else:
  print(0)

### FIXED CODE ###

a,b,c = map(int,input().split())
if(b+c >= a):
  print(b+c-a)
else:
  print(0)
s,t=input().split()
a,b=map(int,iinput().split())
u=input()
if u==s:
  a=a-1
if u==t:
  b=b-1
print(a,b)

### FIXED CODE ###

s,t=input().split(' ')
a,b=map(int,input().split())
u=input()
if u==s:
    a=a-1
if u==t:
    b=b-1
print(str(a)+' '+str(b))
import math
N = int(input())
S = str(input())

if N == 1:
    print('No')
    exit()
if N%2 == 1:
    print('No')
    exit()

n = (N/2)
j = True


for i in range(n):
    if S[i] != S[i + n]:
        j = False

if j:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import math
N = int(input())
S = str(input())

if N == 1:
    print('No')
    exit()
if N%2 == 1:
    print('No')
    exit()

n = (N//2)
j = True


for i in range(n):
    if S[i] != S[i + n]:
        j = False

if j:
    print('Yes')
else:
    print('No')
q1=list(map(int,input().split(" ")))
a1=list(map(int,input().split(" ")))

sumsum=0
for i in range(q[0]-q1[1]+1):
    sum1=sum(a1[i:i+q1[1]])
    if(sumsum<sum1):
        sumsum=sum1
sumsum+=q1[1]
print(sumsum/2)


### FIXED CODE ###

q1=list(map(int,input().split(" ")))
a1=list(map(int,input().split(" ")))


sum1=sum(a1[:q1[1]])
sumsum=sum1
for i in range(q1[0]-q1[1]):
    sum1=sum1+a1[i+q1[1]]-a1[i]
    if(sumsum<sum1):
        sumsum=sum1
sumsum+=q1[1]
print(sumsum/2)
num=raw_input()
tmp=raw_input()
tmp2=raw_input()
bef="none"
n_state=0
af_state=0
if tmp[0]==tmp[1]:
    out=6
else:
    out=3

for i in range(1,len(tmp)):
    if tmp[i]!=bef:
        if i<int(num)-1:
            if tmp[i]==tmp[i+1]:
                if n_state==0:
                    out=out*2
                else:
                    out=out*3
                    n_state=0
            else:
                if n_state==0:
                    out=out*2
                else:
                    out=out*1
                    n_state=0
        else:
            if n_state==0:
                out=out*2
            else:
                out=out*1
                n_state=0
    else:
        n_state=1
    bef=tmp[i]
print out % 1000000007


### FIXED CODE ###

num=raw_input()
tmp=raw_input()
tmp2=raw_input()
bef="none"
n_state=0
af_state=0
if len(tmp)==1:
    out=3
else:
    if tmp[0]==tmp[1]:
        out=6
        n_state=1
        init=2
    else:
        out=3
        init=1
    #out=3

    for i in range(init,len(tmp)):
        if tmp[i]!=bef:
            #print "aaa"
            if i<int(num)-1:
                if tmp[i]==tmp[i+1]:
                    if n_state==0:
                        out=out*2
                    else:
                        out=out*3
                        n_state=0
                else:
                    if n_state==0:
                        out=out*2
                    else:
                        out=out*1
                        n_state=0
            else:
                if n_state==0:
                    out=out*2
                else:
                    out=out*1
                    n_state=0
        else:
            n_state=1
        bef=tmp[i]
print out % 1000000007
x, y = list(map(int, input.split()))
print(x + y // 2)

### FIXED CODE ###

x, y = list(map(int, input().split()))
print(x + y // 2)
N = int(input())
a = 0
n = N
while n >= 10:
    a += n%10
    n //= 10
print('Yes' if N % a == 0 else 'No')


### FIXED CODE ###

N = int(input())
a = 0
n = N
while n >= 1:
    a += n%10
    n //= 10
print('Yes' if N % a == 0 else 'No')
s = dict()
s["a"] = list(input())[::-1]
s["b"] = list(input())[::-1]
s["c"] = list(input())[::-1]

index = s.pop()

while s[index]:
    index = s.pop()

print(index.upper())

### FIXED CODE ###

s = dict()
s["a"] = list(input())[::-1]
s["b"] = list(input())[::-1]
s["c"] = list(input())[::-1]

index = s["a"].pop()

while s[index]:
    index = s[index].pop()

print(index.upper())
N, M = map(int,input().split())
H = []
L = [[] for k in range(M+1)]

for k in range(N):
    P = list(map(int,input().split()))[1:]
    H.append(P)
    for e in P:
        L[e].append(k+1)

G = [0 for k in range(N+1)]
G[1] = 1
Q = [H[0]]
while len(Q) > 0:
    ima = Q.pop()
    if len(ima) == 1 and G[ima[0]] == 1:
        pass
    for tsugi in ima:
        for e in L[tsugi]:
            if G[e] == 0:
                G[e] = 1
                if len(H[e-1]) > 1:
                    Q.append(H[e-1])

for k in range(1,N+1):
    if G[k] == 0:
        print("NO")
        exit(0)
print("YES")


### FIXED CODE ###

N, M = map(int,input().split())
H = []
L = [[] for k in range(M+1)]

for k in range(N):
    P = list(map(int,input().split()))[1:]
    H.append(P)
    for e in P:
        L[e].append(k+1)

G = [0 for k in range(N+1)]
G[1] = 1
Q = [H[0]]
while len(Q) > 0:
    ima = Q.pop()
    for tsugi in ima:
        for e in L[tsugi]:
            if G[e] == 0:
                G[e] = 1
                if len(H[e-1]) > 1:
                    Q.append(H[e-1])

for k in range(1,N+1):
    if G[k] == 0:
        print("NO")
        exit(0)
print("YES")
Nchar = input()
length = len(Nchar)

N = int(Nchar)
tmp = N
fx = 0
for i in range(length):
    kazu = int(tmp*(0.1**(length-i)))
    fx = fx + kazu
    tmp = tmp - kazu

if(N%fx == 0):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N = input()

fx = 0
length = len(N)
for i in range(length):
    fx = fx + int(N[i])

if int(N)%fx == 0:
    print("Yes")
else:
    print("No")
n, m = map(int,input().split())
ab = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    ai,bi = map(int,input().split())
    ab[ai-1][bi-1] = 1
    ab[bi-1][ai-1] = 1

count = 0

def dfs(x,v):
    l = v.copy()
    l.append(x)
    if len(l)==n:
        global count
        count += 1
    for i in range(n):
        if ab[x][i] == 1 and not i in l:
            dfs(i,l)
    
dfs(0,[])
print(count)

### FIXED CODE ###

from copy import copy
n, m = map(int,input().split())
ab = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    ai,bi = map(int,input().split())
    ab[ai-1][bi-1] = 1
    ab[bi-1][ai-1] = 1

count = 0

def dfs(x,v):
    l = copy(v)
    l.append(x)
    if len(l)==n:
        global count
        count += 1
    for i in range(n):
        if ab[x][i] == 1 and not i in l:
            dfs(i,l)
    
dfs(0,[])
print(count)
a,b = map(int, input().split())
tap = a
i = 1
while tap < b:
	tap = tap + a-1
	i += 1
return i


### FIXED CODE ###

a,b = map(int, input().split())
tap = a
i = 0
if b != 1:
	while tap < b:
		tap = tap + a-1
		i += 1
	print(i + 1)
else:
  	print(0)
D = input()

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

### FIXED CODE ###

D = input()

if D == "25":
    print("Christmas\n")
elif D == "24":
    print("Christmas Eve\n")
elif D == "23":
    print("Christmas Eve Eve\n")
else:
    print("Christmas Eve Eve Eve\n")
r,g,a = map(int, input().split())


print("YES" if (g*10+a)%4===0 else "NO")

### FIXED CODE ###

r,g,a = map(int, input().split())


print("YES" if (g*10+a)%4==0 else "NO")
import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=dict()
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[(ri,ci)]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if (0,0) in v:
        if v[(0,0)]>0:
            dp[0][0][1]=v[(0,0)]
    for i in range(r):
        for j in range(c):
            if i>0:
                if (i,j) in v:
                    if v[(i,j)]>0:
                        for k in range(min(3,j+1)+1):
                            dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[(i,j)])
                for k in range(4):
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i-1][j])
            if j>0:
                if (i,j) in v:
                    if v[(i,j)]>0:
                        for k in range(min(3,j+1)+1):
                            if k>0:
                                dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[(i,j)])
                for k in range(4):
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans)
if __name__=="__main__":
    main()

### FIXED CODE ###

import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if v[0][0]>0:
        dp[1][0][0]=v[0][0]
    for i in range(r):
        for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans)
if __name__=="__main__":
    main()
h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1

m = [[-1] * w for _ in range(h)]
for hh in range(h):
    c = input()
    for ww, cc in enumerate(c):
        if cc == '.':
            m[hh][ww] = h*w

from collections import deque
q = deque()

q.append((0, x1, y1))
while q:
    s, x, y = q.popleft()

    for i in range(1, k+1):
        xx, yy = x + i, y
        if xx >= h or m[xx][yy] == -1:
            break
        if m[xx][yy] <= s+1:
            continue
        if xx == x2 and yy == y2:
            print(s+1)
            exit(0)
        m[xx][yy] = s+1
        q.append((s+1, xx, yy))

    for i in range(1, k+1):
        xx, yy = x - i, y
        if xx < 0 or m[xx][yy] == -1:
            break
        if m[xx][yy] <= s+1:
            continue
        if xx == x2 and yy == y2:
            print(s+1)
            exit(0)
        m[xx][yy] = s+1
        q.append((s+1, xx, yy))

    for i in range(1, k+1):
        xx, yy = x, y + i
        if yy >= w or m[xx][yy] == -1:
            break
        if m[xx][yy] <= s+1:
            continue
        if xx == x2 and yy == y2:
            print(s+1)
            exit(0)
        m[xx][yy] = s+1
        q.append((s+1, xx, yy))

    for i in range(1, k+1):
        xx, yy = x, y - i
        if yy < 0 or m[xx][yy] == -1:
            break
        if m[xx][yy] <= s+1:
            continue
        if xx == x2 and yy == y2:
            print(s+1)
            exit(0)
        m[xx][yy] = s+1
        q.append((s+1, xx, yy))

print(-1)


### FIXED CODE ###

x = input().split()

print(x.index('0')+1)
number = input().split()
if number[0] + number[1] + number[2] >= 22:
  print('bust')
else:
  print('win')  


### FIXED CODE ###

number = input().split()
if int(number[0]) + int(number[1]) + int(number[2]) >= 22:
  print('bust')
else:
  print('win')
r, c = [int(i) for i in input().split()]

data = []
sum_row =[0] * (c + 1)

for ri in range(r):
    data[ri].append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri] [ci]

print(" ".join)

from pprint import pprint
pprint(data)
pprint(sum_row)

### FIXED CODE ###

r, c = [int(i) for i in input().split()]
 
data = []
sum_row = [0] * (c + 1)
 
for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]
 
print(" ".join([str(s) for s in sum_row]))
a=""
for i in range(3):
  l=input().split()
  a=a+l[i]
print(a)

### FIXED CODE ###

a=""
for i in range(3):
  l=input().split()
  a=a+l[0][i]
print(a)
a=int(input())
b=int(input())

print(a*b," ",2*a+2*b)


### FIXED CODE ###

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

print(a*b,2*a+2*b)
x, y = [int(i) for i in input.split(" ")]
print(x*y)

### FIXED CODE ###

x,y = [int(i) for i in input().split()]
area = x*y
length = (x*2)+(y*2)
print(area,length)