import sys
input = sys.stdin.buffer.readline

R, C, K = map(int,input().split())
RC = [[0] * (C+1) for _ in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    RC[r-1][c-1] = v


dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]

dp[1][0][0] = RC[0][0]
for r in range(R):
    for c in range(C):
        for i in range(4):
            dp[i][r][c+1] = max(dp[i][r][c], dp[i][r][c+1])
            if i <= 2:
                dp[i+1][r][c+1] = max(dp[i][r][c] + RC[r][c+1], dp[i+1][r][c+1])
            dp[0][r+1][c] = max(dp[i][r][c], dp[0][r+1][c])
        dp[1][r+1][c] = max(dp[1][r+1][c], dp[0][r+1][c] + RC[r+1][c])

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

R, C, K = map(int,input().split())
RC = [[0] * (C+1) for _ in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    RC[r-1][c-1] = v


dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]

dp[1][0][0] = RC[0][0]
for r in range(R):
    for c in range(C):
        for i in range(4):
            dp[i][r][c+1] = max(dp[i][r][c], dp[i][r][c+1])
            if i <= 2:
                dp[i+1][r][c+1] = max(dp[i][r][c] + RC[r][c+1], dp[i+1][r][c+1])
            dp[0][r+1][c] = max(dp[i][r][c], dp[0][r+1][c])
        dp[1][r+1][c] = max(dp[1][r+1][c], dp[0][r+1][c] + RC[r+1][c])

print(max(dp[0][-2][-2], dp[1][-2][-2], dp[2][-2][-2], dp[3][-2][-2]))
