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

R,C,K=map(int,input().split())
rcv=[tuple(map(int,input().split())) for _ in range(K)]

MAP=[[0 for _ in range(C+2)] for _ in range(R+2)]
DP=[[[0 for _ in range(3)] for _ in range(C+2)] for _ in range(R+2)]
for r,c,v in rcv:
    MAP[r-1][c-1]=v

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

ans=0
for i in range(R):
    for j in range(C):
        ans=max(ans,max(DP[i][j]))
print(ans)

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

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)

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

R,C,K=map(int,input().split())
rcv=[list(map(int,input().split())) for _ in range(K)]

MAP=[[0 for _ in range(C+2)] for _ in range(R+2)]
DP=[[[0 for _ in range(3)] for _ in range(C+2)] for _ in range(R+2)]
for r,c,v in rcv:
    MAP[r-1][c-1]=v

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

ans=0
for i in range(R):
    for j in range(C):
        ans=max(ans,max(DP[i][j]))
print(ans)

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

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)

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

R,C,K=map(int,input().split())
rcv=[list(map(int,input().split())) for _ in range(K)]

MAP=[[0 for _ in range(C)] for _ in range(R)]
DP=[[[0 for _ in range(4)] for _ in range(C)] for _ in range(R)]
for r,c,v in rcv:
    MAP[r-1][c-1]=v

DP[0][0][1]=MAP[0][0]
for i in range(R):
    for j in range(C):
        score=max(DP[i][j])
        for num,point in enumerate([[1,0],[0,1]]):
            x,y=point
            X,Y=i+x,j+y
            if 0<=X<R and 0<=Y<C:
                for k in range(3):
                    if num==0:
                        DP[X][Y][1]=max(DP[X][Y][1],score+MAP[X][Y])
                    else:
                        DP[X][Y][k+1]=max(DP[X][Y][k+1],DP[X][Y][k],DP[i][j][k+1],DP[i][j][k]+MAP[X][Y])
print(max(DP[-1][-1]))

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

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)

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

R,C,K=map(int,input().split())
rcv=[list(map(int,input().split())) for _ in range(K)]

MAP=[[0 for _ in range(C)] for _ in range(R)]
DP=[[[0 for _ in range(4)] for _ in range(C)] for _ in range(R)]
for r,c,v in rcv:
    MAP[r-1][c-1]=v

DP[0][0][1]=MAP[0][0]
for i in range(R):
    for j in range(C):
        for num,point in enumerate([[1,0],[0,1]]):
            x,y=point
            X,Y=i+x,j+y
            if 0<=X<R and 0<=Y<C:
                for k in range(3):
                    if num==0:
                        DP[X][Y][1]=max(DP[X][Y][1],max(DP[i][j])+MAP[X][Y])
                    else:
                        DP[X][Y][k+1]=max(DP[X][Y][k+1],DP[X][Y][k],DP[i][j][k+1],DP[i][j][k]+MAP[X][Y])
print(max(DP[-1][-1]))

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

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)

Buggy python submission (verdict: Time Limit Exceeded):
R,C,K=map(int,input().split())
rcv=[list(map(int,input().split())) for _ in range(K)]

MAP=[[0 for _ in range(C)] for _ in range(R)]
DP=[[[0 for _ in range(4)] for _ in range(C)] for _ in range(R)]
for r,c,v in rcv:
    MAP[r-1][c-1]=v

DP[0][0][1]=MAP[0][0]
for i in range(R):
    for j in range(C):
        for num,point in enumerate([[1,0],[0,1]]):
            x,y=point
            X,Y=i+x,j+y
            if 0<=X<R and 0<=Y<C:
                for k in range(3):
                    if num==0:
                        DP[X][Y][1]=max(DP[X][Y][1],max(DP[i][j])+MAP[X][Y])
                    else:
                        DP[X][Y][k+1]=max(DP[X][Y][k+1],DP[X][Y][k],DP[i][j][k+1],DP[i][j][k]+MAP[X][Y])
print(max(DP[-1][-1]))

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

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)

Buggy python submission (verdict: Time Limit Exceeded):
R,C,K=map(int,input().split())
rcv=[list(map(int,input().split())) for _ in range(K)]

MAP=[[0 for _ in range(C)] for _ in range(R)]
DP=[[[0 for _ in range(4)] for _ in range(C)] for _ in range(R)]
for r,c,v in rcv:
    MAP[r-1][c-1]=v

DP[0][0][1]=MAP[0][0]
for i in range(R):
    for j in range(C):
        for num,point in enumerate([[1,0],[0,1]]):
            x,y=point
            X,Y=i+x,j+y
            if 0<=X<R and 0<=Y<C:
                for k in range(3):
                    if num==0:
                        DP[X][Y][1]=max(DP[X][Y][1],max(DP[i][j])+MAP[X][Y])
                    else:
                        DP[X][Y][k+1]=max(DP[X][Y][k+1],DP[X][Y][k],DP[i][j][k+1],DP[i][j][k]+MAP[X][Y])
print(max(DP[-1][-1]))

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

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)