import sys
input=sys.stdin.readline
H,W,K=map(int,input().split())
G=[[0]*W for i in range(H)]

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

dp=[[[-1]*W for i in range(H)] for i in range(4)]

dp[0][0][0]=0
if G[0][0]!=0:
    dp[1][0][0]=G[0][0]

for i in range(H):
    for j in range(W):
        m=max(dp[k][i][j] for k in range(4))
        if i+1<H:
            dp[1][i+1][j]=max(dp[1][i+1][j],m+G[i+1][j])
            dp[0][i+1][j]=max(dp[0][i+1][j],m)
        if j+1<W:
                dp[0][i][j+1]=0
                dp[1][i][j+1]=max(dp[1][i][j+1],dp[1][i][j],dp[0][i][j]+G[i][j+1])
                dp[2][i][j+1]=max(dp[2][i][j+1],dp[2][i][j],dp[1][i][j]+G[i][j+1])
                dp[3][i][j+1]=max(dp[3][i][j+1],dp[3][i][j],dp[2][i][j]+G[i][j+1])
ans=max(dp[i][H-1][W-1] for i in range(4))
print(ans) import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline H,W,K=map(int,input().split()) H map(int,input().split()) map int input().split() ().split () input split W K [0]*W for i in range(H) for i in range(H) i range(H) range H for i in range(H) [0]*W [0] 0 W G=[[0]*W for i in range(H)] G [[0]*W for i in range(H)] for i in range(K):
    r,c,v=map(int,input().split())
    r,c=r-1,c-1
    G[r][c]=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 r,c=r-1,c-1 r r-1 r 1 c c-1 c 1 G[r][c]=v G[r][c] [r] G r c v [[-1]*W for i in range(H)] for i in range(4) for i in range(4) i range(4) range 4 for i in range(4) [[-1]*W for i in range(H)] dp=[[[-1]*W for i in range(H)] for i in range(4)] dp [[[-1]*W for i in range(H)] for i in range(4)] dp[0][0][0]=0 dp[0][0][0] [0] [0] dp 0 0 0 0 if G[0][0]!=0:
    dp[1][0][0]=G[0][0] G[0][0]!=0 G[0][0] [0] G 0 0 0 dp[1][0][0]=G[0][0] dp[1][0][0] [0] [1] dp 1 0 0 G[0][0] [0] G 0 0 for i in range(H):
    for j in range(W):
        m=max(dp[k][i][j] for k in range(4))
        if i+1<H:
            dp[1][i+1][j]=max(dp[1][i+1][j],m+G[i+1][j])
            dp[0][i+1][j]=max(dp[0][i+1][j],m)
        if j+1<W:
                dp[0][i][j+1]=0
                dp[1][i][j+1]=max(dp[1][i][j+1],dp[1][i][j],dp[0][i][j]+G[i][j+1])
                dp[2][i][j+1]=max(dp[2][i][j+1],dp[2][i][j],dp[1][i][j]+G[i][j+1])
                dp[3][i][j+1]=max(dp[3][i][j+1],dp[3][i][j],dp[2][i][j]+G[i][j+1]) i range(H) range H for j in range(W):
        m=max(dp[k][i][j] for k in range(4))
        if i+1<H:
            dp[1][i+1][j]=max(dp[1][i+1][j],m+G[i+1][j])
            dp[0][i+1][j]=max(dp[0][i+1][j],m)
        if j+1<W:
                dp[0][i][j+1]=0
                dp[1][i][j+1]=max(dp[1][i][j+1],dp[1][i][j],dp[0][i][j]+G[i][j+1])
                dp[2][i][j+1]=max(dp[2][i][j+1],dp[2][i][j],dp[1][i][j]+G[i][j+1])
                dp[3][i][j+1]=max(dp[3][i][j+1],dp[3][i][j],dp[2][i][j]+G[i][j+1]) j range(W) range W m=max(dp[k][i][j] for k in range(4)) m max(dp[k][i][j] for k in range(4)) max dp[k][i][j] [i] [k] dp k i j if i+1<H:
            dp[1][i+1][j]=max(dp[1][i+1][j],m+G[i+1][j])
            dp[0][i+1][j]=max(dp[0][i+1][j],m)
         i+1<H i+1 i 1 H dp[1][i+1][j]=max(dp[1][i+1][j],m+G[i+1][j]) dp[1][i+1][j] [i+1] [1] dp 1 i+1 i 1 j max(dp[1][i+1][j],m+G[i+1][j]) max dp[1][i+1][j] [i+1] [1] dp 1 i+1 i 1 j m+G[i+1][j] m G[i+1][j] [i+1] G i+1 i 1 j dp[0][i+1][j]=max(dp[0][i+1][j],m) dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j max(dp[0][i+1][j],m) max dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j m if j+1<W:
                dp[0][i][j+1]=0
                dp[1][i][j+1]=max(dp[1][i][j+1],dp[1][i][j],dp[0][i][j]+G[i][j+1])
                dp[2][i][j+1]=max(dp[2][i][j+1],dp[2][i][j],dp[1][i][j]+G[i][j+1])
                dp[3][i][j+1]=max(dp[3][i][j+1],dp[3][i][j],dp[2][i][j]+G[i][j+1]) j+1<W j+1 j 1 W dp[0][i][j+1]=0 dp[0][i][j+1] [i] [0] dp 0 i j+1 j 1 0 dp[1][i][j+1]=max(dp[1][i][j+1],dp[1][i][j],dp[0][i][j]+G[i][j+1]) dp[1][i][j+1] [i] [1] dp 1 i j+1 j 1 max(dp[1][i][j+1],dp[1][i][j],dp[0][i][j]+G[i][j+1]) max dp[1][i][j+1] [i] [1] dp 1 i j+1 j 1 dp[1][i][j] [i] [1] dp 1 i j dp[0][i][j]+G[i][j+1] dp[0][i][j] [i] [0] dp 0 i j G[i][j+1] [i] G i j+1 j 1 dp[2][i][j+1]=max(dp[2][i][j+1],dp[2][i][j],dp[1][i][j]+G[i][j+1]) dp[2][i][j+1] [i] [2] dp 2 i j+1 j 1 max(dp[2][i][j+1],dp[2][i][j],dp[1][i][j]+G[i][j+1]) max dp[2][i][j+1] [i] [2] dp 2 i j+1 j 1 dp[2][i][j] [i] [2] dp 2 i j dp[1][i][j]+G[i][j+1] dp[1][i][j] [i] [1] dp 1 i j G[i][j+1] [i] G i j+1 j 1 dp[3][i][j+1]=max(dp[3][i][j+1],dp[3][i][j],dp[2][i][j]+G[i][j+1]) dp[3][i][j+1] [i] [3] dp 3 i j+1 j 1 max(dp[3][i][j+1],dp[3][i][j],dp[2][i][j]+G[i][j+1]) max dp[3][i][j+1] [i] [3] dp 3 i j+1 j 1 dp[3][i][j] [i] [3] dp 3 i j dp[2][i][j]+G[i][j+1] dp[2][i][j] [i] [2] dp 2 i j G[i][j+1] [i] G i j+1 j 1 ans=max(dp[i][H-1][W-1] for i in range(4)) ans max(dp[i][H-1][W-1] for i in range(4)) max dp[i][H-1][W-1] [H-1] [i] dp i H-1 H 1 W-1 W 1 print(ans) print ans r,c=r-1,c-1 r-1 r G=[[0]*W for i in range(H)] [[0]*W for i in range(H)] G r,c,v=map(int,input().split()) map(int,input().split()) r v=map(int,input().split()) map(int,input().split()) v H,W,K=map(int,input().split()) map(int,input().split()) H m=max(dp[k][i][j] for k in range(4)) max(dp[k][i][j] for k in range(4)) m dp=[[[-1]*W for i in range(H)] for i in range(4)] [[[-1]*W for i in range(H)] for i in range(4)] dp c=r-1,c-1 c-1 c W,K=map(int,input().split()) map(int,input().split()) W input=sys.stdin.readline sys.stdin.readline input ans=max(dp[i][H-1][W-1] for i in range(4)) max(dp[i][H-1][W-1] for i in range(4)) ans c,v=map(int,input().split()) map(int,input().split()) c K=map(int,input().split()) map(int,input().split()) K
import sys
input=sys.stdin.readline
H,W,K=map(int,input().split())
G=[[0]*W for i in range(H)]

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

dp=[[[-1]*W for i in range(H)] for i in range(4)]

dp[0][0][0]=0
if G[0][0]!=0:
    dp[1][0][0]=G[0][0]

for i in range(H):
    for j in range(W):
        m=max(dp[k][i][j] for k in range(4))
        if i+1<H:
            dp[1][i+1][j]=max(dp[1][i+1][j],m+G[i+1][j])
            dp[0][i+1][j]=max(dp[0][i+1][j],m)
        if j+1<W:
                dp[0][i][j+1]=0
                dp[1][i][j+1]=max(dp[1][i][j+1],dp[1][i][j],dp[0][i][j]+G[i][j+1])
                dp[2][i][j+1]=max(dp[2][i][j+1],dp[2][i][j],dp[1][i][j]+G[i][j+1])
                dp[3][i][j+1]=max(dp[3][i][j+1],dp[3][i][j],dp[2][i][j]+G[i][j+1])
ans=max(dp[i][H-1][W-1] for i in range(4))
print(ans)