import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
# input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

h,w,k=map(int,input().split())
# R=[]
A=[[0]*w for i in range(h)]
dp=[[[0 for j in range(w)] for i in range(h)] for i in range(4)]

for s in sys.stdin.readlines():
    x,y,v=map(int,s.split())
    x-=1;y-=1
    A[x][y]=v
    # dp[x][y][1]=v
    # dp[x][y][2]=v
    # dp[x][y][3]=v;
dp[1][0][0]=A[0][0]
for i in range(h):
    for j in range(w):
        for k in range(4):
            here=dp[k][i][j]
            if i<h-1:
                dp[0][i+1][j] = max(here,dp[0][i+1][j])
                dp[1][i+1][j] = max(here+A[i+1][j], dp[1][i+1][j])
            if j<w-1:
                dp[k][i][j+1] = max(dp[k][i][j+1], here)
                if k<=2:
                    dp[k+1][i][j+1]= max(dp[k+1][i][j+1],here+ A[i][j+1])
ans=0
for i in range(4):
    ans=max(ans, dp[i][-1][-1])
print(ans) import sys sys mod=10**9+7 mod 10**9+7 10**9 10 9 7 inf=float("inf") inf float("inf") float "inf" from math import sqrt, ceil from collections import deque, Counter, defaultdict sys.setrecursionlimit(11451419) sys.setrecursionlimit sys setrecursionlimit 11451419 from decimal import ROUND_HALF_UP,Decimal from functools import lru_cache h,w,k=map(int,input().split()) h map(int,input().split()) map int input().split() ().split () input split w k [0]*w for i in range(h) for i in range(h) i range(h) range h for i in range(h) [0]*w [0] 0 w A=[[0]*w for i in range(h)] A [[0]*w for i in range(h)] [[0 for j in range(w)] for i in range(h)] for i in range(4) for i in range(4) i range(4) range 4 for i in range(4) [[0 for j in range(w)] for i in range(h)] dp=[[[0 for j in range(w)] for i in range(h)] for i in range(4)] dp [[[0 for j in range(w)] for i in range(h)] for i in range(4)] for s in sys.stdin.readlines():
    x,y,v=map(int,s.split())
    x-=1;y-=1
    A[x][y]=v
    # dp[x][y][1]=v
    # dp[x][y][2]=v
    # dp[x][y][3]=v; s sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines x,y,v=map(int,s.split()) x map(int,s.split()) map int s.split() s.split s split y v x-=1 x 1 y-=1 y 1 A[x][y]=v A[x][y] [x] A x y v dp[1][0][0]=A[0][0] dp[1][0][0] [0] [1] dp 1 0 0 A[0][0] [0] A 0 0 for i in range(h):
    for j in range(w):
        for k in range(4):
            here=dp[k][i][j]
            if i<h-1:
                dp[0][i+1][j] = max(here,dp[0][i+1][j])
                dp[1][i+1][j] = max(here+A[i+1][j], dp[1][i+1][j])
            if j<w-1:
                dp[k][i][j+1] = max(dp[k][i][j+1], here)
                if k<=2:
                    dp[k+1][i][j+1]= max(dp[k+1][i][j+1],here+ A[i][j+1]) i range(h) range h for j in range(w):
        for k in range(4):
            here=dp[k][i][j]
            if i<h-1:
                dp[0][i+1][j] = max(here,dp[0][i+1][j])
                dp[1][i+1][j] = max(here+A[i+1][j], dp[1][i+1][j])
            if j<w-1:
                dp[k][i][j+1] = max(dp[k][i][j+1], here)
                if k<=2:
                    dp[k+1][i][j+1]= max(dp[k+1][i][j+1],here+ A[i][j+1]) j range(w) range w for k in range(4):
            here=dp[k][i][j]
            if i<h-1:
                dp[0][i+1][j] = max(here,dp[0][i+1][j])
                dp[1][i+1][j] = max(here+A[i+1][j], dp[1][i+1][j])
            if j<w-1:
                dp[k][i][j+1] = max(dp[k][i][j+1], here)
                if k<=2:
                    dp[k+1][i][j+1]= max(dp[k+1][i][j+1],here+ A[i][j+1]) k range(4) range 4 here=dp[k][i][j] here dp[k][i][j] [i] [k] dp k i j if i<h-1:
                dp[0][i+1][j] = max(here,dp[0][i+1][j])
                dp[1][i+1][j] = max(here+A[i+1][j], dp[1][i+1][j])
             i<h-1 i h-1 h 1 dp[0][i+1][j] = max(here,dp[0][i+1][j]) dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j max(here,dp[0][i+1][j]) max here dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j dp[1][i+1][j] = max(here+A[i+1][j], dp[1][i+1][j]) dp[1][i+1][j] [i+1] [1] dp 1 i+1 i 1 j max(here+A[i+1][j], dp[1][i+1][j]) max here+A[i+1][j] here A[i+1][j] [i+1] A i+1 i 1 j dp[1][i+1][j] [i+1] [1] dp 1 i+1 i 1 j if j<w-1:
                dp[k][i][j+1] = max(dp[k][i][j+1], here)
                if k<=2:
                    dp[k+1][i][j+1]= max(dp[k+1][i][j+1],here+ A[i][j+1]) j<w-1 j w-1 w 1 dp[k][i][j+1] = max(dp[k][i][j+1], here) dp[k][i][j+1] [i] [k] dp k i j+1 j 1 max(dp[k][i][j+1], here) max dp[k][i][j+1] [i] [k] dp k i j+1 j 1 here if k<=2:
                    dp[k+1][i][j+1]= max(dp[k+1][i][j+1],here+ A[i][j+1]) k<=2 k 2 dp[k+1][i][j+1]= max(dp[k+1][i][j+1],here+ A[i][j+1]) dp[k+1][i][j+1] [i] [k+1] dp k+1 k 1 i j+1 j 1 max(dp[k+1][i][j+1],here+ A[i][j+1]) max dp[k+1][i][j+1] [i] [k+1] dp k+1 k 1 i j+1 j 1 here+ A[i][j+1] here A[i][j+1] [i] A i j+1 j 1 ans=0 ans 0 for i in range(4):
    ans=max(ans, dp[i][-1][-1]) i range(4) range 4 ans=max(ans, dp[i][-1][-1]) ans max(ans, dp[i][-1][-1]) max ans dp[i][-1][-1] [-1] [i] dp i -1 -1 print(ans) print ans x,y,v=map(int,s.split()) map(int,s.split()) x w,k=map(int,input().split()) map(int,input().split()) w A=[[0]*w for i in range(h)] [[0]*w for i in range(h)] A k=map(int,input().split()) map(int,input().split()) k y,v=map(int,s.split()) map(int,s.split()) y ans=max(ans, dp[i][-1][-1]) max(ans, dp[i][-1][-1]) ans mod=10**9+7 10**9+7 mod dp=[[[0 for j in range(w)] for i in range(h)] for i in range(4)] [[[0 for j in range(w)] for i in range(h)] for i in range(4)] dp here=dp[k][i][j] dp[k][i][j] here v=map(int,s.split()) map(int,s.split()) v x-=1 1 x h,w,k=map(int,input().split()) map(int,input().split()) h y-=1 1 y inf=float("inf") float("inf") inf ans=0 0 ans
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
# input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

h,w,k=map(int,input().split())
# R=[]
A=[[0]*w for i in range(h)]
dp=[[[0 for j in range(w)] for i in range(h)] for i in range(4)]

for s in sys.stdin.readlines():
    x,y,v=map(int,s.split())
    x-=1;y-=1
    A[x][y]=v
    # dp[x][y][1]=v
    # dp[x][y][2]=v
    # dp[x][y][3]=v;
dp[1][0][0]=A[0][0]
for i in range(h):
    for j in range(w):
        for k in range(4):
            here=dp[k][i][j]
            if i<h-1:
                dp[0][i+1][j] = max(here,dp[0][i+1][j])
                dp[1][i+1][j] = max(here+A[i+1][j], dp[1][i+1][j])
            if j<w-1:
                dp[k][i][j+1] = max(dp[k][i][j+1], here)
                if k<=2:
                    dp[k+1][i][j+1]= max(dp[k+1][i][j+1],here+ A[i][j+1])
ans=0
for i in range(4):
    ans=max(ans, dp[i][-1][-1])
print(ans)