import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

R, C, K = mapint()
dp = [[[0]*C for _ in range(R)] for _ in range(4)]
from collections import defaultdict
dic = [[0]*C for _ in range(R)]
for _ in range(K):
    r, c, v = mapint()
    dic[r-1][c-1] = v

for r in range(R):
    for c in range(C):
        v = dic[r][c]
        for i in range(4):
            if c!=0:
                dp[i][r][c] = dp[i][r][c-1]
            if r!=0:
                dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
        for i in range(2, -1, -1):
            dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v)

ans = 0
for i in range(4):
    ans = max(ans, dp[i][R-1][C-1])
print(ans) import sys sys def input(): return sys.stdin.readline().strip() input def mapint(): return map(int, input().split()) mapint sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 R, C, K = mapint() R mapint() mapint C K [[0]*C for _ in range(R)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*C for _ in range(R)] dp = [[[0]*C for _ in range(R)] for _ in range(4)] dp [[[0]*C for _ in range(R)] for _ in range(4)] from collections import defaultdict [0]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C dic = [[0]*C for _ in range(R)] dic [[0]*C for _ in range(R)] for _ in range(K):
    r, c, v = mapint()
    dic[r-1][c-1] = v _ range(K) range K r, c, v = mapint() r mapint() mapint c v dic[r-1][c-1] = v dic[r-1][c-1] [r-1] dic r-1 r 1 c-1 c 1 v for r in range(R):
    for c in range(C):
        v = dic[r][c]
        for i in range(4):
            if c!=0:
                dp[i][r][c] = dp[i][r][c-1]
            if r!=0:
                dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
        for i in range(2, -1, -1):
            dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v) r range(R) range R for c in range(C):
        v = dic[r][c]
        for i in range(4):
            if c!=0:
                dp[i][r][c] = dp[i][r][c-1]
            if r!=0:
                dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
        for i in range(2, -1, -1):
            dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v) c range(C) range C v = dic[r][c] v dic[r][c] [r] dic r c for i in range(4):
            if c!=0:
                dp[i][r][c] = dp[i][r][c-1]
            if r!=0:
                dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
         i range(4) range 4 if c!=0:
                dp[i][r][c] = dp[i][r][c-1]
             c!=0 c 0 dp[i][r][c] = dp[i][r][c-1] 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 r!=0:
                dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
         r!=0 r 0 dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c]) dp[0][r][c] [r] [0] dp 0 r c max(dp[0][r][c], dp[i][r-1][c]) max dp[0][r][c] [r] [0] dp 0 r c dp[i][r-1][c] [r-1] [i] dp i r-1 r 1 c for i in range(2, -1, -1):
            dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v) i range(2, -1, -1) range 2 -1 -1 dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v) dp[i+1][r][c] [r] [i+1] dp i+1 i 1 r c max(dp[i+1][r][c], dp[i][r][c]+v) max dp[i+1][r][c] [r] [i+1] dp i+1 i 1 r c dp[i][r][c]+v dp[i][r][c] [r] [i] dp i r c v ans = 0 ans 0 for i in range(4):
    ans = max(ans, dp[i][R-1][C-1]) i range(4) range 4 ans = max(ans, dp[i][R-1][C-1]) ans max(ans, dp[i][R-1][C-1]) max ans dp[i][R-1][C-1] [R-1] [i] dp i R-1 R 1 C-1 C 1 print(ans) print ans C, K = mapint() mapint() C def mapint(): return map(int, input().split()) def mapint(): return map(int, input().split()) mapint c, v = mapint() mapint() c R, C, K = mapint() mapint() R v = dic[r][c] dic[r][c] v r, c, v = mapint() mapint() r dp = [[[0]*C for _ in range(R)] for _ in range(4)] [[[0]*C for _ in range(R)] for _ in range(4)] dp ans = max(ans, dp[i][R-1][C-1]) max(ans, dp[i][R-1][C-1]) ans dic = [[0]*C for _ in range(R)] [[0]*C for _ in range(R)] dic ans = 0 0 ans def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input K = mapint() mapint() K v = mapint() mapint() v
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

R, C, K = mapint()
dp = [[[0]*C for _ in range(R)] for _ in range(4)]
from collections import defaultdict
dic = [[0]*C for _ in range(R)]
for _ in range(K):
    r, c, v = mapint()
    dic[r-1][c-1] = v

for r in range(R):
    for c in range(C):
        v = dic[r][c]
        for i in range(4):
            if c!=0:
                dp[i][r][c] = dp[i][r][c-1]
            if r!=0:
                dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
        for i in range(2, -1, -1):
            dp[i+1][r][c] = max(dp[i+1][r][c], dp[i][r][c]+v)

ans = 0
for i in range(4):
    ans = max(ans, dp[i][R-1][C-1])
print(ans)
