Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

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

a = [0]
b = [0]
T = 0
ans = []

for i in range(N):
  a.append(a[i] + A[i])

for i in range(M):
  b.append(b[i] + B[i])

for i in range(N+1):
  for j in range(M+1):
    T = a[i] + b[j]
    if T <= K:
      ans.append(i + j)

    else:
      pass


print(max(ans))

### FIXED CODE ###

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

a = [0]
b = [0]
T = 0
ans = 0

for i in range(N):
  a.append(a[i] + A[i])

for i in range(M):
  b.append(b[i] + B[i])

j = M

for i in range(N+1):
  if a[i] > K:
    break
  while a[i] + b[j] > K:
    j -= 1
  ans = max(ans, i + j)


print(ans)
### BUGGY CODE ###


def main():

    N = int(input())
    food1, food2 = [], []
    for i in range(N):
        a, b = map(int, input().split())
        food1.append([a+b, a, b, i])
        food2.append([-a-b, a, b, i])
    food1.sort(reverse = True)
    food2.sort()
    used = set()
    ans = 0
    while food1 or food2:
        while food1 and food1[0][3] in used:
            food1.pop(0)
        if food1:
            _, a, _, i = food1.pop(0)
            used.add(i)
            ans += a
        while food2 and food2[0][3] in used:
            food2.pop(0)
        if food2:
            _, _, b, i = food2.pop(0)
            used.add(i)
            ans -= b
    return ans


if __name__ == '__main__':
    print(main())

### FIXED CODE ###


def main():

    N = int(input())
    food1, food2 = [], []
    for i in range(N):
        a, b = map(int, input().split())
        food1.append([a+b, a, b, i])
        food2.append([-a-b, a, b, i])
    food1.sort()
    food2.sort(reverse = True)
    used = set()
    ans = 0
    while food1 or food2:
        while food1 and food1[-1][3] in used:
            food1.pop()
        if food1:
            _, a, _, i = food1.pop()
            used.add(i)
            ans += a
        while food2 and food2[-1][3] in used:
            food2.pop()
        if food2:
            _, _, b, i = food2.pop()
            used.add(i)
            ans -= b
    return ans


if __name__ == '__main__':
    print(main())
### BUGGY CODE ###

n,m=map(int, input().split())
a=[int(input())  for i in  range(m)]
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]+=dp[i-1]+dp[i-2]
  #print(dp)
  
print(dp[-1]%x)

### FIXED CODE ###

n,m=map(int, input().split())
a=set(int(input())  for i in  range(m))
x=(10**9)+7

dp=[0]*(n+1)
dp[0]=1
if 1 not in a:
  dp[1]=1

for i in range(2,n+1):
  if i in a:
    continue
  dp[i]+=dp[i-1]+dp[i-2]
  #print(dp)
  
print(dp[-1]%x)
### BUGGY CODE ###

from collections import deque
import queue

N = int(input())
d = list(map(int, input().split()))
b = []
for i in d:
    b.append(i)
    b.reverse()
print(*b)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
print(*A[::-2],*A[N%2::2])
### BUGGY CODE ###

n=int(input())
s=[]
m={}
for i in range(n):
    st=input()
    if(st in s):m[st]+=1
    else:m[st]=1
    s.append(st)
mx=max(m.values())
ans=[]
for i in m:
    if(m[i]==mx):ans.append(i)
ans=sorted(ans)
for i in ans:
    print(i)

### FIXED CODE ###

n=int(input())
s=[]
m={}
for i in range(n):
    st=input()
    if(st in m):m[st]+=1
    else:m[st]=1
mx=max(m.values())
ans=[]
for i in m:
    if(m[i]==mx):ans.append(i)
ans=sorted(ans)
for i in ans:
    print(i)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
from collections import Counter
c = Counter(A)
sorted_key = sorted(c.keys(),reverse=True)
res = [0]*len(sorted_key)
#print(sorted_key)
for i,key in enumerate(sorted_key):
    for j in range(len(sorted_key)-1, i, -1):
        #print(i,key,j,sorted_key[j])
        if (key/sorted_key[j]>=1) and (key%sorted_key[j])==0:
            res[i] = 1
            #print('===========',)
            break

#print('res', res)
#print(c)
ans = 0
for i,v in enumerate(sorted_key):
    if res[i]:
        ans += c[v]
    else:
        if c[v] >1:
            ans += c[v]
print(n-ans)

### FIXED CODE ###

n = int(input())
A = sorted(list(map(int, input().split())))
from collections import Counter
c = Counter(A)

dp = [1]*(max(A)+1)
#print(dp)
for i in c.keys():
    j = i*2
    while j<len(dp):
        dp[j] = 0
        j += i
        #print(j, end=',')
ans = 0
for i in c.keys():
    if c[i] == 1:
        if dp[i] == 1:
            ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()

Max = 0
for i in range(N):
    if i == 0:
        Max = S[1:].count('W')
    elif i < N-1:
        ct = S[:i].count('E') + S[i+1:].count('W')
        Max = max(Max, ct)
    else:
        Max = max(Max, S[:-1].count('E'))

ans = N-1 - Max

print(ans)

### FIXED CODE ###

N = int(input())
S = input()

ct_sum = []
ct_E, ct_W = 0, 0
for i in S:
    if i == 'E':
        ct_E += 1
    else:
        ct_W += 1
    ct_sum.append((ct_E, ct_W))

Max = 0
for i in range(N):
    if i == 0:
        E_l = 0
    else:
        E_l = ct_sum[i-1][0]
    W_i, W_e = ct_sum[i][1], ct_sum[N-1][1]
    W_r = W_e - W_i
    ct = E_l + W_r
    Max = max(Max, ct)

ans = N-1 - Max

print(ans)
### BUGGY CODE ###

icase=0
if icase==0:
    n=int(input())
    v=list(map(int,input().split()))
    c=list(map(int,input().split()))
    tmax=0
    for i in range(2 ** n):
        total = 0
        for j in range(n):  # このループが一番のポイント
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                total = total+v[j]-c[j]  # 買い物累計額にも加算
        tmax=max(total,tmax)
    print(tmax)
    

### FIXED CODE ###

icase=0
if icase==0:
    n=int(input())
    v=list(map(int,input().split()))
    c=list(map(int,input().split()))
    tmax=0
    for i in range(n):
        total = 0
        for j in range(n):
            total = total+max(0,v[j]-c[j])   
        tmax=max(tmax,total)
    print(tmax)
### BUGGY CODE ###

def func(A,b):
  s=0
  for i in range(len(A)):
    s+=abs(A[i]-(b+i))
  return s

N=int(input())
A=[int(i) for i in input().split(' ')]
MIN=None
for b in range(min(A[0],A[-1]-len(A)),max(A[-1],A[0]+len(A))):
  if MIN==None:
    MIN=func(A,b)
  elif MIN>func(A,b):
    MIN=func(A,b)
print(MIN)

### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split(' ')]
for i in range(len(A)):
  A[i]-=i+1
A.sort()
if len(A)%2==1:
  b=A[(len(A)-1)//2]
else:
  b=A[(len(A))//2-1]
s=0
for i in range(len(A)):
  s+=abs(A[i]-b)
print(s)
### BUGGY CODE ###

from collections import deque

N, M= [int(i) for i in input().split(' ')]
graph = {}

for i in range(1,N+1):
  graph[i] = []

for j in range(M):
  a, b= [int(i) for i in input().split(' ')]
  graph[a].append(b)
  graph[b].append(a)
    

def bfs(graph, start):
  queue = [start]
  visited1 = []
  visited = {}
  for i in range(1,N+1):
    visited[i] = 0  
  miti = {}
  for i in range(1,N+1):
    miti[i] = 0
  where_from = [start-1]
  while queue:
    label = queue.pop(0)
    label2 = where_from.pop(0)
    if visited[label]==0:
      visited1.append(label)
      visited[label]=1
      if miti[label] != 0:
        return False
      miti[label] = label2
      queue += graph.get(label, [])
      where_from += [label]*len(graph.get(label, []))
    if len(visited1) == N:
      break
  if len(visited1) != N:
    return False
  return miti

miti = bfs(graph, 1)
if miti:
  print('Yes')
  for i in range(2,N+1):
    print(miti[i])
else:
  print('No')

### FIXED CODE ###

N, M= [int(i) for i in input().split(' ')]
graph = {}
 
for i in range(1,N+1):
  graph[i] = []
 
for j in range(M):
  a, b= [int(i) for i in input().split(' ')]
  graph[a].append(b)
  graph[b].append(a)
    
 
def bfs(graph, start):
  queue = [start]
  miti = [-1 for _ in range(N)]

  while queue:
    label = queue.pop(0)
    for i in graph[label]:
      if miti[i-1] < 0:
        queue.append(i)
        miti[i-1] = label
  return miti
 
miti = bfs(graph, 1)
if miti:
  print('Yes')
  for i in range(2,N+1):
    print(miti[i-1])
else:
  print('No')
### BUGGY CODE ###

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
memo = [[i] for i in range(N)]
flg = [False]*N
for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)

ans = [0]*N
add = [0]*N

for i in range(Q):
    p, x = map(int, input().split())
    if flg[p-1] is False:
        flg[p-1] = True
        ans[p-1] += x
        queue = [p-1]
        while queue:
            par = queue.pop(0)
            if G[par]:
                for i in G[par]:
                    ans[i] += x
                    queue.append(i)
                    memo[p-1].append(i)
    elif flg[p-1] is True:
        add[p-1] += x
        flg[p-1] = -1
    else:
        add[p-1] += x

ct = 0
for i in flg:
    if i == -1:
        for j in memo[ct]:
            ans[j] += add[ct]
    ct += 1

print(*ans)

### FIXED CODE ###

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
ans = [0]*N

for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

for _ in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

judge = [False]*N
judge[0] = True
queue = [0]
while queue:
    a = queue.pop()
    for i in G[a]:
        if not judge[i]:
            judge[i] = True
            ans[i] += ans[a]
            if G[i]:
                queue.append(i)

print(*ans)
### BUGGY CODE ###

import sys
a, b, k = map(int, input().split())

if a + b <= k:
    print(str(0) + " " + str(0))
    sys.exit()

for i in range(k):
    if a >=1:
        a -= 1
    else:
        b -= 1

print(str(a) + " " + str(b))

### FIXED CODE ###

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

if a >= k:
    print(a-k,b)
else:
    b = b - (k - a)
    if b < 0:
        print(0,0)
    else:
        print(0,b)
### BUGGY CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def dfs(k,d,x,c):
        if not f[x]:
            f[x] = c
        if k == d:
            return
        for y in v[x]:
            dfs(k+1,d,y,c)
    n,m = LI()
    f = [0]*n
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    q = I()
    l = LIR(q)
    l = l[::-1]
    for x,d,c in l:
        x -= 1
        dfs(0,d,x,c)
    for i in f:
        print(i)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def dfs(d,x,c):
        if d <= dp[x]:
            return
        dp[x] = d
        if not f[x]:
            f[x] = c
        for y in v[x]:
            dfs(d-1,y,c)
    n,m = LI()
    f = [0]*n
    v = [[] for i in range(n)]
    for i in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    dp = defaultdict(lambda : -1)
    q = I()
    l = LIR(q)
    l = l[::-1]
    for x,d,c in l:
        x -= 1
        dfs(d,x,c)
    for i in f:
        print(i)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()
### BUGGY CODE ###

from collections import deque
N=int(input())
M=(N*(N-1))//2
D=dict()
tmp=0
X=[(0,0) for i in range(M)]
G=[[] for i in range(M)]
H=[[] for i in range(M)]
for i in range(1,N+1):
    for j in range(1,N+1):
        if i<j:
            D[(i,j)]=tmp
            X[tmp]=(i,j)
            tmp+=1
A=[[int(j) for j in input().split()] for i in range(N)]
for i in range(N):
    for j in range(N-2):
        p1=D[(i+1,A[i][j])] if i+1<A[i][j] else D[(A[i][j],i+1)]
        p2=D[(i+1,A[i][j+1])] if i+1<A[i][j+1] else D[(A[i][j+1],i+1)]
        G[p1].append(p2)
        H[p2].append(p1)
K=[0 for i in range(M)]
for i in range(M):
    for p in G[i]:
        K[p]+=1
q=deque(i for i in range(M) if K[i]==0)
res=[]
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in G[v1]:
        K[v2]-=1
        if K[v2]==0:
            q.append(v2)
#print(D)
#print(res)
if len(res)<M:
    print(-1)
    exit()
ans=[0 for i in range(M)]
ans[res[-1]]=1
for i in res[:-1][::-1]:
    if len(G[i])==0:
        ans[i]=1
    else:
        for j in G[i]:
            ans[i]=max(ans[i],ans[j]+1)
print(max(ans))


### FIXED CODE ###

from collections import deque
N=int(input())
M=(N*(N-1))//2
D=dict()
tmp=0
X=[(0,0) for i in range(M)]
G=[[] for i in range(M)]
for i in range(1,N+1):
    for j in range(1,N+1):
        if i<j:
            D[(i,j)]=tmp
            X[tmp]=(i,j)
            tmp+=1
A=[[int(j) for j in input().split()] for i in range(N)]
for i in range(N):
    for j in range(N-2):
        p1=D[(i+1,A[i][j])] if i+1<A[i][j] else D[(A[i][j],i+1)]
        p2=D[(i+1,A[i][j+1])] if i+1<A[i][j+1] else D[(A[i][j+1],i+1)]
        G[p1].append(p2)
K=[0 for i in range(M)]
for i in range(M):
    for p in G[i]:
        K[p]+=1
q=deque(i for i in range(M) if K[i]==0)
res=[]
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in G[v1]:
        K[v2]-=1
        if K[v2]==0:
            q.append(v2)
#print(D)
#print(res)
if len(res)<M:
    print(-1)
    exit()
ans=[0 for i in range(M)]
ans[res[-1]]=1
for i in res[:-1][::-1]:
    if len(G[i])==0:
        ans[i]=1
    else:
        for j in G[i]:
            ans[i]=max(ans[i],ans[j]+1)
print(max(ans))
### BUGGY CODE ###

n, k = map(int, input().split())
ans = 0
n_list = range(0, n+1)

for i in range(k, n+2):
  minsum = sum(n_list[:i])
  maxsum = sum(n_list[-i:])
  ans += maxsum - minsum + 1

print(ans)

### FIXED CODE ###

N, K = map(int, input().split())
mod = 10**9 + 7
count = 0
for n in range(K, N+2):
  maxSum = (n*(N + N-n+1))//2
  minSum = (n*(n-1))//2
  count += maxSum - minSum + 1
  count %= mod

print(count)
### BUGGY CODE ###

N,P=map(int,input().split())
if N==1:
    print(P)
else:
    index=1
    ans=1
    while(index**N<=P):
        if P%(index**N)==0:
            ans=index
        index+=1
    print(ans)


### FIXED CODE ###

N,P=map(int,input().split())
D=dict()
k=2
Q=P
while(True):
    if k*k>P:
        break
    if Q%k==0:
        if k in D:
            D[k]+=1
        else:
            D[k]=1
        Q=Q//k
    else:
        k+=1
if Q in D:
    D[Q]+=1
else:
    D[Q]=1
ans=1
for p in D:
    ans=ans*(p**(D[p]//N))
print(ans)
### BUGGY CODE ###

N,K = map(int,input().split())
H=list(map(int,input().split()))
INF=1000000000
dp=[INF]*(N+1)
dp[0]=0
for i in range(1,N):
  for j in range(1,K+1):
    if (i-j)>=0:
      dp[i]=min(dp[i],dp[i-j]+abs(H[i-j]-H[i]))
print(dp[N-1])

### FIXED CODE ###

N,K=map(int,input().split())
h=[int(i) for i in input().split()]
f_inf=float('inf')
dp=[f_inf]*(N+10)
dp[0]=0
for i in range(1,N):
  for j in range(1,K+1):
    if i-j>=0:
      dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])
print(dp[N-1])
### BUGGY CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = [0]*N
put = []

for i in reversed(range(N)):
    if A[i] != B[i]:
        put.append(i+1)
        # iを素因数分解して、約数に1をxorしていく
        tmp = 1
        n = i+1
        while tmp*tmp <= n:
            if n % tmp == 0:
                B[tmp-1] ^= 1
                if tmp != n//tmp:
                    B[n//tmp-1] ^= 1
            tmp += 1


if len(put) > 0:
    print(len(put))
    print(*put)
else:
    print(0)


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = [0]*N
put = []

for i in reversed(range(N)):
    if A[i] != B[i]:
        put.append(i+1)
        # iを素因数分解して、約数に1をxorしていく
        tmp = 1
        n = i+1
        while tmp*tmp <= n:
            if n % tmp == 0:
                B[tmp-1] ^= 1
                if tmp != n//tmp:
                    B[n//tmp-1] ^= 1
            tmp += 1


if len(put) > 0:
    print(len(put))
    print(*put)
else:
    print(0)
### BUGGY CODE ###

import fractions
A, B = map(int, input().split())
max_n = fractions.gcd(A,B)
ans = 1
first = 2
while True:
    for i in range(first,max_n+1):
        if max_n % i == 0:
            while True:
                max_n //= i
                if max_n % i != 0:
                    break
            ans += 1
            first = i
            break
    if max_n == 1:
        break
print(ans)

### FIXED CODE ###

import fractions
import math

def trial_division(n):
    a = [1]
    for i in range(2,int(math.sqrt(n)) + 1):
        while n % i == 0:
            n //= i
            a.append(i)
    a.append(n)
    return a


A, B = map(int, input().split())
max_n = fractions.gcd(A,B)

ans = set(trial_division(max_n))
print(len(ans))
### BUGGY CODE ###

import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline


n, q = list(map(int, input().split()))
count = (n - 2) ** 2
c = [n] * n
r = [n] * n
mc = n
mr = n
for _ in range(q):
  m,q = list(map(int, input().split()))
  if m == 1:
    pos = r[q-1]
    if q < mc:
        mc = q
        for p in range(pos):
            c[p] = q
    if q not in [1,n]:
      count -= max(0, pos - 2)
  else:
    pos = c[q-1]
    if q < mr:
        mr = q
        for p in range(pos):
            r[p] = q
    if q not in [1,n]:
      count -= max(0, pos-2)
print(count)



### FIXED CODE ###

import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline


n, q = list(map(int, input().split()))
count = (n - 2) ** 2
c = [n] * (n + 1)
r = [n] * (n + 1)
mc = n
mr = n
for _ in range(q):
    m,q = list(map(int, input().split()))
    if m == 1:
        if q <= mc:
            count -= mr -2
            for p in range(q+1, mc):
                c[p] = mr
            c[q] = 0
            mc = q
        else:
            count -= c[q] - 2
    else:
        if q <= mr:
            count -= mc -2
            for p in range(q+1, mr):
                r[p] = mc
            r[q] = 0
            mr = q
        else:
            count -= r[q] - 2
print(count)
### BUGGY CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]


h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]

lst=[[0]*w for i in range(h)]

lst[0][0]={a[0][0]-b[0][0]:1,-a[0][0]+b[0][0]:1}
# print(lst)
d=deque([(0,0)])
while d:
    now=d.popleft()
    if now[0]+1<h:
        if lst[now[0]+1][now[1]]==0:
            d.append((now[0]+1,now[1]))
            lst[now[0]+1][now[1]]={}

        for i in lst[now[0]][now[1]].keys():
            ab=a[now[0]+1][now[1]]-b[now[0]+1][now[1]]
            lst[now[0]+1][now[1]][i+ab]=1
            lst[now[0]+1][now[1]][i-ab]=1

    # print(lst)
    if now[1]+1<w:
        if lst[now[0]][now[1]+1]==0:
            d.append((now[0],now[1]+1))
            lst[now[0]][now[1]+1]={}

        for i in lst[now[0]][now[1]].keys():
            ab=a[now[0]][now[1]+1]-b[now[0]][now[1]+1]
            lst[now[0]][now[1]+1][i+ab]=1
            lst[now[0]][now[1]+1][i-ab]=1
    # print(d)
    # print(lst)
anslst=list(lst[-1][-1].keys())
anslst.sort(key=lambda x: abs(x))
print(abs(anslst[0]))

### FIXED CODE ###

import sys

input = sys.stdin.buffer.readline

h, w = map(int, input().split())
AA = [list(map(int, input().split())) for _ in range(h)]
BB = [list(map(int, input().split())) for _ in range(h)]

kouho = [[0] * (w) for _ in range(h)]
delta = abs(AA[0][0] - BB[0][0])
kouho[0][0] |= 1 << delta
for y in range(h):
    for x in range(w):
        nx = x + 1
        ny = y
        if nx < w:
            delta = abs(AA[ny][nx] - BB[ny][nx])
            temp = 0
            for i in range(1, delta + 1):
                if (kouho[y][x] >> i) % 2:
                    temp |= 1 << (delta - i)
            # print(x,y,kouho[y][x],temp,delta)
            kouho[ny][nx] |= kouho[y][x] << delta
            kouho[ny][nx] |= kouho[y][x] >> delta
            kouho[ny][nx] |= temp

        nx = x
        ny = y + 1
        if ny < h:
            delta = abs(AA[ny][nx] - BB[ny][nx])
            temp = 0
            for i in range(1, delta + 1):
                if (kouho[y][x] >> i) % 2:
                    temp |= 1 << (delta - i)
            # print(x,y,kouho[y][x],temp,delta)
            kouho[ny][nx] |= kouho[y][x] << delta
            kouho[ny][nx] |= kouho[y][x] >> delta
            kouho[ny][nx] |= temp
# print(kouho)
for i in range(81):
    if (kouho[h - 1][w - 1] >> i) % 2:
        print(i)
        exit()
### BUGGY CODE ###

n, k = (int(x) for x in input().split())
p = [(int(x)*(int(x)+1) / 2) / int(x) for x in input().split()]
print(max([sum(p[i:i+k]) for i in range(len(p)-k+1)]))

### FIXED CODE ###

n, k = (int(x) for x in input().split())
p = [int(x) / 2 + 0.5 for x in input().split()]
ans_i = ans = sum(p[:k])
i = 0
while i < n - k:
    ans_i = ans_i - p[i] + p[i+k]
    ans = max(ans, ans_i)
    i += 1
print(ans)
### BUGGY CODE ###

import math
from functools import reduce

n = int(input())
answer = 0

def gcd(*numbers):
    return reduce(math.gcd,numbers)

for i in range(n):
    for j in range(n):
        for k in range(n):
            answer += gcd(i+1,j+1,k+1)
print(answer)

### FIXED CODE ###

import math
from functools import reduce
 
n = int(input())
answer = 0
 
def gcd(*numbers):
    return reduce(math.gcd,numbers)
 
for i in range(n):
    for j in range(n):
        for k in range(n):
            answer += gcd(i+1,j+1,k+1)
print(answer)