Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

R, C, K = map(int,input().split())
MAP = np.zeros((R, C), dtype=np.int64)
DP = np.zeros((R+1, C+1, 4), dtype=np.int64)

for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v

for i in range(R):
    for j in range(C):
        tmp = DP[i][j+1][3]
        DP[i+1][j+1] = DP[i+1][j]
        DP[i+1][j+1][DP[i+1][j+1] < tmp] = tmp
        v = MAP[i][j]
        if v == 0:
            continue
        for k in range(2,-1,-1):
            DP[i+1][j+1][k+1] = max(DP[i+1][j+1][k + 1], DP[i+1][j+1][k] + v)

print(max(DP[R][C]))

Fixed submission:
R, C, K = map(int,input().split())
MAP = [[0 for i in range(C)] for j in range(R)]
DP = [[[0 for i in range(C+1)] for j in range(4)] for k in range(R+1)]
 
for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v
 
for i in range(R):
    for j in range(4):
        for k in range(C):
            DP[i+1][j][k+1] = max(DP[i][3][k+1], DP[i+1][j][k])
            if j == 0:
                continue
            v = MAP[i][k]
            if v == 0:
                continue
            DP[i+1][j][k+1] = max(DP[i+1][j][k+1], max(DP[i][3][k+1], DP[i+1][j-1][k]) + v)

print(DP[R][3][C])

Buggy python submission (verdict: Time Limit Exceeded):
R, C, K = map(int,input().split())
MAP = [[0 for i in range(C)] for j in range(R)]
DP = [[[0 for i in range(4)] for j in range(C+1)] for k in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v

for i in range(R):
    for j in range(C):
        DP[i+1][j+1][0] = max(DP[i+1][j+1][0], max(DP[i][j+1]))
        for k in range(4):
            DP[i+1][j+1][k] = max(DP[i+1][j+1][k], DP[i+1][j][k])
        if MAP[i][j] == 0:
            continue
        DP[i+1][j+1][1] = max(DP[i+1][j+1][1], max(DP[i][j+1]) + MAP[i][j])
        for k in range(3):
            DP[i+1][j+1][k+1] = max(DP[i+1][j+1][k+1], DP[i+1][j][k] + MAP[i][j])

print(max(DP[R][C]))

Fixed submission:
R, C, K = map(int,input().split())
MAP = [[0 for i in range(C)] for j in range(R)]
DP = [[[0 for i in range(C+1)] for j in range(4)] for k in range(R+1)]
 
for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v
 
for i in range(R):
    for j in range(4):
        for k in range(C):
            DP[i+1][j][k+1] = max(DP[i][3][k+1], DP[i+1][j][k])
            if j == 0:
                continue
            v = MAP[i][k]
            if v == 0:
                continue
            DP[i+1][j][k+1] = max(DP[i+1][j][k+1], max(DP[i][3][k+1], DP[i+1][j-1][k]) + v)

print(DP[R][3][C])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

R, C, K = map(int,input().split())
MAP = np.zeros((R, C), dtype=np.int64)
DP = np.zeros((R+1, C+1, 4), dtype=np.int64)

for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v

for i in range(R):
    for j in range(C):
        DP[i+1][j+1][0] = max(DP[i+1][j+1][0], DP[i][j+1].max())
        DP[i+1][j+1] = np.amax([DP[i+1][j+1], DP[i+1][j]], axis=0)
        if MAP[i][j] == 0:
            continue
        DP[i+1][j+1][1] = max(DP[i+1][j+1][1], DP[i][j+1].max() + MAP[i][j])
        DP[i+1][j+1][1:] = np.amax([DP[i+1][j+1][1:], DP[i+1][j][:3] + MAP[i][j]], axis=0)

print(max(DP[R][C]))

Fixed submission:
R, C, K = map(int,input().split())
MAP = [[0 for i in range(C)] for j in range(R)]
DP = [[[0 for i in range(C+1)] for j in range(4)] for k in range(R+1)]
 
for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v
 
for i in range(R):
    for j in range(4):
        for k in range(C):
            DP[i+1][j][k+1] = max(DP[i][3][k+1], DP[i+1][j][k])
            if j == 0:
                continue
            v = MAP[i][k]
            if v == 0:
                continue
            DP[i+1][j][k+1] = max(DP[i+1][j][k+1], max(DP[i][3][k+1], DP[i+1][j-1][k]) + v)

print(DP[R][3][C])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

R, C, K = map(int,input().split())
MAP = np.zeros((R, C), dtype=np.int64)
DP = np.zeros((R+1, C+1, 4), dtype=np.int64)

for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v

for i in range(R):
    for j in range(C):
        DP[i+1][j+1][0] = max(DP[i+1][j+1][0], DP[i][j+1].max())
        DP[i+1][j+1][1] = max(DP[i+1][j+1][1], DP[i][j+1].max() + MAP[i][j])
        DP[i+1][j+1] = np.amax([DP[i+1][j+1], DP[i+1][j]], axis=0)
        DP[i+1][j+1][1:] = np.amax([DP[i+1][j+1][1:], DP[i+1][j][:3] + MAP[i][j]], axis=0)

print(max(DP[R][C]))

Fixed submission:
R, C, K = map(int,input().split())
MAP = [[0 for i in range(C)] for j in range(R)]
DP = [[[0 for i in range(C+1)] for j in range(4)] for k in range(R+1)]
 
for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v
 
for i in range(R):
    for j in range(4):
        for k in range(C):
            DP[i+1][j][k+1] = max(DP[i][3][k+1], DP[i+1][j][k])
            if j == 0:
                continue
            v = MAP[i][k]
            if v == 0:
                continue
            DP[i+1][j][k+1] = max(DP[i+1][j][k+1], max(DP[i][3][k+1], DP[i+1][j-1][k]) + v)

print(DP[R][3][C])

Buggy python submission (verdict: Time Limit Exceeded):
R, C, K = map(int,input().split())
MAP = [[0 for i in range(C)] for j in range(R)]
DP = [[[0 for i in range(4)] for j in range(C+1)] for k in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v

for i in range(R):
    for j in range(C):
        DP[i+1][j+1][0] = max(DP[i+1][j+1][0], max(DP[i][j+1]))
        DP[i+1][j+1][1] = max(DP[i+1][j+1][1], max(DP[i][j+1]) + MAP[i][j])
        for k in range(4):
            DP[i+1][j+1][k] = max(DP[i+1][j+1][k], DP[i+1][j][k])
        for k in range(3):
            DP[i+1][j+1][k+1] = max(DP[i+1][j+1][k+1], DP[i+1][j][k] + MAP[i][j])

print(max(DP[R][C]))

Fixed submission:
R, C, K = map(int,input().split())
MAP = [[0 for i in range(C)] for j in range(R)]
DP = [[[0 for i in range(C+1)] for j in range(4)] for k in range(R+1)]
 
for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v
 
for i in range(R):
    for j in range(4):
        for k in range(C):
            DP[i+1][j][k+1] = max(DP[i][3][k+1], DP[i+1][j][k])
            if j == 0:
                continue
            v = MAP[i][k]
            if v == 0:
                continue
            DP[i+1][j][k+1] = max(DP[i+1][j][k+1], max(DP[i][3][k+1], DP[i+1][j-1][k]) + v)

print(DP[R][3][C])