import sys

input = sys.stdin.readline
R, C, k = map(int, input().split())
xs = [[0] * C for _ in range(R)]
for _ in range(k):
    r, c, v = map(int, input().split())
    xs[r - 1][c - 1] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R):
    for j in range(C):
        for k in range(2, -1, -1):
            dp[k + 1][i][j] = max(dp[k + 1][i][j], dp[k][i][j] + xs[i][j])
        for k in range(4):
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][R - 1][C - 1])
print(ans) 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 [0] * C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0] * C [0] 0 C xs = [[0] * C for _ in range(R)] xs [[0] * C for _ in range(R)] for _ in range(k):
    r, c, v = map(int, input().split())
    xs[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 xs[r - 1][c - 1] = v xs[r - 1][c - 1] [r - 1] xs r - 1 r 1 c - 1 c 1 v [[0] * (C + 1) for _ in range(R + 1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0] * (C + 1) for _ in range(R + 1)] dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] dp [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] for i in range(R):
    for j in range(C):
        for k in range(2, -1, -1):
            dp[k + 1][i][j] = max(dp[k + 1][i][j], dp[k][i][j] + xs[i][j])
        for k in range(4):
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j]) i range(R) range R for j in range(C):
        for k in range(2, -1, -1):
            dp[k + 1][i][j] = max(dp[k + 1][i][j], dp[k][i][j] + xs[i][j])
        for k in range(4):
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j]) j range(C) range C for k in range(2, -1, -1):
            dp[k + 1][i][j] = max(dp[k + 1][i][j], dp[k][i][j] + xs[i][j])
         k range(2, -1, -1) range 2 -1 -1 dp[k + 1][i][j] = max(dp[k + 1][i][j], dp[k][i][j] + xs[i][j]) dp[k + 1][i][j] [i] [k + 1] dp k + 1 k 1 i j max(dp[k + 1][i][j], dp[k][i][j] + xs[i][j]) max dp[k + 1][i][j] [i] [k + 1] dp k + 1 k 1 i j dp[k][i][j] + xs[i][j] dp[k][i][j] [i] [k] dp k i j xs[i][j] [i] xs i j for k in range(4):
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j]) k range(4) range 4 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 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 ans = 0 ans 0 for k in range(4):
    ans = max(ans, dp[k][R - 1][C - 1]) k range(4) range 4 ans = max(ans, dp[k][R - 1][C - 1]) ans max(ans, dp[k][R - 1][C - 1]) max ans dp[k][R - 1][C - 1] [R - 1] [k] dp k R - 1 R 1 C - 1 C 1 print(ans) print ans r, c, v = map(int, input().split()) map(int, input().split()) r ans = max(ans, dp[k][R - 1][C - 1]) max(ans, dp[k][R - 1][C - 1]) ans c, v = map(int, input().split()) map(int, input().split()) c input = sys.stdin.readline sys.stdin.readline input xs = [[0] * C for _ in range(R)] [[0] * C for _ in range(R)] xs C, k = map(int, input().split()) map(int, input().split()) C v = map(int, input().split()) map(int, input().split()) v k = map(int, input().split()) map(int, input().split()) k ans = 0 0 ans R, C, k = map(int, input().split()) map(int, input().split()) R dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] dp
import sys

input = sys.stdin.readline
R, C, k = map(int, input().split())
xs = [[0] * C for _ in range(R)]
for _ in range(k):
    r, c, v = map(int, input().split())
    xs[r - 1][c - 1] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R):
    for j in range(C):
        for k in range(2, -1, -1):
            dp[k + 1][i][j] = max(dp[k + 1][i][j], dp[k][i][j] + xs[i][j])
        for k in range(4):
            dp[k][i][j + 1] = max(dp[k][i][j + 1], dp[k][i][j])
            dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[k][i][j])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][R - 1][C - 1])
print(ans)
