Problem p02839 (python)

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

def main():
    H,W = map(int,input().split())
    point = [[0]*W for _ in range(H)]
    
    for i in range(H):
        a = list(map(int,input().split()))
        for j in range(W):
            point[i][j] += a[j]

    for i in range(H):
        b = list(map(int,input().split()))
        for j in range(W):
            point[i][j] = abs(point[i][j]-b[j])
    
    base = 3200
    dp = [[0]*W for _ in range(H)]
    dp[0][0] = (1 << (base+point[0][0])) | (1 << (base-point[0][0]))
    
    for i in range(H):
        for j in range(W):
            if j < W-1:
                dp[i][j+1] |= (dp[i][j] << point[i][j+1])
                dp[i][j+1] |= (dp[i][j] >> point[i][j+1])
            if i < H-1:
                dp[i+1][j] |= (dp[i][j] << point[i+1][j])
                dp[i+1][j] |= (dp[i][j] >> point[i+1][j])
    
    ans = dp[-1][-1] >> base
    for i in range(ans.bit_length()):
        if (ans >> i)&1:
            print(i)
            exit()
    
if __name__ == "__main__":
    main()

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

def main():
    H,W = map(int,input().split())
    point = [[0]*(W+1) for _ in range(H+1)]
    
    for i in range(H):
        a = list(map(int,input().split()))
        for j in range(W):
            point[i][j] += a[j]
    
    cnt = 0
    for i in range(H):
        b = list(map(int,input().split()))
        for j in range(W):
            point[i][j] = abs(point[i][j]-b[j])
            cnt += point[i][j]

    dp = [[[False]*(cnt+1) for _ in range(W+1)] for _ in range(H+1)]
    dp[0][0][point[0][0]] = True
    for i in range(H):
        for j in range(W):
            for k in range(cnt):
                if k+point[i+1][j] <= cnt:
                    dp[i+1][j][k+point[i+1][j]] = dp[i+1][j][k+point[i+1][j]] or dp[i][j][k]
                if k+point[i][j+1] <= cnt:
                    dp[i][j+1][k+point[i][j+1]] = dp[i][j+1][k+point[i][j+1]] or dp[i][j][k]
                dp[i+1][j][abs(k-point[i+1][j])] = dp[i+1][j][abs(k-point[i+1][j])] or dp[i][j][k]
                dp[i][j+1][abs(k-point[i][j+1])] = dp[i][j+1][abs(k-point[i][j+1])] or dp[i][j][k]
    
    print(dp[H-1][W-1].index(True))
    
if __name__ == "__main__":
    main()

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

def main():
    H,W = map(int,input().split())
    point = [[0]*(W+1) for _ in range(H+1)]
    
    for i in range(H):
        a = list(map(int,input().split()))
        for j in range(W):
            point[i][j] += a[j]
    
    cnt = 0
    for i in range(H):
        b = list(map(int,input().split()))
        for j in range(W):
            point[i][j] = abs(point[i][j]-b[j])
            cnt += point[i][j]

    dp = [[[False]*(cnt+1) for _ in range(W+1)] for _ in range(H+1)]
    dp[0][0][point[0][0]] = True
    for i in range(H):
        for j in range(W):
            for k in range(cnt):
                if k+point[i+1][j] <= cnt:
                    dp[i+1][j][k+point[i+1][j]] = dp[i+1][j][k+point[i+1][j]] or dp[i][j][k]
                if k+point[i][j+1] <= cnt:
                    dp[i][j+1][k+point[i][j+1]] = dp[i][j+1][k+point[i][j+1]] or dp[i][j][k]
                dp[i+1][j][abs(k-point[i+1][j])] = dp[i+1][j][abs(k-point[i+1][j])] or dp[i][j][k]
                dp[i][j+1][abs(k-point[i][j+1])] = dp[i][j+1][abs(k-point[i][j+1])] or dp[i][j][k]
    
    print(dp[H-1][W-1].index(True))
    
if __name__ == "__main__":
    main()