Harryxun/stf_run huggingface dataset:
import numpy as np

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

C = np.zeros((N, N))

for i in range(N-1):
  C[i][i] = 0.5
  C[i+1][i] = 0.5

C[0][N-1] = 0.5
C[N-1][N-1] = 0.5

Cin = np.linalg.inv(C)
B = np.dot(A , Cin)

print (int(B[0]), end = "")
for i in range(1,N):
  print ( " " + str(int(B[i])), end = "")
  

### FIXED CODE ###

import numpy as np

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

X = [0]*N
X[0] = sum(A) - 2 * (sum(A[1:N-1:2]))
for i in range(1, N):
  X[i] = 2 * A[i-1] - X[i-1]
print (' '.join(map(lambda x: str(x), X)))
from sys import stdin
import operator as op
from functools import reduce

def nCr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom

if __name__ == "__main__":
	N, A, B = stdin.readline().split(" ")
	N = int(N)
	A = int(A)
	B = int(B)
	V = []
	line = stdin.readline().split(" ")
	unique_elements = dict()
	for e in line:
		V.append(int(e)) 
		if not int(e) in unique_elements:
			unique_elements[int(e)] = 1
		else:
			unique_elements[int(e)] += 1
	V.sort(reverse=True)


	# find optimal selections between A and B
	optimal = [A]
	highest_avg = -1
	for i in range(A, B+1):
		avg = float(sum(V[:i])) / float(i)
		if (avg > highest_avg):
			highest_avg = avg
			optimal = [i] # reset the list
		elif (avg == highest_avg):
			if not i in optimal:
				optimal.append(i)

	total = 1
	for e in optimal:
		# unique elements and count in for optimal value
		op_elemements = dict()
		for i in range(e):
			if V[i] in op_elemements:
				op_elemements[V[i]] += 1
			else:
				op_elemements[V[i]] = 1

		# find the sum
		for key, value in op_elemements.items():
			total = total * nCr(unique_elements[key], value)

	print ("{:6f}".format(highest_avg))
	print (int(total))


### FIXED CODE ###

from sys import stdin

def combination_table(N):
	C = []
	for i in range(N+1):
		C.append([0] * (N+1))
	for i in range(N+1):
		for j in range(i+1):
			if (j==0 or j==i):
				C[i][j] = 1
			else:
				C[i][j] = C[i-1][j-1]+C[i-1][j]
	return C

if __name__ == "__main__":
	N, A, B = stdin.readline().split(" ")
	N = int(N)
	A = int(A)
	B = int(B)
	V = []
	line = stdin.readline().split(" ")
	unique_elements = dict()
	for e in line:
		V.append(int(e)) 
		if not int(e) in unique_elements:
			unique_elements[int(e)] = 1
		else:
			unique_elements[int(e)] += 1
	V.sort(reverse=True)

	C = combination_table(N)

	# find optimal selections between A and B
	a_th_val_pos = 0
	a_th_val_num = 0
	highest_avg = float(sum(V[:A])) / float(A)
	for i in range(N):
		if V[i] == V[A-1]:
			a_th_val_num += 1
			if i < A:
				a_th_val_pos += 1


	cnt = 0
	if a_th_val_pos == A:
		for i in range(A, B+1):
			cnt += C[a_th_val_num][i]
	else:
		cnt += C[a_th_val_num][a_th_val_pos]

	print ("{:6f}".format(highest_avg))
	print (cnt)
merry=[4,1,4,1,2,1,2,1]
while True:
    try:
        guest=map(int,raw_input().split())
    except EOFError:
        break
    m=10000
    for i in range(len(merry)):
        temp=merry[i:]+merry[:i]
        s=sum([guest[i]-temp[i] for i in range(len(merry)) if guest[i]-temp[i]>\
=0])
        m=min(m,s)
    P=set([])
    for i in range(len(merry)):
        temp=merry[i:]+merry[:i]
        s=sum([guest[i]-temp[i] for i in range(len(merry)) if guest[i]-temp[i]>\
=0])
        if s==m:
            P.add(int("".join(map(str,temp))))
    print " ".join(list(str(min(P))))

### FIXED CODE ###

c=[4,1,4,1,2,1,2,1]
while True:
    try:
        p=map(int,raw_input().split())
    except EOFError:
        break
    m,ans=100000000,"9"*10
    for i in range(len(c)):
        t=c[i:]+c[:i]
        s=sum([p[i]-t[i] for i in range(len(c)) if p[i]>t[i]])
        if (s<m) or (s==m and int(ans)>int("".join(map(str,t)))):
            m=s
            ans="".join(map(str,t))
    print " ".join(ans)
nums=input().split()
t=int(nums[1])/int(nums[3])
if t<=int(nums[2]):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

nums=input().split()
t=int(nums[0])/int(nums[2])
if t<=int(nums[1]):
  print("Yes")
else:
  print("No")
from itertools import product
import numpy as np

H, W, K = [int(n) for n in input().split()]
arr = np.zeros((H, W))
count = 0

for h in range(H):
    row = input()
    arr[h, :] = np.array([0 if mark=='.' else 1 for mark in row])

for row_onehot, col_onehot in product(product(range(2), repeat=H), product(range(2), repeat=W)):
    row_indexes = np.argwhere(np.array(row_onehot)==1).flatten()
    col_indexes = np.argwhere(np.array(col_onehot)==1).flatten()
    arr_ = arr.copy()
    for row_idx in row_indexes:
        arr_[row_idx, :] = 0
    for col_idx in col_indexes:
        arr_[:, col_idx] = 0
    if arr_.sum() == K:
        count += 1

print(count)

### FIXED CODE ###

from itertools import product
import numpy as np

H, W, K = [int(n) for n in input().split()]
arr = np.zeros((H, W))
count = 0

for h in range(H):
    row = input()
    arr[h, :] = np.array([0 if mark=='.' else 1 for mark in row])

for row_onehot, col_onehot in product(product(range(2), repeat=H), product(range(2), repeat=W)):
    row_indexes = np.argwhere(np.array(row_onehot)==1).flatten()
    col_indexes = np.argwhere(np.array(col_onehot)==1).flatten()
    arr_ = arr.copy()
    for row_idx in row_indexes:
        arr_[row_idx, :] = 0
    for col_idx in col_indexes:
        arr_[:, col_idx] = 0
    if arr_.sum() == K:
        count += 1

print(count)
A,B,C,D,E=map(int,input().split())
    if A == 0:
        print('1')
    elif B == 0:
        print('2')
    elif C == 0:
        print('3')
    elif D == 0:
        print('4')
    else E == 0:
        print('5')


### FIXED CODE ###

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

if A == 0:
    print(1)
elif B == 0:
    print(2)
elif C == 0:
    print(3)
elif D == 0:
    print(4)
else:
    print(5)
def main():
    import sys
    from collections import deque
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, M = [int(x) for x in input().strip().split()]
    G = [deque([]) for _ in range(M)]
    for m in range(M):
        a, b = [int(x) for x in input().strip().split()]
        G[a-1].append(b)
        G[b-1].append(a)
    
    vec = [-1] * N
    q = deque([(0, 1)])
    while q:
        cur, np = q.popleft()
        if vec[np-1] == -1:
            vec[np-1] = cur
            for g in G[np-1]:
                q.append((np, g))
    
    if -1 in vec:
        print(vec)
        print('No')
    else:
        print('Yes')
        for v in vec[1:]:
            print(v)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    from collections import deque
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, M = [int(x) for x in input().strip().split()]
    G = [deque([]) for _ in range(N)]
    for m in range(M):
        a, b = [int(x) for x in input().strip().split()]
        G[a-1].append(b)
        G[b-1].append(a)
    
    vec = [-1] * N
    q = deque([(0, 1)])
    while q:
        cur, np = q.popleft()
        if vec[np-1] == -1:
            vec[np-1] = cur
            for g in G[np-1]:
                q.append((np, g))
    
    if -1 in vec:
        print('No')
    else:
        print('Yes')
        for v in vec[1:]:
            print(v)

if __name__ == '__main__':
    main()
w,h,x,y=map(int,input().split())
z=0
if x==h//2 or x==w//2 or y==h//2 or y==w//2:
    z=1
print(w*h/2+' '+z)

### FIXED CODE ###

w,h,x,y=map(int,input().split())
z=0
if x==h//2 and y==w//2 :
    z=1
elif y==h//2 and x==w//2:
    z=1
if w%2==1 or h%2==1:
    z=0
print(w*h/2,z)
import sys
sys.stdin.readline()
#sys.stdin = f

N = int(input())
A = [ int(input()) for _ in range(N)]
cntA = [0 for _ in range(max(A)+1)]
for a in A:
    cntA[a] += 1
    cntA[a] %= 2
print(sum(cntA))

### FIXED CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
cnt = 1
ans = 0
if len(A) == 1:
    print(1)
    exit()
for i in range(1,N):
    if A[i-1] == A[i]:
        cnt += 1
    else:
        ans += cnt%2
        cnt = 1
if cnt >= 1:
    ans += cnt%2
print(ans)
from fractions import Fraction
from collections import Counter


class PickingUp:
    def __init__(self):
        self.N = int(input())
        self.points = []
        for n in range(self.N):
            self.points.append([int(n) for n in input().split()])

    def main(self):
        pattern_list = []
        slope_list = []
        for s in range(self.N):
            for e in range(s + 1, self.N):
                slope = self.__cal_slope(self.points[s], self.points[e])
                slope_list.append(slope)

        c = Counter(slope_list)
        most = c.most_common()[0][1]

        if self.N == 1:
            pattern_list.append(1)
        else:
            print(self.N - most)

    def __cal_slope(self, s, e):
        if s[0] != e[0]:
            return Fraction((s[1] - e[1]), (s[0] - e[0]))
        else:
            return None

    def __cal_section(self, slope, point):
        if slope is not None:
            return point[1] - slope * point[0]
        else:
            return point[0]


pickingUp = PickingUp()
pickingUp.main()


### FIXED CODE ###

from collections import Counter


class PickingUp:
    def __init__(self):
        self.N = int(input())
        self.points = []
        for n in range(self.N):
            self.points.append([int(n) for n in input().split()])

    def main(self):
        dif_list = []

        if self.N == 1:
            print(1)
            return

        for s in range(self.N):
            for e in range(self.N):
                if s == e:
                    continue
                dif = self.__cal_dif(self.points[s], self.points[e])
                dif_list.append("{},{}".format(dif[0], dif[1]))

        c = Counter(dif_list)
        most = c.most_common()[0][1]

        print(self.N - most)

    def __cal_dif(self, s, e):
        dif_x = s[0] - e[0]
        dif_y = s[1] - e[1]
        return [dif_x, dif_y]


pickingUp = PickingUp()
pickingUp.main()
n,q=map(int,input().split())
s=[0]*-~n
w=m=0
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v
 if v<0 and a==w:m=max(s);w=s.index(m)
 elif s[a]>maxv:w,m=a,s[a]
 elif s[a]==maxv:w=min(w,a)
 print(w,m)


### FIXED CODE ###

import sys
def f():
 w=m=0;n,q=map(int,input().split());s=[0]*-~n
 for e in sys.stdin:
  a,v=map(int,e.split());s[a]+=v
  if v<0 and a==w:m=max(s);w=s.index(m)
  elif s[a]>m:w,m=a,s[a]
  elif s[a]==m and w>a:w=a
  print(w,m)
f()
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 22:03:19 2020

@author: liang
"""

N, X, M = map(int,input().split())
mod_set = {X}
mod_lis = [X]
A = [0]*(10**5+1)
A[0] = X
for i in range(1,N):
    tmp = A[i-1]**2%M
    if tmp in mod_set:
        break
    A[i] = tmp
    mod_set.add(tmp)
    mod_lis.append(tmp)

j = mod_lis.index(tmp)
T = i - j
ans = 0
if T != 0:  
    ans += sum(mod_lis[:j])
    T_sum = sum(mod_lis[j:i])
    ans += T_sum * (N-j)//T
    T_lis = mod_lis[j:i]    
    ans += sum(T_lis[:(N-j)%T])
else:
    ans = sum(mod_lis)
#print(T_lis)
print(ans)
#print(T_sum)
#print(sum(T_lis))


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Sep 19 22:58:03 2020

@author: liang
"""

N,X,M=map(int,input().split())
a = X
hist = [a]
indices = [-1]*M
indices[a] = 0
flag=0
for i in range(1,min(10**6,N)):
  a = a**2 % M
  if indices[a] != -1:
    idx = indices[a]
    flag=1
    break
  hist.append(a)
  indices[a] = i
  
if flag==0:
  print(sum(hist))
  exit()
  
cycle = hist[idx:]
margin = hist[:idx]
q,r = divmod((N-len(margin)),len(cycle))
ans = 0
ans += sum(margin)
ans += sum(cycle)*q
#print(q,sum(cycle))
ans += sum(cycle[:r])
#print(r)
#print(cycle[:10])
print(ans)
print(B*(T//A))


### FIXED CODE ###

A, B, T = map(int, input().split())
print(B*(T//A))
s = input()

if s[-1] != "s":
  s.append("s")
  
else:
  s.append("es")
  
print(s)

### FIXED CODE ###

s = input()

if s[-1] != "s":
  s = s + "s"
  
else:
  s = s + "es"
  
print(s)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = [0] * N
    for i, a in enumerate(reversed(A)):
        tmp = N - i 
        cnt = 1
        tmp_sum = 0
        if tmp == 1:
            if a % 2 == sum(ans) % 2:
                break
            else:
                ans[tmp-1] = 1
                break
        while tmp <= N:
            tmp_sum += ans[tmp-1]
            cnt = cnt + 1
            tmp = tmp * cnt
        
        if a % 2 == tmp_sum % 2:
            continue
        else:
            ans[tmp-1] = 1
    if ans.count(0) == len(ans):
        print(0)
    else:
        print(len(ans))
        print(*ans)
main()

### FIXED CODE ###

def main():
    N = int(input())
    a = [0] + list(map(int, input().split()))

    b = [0] * (N + 1) 

    for i in range(N,0,-1):
        sum = 0
        for j in range(2*i, N+1, i):
            sum += b[j]
        if sum % 2 != a[i] % 2:
            b[i] = 1
    
    ans = []
    for i in range(1,N+1):
        if b[i] == 1:
            ans.append(i)
    
    print(len(ans))
    print(*ans)

main()
N = map(int, input().split())
# M=1
# A=[5,4,2,1]

cnt = 0
cnt1 = 0

# for i in range(N):
#     cnt = cnt + A[i]
#
# for i in range(N):
#     if A[i] / cnt > 1 / 4 / M:
#         cnt1 = cnt1 + 1

sum=0
for i in range(N+1):
    if (i % 3) != 0 and (i % 5) != 0:
        sum=sum+i
        # print(i,sum)

# a1 = N % 10
# a2 = ((N-a1*10) % 100)/10
# a3 = ((N-a1*100-a2*10))/100

print(sum)

### FIXED CODE ###

N = int(input())+1
# M=1
# A=[5,4,2,1]
 
cnt = 0
cnt1 = 0
 
# for i in range(N):
#     cnt = cnt + A[i]
#
# for i in range(N):
#     if A[i] / cnt > 1 / 4 / M:
#         cnt1 = cnt1 + 1
 
sum=0
for i in range(N):
    if (i % 3) != 0 and (i % 5) != 0:
        sum = sum + i
        # print(i,sum)
 
# a1 = N % 10
# a2 = ((N-a1*10) % 100)/10
# a3 = ((N-a1*100-a2*10))/100
 
print(sum)
n=int(input())
a=list(map(int,input().split()))
s=0
for i in a:
  if a%2==0:
    if a%3!=0 and a%5!=0:
      s=s+1
print('DENIED' if s>0 else 'APPROVED')

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
s=0
for i in a:
  if i%2==0:
    if i%3!=0 and i%5!=0:
      s=s+1
print('DENIED' if s>0 else 'APPROVED')
N=input()
S=input()
T=input()

strings=[]
for s,t in zip(S,T):
    strings.append(s+t)
print(''.join( strings))

### FIXED CODE ###

N=input()
S,T=input().split()
strings=[]
for i in range(int(N)):
    strings.append(S[i]+T[i])
print(''.join(strings))
N, M = map(int, input(). split())
A = list(map(int, input().split())
A.sort()
S = sum(A)
         
if 1/(4*M) <= A[N-M]/S :
	print("YES")
else:
	print("NO")

### FIXED CODE ###

N, M = map(int, input(). split())
A = list(map(int, input().split()))
A.sort()
S = sum(A)
         
if 1/(4*M) <= A[N-M]/S :
	print("Yes")
else:
	print("No")
print("Yes" if int(input().replace(" ",""))**0.5%1==0 else "No)

### FIXED CODE ###

print("Yes" if int(input().replace(" ",""))**0.5%1==0 else "No")
a,b,c = map(int, input().split)
if a<b<c:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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

result = "Yes" if a<b<c else "No"
print(result)
import math

r = int(input())
l = 2*math.py*r
print(l)

### FIXED CODE ###

import math
 
r = int(input())
l = 2*math.pi*r
print(l)
s=input()
if s[4] == s[5] and s[6] == s[7]:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

s=input()
if s[2] == s[3] and s[4] == s[5]:
  print('Yes')
else:
  print('No')
i = 0

while 1:
  x = raw_input()
  i += 1
  if x == "0":
    break
  print "Case %d: %d" % (i,x)

### FIXED CODE ###

i = 0

while 1:
  x = raw_input()
  i += 1
  if x == "0":
    break
  print "Case %d: %s" % (i,x)
def find_next(room, move):
    for next in path[room]:
        if mark[next] != None:
            if mark[next][1] < move:
                continue
            else:
                mark[next] = (room, move)
                find_next(next, move + 1)
        else:
            mark[next] = (room, move)
            find_next(next, move + 1)

N, M = map(int, input().split())
path = [[] for _ in range(N)]
for i in range(M):
    A_i, B_i = map(int, input().split())
    path[A_i - 1].append(B_i - 1)
    path[B_i - 1].append(A_i - 1)
mark = [None] * N
mark[0] = (0, 0)
find_next(0, 1)
if None in mark:
    print("No")
else:
    print("Yes")
    for i in range(1, len(mark)):
        print(mark[i][0] + 1)

### FIXED CODE ###

from collections import deque
n, m = map(int,input().split())
AB = [tuple(map(int, input().split())) for _ in range(m)]

def bfs(start):
    queue = deque()
    visited = [False] * n
    visited[start-1] = True
    queue.append(start)
    while queue:
        target = queue.popleft()
        for i in g[target]:
            if not visited[i-1]:
                ans[i-2] = target
                visited[i-1] = True
                queue.append(i)

ans = [0] * (n-1)
g = dict()
for a, b in AB:
    if a in g:
        g[a].append(b)
    if b in g:
        g[b].append(a)
    if a not in g:
        g[a] = [b]
    if b not in g:
        g[b] = [a]
start = 1
bfs(start)
if len([i for i in ans if i == 0]) == 0:
    print("Yes")
    print(*ans, sep="\n")
else:
    print("No")
n=int(input())
A=list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    a=1
    for i in A:
        a=a*i
        if a>1000000000000000000:
            print(-1)
        else:
            print(a)

        

### FIXED CODE ###

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

ans=1

if 0 in A:
    print(0)
    exit()

for i in A:
   ans=ans*i
   if ans>10**18:
    print(-1)
    exit()


print(ans)
a,b=map(float,input().split())

x=int(a*b)
print('{.0}'.format(x))

### FIXED CODE ###

a,b =input().split()
a=int(a)
b=int(b.replace(".",""))


print(a*b//100)
s=''
for i in range(3):
  temp=input()
  s=s+temp[i]
 print(s)

### FIXED CODE ###

s=''
for i in range(3):
  temp=input()
  s=s+temp[i]
print(s)
N = int(input())
S = lisr(input())
cnt = 0
for i in range(1, N):
    if S[i-1] == "#" and S[i] == ".":
        s[i-1] = "."
         cnt += 1
print(cnt)

### FIXED CODE ###

A, B, C = map(int, input().split())
if A > B:
    tmp = A
    A =  B
    B = tmp 

if C >= A and C <= B:
    print("Yes")
else:
    print("No")
N = int(input())
D = [int(input()) for _ in range(n)]
print(len(set(D)))

### FIXED CODE ###

N = int(input())
D = [int(input()) for _ in range(N)]
print(len(set(D)))
a = input()
op = raw_input()
b = input()

if op == "+":
   print a+b
elif op == "-":
   print a-b
elif op == "*":
   print a*b
elif op == "/":
   print int(a)/b
elif op == "?":
   return

### FIXED CODE ###

while 1:
   a, op, b = raw_input().split()
   A = int(a)
   B = int(b)
 
   if op == '?':
      break
   elif op == '+':
      print A+B
   elif op == '-':
      print A-B
   elif op == '*':
      print A*B
   elif op == '/':
      print A/B
a = 10
b = int(input())
if a % b == 0:
    print("even")
elif a % b != 0:
    print("odd")

### FIXED CODE ###

a, b = map(int, input().split())
if (a*b) % 2:
  print('Odd')
else:
  print('Even')
N = int(input())

d = {}
x, y, h = map(int, input().split())

for i in range(101):
  for j in range(101):
    d[(i, j)] = abs(i- x)+ abs(j- y)+ h

for k in range(N- 1):
  x, y, h = map(int, input().split())
  for i in range(101):
    for j in range(101):
      if((i, j) in d):
        if(d[(i, j)] != abs(i- x)+ abs(j- y)+ h):
          del d[(i, j)]
          
zahyou, height = list(d.items())[0]
print("{0[0]} {0[1]} {1}".format(zahyou, height))

### FIXED CODE ###

N = int(input())

d = {}
l = []
p = 0

for i in range(N):
  l.append(list(map(int, input().split())))

while True:
  if(l[0][2] == 0):
    l.append(l[0])
    del l[0]
  else:
    x, y, h= l[0]
    for i in range(101):
      for j in range(101):
        d[(i, j)] = abs(i- x)+ abs(j- y)+ h
    break

for k in range(N- 1):
  x, y, h = l[k+ 1]
  if(h == 0):
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)]- abs(i- x)- abs(j- y)> 0):
            del d[(i, j)]
  else:
    for i in range(101):
      for j in range(101):
        if((i, j) in d):
          if(d[(i, j)] != abs(i- x)+ abs(j- y)+ h):
            del d[(i, j)]

zahyou, height = list(d.items())[0]
  
print("{0[0]} {0[1]} {1}".format(zahyou, height))
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect,copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

h,w=map(int,input().split())
A=[tuple(map(int,input().split())) for i in range(h)]
B=[tuple(map(int,input().split())) for i in range(h)]
K = 55000
dp = [[[]*K for j in range(w)] for i in range(h)]
dp[0][0][0]=1
for i in range(h):
    for j in range(w):
        d=abs(A[i][j]-B[i][j])
        if i-1>=0:
            for k in range(K):
                if dp[i-1][j][k]:
                    dp[i][j][k+d]=1
                    dp[i][j][abs(k-d)]
        if j-1>=0:
            for k in range(K):
                if dp[i][j-1][k]:
                    dp[i][j][k+d] = 1
                    dp[i][j][abs(k-d)]
for ki in dp[h-1][w-1]:
    ans=min(ans,ki)
print(ans)
# for di in dp:
#     print(di)



### FIXED CODE ###

#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect,copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

h,w=map(int,input().split())
A=[tuple(map(int,input().split())) for i in range(h)]
B=[tuple(map(int,input().split())) for i in range(h)]
# a=[set() for j in range(w)]
K=160*80
dp = [[0]*w for i in range(h)]
dp[0][0]=1<<K
for i in range(h):
    for j in range(w):
        d=abs(A[i][j]-B[i][j])
        if i-1>=0:
            dp[i][j] |= dp[i-1][j]
        if j-1>=0:
            dp[i][j] |= dp[i][j-1]
        dp[i][j] = (dp[i][j]<<d) | (dp[i][j]>>d)


ans = K
for i in range(2*K):
    if dp[h-1][w-1]  & (1 << i)>0:
        ans = min(ans,abs(K-i))
print(ans)
# for di in dp:
#     print(di)
def left(arr, idx):
    if L[idx] != None:
        return L[idx]
    if idx == -1:
        ret =  0
    else:
        if arr[idx] == '<':
            ret = left(arr, idx-1) + 1
        else:
            ret = 0
    L[idx] = ret
    return ret
        
def right(arr, idx):
    if R[idx] != None:
        return R[idx]
    if idx == len(arr):
        ret =  0 
    else:
        if arr[idx] == '>':
            ret = right(arr, idx+1) + 1
        else:
            ret = 0
    R[idx] = ret
    return ret

def main():
    S = list(input())
    N = len(S)
    A = [0 for _ in range(N+1)]
    
    global L; L = [None for _ in range(N+1)]
    global R; R = [None for _ in range(N+1)]

    for i in range(len(A)):
        A[i] = max(left(S, i-1), right(S, i))
            
    print(sum(A))
    print(L)
    print(R)
    print(A)

if __name__ == "__main__":
    main()


### FIXED CODE ###

def left(arr, idx):
    if L[idx] != None:
        return L[idx]

    if arr[idx] == '<':
        if idx == 0:
            ret = 1
        else:
            ret = left(arr, idx-1) + 1
    else:
        ret = 0

    L[idx] = ret
    return ret
        
def right(arr, idx):
    if R[idx] != None:
        return R[idx]

    if arr[idx] == '>':    
        if idx == len(arr)-1:
            ret =  1
        else:
            ret = right(arr, idx+1) + 1
    else:
        ret = 0
    R[idx] = ret
    return ret

def main():
    S = list(input())
    N = len(S)
    A = [0 for _ in range(N+1)]
    
    global L; L = [None for _ in range(N)]
    global R; R = [None for _ in range(N)]

    for i in range(N):
        j = N - i - 1
        L[i] = left(S, i)
        R[j] = right(S, j)
    
    L = [0] + L
    R = R + [0]

    for i in range(len(A)):
        A[i] = max(L[i], R[i])
            
    print(sum(A))

if __name__ == "__main__":
    main()