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

items = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    items[r - 1][c - 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 r in range(R):
    for c in range(C):
        v = items[r][c]
        for fr, to in ((dp2, dp3), (dp1, dp2), (dp0, dp1)):
            to[r][c] = max(to[r][c], fr[r][c] + v)

        for dp in (dp0, dp1, dp2, dp3):
            dp[r][c + 1] = max(dp[r][c + 1], dp[r][c])
            dp0[r + 1][c] = max(dp0[r + 1][c], dp[r][c])

ans = max(
    dp0[R - 1][C], dp0[R][C - 1],
    dp1[R - 1][C], dp1[R][C - 1],
    dp2[R - 1][C], dp2[R][C - 1],
    dp3[R - 1][C], dp3[R][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 items = [[0] * C for _ in range(R)] items [[0] * C for _ in range(R)] for _ in range(K):
    r, c, v = map(int, input().split())
    items[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 items[r - 1][c - 1] = v items[r - 1][c - 1] [r - 1] items r - 1 r 1 c - 1 c 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 r in range(R):
    for c in range(C):
        v = items[r][c]
        for fr, to in ((dp2, dp3), (dp1, dp2), (dp0, dp1)):
            to[r][c] = max(to[r][c], fr[r][c] + v)

        for dp in (dp0, dp1, dp2, dp3):
            dp[r][c + 1] = max(dp[r][c + 1], dp[r][c])
            dp0[r + 1][c] = max(dp0[r + 1][c], dp[r][c]) r range(R) range R for c in range(C):
        v = items[r][c]
        for fr, to in ((dp2, dp3), (dp1, dp2), (dp0, dp1)):
            to[r][c] = max(to[r][c], fr[r][c] + v)

        for dp in (dp0, dp1, dp2, dp3):
            dp[r][c + 1] = max(dp[r][c + 1], dp[r][c])
            dp0[r + 1][c] = max(dp0[r + 1][c], dp[r][c]) c range(C) range C v = items[r][c] v items[r][c] [r] items r c for fr, to in ((dp2, dp3), (dp1, dp2), (dp0, dp1)):
            to[r][c] = max(to[r][c], fr[r][c] + v)

         fr to ((dp2, dp3), (dp1, dp2), (dp0, dp1)) (dp2, dp3) dp2 dp3 (dp1, dp2) dp1 dp2 (dp0, dp1) dp0 dp1 to[r][c] = max(to[r][c], fr[r][c] + v) to[r][c] [r] to r c max(to[r][c], fr[r][c] + v) max to[r][c] [r] to r c fr[r][c] + v fr[r][c] [r] fr r c v for dp in (dp0, dp1, dp2, dp3):
            dp[r][c + 1] = max(dp[r][c + 1], dp[r][c])
            dp0[r + 1][c] = max(dp0[r + 1][c], dp[r][c]) dp (dp0, dp1, dp2, dp3) dp0 dp1 dp2 dp3 dp[r][c + 1] = max(dp[r][c + 1], dp[r][c]) dp[r][c + 1] [r] dp r c + 1 c 1 max(dp[r][c + 1], dp[r][c]) max dp[r][c + 1] [r] dp r c + 1 c 1 dp[r][c] [r] dp r c dp0[r + 1][c] = max(dp0[r + 1][c], dp[r][c]) dp0[r + 1][c] [r + 1] dp0 r + 1 r 1 c max(dp0[r + 1][c], dp[r][c]) max dp0[r + 1][c] [r + 1] dp0 r + 1 r 1 c dp[r][c] [r] dp r c ans = max(
    dp0[R - 1][C], dp0[R][C - 1],
    dp1[R - 1][C], dp1[R][C - 1],
    dp2[R - 1][C], dp2[R][C - 1],
    dp3[R - 1][C], dp3[R][C - 1],
) ans max(
    dp0[R - 1][C], dp0[R][C - 1],
    dp1[R - 1][C], dp1[R][C - 1],
    dp2[R - 1][C], dp2[R][C - 1],
    dp3[R - 1][C], dp3[R][C - 1],
) max dp0[R - 1][C] [R - 1] dp0 R - 1 R 1 C dp0[R][C - 1] [R] dp0 R C - 1 C 1 dp1[R - 1][C] [R - 1] dp1 R - 1 R 1 C dp1[R][C - 1] [R] dp1 R C - 1 C 1 dp2[R - 1][C] [R - 1] dp2 R - 1 R 1 C dp2[R][C - 1] [R] dp2 R C - 1 C 1 dp3[R - 1][C] [R - 1] dp3 R - 1 R 1 C dp3[R][C - 1] [R] dp3 R C - 1 C 1 print(ans) print ans C, K = map(int, input().split()) map(int, input().split()) C r, c, v = map(int, input().split()) map(int, input().split()) r v = items[r][c] items[r][c] v dp0 = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] dp0 v = map(int, input().split()) map(int, input().split()) v dp1 = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] dp1 R, C, K = map(int, input().split()) map(int, input().split()) R items = [[0] * C for _ in range(R)] [[0] * C for _ in range(R)] items dp3 = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] dp3 ans = max(
    dp0[R - 1][C], dp0[R][C - 1],
    dp1[R - 1][C], dp1[R][C - 1],
    dp2[R - 1][C], dp2[R][C - 1],
    dp3[R - 1][C], dp3[R][C - 1],
) max(
    dp0[R - 1][C], dp0[R][C - 1],
    dp1[R - 1][C], dp1[R][C - 1],
    dp2[R - 1][C], dp2[R][C - 1],
    dp3[R - 1][C], dp3[R][C - 1],
) ans c, v = map(int, input().split()) map(int, input().split()) c dp2 = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] dp2 K = map(int, input().split()) map(int, input().split()) K
R, C, K = map(int, input().split())

items = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    items[r - 1][c - 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 r in range(R):
    for c in range(C):
        v = items[r][c]
        for fr, to in ((dp2, dp3), (dp1, dp2), (dp0, dp1)):
            to[r][c] = max(to[r][c], fr[r][c] + v)

        for dp in (dp0, dp1, dp2, dp3):
            dp[r][c + 1] = max(dp[r][c + 1], dp[r][c])
            dp0[r + 1][c] = max(dp0[r + 1][c], dp[r][c])

ans = max(
    dp0[R - 1][C], dp0[R][C - 1],
    dp1[R - 1][C], dp1[R][C - 1],
    dp2[R - 1][C], dp2[R][C - 1],
    dp3[R - 1][C], dp3[R][C - 1],
)

print(ans)
