r,c,k=map(int, input().split())
grid=[[0]*(c+1) for _ in range(r+1)]
for i in range(k):
    ri,ci,vi=map(int, input().split())
    grid[ri][ci]=vi

dp=[[[0]*(c+1) for _ in range(r+1)] for _ in range(4)]

for i in range(1,r+1):
    for j in range(1,c+1):
        for k in range(4):
            dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
            dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
        if grid[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],dp[0][i-1][j]+grid[i][j])
            for k in range(1,4):
                dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+grid[i][j])
                dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+grid[i][j])

ans=0
for k in range(4):
    ans=max(ans,dp[k][-1][-1])
print(ans) 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 grid=[[0]*(c+1) for _ in range(r+1)] grid [[0]*(c+1) for _ in range(r+1)] for i in range(k):
    ri,ci,vi=map(int, input().split())
    grid[ri][ci]=vi i range(k) range k ri,ci,vi=map(int, input().split()) ri map(int, input().split()) map int input().split() ().split () input split ci vi grid[ri][ci]=vi grid[ri][ci] [ri] grid ri ci vi [[0]*(c+1) for _ in range(r+1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*(c+1) for _ in range(r+1)] dp=[[[0]*(c+1) for _ in range(r+1)] for _ in range(4)] dp [[[0]*(c+1) for _ in range(r+1)] for _ in range(4)] for i in range(1,r+1):
    for j in range(1,c+1):
        for k in range(4):
            dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
            dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
        if grid[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],dp[0][i-1][j]+grid[i][j])
            for k in range(1,4):
                dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+grid[i][j])
                dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+grid[i][j]) i range(1,r+1) range 1 r+1 r 1 for j in range(1,c+1):
        for k in range(4):
            dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
            dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
        if grid[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],dp[0][i-1][j]+grid[i][j])
            for k in range(1,4):
                dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+grid[i][j])
                dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+grid[i][j]) j range(1,c+1) range 1 c+1 c 1 for k in range(4):
            dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
            dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
         k range(4) range 4 dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j]) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j],dp[k][i-1][j]) max dp[0][i][j] [i] [0] dp 0 i j dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j],dp[k][i][j-1]) max dp[k][i][j] [i] [k] dp k i j dp[k][i][j-1] [i] [k] dp k i j-1 j 1 if grid[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],dp[0][i-1][j]+grid[i][j])
            for k in range(1,4):
                dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+grid[i][j])
                dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+grid[i][j]) grid[i][j]!=0 grid[i][j] [i] grid i j 0 dp[1][i][j]=max(dp[1][i][j],dp[0][i-1][j]+grid[i][j]) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j],dp[0][i-1][j]+grid[i][j]) max dp[1][i][j] [i] [1] dp 1 i j dp[0][i-1][j]+grid[i][j] dp[0][i-1][j] [i-1] [0] dp 0 i-1 i 1 j grid[i][j] [i] grid i j for k in range(1,4):
                dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+grid[i][j])
                dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+grid[i][j]) k range(1,4) range 1 4 dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+grid[i][j]) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j],dp[k][i-1][j]+grid[i][j]) max dp[1][i][j] [i] [1] dp 1 i j dp[k][i-1][j]+grid[i][j] dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j grid[i][j] [i] grid i j dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+grid[i][j]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j],dp[k-1][i][j-1]+grid[i][j]) max dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j-1]+grid[i][j] dp[k-1][i][j-1] [i] [k-1] dp k-1 k 1 i j-1 j 1 grid[i][j] [i] grid i j ans=0 ans 0 for k in range(4):
    ans=max(ans,dp[k][-1][-1]) k range(4) range 4 ans=max(ans,dp[k][-1][-1]) ans max(ans,dp[k][-1][-1]) max ans dp[k][-1][-1] [-1] [k] dp k -1 -1 print(ans) print ans ci,vi=map(int, input().split()) map(int, input().split()) ci c,k=map(int, input().split()) map(int, input().split()) c vi=map(int, input().split()) map(int, input().split()) vi ans=0 0 ans grid=[[0]*(c+1) for _ in range(r+1)] [[0]*(c+1) for _ in range(r+1)] grid k=map(int, input().split()) map(int, input().split()) k ri,ci,vi=map(int, input().split()) map(int, input().split()) ri r,c,k=map(int, input().split()) map(int, input().split()) r ans=max(ans,dp[k][-1][-1]) max(ans,dp[k][-1][-1]) ans dp=[[[0]*(c+1) for _ in range(r+1)] for _ in range(4)] [[[0]*(c+1) for _ in range(r+1)] for _ in range(4)] dp
r,c,k=map(int, input().split())
grid=[[0]*(c+1) for _ in range(r+1)]
for i in range(k):
    ri,ci,vi=map(int, input().split())
    grid[ri][ci]=vi

dp=[[[0]*(c+1) for _ in range(r+1)] for _ in range(4)]

for i in range(1,r+1):
    for j in range(1,c+1):
        for k in range(4):
            dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
            dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
        if grid[i][j]!=0:
            dp[1][i][j]=max(dp[1][i][j],dp[0][i-1][j]+grid[i][j])
            for k in range(1,4):
                dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+grid[i][j])
                dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+grid[i][j])

ans=0
for k in range(4):
    ans=max(ans,dp[k][-1][-1])
print(ans)