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

grid=[[0]*C for _ in range(R)]
for i in range(K):
    x,y,v = map(int,input().split())
    grid[x-1][y-1] = v


dp0 = [[0]*(C+1) for _ in range(R+1)]
dp1 = [[0]*(C+1) for _ in range(R+1)]
dp2 = [[0]*(C+1) for _ in range(R+1)]
dp3 = [[0]*(C+1) for _ in range(R+1)]

for i in range(R):
    for j in range(C):
        dp1[i][j] = max(dp1[i][j-1],dp1[i-1][j]+grid[i][j],
                    dp2[i-1][j]+grid[i][j],dp3[i-1][j]+grid[i][j])
        dp2[i][j] = max(dp2[i][j-1],dp1[i][j-1]+grid[i][j])
        dp3[i][j] = max(dp3[i][j-1],dp2[i][j-1]+grid[i][j])
ans=max(dp1[R-1][C-1],dp2[R-1][C-1],dp3[R-1][C-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 for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C grid=[[0]*C for _ in range(R)] grid [[0]*C for _ in range(R)] for i in range(K):
    x,y,v = map(int,input().split())
    grid[x-1][y-1] = v i range(K) range K x,y,v = map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y v grid[x-1][y-1] = v grid[x-1][y-1] [x-1] grid x-1 x 1 y-1 y 1 v [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 dp0 = [[0]*(C+1) for _ in range(R+1)] dp0 [[0]*(C+1) for _ in range(R+1)] [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 dp1 = [[0]*(C+1) for _ in range(R+1)] dp1 [[0]*(C+1) for _ in range(R+1)] [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 dp2 = [[0]*(C+1) for _ in range(R+1)] dp2 [[0]*(C+1) for _ in range(R+1)] [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 dp3 = [[0]*(C+1) for _ in range(R+1)] dp3 [[0]*(C+1) for _ in range(R+1)] for i in range(R):
    for j in range(C):
        dp1[i][j] = max(dp1[i][j-1],dp1[i-1][j]+grid[i][j],
                    dp2[i-1][j]+grid[i][j],dp3[i-1][j]+grid[i][j])
        dp2[i][j] = max(dp2[i][j-1],dp1[i][j-1]+grid[i][j])
        dp3[i][j] = max(dp3[i][j-1],dp2[i][j-1]+grid[i][j]) i range(R) range R for j in range(C):
        dp1[i][j] = max(dp1[i][j-1],dp1[i-1][j]+grid[i][j],
                    dp2[i-1][j]+grid[i][j],dp3[i-1][j]+grid[i][j])
        dp2[i][j] = max(dp2[i][j-1],dp1[i][j-1]+grid[i][j])
        dp3[i][j] = max(dp3[i][j-1],dp2[i][j-1]+grid[i][j]) j range(C) range C dp1[i][j] = max(dp1[i][j-1],dp1[i-1][j]+grid[i][j],
                    dp2[i-1][j]+grid[i][j],dp3[i-1][j]+grid[i][j]) dp1[i][j] [i] dp1 i j max(dp1[i][j-1],dp1[i-1][j]+grid[i][j],
                    dp2[i-1][j]+grid[i][j],dp3[i-1][j]+grid[i][j]) max dp1[i][j-1] [i] dp1 i j-1 j 1 dp1[i-1][j]+grid[i][j] dp1[i-1][j] [i-1] dp1 i-1 i 1 j grid[i][j] [i] grid i j dp2[i-1][j]+grid[i][j] dp2[i-1][j] [i-1] dp2 i-1 i 1 j grid[i][j] [i] grid i j dp3[i-1][j]+grid[i][j] dp3[i-1][j] [i-1] dp3 i-1 i 1 j grid[i][j] [i] grid i j dp2[i][j] = max(dp2[i][j-1],dp1[i][j-1]+grid[i][j]) dp2[i][j] [i] dp2 i j max(dp2[i][j-1],dp1[i][j-1]+grid[i][j]) max dp2[i][j-1] [i] dp2 i j-1 j 1 dp1[i][j-1]+grid[i][j] dp1[i][j-1] [i] dp1 i j-1 j 1 grid[i][j] [i] grid i j dp3[i][j] = max(dp3[i][j-1],dp2[i][j-1]+grid[i][j]) dp3[i][j] [i] dp3 i j max(dp3[i][j-1],dp2[i][j-1]+grid[i][j]) max dp3[i][j-1] [i] dp3 i j-1 j 1 dp2[i][j-1]+grid[i][j] dp2[i][j-1] [i] dp2 i j-1 j 1 grid[i][j] [i] grid i j ans=max(dp1[R-1][C-1],dp2[R-1][C-1],dp3[R-1][C-1]) ans max(dp1[R-1][C-1],dp2[R-1][C-1],dp3[R-1][C-1]) max dp1[R-1][C-1] [R-1] dp1 R-1 R 1 C-1 C 1 dp2[R-1][C-1] [R-1] dp2 R-1 R 1 C-1 C 1 dp3[R-1][C-1] [R-1] dp3 R-1 R 1 C-1 C 1 print(ans) print ans y,v = map(int,input().split()) map(int,input().split()) y dp2 = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] dp2 R,C,K = map(int,input().split()) map(int,input().split()) R v = map(int,input().split()) map(int,input().split()) v dp3 = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] dp3 C,K = map(int,input().split()) map(int,input().split()) C ans=max(dp1[R-1][C-1],dp2[R-1][C-1],dp3[R-1][C-1]) max(dp1[R-1][C-1],dp2[R-1][C-1],dp3[R-1][C-1]) ans x,y,v = map(int,input().split()) map(int,input().split()) x grid=[[0]*C for _ in range(R)] [[0]*C for _ in range(R)] grid dp1 = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] dp1 K = map(int,input().split()) map(int,input().split()) K dp0 = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] dp0
R,C,K = map(int,input().split())

grid=[[0]*C for _ in range(R)]
for i in range(K):
    x,y,v = map(int,input().split())
    grid[x-1][y-1] = v


dp0 = [[0]*(C+1) for _ in range(R+1)]
dp1 = [[0]*(C+1) for _ in range(R+1)]
dp2 = [[0]*(C+1) for _ in range(R+1)]
dp3 = [[0]*(C+1) for _ in range(R+1)]

for i in range(R):
    for j in range(C):
        dp1[i][j] = max(dp1[i][j-1],dp1[i-1][j]+grid[i][j],
                    dp2[i-1][j]+grid[i][j],dp3[i-1][j]+grid[i][j])
        dp2[i][j] = max(dp2[i][j-1],dp1[i][j-1]+grid[i][j])
        dp3[i][j] = max(dp3[i][j-1],dp2[i][j-1]+grid[i][j])
ans=max(dp1[R-1][C-1],dp2[R-1][C-1],dp3[R-1][C-1])
print(ans)