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

R, C, K = mapint()
last_dp = [[0]*4 for _ in range(C)]
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):
    dp = [[0]*4 for _ in range(C)]
    for c in range(C):
        v = dic[r][c]
        for i in range(4):
            if c!=0:
                dp[c][i] = dp[c-1][i]
            if r!=0:
                dp[c][0] = max(dp[c][0], last_dp[c][i])
        if v!=0:
            for i in range(2, -1, -1):
                dp[c][i+1] = max(dp[c][i+1], dp[c][i]+v)
    last_dp = dp

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

R, C, K = mapint()
last_dp = [[0]*4 for _ in range(C)]
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):
    dp = [[0]*4 for _ in range(C)]
    for c in range(C):
        v = dic[r][c]
        for i in range(4):
            if c!=0:
                dp[c][i] = dp[c-1][i]
            if r!=0:
                dp[c][0] = max(dp[c][0], last_dp[c][i])
        if v!=0:
            for i in range(2, -1, -1):
                dp[c][i+1] = max(dp[c][i+1], dp[c][i]+v)
    last_dp = dp

print(max(dp[C-1]))