import sys

input = sys.stdin.readline

R, C, K = map(int, input().split())
D = dict()
for _ in range(K):
    r, c, v = map(int, input().split())
    D[(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 r in range(1, R + 1):
    for c in range(1, C + 1):
        m = max(dp0[r - 1][c], dp1[r - 1][c], dp2[r - 1][c], dp3[r - 1][c])
        dp0[r][c] = max(m, dp0[r][c - 1])
        dp1[r][c] = max(m, dp1[r][c - 1])
        dp2[r][c] = max(m, dp2[r][c - 1])
        dp3[r][c] = max(m, dp3[r][c - 1])
        if (r, c) in D:
            dp1[r][c] = max(dp1[r][c], m + D[(r, c)], dp0[r][c - 1] + D[(r, c)])
            dp2[r][c] = max(dp2[r][c], m + D[(r, c)], dp1[r][c - 1] + D[(r, c)])
            dp3[r][c] = max(dp3[r][c], m + D[(r, c)], dp2[r][c - 1] + D[(r, c)])
print(max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K D = dict() D dict() dict for _ in range(K):
    r, c, v = map(int, input().split())
    D[(r, c)] = 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 D[(r, c)] = v D[(r, c)] D (r, c) 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 r in range(1, R + 1):
    for c in range(1, C + 1):
        m = max(dp0[r - 1][c], dp1[r - 1][c], dp2[r - 1][c], dp3[r - 1][c])
        dp0[r][c] = max(m, dp0[r][c - 1])
        dp1[r][c] = max(m, dp1[r][c - 1])
        dp2[r][c] = max(m, dp2[r][c - 1])
        dp3[r][c] = max(m, dp3[r][c - 1])
        if (r, c) in D:
            dp1[r][c] = max(dp1[r][c], m + D[(r, c)], dp0[r][c - 1] + D[(r, c)])
            dp2[r][c] = max(dp2[r][c], m + D[(r, c)], dp1[r][c - 1] + D[(r, c)])
            dp3[r][c] = max(dp3[r][c], m + D[(r, c)], dp2[r][c - 1] + D[(r, c)]) r range(1, R + 1) range 1 R + 1 R 1 for c in range(1, C + 1):
        m = max(dp0[r - 1][c], dp1[r - 1][c], dp2[r - 1][c], dp3[r - 1][c])
        dp0[r][c] = max(m, dp0[r][c - 1])
        dp1[r][c] = max(m, dp1[r][c - 1])
        dp2[r][c] = max(m, dp2[r][c - 1])
        dp3[r][c] = max(m, dp3[r][c - 1])
        if (r, c) in D:
            dp1[r][c] = max(dp1[r][c], m + D[(r, c)], dp0[r][c - 1] + D[(r, c)])
            dp2[r][c] = max(dp2[r][c], m + D[(r, c)], dp1[r][c - 1] + D[(r, c)])
            dp3[r][c] = max(dp3[r][c], m + D[(r, c)], dp2[r][c - 1] + D[(r, c)]) c range(1, C + 1) range 1 C + 1 C 1 m = max(dp0[r - 1][c], dp1[r - 1][c], dp2[r - 1][c], dp3[r - 1][c]) m max(dp0[r - 1][c], dp1[r - 1][c], dp2[r - 1][c], dp3[r - 1][c]) max dp0[r - 1][c] [r - 1] dp0 r - 1 r 1 c dp1[r - 1][c] [r - 1] dp1 r - 1 r 1 c dp2[r - 1][c] [r - 1] dp2 r - 1 r 1 c dp3[r - 1][c] [r - 1] dp3 r - 1 r 1 c dp0[r][c] = max(m, dp0[r][c - 1]) dp0[r][c] [r] dp0 r c max(m, dp0[r][c - 1]) max m dp0[r][c - 1] [r] dp0 r c - 1 c 1 dp1[r][c] = max(m, dp1[r][c - 1]) dp1[r][c] [r] dp1 r c max(m, dp1[r][c - 1]) max m dp1[r][c - 1] [r] dp1 r c - 1 c 1 dp2[r][c] = max(m, dp2[r][c - 1]) dp2[r][c] [r] dp2 r c max(m, dp2[r][c - 1]) max m dp2[r][c - 1] [r] dp2 r c - 1 c 1 dp3[r][c] = max(m, dp3[r][c - 1]) dp3[r][c] [r] dp3 r c max(m, dp3[r][c - 1]) max m dp3[r][c - 1] [r] dp3 r c - 1 c 1 if (r, c) in D:
            dp1[r][c] = max(dp1[r][c], m + D[(r, c)], dp0[r][c - 1] + D[(r, c)])
            dp2[r][c] = max(dp2[r][c], m + D[(r, c)], dp1[r][c - 1] + D[(r, c)])
            dp3[r][c] = max(dp3[r][c], m + D[(r, c)], dp2[r][c - 1] + D[(r, c)]) (r, c) in D (r, c) r c D dp1[r][c] = max(dp1[r][c], m + D[(r, c)], dp0[r][c - 1] + D[(r, c)]) dp1[r][c] [r] dp1 r c max(dp1[r][c], m + D[(r, c)], dp0[r][c - 1] + D[(r, c)]) max dp1[r][c] [r] dp1 r c m + D[(r, c)] m D[(r, c)] D (r, c) r c dp0[r][c - 1] + D[(r, c)] dp0[r][c - 1] [r] dp0 r c - 1 c 1 D[(r, c)] D (r, c) r c dp2[r][c] = max(dp2[r][c], m + D[(r, c)], dp1[r][c - 1] + D[(r, c)]) dp2[r][c] [r] dp2 r c max(dp2[r][c], m + D[(r, c)], dp1[r][c - 1] + D[(r, c)]) max dp2[r][c] [r] dp2 r c m + D[(r, c)] m D[(r, c)] D (r, c) r c dp1[r][c - 1] + D[(r, c)] dp1[r][c - 1] [r] dp1 r c - 1 c 1 D[(r, c)] D (r, c) r c dp3[r][c] = max(dp3[r][c], m + D[(r, c)], dp2[r][c - 1] + D[(r, c)]) dp3[r][c] [r] dp3 r c max(dp3[r][c], m + D[(r, c)], dp2[r][c - 1] + D[(r, c)]) max dp3[r][c] [r] dp3 r c m + D[(r, c)] m D[(r, c)] D (r, c) r c dp2[r][c - 1] + D[(r, c)] dp2[r][c - 1] [r] dp2 r c - 1 c 1 D[(r, c)] D (r, c) r c 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 dp0 = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] dp0 R, C, K = map(int, input().split()) map(int, input().split()) R C, K = map(int, input().split()) map(int, input().split()) C K = map(int, input().split()) map(int, input().split()) K v = map(int, input().split()) map(int, input().split()) v c, v = map(int, input().split()) map(int, input().split()) c r, c, v = map(int, input().split()) map(int, input().split()) r dp1 = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] dp1 D = dict() dict() D dp2 = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] dp2 m = max(dp0[r - 1][c], dp1[r - 1][c], dp2[r - 1][c], dp3[r - 1][c]) max(dp0[r - 1][c], dp1[r - 1][c], dp2[r - 1][c], dp3[r - 1][c]) m input = sys.stdin.readline sys.stdin.readline input dp3 = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] dp3
import sys

input = sys.stdin.readline

R, C, K = map(int, input().split())
D = dict()
for _ in range(K):
    r, c, v = map(int, input().split())
    D[(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 r in range(1, R + 1):
    for c in range(1, C + 1):
        m = max(dp0[r - 1][c], dp1[r - 1][c], dp2[r - 1][c], dp3[r - 1][c])
        dp0[r][c] = max(m, dp0[r][c - 1])
        dp1[r][c] = max(m, dp1[r][c - 1])
        dp2[r][c] = max(m, dp2[r][c - 1])
        dp3[r][c] = max(m, dp3[r][c - 1])
        if (r, c) in D:
            dp1[r][c] = max(dp1[r][c], m + D[(r, c)], dp0[r][c - 1] + D[(r, c)])
            dp2[r][c] = max(dp2[r][c], m + D[(r, c)], dp1[r][c - 1] + D[(r, c)])
            dp3[r][c] = max(dp3[r][c], m + D[(r, c)], dp2[r][c - 1] + D[(r, c)])
print(max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1]))
