import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
import sys

R, C, K = map(int, input().split())
rcvs = [list(map(int, input().split())) for _ in range(K)]
rcvs = np.array(rcvs, dtype=np.int64)
#%%
@njit
def main(rcvs):
    rewards = np.zeros((R, C), dtype=np.int64)
    
    for i in range(len(rcvs)):
        rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2]
    
    dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
    
    for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
    return max(dp[-1][-1])

print(main(rcvs))

"""
メモ
ndarrayの型宣言でtype指定できない
typeコマンドも機能しない
iteration使えない
グローバル変数使える
main(As)
""" import sys sys import numpy as np numpy import numba numba from numba import njit, b1, i4, i8, f8 import sys sys R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K list(map(int, input().split())) for _ in range(K) for _ in range(K) _ range(K) range K for _ in range(K) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split rcvs = [list(map(int, input().split())) for _ in range(K)] rcvs [list(map(int, input().split())) for _ in range(K)] rcvs = np.array(rcvs, dtype=np.int64) rcvs np.array(rcvs, dtype=np.int64) np.array np array rcvs dtype=np.int64 dtype np.int64 np int64 def main(rcvs):
    rewards = np.zeros((R, C), dtype=np.int64)
    
    for i in range(len(rcvs)):
        rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2]
    
    dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
    
    for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
    return max(dp[-1][-1]) main rewards = np.zeros((R, C), dtype=np.int64) rewards np.zeros((R, C), dtype=np.int64) np.zeros np zeros (R, C) R C dtype=np.int64 dtype np.int64 np int64 for i in range(len(rcvs)):
        rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2]
    
     i range(len(rcvs)) range len(rcvs) len rcvs rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2] rewards[rcvs[i][0]-1][rcvs[i][1]-1] [rcvs[i][0]-1] rewards rcvs[i][0]-1 rcvs[i][0] [i] rcvs i 0 1 rcvs[i][1]-1 rcvs[i][1] [i] rcvs i 1 1 rcvs[i][2] [i] rcvs i 2 dp = np.zeros((R+1, C+1, 4), dtype=np.int64) dp np.zeros((R+1, C+1, 4), dtype=np.int64) np.zeros np zeros (R+1, C+1, 4) R+1 R 1 C+1 C 1 4 dtype=np.int64 dtype np.int64 np int64 for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
     i range(R) range R for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
     j range(C) range C reward = rewards[i][j] reward rewards[i][j] [i] rewards i j dp[i+1][j+1][0] = max(dp[i][j+1]) dp[i+1][j+1][0] [j+1] [i+1] dp i+1 i 1 j+1 j 1 0 max(dp[i][j+1]) max dp[i][j+1] [i] dp i j+1 j 1 dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward dp[i+1][j+1][1] [j+1] [i+1] dp i+1 i 1 j+1 j 1 1 dp[i+1][j+1][0] + reward dp[i+1][j+1][0] [j+1] [i+1] dp i+1 i 1 j+1 j 1 0 reward for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
             k range(4) range 4 dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k]) dp[i+1][j+1][k] [j+1] [i+1] dp i+1 i 1 j+1 j 1 k max(dp[i+1][j][k], dp[i+1][j+1][k]) max dp[i+1][j][k] [j] [i+1] dp i+1 i 1 j k dp[i+1][j+1][k] [j+1] [i+1] dp i+1 i 1 j+1 j 1 k if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
     reward > 0 reward 0 for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
     k range(3) range 3 dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1]) dp[i+1][j+1][k+1] [j+1] [i+1] dp i+1 i 1 j+1 j 1 k+1 k 1 max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1]) max dp[i+1][j][k]+reward dp[i+1][j][k] [j] [i+1] dp i+1 i 1 j k reward dp[i+1][j+1][k+1] [j+1] [i+1] dp i+1 i 1 j+1 j 1 k+1 k 1 return max(dp[-1][-1]) max(dp[-1][-1]) max dp[-1][-1] [-1] dp -1 -1 rcvs rcvs @njit main njit main print(main(rcvs)) print main(rcvs) main rcvs """
メモ
ndarrayの型宣言でtype指定できない
typeコマンドも機能しない
iteration使えない
グローバル変数使える
main(As)
""" def main(rcvs):
    rewards = np.zeros((R, C), dtype=np.int64)
    
    for i in range(len(rcvs)):
        rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2]
    
    dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
    
    for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
    return max(dp[-1][-1]) def main(rcvs):
    rewards = np.zeros((R, C), dtype=np.int64)
    
    for i in range(len(rcvs)):
        rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2]
    
    dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
    
    for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
    return max(dp[-1][-1]) main rcvs = [list(map(int, input().split())) for _ in range(K)] [list(map(int, input().split())) for _ in range(K)] rcvs C, K = map(int, input().split()) map(int, input().split()) C rcvs = np.array(rcvs, dtype=np.int64) np.array(rcvs, dtype=np.int64) rcvs R, C, K = map(int, input().split()) map(int, input().split()) R K = map(int, input().split()) map(int, input().split()) K
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
import sys

R, C, K = map(int, input().split())
rcvs = [list(map(int, input().split())) for _ in range(K)]
rcvs = np.array(rcvs, dtype=np.int64)
#%%
@njit
def main(rcvs):
    rewards = np.zeros((R, C), dtype=np.int64)
    
    for i in range(len(rcvs)):
        rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2]
    
    dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
    
    for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
    return max(dp[-1][-1])

print(main(rcvs))

"""
メモ
ndarrayの型宣言でtype指定できない
typeコマンドも機能しない
iteration使えない
グローバル変数使える
main(As)
"""