import sys
def input(): return sys.stdin.readline().rstrip()

R, C, k = (int(x) for x in input().split())
V = [[0] * (C + 5) for _ in range(R + 5)]
for _ in range(k):
    r, c, v = (int(x) for x in input().split())
    V[r][c] = v

# dp[3][i][j]
dp = [[[0] * (C + 5) for _ in range(R + 5)] for _ in range(4)]
for i in range(R + 3):
    for j in range(C + 3):
        for k in range(4):
            # 行移動
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j])
            dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[k][i][j] + V[i + 1][j])
            # 列移動
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            if k < 3:
                dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1])
print(max(dp[k][R][C] for k in range(4))) import sys sys def input(): return sys.stdin.readline().rstrip() input int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x R, C, k = (int(x) for x in input().split()) R (int(x) for x in input().split()) C k [0] * (C + 5) for _ in range(R + 5) for _ in range(R + 5) _ range(R + 5) range R + 5 R 5 for _ in range(R + 5) [0] * (C + 5) [0] 0 C + 5 C 5 V = [[0] * (C + 5) for _ in range(R + 5)] V [[0] * (C + 5) for _ in range(R + 5)] for _ in range(k):
    r, c, v = (int(x) for x in input().split())
    V[r][c] = v

# dp[3][i][j] _ range(k) range k int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x r, c, v = (int(x) for x in input().split()) r (int(x) for x in input().split()) c v V[r][c] = v V[r][c] [r] V r c v [[0] * (C + 5) for _ in range(R + 5)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0] * (C + 5) for _ in range(R + 5)] dp = [[[0] * (C + 5) for _ in range(R + 5)] for _ in range(4)] dp [[[0] * (C + 5) for _ in range(R + 5)] for _ in range(4)] for i in range(R + 3):
    for j in range(C + 3):
        for k in range(4):
            # 行移動
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j])
            dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[k][i][j] + V[i + 1][j])
            # 列移動
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            if k < 3:
                dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1]) i range(R + 3) range R + 3 R 3 for j in range(C + 3):
        for k in range(4):
            # 行移動
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j])
            dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[k][i][j] + V[i + 1][j])
            # 列移動
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            if k < 3:
                dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1]) j range(C + 3) range C + 3 C 3 for k in range(4):
            # 行移動
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j])
            dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[k][i][j] + V[i + 1][j])
            # 列移動
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            if k < 3:
                dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1]) k range(4) range 4 dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j]) dp[0][i + 1][j] [i + 1] [0] dp 0 i + 1 i 1 j max(dp[0][i + 1][j], dp[k][i][j]) max dp[0][i + 1][j] [i + 1] [0] dp 0 i + 1 i 1 j dp[k][i][j] [i] [k] dp k i j dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[k][i][j] + V[i + 1][j]) dp[1][i + 1][j] [i + 1] [1] dp 1 i + 1 i 1 j max(dp[1][i + 1][j], dp[k][i][j] + V[i + 1][j]) max dp[1][i + 1][j] [i + 1] [1] dp 1 i + 1 i 1 j dp[k][i][j] + V[i + 1][j] dp[k][i][j] [i] [k] dp k i j V[i + 1][j] [i + 1] V i + 1 i 1 j dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j]) dp[k][i][j + 1] [i] [k] dp k i j + 1 j 1 max(dp[k][i][j + 1], dp[k][i][j]) max dp[k][i][j + 1] [i] [k] dp k i j + 1 j 1 dp[k][i][j] [i] [k] dp k i j if k < 3:
                dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1]) k < 3 k 3 dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1]) dp[k + 1][i][j + 1] [i] [k + 1] dp k + 1 k 1 i j + 1 j 1 max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1]) max dp[k + 1][i][j + 1] [i] [k + 1] dp k + 1 k 1 i j + 1 j 1 dp[k][i][j] + V[i][j + 1] dp[k][i][j] [i] [k] dp k i j V[i][j + 1] [i] V i j + 1 j 1 print(max(dp[k][R][C] for k in range(4))) print max(dp[k][R][C] for k in range(4)) max dp[k][R][C] [R] [k] dp k R C c, v = (int(x) for x in input().split()) (int(x) for x in input().split()) c v = (int(x) for x in input().split()) (int(x) for x in input().split()) v R, C, k = (int(x) for x in input().split()) (int(x) for x in input().split()) R def input(): return sys.stdin.readline().rstrip() def input(): return sys.stdin.readline().rstrip() input V = [[0] * (C + 5) for _ in range(R + 5)] [[0] * (C + 5) for _ in range(R + 5)] V C, k = (int(x) for x in input().split()) (int(x) for x in input().split()) C k = (int(x) for x in input().split()) (int(x) for x in input().split()) k dp = [[[0] * (C + 5) for _ in range(R + 5)] for _ in range(4)] [[[0] * (C + 5) for _ in range(R + 5)] for _ in range(4)] dp r, c, v = (int(x) for x in input().split()) (int(x) for x in input().split()) r
import sys
def input(): return sys.stdin.readline().rstrip()

R, C, k = (int(x) for x in input().split())
V = [[0] * (C + 5) for _ in range(R + 5)]
for _ in range(k):
    r, c, v = (int(x) for x in input().split())
    V[r][c] = v

# dp[3][i][j]
dp = [[[0] * (C + 5) for _ in range(R + 5)] for _ in range(4)]
for i in range(R + 3):
    for j in range(C + 3):
        for k in range(4):
            # 行移動
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j])
            dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[k][i][j] + V[i + 1][j])
            # 列移動
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            if k < 3:
                dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], dp[k][i][j] + V[i][j + 1])
print(max(dp[k][R][C] for k in range(4)))
