import sys
input = sys.stdin.readline

R,C,K = map(int,input().split())

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

for i in range(K):
    r,c,v = map(int,input().split())
    tb[r][c] = v

for i in range(1,R+1):
    for j in range(1,C+1):
        pmx = 0
        for k in range(4):
            mx = dp[j-1][k]
            if k > 0:
                mx = max(mx,dp[j-1][k-1]+tb[i][j])
            if k == 0:
                mx = max(mx,prev[j])
            elif k == 1:
                mx = max(mx,prev[j]+tb[i][j])
            dp[j][k] = mx
            pmx = max(pmx,mx)
        prev[j] = pmx

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

R,C,K = map(int,input().split())

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

for i in range(K):
    r,c,v = map(int,input().split())
    tb[r][c] = v

for i in range(1,R+1):
    for j in range(1,C+1):
        pmx = 0
        for k in range(4):
            mx = dp[j-1][k]
            if k > 0:
                mx = max(mx,dp[j-1][k-1]+tb[i][j])
            if k == 0:
                mx = max(mx,prev[j])
            elif k == 1:
                mx = max(mx,prev[j]+tb[i][j])
            dp[j][k] = mx
            pmx = max(pmx,mx)
        prev[j] = pmx

print(prev[C])
