import sys

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

dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]

for r in range(R-1, -1, -1):
    # dp[0][r][C - 1] = dp[3][r + 1][C - 1]
    # for i in range(1, 4):
    #    dp[i][r][C-1] = dp[3][r + 1][C-1][3]+values[r][C-1]
    for c in range(C-1, -1, -1):
        v = values[r][c]
        for i in range(4):
            if i == 0 or v == 0:
                dp[i][r][c] = max(dp[3][r+1][c], dp[i][r][c+1])
            else:
                dp[i][r][c] = max(dp[3][r + 1][c]+v, dp[i][r][c + 1], dp[i-1][r][c + 1] + v)

print(dp[3][0][0]) 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 values = [[0]*C for _ in range(R)] values [[0]*C for _ in range(R)] for _ in range(K):
    r, c, v = map(int, input().split())
    values[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 values[r-1][c-1] = v values[r-1][c-1] [r-1] values r-1 r 1 c-1 c 1 v [[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0 for _ in range(C+1)] for _ in range(R+1)] dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] dp [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] for r in range(R-1, -1, -1):
    # dp[0][r][C - 1] = dp[3][r + 1][C - 1]
    # for i in range(1, 4):
    #    dp[i][r][C-1] = dp[3][r + 1][C-1][3]+values[r][C-1]
    for c in range(C-1, -1, -1):
        v = values[r][c]
        for i in range(4):
            if i == 0 or v == 0:
                dp[i][r][c] = max(dp[3][r+1][c], dp[i][r][c+1])
            else:
                dp[i][r][c] = max(dp[3][r + 1][c]+v, dp[i][r][c + 1], dp[i-1][r][c + 1] + v) r range(R-1, -1, -1) range R-1 R 1 -1 -1 for c in range(C-1, -1, -1):
        v = values[r][c]
        for i in range(4):
            if i == 0 or v == 0:
                dp[i][r][c] = max(dp[3][r+1][c], dp[i][r][c+1])
            else:
                dp[i][r][c] = max(dp[3][r + 1][c]+v, dp[i][r][c + 1], dp[i-1][r][c + 1] + v) c range(C-1, -1, -1) range C-1 C 1 -1 -1 v = values[r][c] v values[r][c] [r] values r c for i in range(4):
            if i == 0 or v == 0:
                dp[i][r][c] = max(dp[3][r+1][c], dp[i][r][c+1])
            else:
                dp[i][r][c] = max(dp[3][r + 1][c]+v, dp[i][r][c + 1], dp[i-1][r][c + 1] + v) i range(4) range 4 if i == 0 or v == 0:
                dp[i][r][c] = max(dp[3][r+1][c], dp[i][r][c+1])
            else:
                dp[i][r][c] = max(dp[3][r + 1][c]+v, dp[i][r][c + 1], dp[i-1][r][c + 1] + v) i == 0 or v == 0 i == 0 i 0 v == 0 v 0 dp[i][r][c] = max(dp[3][r+1][c], dp[i][r][c+1]) dp[i][r][c] [r] [i] dp i r c max(dp[3][r+1][c], dp[i][r][c+1]) max dp[3][r+1][c] [r+1] [3] dp 3 r+1 r 1 c dp[i][r][c+1] [r] [i] dp i r c+1 c 1 dp[i][r][c] = max(dp[3][r + 1][c]+v, dp[i][r][c + 1], dp[i-1][r][c + 1] + v) dp[i][r][c] [r] [i] dp i r c max(dp[3][r + 1][c]+v, dp[i][r][c + 1], dp[i-1][r][c + 1] + v) max dp[3][r + 1][c]+v dp[3][r + 1][c] [r + 1] [3] dp 3 r + 1 r 1 c v dp[i][r][c + 1] [r] [i] dp i r c + 1 c 1 dp[i-1][r][c + 1] + v dp[i-1][r][c + 1] [r] [i-1] dp i-1 i 1 r c + 1 c 1 v print(dp[3][0][0]) print dp[3][0][0] [0] [3] dp 3 0 0 input = sys.stdin.readline sys.stdin.readline input v = map(int, input().split()) map(int, input().split()) v dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] dp v = values[r][c] values[r][c] v R, C, K = map(int, input().split()) map(int, input().split()) R K = map(int, input().split()) map(int, input().split()) K values = [[0]*C for _ in range(R)] [[0]*C for _ in range(R)] values r, c, v = map(int, input().split()) map(int, input().split()) r C, K = map(int, input().split()) map(int, input().split()) C c, v = map(int, input().split()) map(int, input().split()) c
import sys

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

dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]

for r in range(R-1, -1, -1):
    # dp[0][r][C - 1] = dp[3][r + 1][C - 1]
    # for i in range(1, 4):
    #    dp[i][r][C-1] = dp[3][r + 1][C-1][3]+values[r][C-1]
    for c in range(C-1, -1, -1):
        v = values[r][c]
        for i in range(4):
            if i == 0 or v == 0:
                dp[i][r][c] = max(dp[3][r+1][c], dp[i][r][c+1])
            else:
                dp[i][r][c] = max(dp[3][r + 1][c]+v, dp[i][r][c + 1], dp[i-1][r][c + 1] + v)

print(dp[3][0][0])
