r,c,k=map(int,input().split())
items=[list(map(int,input().split())) for _ in range(k)]
dp=[[[0 for _ in range(c+1)] for _ in range(r+1)] for _ in range(5)]
for x,y,z in items:
    dp[4][x][y]=z
for i in range(1,r+1):
    for j in range(1,c+1):
        v=dp[4][i][j]
        dp[0][i][j]=max(dp[0][i][j-1],dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
        dp[1][i][j]=max(dp[1][i][j-1],dp[0][i][j-1]+v,max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])+v)
        dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+v)
        dp[3][i][j]=max(dp[3][i][j-1],dp[2][i][j-1]+v)
print(max(dp[i][r][c] for i in range(4))) r,c,k=map(int,input().split()) r map(int,input().split()) map int input().split() ().split () input split c k list(map(int,input().split())) for _ in range(k) for _ in range(k) _ range(k) range k for _ in range(k) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split items=[list(map(int,input().split())) for _ in range(k)] items [list(map(int,input().split())) for _ in range(k)] [[0 for _ in range(c+1)] for _ in range(r+1)] for _ in range(5) for _ in range(5) _ range(5) range 5 for _ in range(5) [[0 for _ in range(c+1)] for _ in range(r+1)] dp=[[[0 for _ in range(c+1)] for _ in range(r+1)] for _ in range(5)] dp [[[0 for _ in range(c+1)] for _ in range(r+1)] for _ in range(5)] for x,y,z in items:
    dp[4][x][y]=z x y z items dp[4][x][y]=z dp[4][x][y] [x] [4] dp 4 x y z for i in range(1,r+1):
    for j in range(1,c+1):
        v=dp[4][i][j]
        dp[0][i][j]=max(dp[0][i][j-1],dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
        dp[1][i][j]=max(dp[1][i][j-1],dp[0][i][j-1]+v,max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])+v)
        dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+v)
        dp[3][i][j]=max(dp[3][i][j-1],dp[2][i][j-1]+v) i range(1,r+1) range 1 r+1 r 1 for j in range(1,c+1):
        v=dp[4][i][j]
        dp[0][i][j]=max(dp[0][i][j-1],dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
        dp[1][i][j]=max(dp[1][i][j-1],dp[0][i][j-1]+v,max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])+v)
        dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+v)
        dp[3][i][j]=max(dp[3][i][j-1],dp[2][i][j-1]+v) j range(1,c+1) range 1 c+1 c 1 v=dp[4][i][j] v dp[4][i][j] [i] [4] dp 4 i j dp[0][i][j]=max(dp[0][i][j-1],dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j]) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j-1],dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j]) max dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 dp[0][i-1][j] [i-1] [0] dp 0 i-1 i 1 j dp[1][i-1][j] [i-1] [1] dp 1 i-1 i 1 j dp[2][i-1][j] [i-1] [2] dp 2 i-1 i 1 j dp[3][i-1][j] [i-1] [3] dp 3 i-1 i 1 j dp[1][i][j]=max(dp[1][i][j-1],dp[0][i][j-1]+v,max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])+v) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j-1],dp[0][i][j-1]+v,max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])+v) max dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 dp[0][i][j-1]+v dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 v max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])+v max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j]) max dp[0][i-1][j] [i-1] [0] dp 0 i-1 i 1 j dp[1][i-1][j] [i-1] [1] dp 1 i-1 i 1 j dp[2][i-1][j] [i-1] [2] dp 2 i-1 i 1 j dp[3][i-1][j] [i-1] [3] dp 3 i-1 i 1 j v dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+v) dp[2][i][j] [i] [2] dp 2 i j max(dp[2][i][j-1],dp[1][i][j-1]+v) max dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 dp[1][i][j-1]+v dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 v dp[3][i][j]=max(dp[3][i][j-1],dp[2][i][j-1]+v) dp[3][i][j] [i] [3] dp 3 i j max(dp[3][i][j-1],dp[2][i][j-1]+v) max dp[3][i][j-1] [i] [3] dp 3 i j-1 j 1 dp[2][i][j-1]+v dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 v print(max(dp[i][r][c] for i in range(4))) print max(dp[i][r][c] for i in range(4)) max dp[i][r][c] [r] [i] dp i r c items=[list(map(int,input().split())) for _ in range(k)] [list(map(int,input().split())) for _ in range(k)] items r,c,k=map(int,input().split()) map(int,input().split()) r k=map(int,input().split()) map(int,input().split()) k v=dp[4][i][j] dp[4][i][j] v c,k=map(int,input().split()) map(int,input().split()) c dp=[[[0 for _ in range(c+1)] for _ in range(r+1)] for _ in range(5)] [[[0 for _ in range(c+1)] for _ in range(r+1)] for _ in range(5)] dp
r,c,k=map(int,input().split())
items=[list(map(int,input().split())) for _ in range(k)]
dp=[[[0 for _ in range(c+1)] for _ in range(r+1)] for _ in range(5)]
for x,y,z in items:
    dp[4][x][y]=z
for i in range(1,r+1):
    for j in range(1,c+1):
        v=dp[4][i][j]
        dp[0][i][j]=max(dp[0][i][j-1],dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
        dp[1][i][j]=max(dp[1][i][j-1],dp[0][i][j-1]+v,max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])+v)
        dp[2][i][j]=max(dp[2][i][j-1],dp[1][i][j-1]+v)
        dp[3][i][j]=max(dp[3][i][j-1],dp[2][i][j-1]+v)
print(max(dp[i][r][c] for i in range(4)))