Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys,heapq
input = sys.stdin.buffer.readline


n,m = map(int,input().split())
edge = [[] for _ in range(n)]

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

#True:訪問済み False:未訪問
flag = [False]*n

def dfs(now):
    if flag[now]:
        return 0
    
    flag[now] = True

    size = 0
    for nxt in edge[now]:
        if not flag[nxt]:
            size += dfs(nxt)

    return size + 1

res = 0

for i in range(n):
    if flag[i]:
        continue
    res = max(res,dfs(i))

print(res)


Fixed submission:
import sys
input = sys.stdin.buffer.readline

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

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]



#初期化
#根なら-size,子なら親の頂点
par = [-1]*n


for _ in range(m):
    a,b = map(int,input().split())
    unite(a-1,b-1)

res = 0
for e in par:
    if e < 0:
        res = max(res,-e)
print(res)

Buggy python submission (verdict: Runtime Error):
import sys,heapq
input = sys.stdin.buffer.readline


n,m = map(int,input().split())
edge = [[] for _ in range(n)]

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

#True:訪問済み False:未訪問
flag = [False]*n

def dfs(now):
    if flag[now]:
        return 0
    
    flag[now] = True

    size = 0
    for nxt in edge[now]:
        if not flag[nxt]:
            size += dfs(nxt)

    return size + 1

res = 0

for i in range(n):
    if flag[i]:
        continue
    res = max(res,dfs(i))

print(res)


Fixed submission:
import sys
input = sys.stdin.buffer.readline

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

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]



#初期化
#根なら-size,子なら親の頂点
par = [-1]*n


for _ in range(m):
    a,b = map(int,input().split())
    unite(a-1,b-1)

res = 0
for e in par:
    if e < 0:
        res = max(res,-e)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline

n,Q = map(int,input().split())
c = list(map(int,input().split()))


#####segfunc######
def segfunc(x,y):
    return x|y

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

for i in range(n):
    update(i,1<<c[i])

for i in range(Q):
    l,r = map(int,input().split())
    l -= 1

    res = query(l,r)

    print(popcnt(res))

Fixed submission:
import sys
input = sys.stdin.buffer.readline

n,Q = map(int,input().split())
c = [0] + list(map(int,input().split()))
dg = 10**6
dg2 = 10**12
res = [0]*Q
LRI = []
for i in range(Q):
    l,r = map(int,input().split())
    LRI.append(l*dg2 + r*dg + i)
LRI.sort()

#A1 ... AnのBIT(1-indexed)
BIT = [0]*(n+1)

#A1 ~ Aiまでの和 O(logN)
def BIT_query(idx):
    res_sum = 0
    while idx > 0:
        res_sum += BIT[idx]
        idx -= idx&(-idx)
    return res_sum

#Ai += x O(logN)
def BIT_update(idx,x):
    while idx <= n:
        BIT[idx] += x
        idx += idx&(-idx)
    return

fi = [[] for i in range(n+1)]
nxt = [-1]*(n+1)
for i in range(1,n+1):
    num = c[i]
    if len(fi[num]) == 0:
        BIT_update(i,1)
    else:
        nxt[fi[num][-1]] = i
    fi[num].append(i)

idx = 0

for i in range(1,n+1):

    while idx < Q:
        l,ri = divmod(LRI[idx],dg2)
        if l != i:
            break
        r,resi = divmod(ri,dg)
        res[resi] = BIT_query(r)
        idx += 1
    BIT_update(i,-1)
    if nxt[i] != -1:
        BIT_update(nxt[i],1)


print(*res,sep='\n')
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())

cnt = [0]*n

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            if x**2 + y**2 + z**2 + x*y + x*z + y*z - 1 < n:
                cnt[x**2 + y**2 + z**2 + x*y + x*z + y*z - 1] += 1
print(*cnt,sep='\n')
        

Fixed submission:
l,r,d = map(int,input().split())

ans = 0

for i in range(l,r+1):
    if i%d == 0:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

print(a + a*a + a*a*a)

Fixed submission:
import sys
input = sys.stdin.readline

a = int(input())
print(a + a*a + a*a*a)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline

mod = 10**9+7
MAX_N = 10**6 + 10

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

k = int(input())
s = list(input())

n = len(s)-1

res = 0

for i in range(n,n+k+1):
    res = (res + (mod_comb_k(i-1,n-1,mod)*pow(25,i-n,mod)%mod)*pow(26,n+k-i,mod))%mod

print(res)

Fixed submission:
import sys
input = sys.stdin.buffer.readline

mod = 10**9+7
MAX_N = 10**7 + 10

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

k = int(input())
s = list(input())

n = len(s)-1

res = 0

for i in range(n,n+k+1):
    res = (res + (mod_comb_k(i-1,n-1,mod)*pow(25,i-n,mod)%mod)*pow(26,n+k-i,mod))%mod

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.buffer.readline

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

#46 . 64 @
c = [list(input()) for i in range(h)]

dp = [10**7]*(h*w)

dp[x1*w + y1] = 0
tank = deque([x1*w+y1])

while tank:

    
    now = tank.popleft()
    cost = dp[now]
    
    for i in range(1,k+1):
        if (now+i)%w != 0 and dp[now+i] > cost and c[(now+i)//w][(now+i)%w] == 46:
            dp[now+i] = cost+1
            tank.append(now+i)
        else:
            break
    for i in range(1,k+1):
        if (now-i)%w != w-1 and dp[now-i] > cost and c[(now-i)//w][(now-i)%w] == 46:
            dp[now-i] = cost+1
            tank.append(now-i)
        else:
            break

    for i in range(1,k+1):
        if (now+i*w) < h*w and dp[now+i*w] > cost and c[(now+i*w)//w][(now+i*w)%w] == 46:
            dp[now+i*w] = cost+1
            tank.append(now+i*w)
        else:
            break
    for i in range(1,k+1):
        if (now-i*w) >= 0 and dp[now-i*w] > cost and c[(now-i*w)//w][(now-i*w)%w] == 46:
            dp[now-i*w] = cost+1
            tank.append(now-i*w)
        else:
            break


if dp[x2*w+y2] == 10**7:
    print(-1)
else:
    print(dp[x2*w+y2])





Fixed submission:
import sys
from collections import deque
input = sys.stdin.buffer.readline

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

#46 . 64 @
c = [list(input()) for i in range(h)]

pq = [0]*(h*w)


dp = [10**7]*(h*w)


pq[x1*w + y1] = 3
dp[x1*w + y1] = 0
tank = deque([x1*w+y1])



while tank:

    
    now = tank.popleft()
    cost = dp[now]
    
    for i in range(1,k+1):
        if (now+i)%w != 0 and dp[now+i] > cost and c[(now+i)//w][(now+i)%w] == 46 and pq[now+i] < 5:
            pq[now+i] += 1 
            dp[now+i] = cost+1
            tank.append(now+i)
        else:
            break
    for i in range(1,k+1):
        if (now-i)%w != w-1 and dp[now-i] > cost and c[(now-i)//w][(now-i)%w] == 46 and pq[now-i] < 5:
            pq[now-i] += 1
            dp[now-i] = cost+1
            tank.append(now-i)
        else:
            break

    for i in range(1,k+1):
        if (now+i*w) < h*w and dp[now+i*w] > cost and c[(now+i*w)//w][(now+i*w)%w] == 46 and pq[now+i*w] < 5:
            pq[now+i*w] += 1
            dp[now+i*w] = cost+1
            tank.append(now+i*w)
        else:
            break
    for i in range(1,k+1):
        if (now-i*w) >= 0 and dp[now-i*w] > cost and c[(now-i*w)//w][(now-i*w)%w] == 46 and pq[now-i*w] < 5:
            pq[now-i*w] += 1
            dp[now-i*w] = cost+1
            tank.append(now-i*w)
        else:
            break


if dp[x2*w+y2] == 10**7:
    print(-1)
else:
    print(dp[x2*w+y2])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline


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



res = 1
for e in a:
    res = res*e

if res > 10**18:
    print(-1)
else:
    print(res)

Fixed submission:
import sys
input = sys.stdin.buffer.readline


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

judge = False

for e in a:
    if e == 0:
        judge = True
if judge:
    print(0)
    exit()

res = 1
for e in a:
    res = res*e
    if res > 10**18:
        res = -1
        break


if res == -1:
    print(-1)
else:
    print(res)
Buggy python submission (verdict: Runtime Error):
import sys,bisect
input = sys.stdin.readline

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

ans = [1]*n

edge = [[] for i in range(n)]
for i in range(n-1):
    u,v = map(int,input().split())
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

root = 0
chi = [[] for i in range(n)]
par = [-1]*n
used = [False]*n
tank = [0]

while tank:
    q = tank.pop()
    used[q] = True
    for e in edge[q]:
        if not used[e]:
            chi[q].append(e)
            tank.append(e)
            par[e] = q

tank = [root]

idx = dict()
val = dict()
dp = [10**6]*n

eulerNum = -1

while tank:
    q = tank.pop()
    if q >= 0:
        #first time
        num = a[q]
        kk = bisect.bisect_left(dp,num)
        val[q] = dp[kk]
        idx[q] = kk
        dp[kk] = num
        ans[q] = kk+1

        eulerNum += 1
        tank.append(~q)
        for ch in chi[q]:
            tank.append(ch)
    else:
        if ~q != root:
            dp[idx[~q]] = val[~q]
            eulerNum += 1

print(*ans,sep = "\n")

Fixed submission:
import sys,bisect
input = sys.stdin.readline

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

ans = [1]*n

edge = [[] for i in range(n)]
for i in range(n-1):
    u,v = map(int,input().split())
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

root = 0
chi = [[] for i in range(n)]
par = [-1]*n
used = [False]*n
tank = [0]

while tank:
    q = tank.pop()
    used[q] = True
    for e in edge[q]:
        if not used[e]:
            chi[q].append(e)
            tank.append(e)
            par[e] = q

tank = [root]

idx = dict()
val = dict()
dp = [10**10]*n

eulerNum = -1

while tank:
    q = tank.pop()
    if q >= 0:
        #first time
        num = a[q]
        kk = bisect.bisect_left(dp,num)
        
        val[q] = dp[kk]
        idx[q] = kk
        dp[kk] = num
        ans[q] = bisect.bisect_left(dp,10**10)

        eulerNum += 1
        tank.append(~q)
        for ch in chi[q]:
            tank.append(ch)
    else:
        if ~q != root:
            if dp[idx[~q]] == a[~q]:
                dp[idx[~q]] = val[~q]
                eulerNum += 1

print(*ans,sep = "\n")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
a = set()

for i in range(n):
    a.add(input())

print(len(a))

Fixed submission:
import sys
input = sys.stdin.buffer.readline

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

flag = 1
while True:
    if flag > 0:
        c -= b
        if c <= 0:
            break
    else:
        a -= d
        if a <= 0:
            break
    flag = flag * (-1)

if flag > 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,s = map(int,input().split())
a = list(map(int,input().split()))

mod = 998244353

res = 0

#dp[i][j]:a[i]まででf(L,?) = jとなるLの合計数
dp = [[0]*3003 for i in range(n)]

for i in range(n):
    if a[i] < s:
        res = (res+dp[i-1][s-a[i]]*(n-i))%mod
    elif a[i] == s:
        res = (res+(i+1)*(n-i))%mod
    for j in range(3003):
        if j < a[i]:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = dp[i-1][j] + dp[i-1][j-a[i]]
    dp[i][a[i]] += i+1
print(res)



Fixed submission:
import sys
input = sys.stdin.readline

def main():
    n,s = map(int,input().split())
    a = tuple(map(int,input().split()))

    mod = 998244353

    res = 0

    #dp[i][j]:a[i]まででf(L,?) = jとなるLの合計数
    dp = [[0]*3003 for i in range(n)]

    for i in range(n):
        if a[i] < s:
            res = (res+dp[i-1][s-a[i]]*(n-i))%mod
        elif a[i] == s:
            res = (res+(i+1)*(n-i))%mod
        for j in range(3003):
            if j < a[i]:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = (dp[i-1][j] + dp[i-1][j-a[i]])%mod
        dp[i][a[i]] += i+1
    print(res)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
import copy
#Z[i]:length of the longest list starting from S[i] which is also a prefix of S
#O(|S|)
def Z_algorithm(s,L):
    N = len(s)
    Z_alg = [0]*N

    Z_alg[0] = N
    i = L
    j = 0
    while i < N:
        while i+j < N and (s[j] == s[i+j] or s[j] == "?" or s[i+j] == "?"):
            j += 1
        Z_alg[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while i+k < N and k + Z_alg[k]<j:
            Z_alg[i+k] = Z_alg[k]
            k += 1
        i += k
        j -= k
    return Z_alg

a = list(input())
b = list(input())
c = list(input())

def unite(x,y):
    X,Y = len(x),len(y)
    z = Z_algorithm(y+x,Y)

    tmp = -1
    for i in range(Y,X+Y):
        if z[i]+i == X+Y or z[i] == Y:
            tmp = i
            break


    if tmp == -1:
        return x+y
    else:
        if z[tmp] == Y:
            res = x
            for i in range(tmp-Y,tmp):
                if res[i+Y-tmp] == "?":
                    res[i] = y[i-(tmp-Y)]
            return res
        else:
            res = x
            for i in range(tmp-Y,X):
                if res[i] == "?":
                    res[i] = y[i-(tmp-Y)]
            for i in range(X-tmp+Y,Y):
                res.append(y[i])
            return res

print(min(
len(unite(unite(a,b),c)),
len(unite(unite(a,c),b)),
len(unite(unite(b,a),c)),
len(unite(unite(b,c),a)),
len(unite(unite(c,a),b)),
len(unite(unite(c,b),a))))


Fixed submission:
a = input()
b = input()
c = input()

la = len(a)
lb = len(b)
lc = len(c)

def match(x,y):
    if x == y or x == "?" or y == "?":
        return True
    return False
    
ab = [True]*15000
ac = [True]*15000
bc = [True]*15000

for i in range(4000-lb,4000+la):
    for j in range(lb):
        if 4000 <= i+j < 4000+la:
            if not match(a[i+j-4000],b[j]):
                ab[i] = False

for i in range(4000-lc,4000+la):
    for j in range(lc):
        if 4000 <= i+j < 4000+la:
            if not match(a[i+j-4000],c[j]):
                ac[i] = False

for i in range(4000-lc,4000+lb):
    for j in range(lc):
        if 4000 <= i+j < 4000+lb:
            if not match(b[i+j-4000],c[j]):
                bc[i] = False

res = la+lb+lc

for i in range(4000-lb-lc,4000+la+lc+1):
    for j in range(0,4000+la+lb+1):
        if ab[i] and ac[j]:
            if (j-i+4000 >= 15000) or bc[j-i+4000]:
                res = min(res, max(4000+la,i+lb,j+lc)-min(4000,i,j))

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
  h,n = map(int,input().split())

  dg = 10**5

  ba = []
  for _ in [0]*n:
      a,b = map(int,input().split())
      ba.append(b*dg+a)

  d = [10**9]*(h+1)

  d[0] = 0

  for i in range(1,h+1):
      for e in ba:
          a,b = e%dg,e//dg
          if i<=a:
              if d[i] > b:
                  d[i] = b
          else:
              if d[i] > d[i-a]+b:
                  d[i] = d[i-a]+b

  print(d[-1])
if __name__ == '__main__':
  main()


Fixed submission:
h,n = map(int,input().split())

dg = 10**5

ba = []
for _ in [0]*n:
    a,b = map(int,input().split())
    if a >= h:
        a = h
    ba.append(b*dg+a)
ba.sort()

d = [10**9]*(h+1)

d[0] = 0

for i in range(1,h+1):
    for e in ba:
        a,b = e%dg,e//dg
        if i<=a:
            if d[i] > b:
                d[i] = b
        else:
            if d[i] > d[i-a]+b:
                d[i] = d[i-a]+b

print(d[-1])

Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int,input().split())

dg = 10**5

ba = []
for _ in [0]*n:
    a,b = map(int,input().split())
    if a >= h:
        a = h
    ba.append(b*dg+a)
ba.sort()

d = [10**9]*(h+1)

d[0] = 0

for i in range(1,h+1):
    for e in ba:
        a,b = e%dg,e//dg
        if i<=a:
            if d[i] > b:
                d[i] = b
        else:
            if d[i] > d[i-a]+b:
                d[i] = d[i-a]+b

print(d[-1])


Fixed submission:
h,n = map(int,input().split())

dg = 10**5

ba = []
for _ in [0]*n:
    a,b = map(int,input().split())
    if a >= h:
        a = h
    ba.append(b*dg+a)
ba.sort()

d = [10**9]*(h+1)

d[0] = 0

for i in range(1,h+1):
    for e in ba:
        a,b = e%dg,e//dg
        if i<=a:
            if d[i] > b:
                d[i] = b
        else:
            if d[i] > d[i-a]+b:
                d[i] = d[i-a]+b

print(d[-1])

Buggy python submission (verdict: Runtime Error):
h,n = map(int,input().split())

dg = 10**5

ba = []
for _ in [0]*n:
    a,b = map(int,input().split())
    ba.append(b*dg+a)
ba.sort()

d = [0]*(h+1)

a,b = ba[0]%dg,ba[0]//dg
d[0] = 0
for i in range(1,h+1):
    if i%a == 0:
        d[i] = (i//a)*b
    else:
        d[i] = (i//a+1)*b


for i in range(1,n):
    a,b = ba[i]%dg,ba[i]//dg
    if d[a] >= b:
        for j in range(a,h+1):
            if d[j] > d[j-a]+b:
                d[j] = d[j-a]+b

print(d[-1])

Fixed submission:
h,n = map(int,input().split())

dg = 10**5

ba = []
for _ in [0]*n:
    a,b = map(int,input().split())
    if a >= h:
        a = h
    ba.append(b*dg+a)
ba.sort()

d = [10**9]*(h+1)

d[0] = 0

for i in range(1,h+1):
    for e in ba:
        a,b = e%dg,e//dg
        if i<=a:
            if d[i] > b:
                d[i] = b
        else:
            if d[i] > d[i-a]+b:
                d[i] = d[i-a]+b

print(d[-1])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

cnt = [0]*65

for e in a:
    for i in range(65):
        if (e>>i)&1 == 1:
            cnt[i] += 1

res = 0
p = 1

for e in cnt:
    res = (res+p*e*(n-e)%mod)%mod
    p = p*2%mod

print(res)


Fixed submission:
a,b,c = map(int,input().split())
if a+b+c >= 22:
    print('bust')
else:
    print('win')
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    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)]

    dp = [[[False]*4000 for j in range(w)] for i in range(h)]

    dp[0][0][2000+a[0][0]-b[0][0]] = True
    dp[0][0][2000-a[0][0]+b[0][0]] = True


    for i in range(1,h):
        for k in range(4000):
            if 0 <= k+a[i][0]-b[i][0] <= 3999 and dp[i-1][0][k+a[i][0]-b[i][0]]:
                dp[i][0][k] = True
            elif 0 <= k-a[i][0]+b[i][0] <= 3999 and dp[i-1][0][k-a[i][0]+b[i][0]]:
                dp[i][0][k] = True

    for j in range(1,w):
        for k in range(4000):
            if 0 <= k+a[0][j]-b[0][j] <= 3999 and dp[0][j-1][k+a[0][j]-b[0][j]]:
                dp[0][j][k] = True
            elif 0 <= k-a[0][j]+b[0][j] <= 3999 and dp[0][j-1][k-a[0][j]+b[0][j]]:
                dp[0][j][k] = True       


    for i in range(1,h):
        for j in range(1,w):
            for k in range(4000):
                if 0 <= k+a[i][j]-b[i][j] <= 3999 and dp[i-1][j][k+a[i][j]-b[i][j]]:
                    dp[i][j][k] = True
                elif 0 <= k+a[i][j]-b[i][j] <= 3999 and dp[i][j-1][k+a[i][j]-b[i][j]]:
                    dp[i][j][k] = True
                elif 0 <= k-a[i][j]+b[i][j] <= 3999 and dp[i-1][j][k-a[i][j]+b[i][j]]:
                    dp[i][j][k] = True
                elif 0 <= k-a[i][j]+b[i][j] <= 3999 and dp[i][j-1][k-a[i][j]+b[i][j]]:
                    dp[i][j][k] = True

    res = 10**9
    for k in range(4000):
        if dp[-1][-1][k]:
            res = min(res,abs(2000-k))

    print(res)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline

h,w =map(int,input().split())
a = [tuple(map(int,input().split())) for _ in [0]*h]
b = [tuple(map(int,input().split())) for _ in [0]*h]


mid = 1<<(80*160)
dp = [[0]*w for _ in [0]*h]

for i in range(h):
    for j in range(w):
        diff = abs(a[i][j]-b[i][j])
        new = 0
        if i > 0:
            new |= dp[i-1][j]
        if j > 0:
            new |= dp[i][j-1]
        if (i,j) == (0,0):
            new = mid
        dp[i][j] = (new<<diff)|(new>>diff)


res = 10**9
p = dp[-1][-1]
for i in range(80*321):
    if p&1 == 1:
        res = min(res,abs(80*160-i))
    p = p>> 1
print(res)