R, C, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(K)]

items = [[0] * (C + 1) for _ in range(R + 1)]
for r, c, v in X:
    items[r][c] = 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(1, R + 1):
    for j in range(1, C + 1):
        dp0[i][j] = max(dp0[i - 1][j], dp1[i - 1][j], dp2[i - 1][j], dp3[i - 1][j])

        dp3[i][j] = max(dp3[i][j], dp3[i][j - 1])
        dp2[i][j] = max(dp2[i][j], dp2[i][j - 1])
        dp1[i][j] = max(dp1[i][j], dp1[i][j - 1])
        dp0[i][j] = max(dp0[i][j], dp0[i][j - 1])

        if items[i][j]:
            dp3[i][j] = max(dp3[i][j], dp2[i][j] + items[i][j])
            dp2[i][j] = max(dp2[i][j], dp1[i][j] + items[i][j])
            dp1[i][j] = max(dp1[i][j], dp0[i][j] + items[i][j])

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

        dp3[i][j] = max(dp3[i][j], dp3[i][j - 1])
        dp2[i][j] = max(dp2[i][j], dp2[i][j - 1])
        dp1[i][j] = max(dp1[i][j], dp1[i][j - 1])
        dp0[i][j] = max(dp0[i][j], dp0[i][j - 1])

        if items[i][j]:
            dp3[i][j] = max(dp3[i][j], dp2[i][j] + items[i][j])
            dp2[i][j] = max(dp2[i][j], dp1[i][j] + items[i][j])
            dp1[i][j] = max(dp1[i][j], dp0[i][j] + items[i][j]) i range(1, R + 1) range 1 R + 1 R 1 for j in range(1, C + 1):
        dp0[i][j] = max(dp0[i - 1][j], dp1[i - 1][j], dp2[i - 1][j], dp3[i - 1][j])

        dp3[i][j] = max(dp3[i][j], dp3[i][j - 1])
        dp2[i][j] = max(dp2[i][j], dp2[i][j - 1])
        dp1[i][j] = max(dp1[i][j], dp1[i][j - 1])
        dp0[i][j] = max(dp0[i][j], dp0[i][j - 1])

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

items = [[0] * (C + 1) for _ in range(R + 1)]
for r, c, v in X:
    items[r][c] = 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(1, R + 1):
    for j in range(1, C + 1):
        dp0[i][j] = max(dp0[i - 1][j], dp1[i - 1][j], dp2[i - 1][j], dp3[i - 1][j])

        dp3[i][j] = max(dp3[i][j], dp3[i][j - 1])
        dp2[i][j] = max(dp2[i][j], dp2[i][j - 1])
        dp1[i][j] = max(dp1[i][j], dp1[i][j - 1])
        dp0[i][j] = max(dp0[i][j], dp0[i][j - 1])

        if items[i][j]:
            dp3[i][j] = max(dp3[i][j], dp2[i][j] + items[i][j])
            dp2[i][j] = max(dp2[i][j], dp1[i][j] + items[i][j])
            dp1[i][j] = max(dp1[i][j], dp0[i][j] + items[i][j])

print(max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1]))
