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

grid = [[0 for c in range(C)] for r in range(R)]

for k in range(K):
    r, c, v = map(int, input().split())
    grid[r-1][c-1] = v

dp = [[[-1000 for c in range(C)] for r in range(R)] for k in range(4)]

if grid[0][0] > 0:
    dp[1][0][0] = grid[0][0]
dp[0][0][0] = 0

for r in range(R):
    for c in range(C):
        if c >= 1:
            dp[0][r][c] = max(dp[0][r][c], dp[0][r][c-1])
            dp[1][r][c] = max(dp[1][r][c], dp[1][r][c-1])
            dp[2][r][c] = max(dp[2][r][c], dp[2][r][c-1])
            dp[3][r][c] = max(dp[3][r][c], dp[3][r][c-1])
        if r >= 1:
            dp[0][r][c] = max(dp[0][r][c], dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
        v = grid[r][c]
        if v > 0:
            if c >= 1:
                dp[1][r][c] = max(dp[1][r][c], dp[0][r][c-1] + v)
                dp[2][r][c] = max(dp[2][r][c], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c], dp[2][r][c-1] + v)
            if r >= 1:
                dp[1][r][c] = max(dp[1][r][c], dp[0][r-1][c]+v, dp[1][r-1][c]+v, dp[2][r-1][c]+v, dp[3][r-1][c]+v)

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

grid = [[0 for c in range(C)] for r in range(R)]

for k in range(K):
    r, c, v = map(int, input().split())
    grid[r-1][c-1] = v

dp = [[[-1000 for c in range(C)] for r in range(R)] for k in range(4)]

if grid[0][0] > 0:
    dp[1][0][0] = grid[0][0]
dp[0][0][0] = 0

for r in range(R):
    for c in range(C):
        if c >= 1:
            dp[0][r][c] = max(dp[0][r][c], dp[0][r][c-1])
            dp[1][r][c] = max(dp[1][r][c], dp[1][r][c-1])
            dp[2][r][c] = max(dp[2][r][c], dp[2][r][c-1])
            dp[3][r][c] = max(dp[3][r][c], dp[3][r][c-1])
        if r >= 1:
            dp[0][r][c] = max(dp[0][r][c], dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
        v = grid[r][c]
        if v > 0:
            if c >= 1:
                dp[1][r][c] = max(dp[1][r][c], dp[0][r][c-1] + v)
                dp[2][r][c] = max(dp[2][r][c], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c], dp[2][r][c-1] + v)
            if r >= 1:
                dp[1][r][c] = max(dp[1][r][c], dp[0][r-1][c]+v, dp[1][r-1][c]+v, dp[2][r-1][c]+v, dp[3][r-1][c]+v)

print(max(dp[0][R-1][C-1], dp[1][R-1][C-1], dp[2][R-1][C-1], dp[3][R-1][C-1]))
