R, C, K = map(int, input().split())
grid = [[0]*C for _ in range(R)]
for i in range(K):
    r, c, v= map(int, input().split())
    grid[r-1][c-1] = v
dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
for i in range(1,R+1):
    for k in range(1,C+1):
        tmp = max(dp[0][i-1][k],dp[1][i-1][k],dp[2][i-1][k],dp[3][i-1][k])
        target = grid[i-1][k-1]
        dp[0][i][k] = max(dp[0][i][k-1],tmp)
        dp[1][i][k] = dp[1][i][k-1]
        dp[2][i][k] = dp[2][i][k-1]
        dp[3][i][k] = dp[3][i][k-1]
        if target != 0:
            dp[1][i][k] = max(dp[0][i][k-1]+target,tmp+target,dp[1][i][k])
            if dp[1][i][k-1] != 0:
                dp[2][i][k] = max(dp[1][i][k-1]+target,dp[2][i][k])
            if dp[2][i][k-1] != 0:
                dp[3][i][k] = max(dp[2][i][k-1]+target,dp[3][i][k])
print(max(dp[0][-1][-1],dp[1][-1][-1],dp[2][-1][-1],dp[3][-1][-1])) 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):
    r, c, v= map(int, input().split())
    grid[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 grid[r-1][c-1] = v grid[r-1][c-1] [r-1] grid r-1 r 1 c-1 c 1 v [[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 k in range(1,C+1):
        tmp = max(dp[0][i-1][k],dp[1][i-1][k],dp[2][i-1][k],dp[3][i-1][k])
        target = grid[i-1][k-1]
        dp[0][i][k] = max(dp[0][i][k-1],tmp)
        dp[1][i][k] = dp[1][i][k-1]
        dp[2][i][k] = dp[2][i][k-1]
        dp[3][i][k] = dp[3][i][k-1]
        if target != 0:
            dp[1][i][k] = max(dp[0][i][k-1]+target,tmp+target,dp[1][i][k])
            if dp[1][i][k-1] != 0:
                dp[2][i][k] = max(dp[1][i][k-1]+target,dp[2][i][k])
            if dp[2][i][k-1] != 0:
                dp[3][i][k] = max(dp[2][i][k-1]+target,dp[3][i][k]) i range(1,R+1) range 1 R+1 R 1 for k in range(1,C+1):
        tmp = max(dp[0][i-1][k],dp[1][i-1][k],dp[2][i-1][k],dp[3][i-1][k])
        target = grid[i-1][k-1]
        dp[0][i][k] = max(dp[0][i][k-1],tmp)
        dp[1][i][k] = dp[1][i][k-1]
        dp[2][i][k] = dp[2][i][k-1]
        dp[3][i][k] = dp[3][i][k-1]
        if target != 0:
            dp[1][i][k] = max(dp[0][i][k-1]+target,tmp+target,dp[1][i][k])
            if dp[1][i][k-1] != 0:
                dp[2][i][k] = max(dp[1][i][k-1]+target,dp[2][i][k])
            if dp[2][i][k-1] != 0:
                dp[3][i][k] = max(dp[2][i][k-1]+target,dp[3][i][k]) k range(1,C+1) range 1 C+1 C 1 tmp = max(dp[0][i-1][k],dp[1][i-1][k],dp[2][i-1][k],dp[3][i-1][k]) tmp max(dp[0][i-1][k],dp[1][i-1][k],dp[2][i-1][k],dp[3][i-1][k]) max dp[0][i-1][k] [i-1] [0] dp 0 i-1 i 1 k dp[1][i-1][k] [i-1] [1] dp 1 i-1 i 1 k dp[2][i-1][k] [i-1] [2] dp 2 i-1 i 1 k dp[3][i-1][k] [i-1] [3] dp 3 i-1 i 1 k target = grid[i-1][k-1] target grid[i-1][k-1] [i-1] grid i-1 i 1 k-1 k 1 dp[0][i][k] = max(dp[0][i][k-1],tmp) dp[0][i][k] [i] [0] dp 0 i k max(dp[0][i][k-1],tmp) max dp[0][i][k-1] [i] [0] dp 0 i k-1 k 1 tmp dp[1][i][k] = dp[1][i][k-1] dp[1][i][k] [i] [1] dp 1 i k dp[1][i][k-1] [i] [1] dp 1 i k-1 k 1 dp[2][i][k] = dp[2][i][k-1] dp[2][i][k] [i] [2] dp 2 i k dp[2][i][k-1] [i] [2] dp 2 i k-1 k 1 dp[3][i][k] = dp[3][i][k-1] dp[3][i][k] [i] [3] dp 3 i k dp[3][i][k-1] [i] [3] dp 3 i k-1 k 1 if target != 0:
            dp[1][i][k] = max(dp[0][i][k-1]+target,tmp+target,dp[1][i][k])
            if dp[1][i][k-1] != 0:
                dp[2][i][k] = max(dp[1][i][k-1]+target,dp[2][i][k])
            if dp[2][i][k-1] != 0:
                dp[3][i][k] = max(dp[2][i][k-1]+target,dp[3][i][k]) target != 0 target 0 dp[1][i][k] = max(dp[0][i][k-1]+target,tmp+target,dp[1][i][k]) dp[1][i][k] [i] [1] dp 1 i k max(dp[0][i][k-1]+target,tmp+target,dp[1][i][k]) max dp[0][i][k-1]+target dp[0][i][k-1] [i] [0] dp 0 i k-1 k 1 target tmp+target tmp target dp[1][i][k] [i] [1] dp 1 i k if dp[1][i][k-1] != 0:
                dp[2][i][k] = max(dp[1][i][k-1]+target,dp[2][i][k])
             dp[1][i][k-1] != 0 dp[1][i][k-1] [i] [1] dp 1 i k-1 k 1 0 dp[2][i][k] = max(dp[1][i][k-1]+target,dp[2][i][k]) dp[2][i][k] [i] [2] dp 2 i k max(dp[1][i][k-1]+target,dp[2][i][k]) max dp[1][i][k-1]+target dp[1][i][k-1] [i] [1] dp 1 i k-1 k 1 target dp[2][i][k] [i] [2] dp 2 i k if dp[2][i][k-1] != 0:
                dp[3][i][k] = max(dp[2][i][k-1]+target,dp[3][i][k]) dp[2][i][k-1] != 0 dp[2][i][k-1] [i] [2] dp 2 i k-1 k 1 0 dp[3][i][k] = max(dp[2][i][k-1]+target,dp[3][i][k]) dp[3][i][k] [i] [3] dp 3 i k max(dp[2][i][k-1]+target,dp[3][i][k]) max dp[2][i][k-1]+target dp[2][i][k-1] [i] [2] dp 2 i k-1 k 1 target dp[3][i][k] [i] [3] dp 3 i k print(max(dp[0][-1][-1],dp[1][-1][-1],dp[2][-1][-1],dp[3][-1][-1])) print max(dp[0][-1][-1],dp[1][-1][-1],dp[2][-1][-1],dp[3][-1][-1]) max dp[0][-1][-1] [-1] [0] dp 0 -1 -1 dp[1][-1][-1] [-1] [1] dp 1 -1 -1 dp[2][-1][-1] [-1] [2] dp 2 -1 -1 dp[3][-1][-1] [-1] [3] dp 3 -1 -1 R, C, K = map(int, input().split()) map(int, input().split()) R v= map(int, input().split()) map(int, input().split()) v tmp = max(dp[0][i-1][k],dp[1][i-1][k],dp[2][i-1][k],dp[3][i-1][k]) max(dp[0][i-1][k],dp[1][i-1][k],dp[2][i-1][k],dp[3][i-1][k]) tmp target = grid[i-1][k-1] grid[i-1][k-1] target r, c, v= map(int, input().split()) map(int, input().split()) r C, K = map(int, input().split()) map(int, input().split()) C c, v= map(int, input().split()) map(int, input().split()) c 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 K = map(int, input().split()) map(int, input().split()) K grid = [[0]*C for _ in range(R)] [[0]*C for _ in range(R)] grid
R, C, K = map(int, input().split())
grid = [[0]*C for _ in range(R)]
for i in range(K):
    r, c, v= map(int, input().split())
    grid[r-1][c-1] = v
dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
for i in range(1,R+1):
    for k in range(1,C+1):
        tmp = max(dp[0][i-1][k],dp[1][i-1][k],dp[2][i-1][k],dp[3][i-1][k])
        target = grid[i-1][k-1]
        dp[0][i][k] = max(dp[0][i][k-1],tmp)
        dp[1][i][k] = dp[1][i][k-1]
        dp[2][i][k] = dp[2][i][k-1]
        dp[3][i][k] = dp[3][i][k-1]
        if target != 0:
            dp[1][i][k] = max(dp[0][i][k-1]+target,tmp+target,dp[1][i][k])
            if dp[1][i][k-1] != 0:
                dp[2][i][k] = max(dp[1][i][k-1]+target,dp[2][i][k])
            if dp[2][i][k-1] != 0:
                dp[3][i][k] = max(dp[2][i][k-1]+target,dp[3][i][k])
print(max(dp[0][-1][-1],dp[1][-1][-1],dp[2][-1][-1],dp[3][-1][-1]))