R, C, K = map(int, input().split())
goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    goods[r-1][c-1] = v

dp = [[[0] * C for _ in range(4)] for _ in range(R)]
dp[0][1][0] = goods[0][0]
for i in range(R):
    for j in range(4):
        for k in range(C):
            if i < R - 1:
                dp[i+1][0][k] = max(dp[i+1][0][k], dp[i][j][k])
                dp[i+1][1][k] = max(dp[i+1][1][k], dp[i][j][k] + goods[i+1][k])
        
            if k < C - 1:
                dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k])
                if j < 3:
                    dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + goods[i][k+1])

res = 0
for i in range(4):
    res = max(res, dp[R-1][i][C-1])

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

dp = [[[0] * C for _ in range(4)] for _ in range(R)]
dp[0][1][0] = goods[0][0]
for i in range(R):
    for j in range(4):
        for k in range(C):
            if i < R - 1:
                dp[i+1][0][k] = max(dp[i+1][0][k], dp[i][j][k])
                dp[i+1][1][k] = max(dp[i+1][1][k], dp[i][j][k] + goods[i+1][k])
        
            if k < C - 1:
                dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k])
                if j < 3:
                    dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + goods[i][k+1])

res = 0
for i in range(4):
    res = max(res, dp[R-1][i][C-1])

print(res)