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

V=[[0 for _ in range(C)] for _ in range(R)]

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

dp=[[0 for _ in range(4)] for _ in range(C+1)]
for i in range(R):
    ndp=[[0 for _ in range(4)] for _ in range(C+1)]
    for j in range(C):
        ndp[j][0]=max(dp[j])

    for j in range(C):
        v=V[i][j]
        for n in range(1,4):
            ndp[j][n]=max(ndp[j-1][n-1]+v,dp[j][3]+v,ndp[j-1][n])

    dp=ndp

print(max(dp[C-1])) R,C,K=map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [0 for _ in range(C)] for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] V=[[0 for _ in range(C)] for _ in range(R)] V [[0 for _ in range(C)] for _ in range(R)] for i in range(K):
    r,c,v=map(int,input().split())
    V[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 V[r-1][c-1]=v V[r-1][c-1] [r-1] V r-1 r 1 c-1 c 1 v [0 for _ in range(4)] for _ in range(C+1) for _ in range(C+1) _ range(C+1) range C+1 C 1 for _ in range(C+1) [0 for _ in range(4)] dp=[[0 for _ in range(4)] for _ in range(C+1)] dp [[0 for _ in range(4)] for _ in range(C+1)] for i in range(R):
    ndp=[[0 for _ in range(4)] for _ in range(C+1)]
    for j in range(C):
        ndp[j][0]=max(dp[j])

    for j in range(C):
        v=V[i][j]
        for n in range(1,4):
            ndp[j][n]=max(ndp[j-1][n-1]+v,dp[j][3]+v,ndp[j-1][n])

    dp=ndp i range(R) range R [0 for _ in range(4)] for _ in range(C+1) for _ in range(C+1) _ range(C+1) range C+1 C 1 for _ in range(C+1) [0 for _ in range(4)] ndp=[[0 for _ in range(4)] for _ in range(C+1)] ndp [[0 for _ in range(4)] for _ in range(C+1)] for j in range(C):
        ndp[j][0]=max(dp[j])

     j range(C) range C ndp[j][0]=max(dp[j]) ndp[j][0] [j] ndp j 0 max(dp[j]) max dp[j] dp j for j in range(C):
        v=V[i][j]
        for n in range(1,4):
            ndp[j][n]=max(ndp[j-1][n-1]+v,dp[j][3]+v,ndp[j-1][n])

     j range(C) range C v=V[i][j] v V[i][j] [i] V i j for n in range(1,4):
            ndp[j][n]=max(ndp[j-1][n-1]+v,dp[j][3]+v,ndp[j-1][n])

     n range(1,4) range 1 4 ndp[j][n]=max(ndp[j-1][n-1]+v,dp[j][3]+v,ndp[j-1][n]) ndp[j][n] [j] ndp j n max(ndp[j-1][n-1]+v,dp[j][3]+v,ndp[j-1][n]) max ndp[j-1][n-1]+v ndp[j-1][n-1] [j-1] ndp j-1 j 1 n-1 n 1 v dp[j][3]+v dp[j][3] [j] dp j 3 v ndp[j-1][n] [j-1] ndp j-1 j 1 n dp=ndp dp ndp print(max(dp[C-1])) print max(dp[C-1]) max dp[C-1] dp C-1 C 1 r,c,v=map(int,input().split()) map(int,input().split()) r C,K=map(int,input().split()) map(int,input().split()) C K=map(int,input().split()) map(int,input().split()) K dp=ndp ndp dp V=[[0 for _ in range(C)] for _ in range(R)] [[0 for _ in range(C)] for _ in range(R)] V v=V[i][j] V[i][j] v R,C,K=map(int,input().split()) map(int,input().split()) R c,v=map(int,input().split()) map(int,input().split()) c ndp=[[0 for _ in range(4)] for _ in range(C+1)] [[0 for _ in range(4)] for _ in range(C+1)] ndp v=map(int,input().split()) map(int,input().split()) v dp=[[0 for _ in range(4)] for _ in range(C+1)] [[0 for _ in range(4)] for _ in range(C+1)] dp
R,C,K=map(int,input().split())

V=[[0 for _ in range(C)] for _ in range(R)]

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

dp=[[0 for _ in range(4)] for _ in range(C+1)]
for i in range(R):
    ndp=[[0 for _ in range(4)] for _ in range(C+1)]
    for j in range(C):
        ndp[j][0]=max(dp[j])

    for j in range(C):
        v=V[i][j]
        for n in range(1,4):
            ndp[j][n]=max(ndp[j-1][n-1]+v,dp[j][3]+v,ndp[j-1][n])

    dp=ndp

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