from copy import copy

C,R,K=map(int,input().split())
dp=[[0]*(R+1) for i1 in range(4)]
M=[[0]*R for i in range(C)]
for i in range(K):
    r,c,v=map(int,input().split())
    M[r-1][c-1]=v
for i,l in enumerate(M):
    for num in range(1,4):
        for j in range(R):
            if num==1:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j])
            else:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j])
    dp[0]=dp[-1][1:-1]+[0,dp[-1][0]]

print(dp[-1][-2]) from copy import copy C,R,K=map(int,input().split()) C map(int,input().split()) map int input().split() ().split () input split R K [0]*(R+1) for i1 in range(4) for i1 in range(4) i1 range(4) range 4 for i1 in range(4) [0]*(R+1) [0] 0 R+1 R 1 dp=[[0]*(R+1) for i1 in range(4)] dp [[0]*(R+1) for i1 in range(4)] [0]*R for i in range(C) for i in range(C) i range(C) range C for i in range(C) [0]*R [0] 0 R M=[[0]*R for i in range(C)] M [[0]*R for i in range(C)] for i in range(K):
    r,c,v=map(int,input().split())
    M[r-1][c-1]=v i 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 M[r-1][c-1]=v M[r-1][c-1] [r-1] M r-1 r 1 c-1 c 1 v for i,l in enumerate(M):
    for num in range(1,4):
        for j in range(R):
            if num==1:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j])
            else:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j])
    dp[0]=dp[-1][1:-1]+[0,dp[-1][0]] i l enumerate(M) enumerate M for num in range(1,4):
        for j in range(R):
            if num==1:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j])
            else:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j])
     num range(1,4) range 1 4 for j in range(R):
            if num==1:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j])
            else:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j])
     j range(R) range R if num==1:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j])
            else:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j])
     num==1 num 1 dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j]) dp[num][j] [num] dp num j max(dp[num][j-1],dp[num-1][j-1]+M[i][j]) max dp[num][j-1] [num] dp num j-1 j 1 dp[num-1][j-1]+M[i][j] dp[num-1][j-1] [num-1] dp num-1 num 1 j-1 j 1 M[i][j] [i] M i j dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j]) dp[num][j] [num] dp num j max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j]) max dp[num][j-1] [num] dp num j-1 j 1 dp[num-1][j] [num-1] dp num-1 num 1 j dp[num-1][j-1]+M[i][j] dp[num-1][j-1] [num-1] dp num-1 num 1 j-1 j 1 M[i][j] [i] M i j dp[0]=dp[-1][1:-1]+[0,dp[-1][0]] dp[0] dp 0 dp[-1][1:-1]+[0,dp[-1][0]] dp[-1][1:-1] [-1] dp -1 1:-1 1 -1 [0,dp[-1][0]] 0 dp[-1][0] [-1] dp -1 0 print(dp[-1][-2]) print dp[-1][-2] [-1] dp -1 -2 M=[[0]*R for i in range(C)] [[0]*R for i in range(C)] M v=map(int,input().split()) map(int,input().split()) v c,v=map(int,input().split()) map(int,input().split()) c R,K=map(int,input().split()) map(int,input().split()) R K=map(int,input().split()) map(int,input().split()) K C,R,K=map(int,input().split()) map(int,input().split()) C dp=[[0]*(R+1) for i1 in range(4)] [[0]*(R+1) for i1 in range(4)] dp r,c,v=map(int,input().split()) map(int,input().split()) r
from copy import copy

C,R,K=map(int,input().split())
dp=[[0]*(R+1) for i1 in range(4)]
M=[[0]*R for i in range(C)]
for i in range(K):
    r,c,v=map(int,input().split())
    M[r-1][c-1]=v
for i,l in enumerate(M):
    for num in range(1,4):
        for j in range(R):
            if num==1:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j-1]+M[i][j])
            else:
                dp[num][j]= max(dp[num][j-1],dp[num-1][j],dp[num-1][j-1]+M[i][j])
    dp[0]=dp[-1][1:-1]+[0,dp[-1][0]]

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