Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

r,c,k = map(int,readline().split())
items = [[0]*c for _ in range(r)]
for i in range(k):
    a,b,v = map(int,readline().split())
    a,b = a-1,b-1
    items[a][b] = v

dp = [[[0]*4 for i in range(c+1)] for j in range(r+1)]

#process1
#移動は→↓の２通りのみなので、その方向に探索していけば良い。
for i in range(1,r+1):
    for j in range(1,c+1):
        if items[i-1][j-1]:
            dp[i][j][0] = max(max(dp[i-1][j]),dp[i][j-1][0])
            dp[i][j][1] = max(max(dp[i-1][j])+items[i-1][j-1],dp[i][j-1][1],dp[i][j-1][0]+items[i-1][j-1])
            dp[i][j][2] = max(dp[i][j-1][2],dp[i][j-1][1]+items[i-1][j-1])
            dp[i][j][3] = max(dp[i][j-1][3],dp[i][j-1][2]+items[i-1][j-1])
        else:
            dp[i][j][0] = max(max(dp[i-1][j]),dp[i][j-1][0])
            dp[i][j][1] = dp[i][j-1][1]
            dp[i][j][2] = dp[i][j-1][2]
            dp[i][j][3] = dp[i][j-1][3]

print(max(dp[-1][-1]))

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
r,c,k = map(int,readline().split())
items = [[0]*c for _ in range(r)]
for i in range(k):
    a,b,v = map(int,readline().split())
    a,b = a-1,b-1
    items[a][b] = v

dp0 = [[0]*(c+1) for j in range(r+1)]
dp1 = [[0]*(c+1) for j in range(r+1)]
dp2 = [[0]*(c+1) for j in range(r+1)]
dp3 = [[0]*(c+1) for j in range(r+1)]

for i in range(1,r+1):
    for j in range(1,c+1):
        #dp[i][j][0] = max(maximam[i-1][j],dp[i][j-1][0])
        #dp[i][j][1] = max(maximam[i-1][j]+items[i-1][j-1],dp[i][j-1][1],dp[i][j-1][0]+items[i-1][j-1])
        dp1[i][j] = max(dp0[i][j]+items[i-1][j-1],dp1[i][j-1],dp0[i][j-1]+items[i-1][j-1])
        dp2[i][j] = max(dp2[i][j-1],dp1[i][j-1]+items[i-1][j-1])
        dp3[i][j] = max(dp3[i][j-1],dp2[i][j-1]+items[i-1][j-1])
        if i < r:
            dp0[i+1][j] = max(dp0[i][j],dp1[i][j],dp2[i][j],dp3[i][j])
        #maximam[i][j] = max(dp[i][j])

print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))

Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

#Educational DP Contest
#H-Grid1


r,c,k = map(int,input().split())
items = [[0]*c for _ in range(r)]
for i in range(k):
    a,b,v = map(int,readline().split())
    a,b = a-1,b-1
    items[a][b] = v

dp = [[[0]*4 for i in range(c+1)] for j in range(r+1)]

#process1
#移動は→↓の２通りのみなので、その方向に探索していけば良い。
for i in range(1,r+1):
    for j in range(1,c+1):
        if items[i-1][j-1]:
            dp[i][j][0] = max(max(dp[i-1][j]),dp[i][j-1][0])
            dp[i][j][1] = max(max(dp[i-1][j])+items[i-1][j-1],dp[i][j-1][1],dp[i][j-1][0]+items[i-1][j-1])
            dp[i][j][2] = max(dp[i][j-1][2],dp[i][j-1][1]+items[i-1][j-1])
            dp[i][j][3] = max(dp[i][j-1][3],dp[i][j-1][2]+items[i-1][j-1])
        else:
            dp[i][j][0] = max(max(dp[i-1][j]),dp[i][j-1][0])
            dp[i][j][1] = dp[i][j-1][1]
            dp[i][j][2] = dp[i][j-1][2]
            dp[i][j][3] = dp[i][j-1][3]
        """if maze[i][j] == "#":
            continue
        if i > 0: #i-1を参照するため端っこは除く
            dp[i][j] += dp[i-1][j]
        if j > 0:
            dp[i][j] += dp[i][j-1]
        dp[i][j] %= mod"""
"""ans = 0
for i in range(c):
    ans = max(ans,max(dp[-1][i]))

print(ans)"""
print(max(dp[-1][-1]))

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
r,c,k = map(int,readline().split())
items = [[0]*c for _ in range(r)]
for i in range(k):
    a,b,v = map(int,readline().split())
    a,b = a-1,b-1
    items[a][b] = v

dp0 = [[0]*(c+1) for j in range(r+1)]
dp1 = [[0]*(c+1) for j in range(r+1)]
dp2 = [[0]*(c+1) for j in range(r+1)]
dp3 = [[0]*(c+1) for j in range(r+1)]

for i in range(1,r+1):
    for j in range(1,c+1):
        #dp[i][j][0] = max(maximam[i-1][j],dp[i][j-1][0])
        #dp[i][j][1] = max(maximam[i-1][j]+items[i-1][j-1],dp[i][j-1][1],dp[i][j-1][0]+items[i-1][j-1])
        dp1[i][j] = max(dp0[i][j]+items[i-1][j-1],dp1[i][j-1],dp0[i][j-1]+items[i-1][j-1])
        dp2[i][j] = max(dp2[i][j-1],dp1[i][j-1]+items[i-1][j-1])
        dp3[i][j] = max(dp3[i][j-1],dp2[i][j-1]+items[i-1][j-1])
        if i < r:
            dp0[i+1][j] = max(dp0[i][j],dp1[i][j],dp2[i][j],dp3[i][j])
        #maximam[i][j] = max(dp[i][j])

print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))