R,C,K=map(int,input().split())

Value=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r,c,v=map(int,input().split())
    Value[r][c]=v

DP=[[0,0,0,0] for _ in range(C+1) ]

for y in range(1,R+1):
    #下に移動
    for x in range(1,C+1):
        DP[x][0]=max(DP[x])
        DP[x][1]=DP[x][0]+Value[y][x]
        DP[x][2]=DP[x][3]=0

    #右に移動
    for x in range(1,C+1):
        for k in range(0,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k])

        for k in range(1,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k-1]+Value[y][x])

print(max(DP[-1])) R,C,K=map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [0]*(C+1) for _ in range(R+1) for _ in range(R+1) _ range(R+1) range R+1 R 1 for _ in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 Value=[[0]*(C+1) for _ in range(R+1)] Value [[0]*(C+1) for _ in range(R+1)] for _ in range(K):
    r,c,v=map(int,input().split())
    Value[r][c]=v _ range(K) range K r,c,v=map(int,input().split()) r map(int,input().split()) map int input().split() ().split () input split c v Value[r][c]=v Value[r][c] [r] Value r c v [0,0,0,0] for _ in range(C+1) for _ in range(C+1) _ range(C+1) range C+1 C 1 for _ in range(C+1) [0,0,0,0] 0 0 0 0 DP=[[0,0,0,0] for _ in range(C+1) ] DP [[0,0,0,0] for _ in range(C+1) ] for y in range(1,R+1):
    #下に移動
    for x in range(1,C+1):
        DP[x][0]=max(DP[x])
        DP[x][1]=DP[x][0]+Value[y][x]
        DP[x][2]=DP[x][3]=0

    #右に移動
    for x in range(1,C+1):
        for k in range(0,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k])

        for k in range(1,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k-1]+Value[y][x]) y range(1,R+1) range 1 R+1 R 1 for x in range(1,C+1):
        DP[x][0]=max(DP[x])
        DP[x][1]=DP[x][0]+Value[y][x]
        DP[x][2]=DP[x][3]=0

    #右に移動
     x range(1,C+1) range 1 C+1 C 1 DP[x][0]=max(DP[x]) DP[x][0] [x] DP x 0 max(DP[x]) max DP[x] DP x DP[x][1]=DP[x][0]+Value[y][x] DP[x][1] [x] DP x 1 DP[x][0]+Value[y][x] DP[x][0] [x] DP x 0 Value[y][x] [y] Value y x DP[x][2]=DP[x][3]=0 DP[x][2] [x] DP x 2 0 =DP[x][3]=0 DP[x][3] [x] DP x 3 0 for x in range(1,C+1):
        for k in range(0,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k])

        for k in range(1,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k-1]+Value[y][x]) x range(1,C+1) range 1 C+1 C 1 for k in range(0,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k])

         k range(0,3+1) range 0 3+1 3 1 DP[x][k]=max(DP[x][k],DP[x-1][k]) DP[x][k] [x] DP x k max(DP[x][k],DP[x-1][k]) max DP[x][k] [x] DP x k DP[x-1][k] [x-1] DP x-1 x 1 k for k in range(1,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k-1]+Value[y][x]) k range(1,3+1) range 1 3+1 3 1 DP[x][k]=max(DP[x][k],DP[x-1][k-1]+Value[y][x]) DP[x][k] [x] DP x k max(DP[x][k],DP[x-1][k-1]+Value[y][x]) max DP[x][k] [x] DP x k DP[x-1][k-1]+Value[y][x] DP[x-1][k-1] [x-1] DP x-1 x 1 k-1 k 1 Value[y][x] [y] Value y x print(max(DP[-1])) print max(DP[-1]) max DP[-1] DP -1 Value=[[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] Value v=map(int,input().split()) map(int,input().split()) v r,c,v=map(int,input().split()) map(int,input().split()) r c,v=map(int,input().split()) map(int,input().split()) c R,C,K=map(int,input().split()) map(int,input().split()) R K=map(int,input().split()) map(int,input().split()) K DP=[[0,0,0,0] for _ in range(C+1) ] [[0,0,0,0] for _ in range(C+1) ] DP C,K=map(int,input().split()) map(int,input().split()) C
R,C,K=map(int,input().split())

Value=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r,c,v=map(int,input().split())
    Value[r][c]=v

DP=[[0,0,0,0] for _ in range(C+1) ]

for y in range(1,R+1):
    #下に移動
    for x in range(1,C+1):
        DP[x][0]=max(DP[x])
        DP[x][1]=DP[x][0]+Value[y][x]
        DP[x][2]=DP[x][3]=0

    #右に移動
    for x in range(1,C+1):
        for k in range(0,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k])

        for k in range(1,3+1):
            DP[x][k]=max(DP[x][k],DP[x-1][k-1]+Value[y][x])

print(max(DP[-1]))