Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    dp[0][0]|=1<<x

    from itertools import product
    for i,j in product(range(h),range(w)):
        x=abs(A[i][j]-B[i][j])
        if(i-1>=0):
            for y,s in enumerate(bin(dp[i-1][j])[:1:-1]):
                if(s=='1'):
                    dp[i][j]|=1<<(y+x)
                    dp[i][j]|=1<<(abs(y-x))
        if(j-1>=0):
            for y,s in enumerate(bin(dp[i][j-1])[:1:-1]):
                if(s=='1'):
                    dp[i][j]|=1<<(y+x)
                    dp[i][j]|=1<<(abs(y-x))

    for i,s in enumerate(bin(dp[-1][-1])[:1:-1]):
        if(s=='1'):
            print(i)
            return
resolve()

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    offset=12800
    dp[0][0]|=1<<(x+offset)
    dp[0][0]|=1<<(-x+offset)

    from itertools import product
    for i,j in product(range(h),range(w)):
        if(i==0 and j==0): continue
        x=abs(A[i][j]-B[i][j])
        S=0
        if(i>0): S|=dp[i-1][j]
        if(j>0): S|=dp[i][j-1]
        dp[i][j]=(S<<x)|(S>>x)

    for i in range(12800):
        if((dp[-1][-1]>>(i+offset))&1):
            print(i)
            return
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    dp[0][0]|=1<<x

    from itertools import product
    for i,j in product(range(h),range(w)):
        x=abs(A[i][j]-B[i][j])
        if(i-1>=0):
            for k,s in enumerate(bin(dp[i-1][j])[2:][::-1]):
                if(s=='1'):
                    dp[i][j]|=1<<(k+x)
                    dp[i][j]|=1<<(abs(k-x))
        if(j-1>=0):
            for k,s in enumerate(bin(dp[i][j-1])[2:][::-1]):
                if(s=='1'):
                    dp[i][j]|=1<<(k+x)
                    dp[i][j]|=1<<(abs(k-x))

    for k,s in enumerate(bin(dp[-1][-1])[2::][::-1]):
        if(s=='1'):
            print(k)
            return
resolve()

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    offset=12800
    dp[0][0]|=1<<(x+offset)
    dp[0][0]|=1<<(-x+offset)

    from itertools import product
    for i,j in product(range(h),range(w)):
        if(i==0 and j==0): continue
        x=abs(A[i][j]-B[i][j])
        S=0
        if(i>0): S|=dp[i-1][j]
        if(j>0): S|=dp[i][j-1]
        dp[i][j]=(S<<x)|(S>>x)

    for i in range(12800):
        if((dp[-1][-1]>>(i+offset))&1):
            print(i)
            return
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
from itertools import product
def resolve():
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[defaultdict(int) for _ in range(w)] for _ in range(h)]
    x=A[-1][-1]-B[-1][-1]
    dp[-1][-1][x]=1
    dp[-1][-1][-x]=1

    for i,j in product(range(h-1,-1,-1),range(w-1,-1,-1)):
        x=A[i][j]-B[i][j]
        if(i+1<h):
            for key,val in dp[i+1][j].items():
                if(val==1):
                    dp[i][j][key+x]=1
                    dp[i][j][key-x]=1
        if(j+1<w):
            for key,val in dp[i][j+1].items():
                if(val==1):
                    dp[i][j][key+x]=1
                    dp[i][j][key-x]=1

    ans=INF
    for key,val in dp[0][0].items():
        if(val==1): ans=min(ans,abs(key))

    print(ans)
resolve()

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    offset=12800
    dp[0][0]|=1<<(x+offset)
    dp[0][0]|=1<<(-x+offset)

    from itertools import product
    for i,j in product(range(h),range(w)):
        if(i==0 and j==0): continue
        x=abs(A[i][j]-B[i][j])
        S=0
        if(i>0): S|=dp[i-1][j]
        if(j>0): S|=dp[i][j-1]
        dp[i][j]=(S<<x)|(S>>x)

    for i in range(12800):
        if((dp[-1][-1]>>(i+offset))&1):
            print(i)
            return
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[[] for _ in range(w)] for _ in range(h)]
    dp[-1][-1].append(A[-1][-1]-B[-1][-1])
    dp[-1][-1].append(-A[-1][-1]+B[-1][-1])

    from itertools import product
    for i,j in product(range(h-1,-1,-1),range(w-1,-1,-1)):
        p=A[i][j]-B[i][j]
        if(i+1<h):
            for x in dp[i+1][j]:
                dp[i][j].append(x+p)
                dp[i][j].append(x-p)
        if(j+1<w):
            for x in dp[i][j+1]:
                dp[i][j].append(x+p)
                dp[i][j].append(x-p)

    print(min(*(abs(x) for x in dp[0][0])))
resolve()

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]
    dp=[[0]*w for _ in range(h)]
    x=abs(A[0][0]-B[0][0])
    offset=12800
    dp[0][0]|=1<<(x+offset)
    dp[0][0]|=1<<(-x+offset)

    from itertools import product
    for i,j in product(range(h),range(w)):
        if(i==0 and j==0): continue
        x=abs(A[i][j]-B[i][j])
        S=0
        if(i>0): S|=dp[i-1][j]
        if(j>0): S|=dp[i][j-1]
        dp[i][j]=(S<<x)|(S>>x)

    for i in range(12800):
        if((dp[-1][-1]>>(i+offset))&1):
            print(i)
            return
resolve()