# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

R,C,K=map(int,input().split())
V=[[0]*C for _ in range(R)]
for i in range(K):
    r,c,v=map(int,input().split())
    r-=1
    c-=1
    V[r][c]=v
dp=[[0]*C for _ in range(4)]
for y in range(R):
    for x in range(C):
        for i in range(2,-1,-1):
            dp[i+1][x]=max(dp[i+1][x],dp[i][x]+V[y][x])
        if x<C-1:
            for i in range(3,-1,-1):
                dp[i][x+1]=max(dp[i][x+1],dp[i][x])
    if y+1<R:
        MAX=0
        for x in range(C):
            for i in range(4):
                MAX=max(MAX,dp[i][x])
                dp[i][x]=0
            dp[0][x]=MAX
print(max(dp[0][-1],dp[1][-1],dp[2][-1],dp[3][-1])) import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 INF=10**18 INF 10**18 10 18 MOD=10**9+7 MOD 10**9+7 10**9 10 9 7 input=lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip YesNo=lambda b: bool([print('Yes')] if b else print('No')) YesNo lambda b: bool([print('Yes')] if b else print('No')) bool([print('Yes')] if b else print('No')) bool [print('Yes')] if b else print('No') b [print('Yes')] print('Yes') print 'Yes' print('No') print 'No' b YESNO=lambda b: bool([print('YES')] if b else print('NO')) YESNO lambda b: bool([print('YES')] if b else print('NO')) bool([print('YES')] if b else print('NO')) bool [print('YES')] if b else print('NO') b [print('YES')] print('YES') print 'YES' print('NO') print 'NO' b int1=lambda x:int(x)-1 int1 lambda x:int(x)-1 int(x)-1 int(x) int x 1 x R,C,K=map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [0]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C V=[[0]*C for _ in range(R)] V [[0]*C for _ in range(R)] for i in range(K):
    r,c,v=map(int,input().split())
    r-=1
    c-=1
    V[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 r-=1 r 1 c-=1 c 1 V[r][c]=v V[r][c] [r] V r c v [0]*C for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [0]*C [0] 0 C dp=[[0]*C for _ in range(4)] dp [[0]*C for _ in range(4)] for y in range(R):
    for x in range(C):
        for i in range(2,-1,-1):
            dp[i+1][x]=max(dp[i+1][x],dp[i][x]+V[y][x])
        if x<C-1:
            for i in range(3,-1,-1):
                dp[i][x+1]=max(dp[i][x+1],dp[i][x])
    if y+1<R:
        MAX=0
        for x in range(C):
            for i in range(4):
                MAX=max(MAX,dp[i][x])
                dp[i][x]=0
            dp[0][x]=MAX y range(R) range R for x in range(C):
        for i in range(2,-1,-1):
            dp[i+1][x]=max(dp[i+1][x],dp[i][x]+V[y][x])
        if x<C-1:
            for i in range(3,-1,-1):
                dp[i][x+1]=max(dp[i][x+1],dp[i][x])
     x range(C) range C for i in range(2,-1,-1):
            dp[i+1][x]=max(dp[i+1][x],dp[i][x]+V[y][x])
         i range(2,-1,-1) range 2 -1 -1 dp[i+1][x]=max(dp[i+1][x],dp[i][x]+V[y][x]) dp[i+1][x] [i+1] dp i+1 i 1 x max(dp[i+1][x],dp[i][x]+V[y][x]) max dp[i+1][x] [i+1] dp i+1 i 1 x dp[i][x]+V[y][x] dp[i][x] [i] dp i x V[y][x] [y] V y x if x<C-1:
            for i in range(3,-1,-1):
                dp[i][x+1]=max(dp[i][x+1],dp[i][x])
     x<C-1 x C-1 C 1 for i in range(3,-1,-1):
                dp[i][x+1]=max(dp[i][x+1],dp[i][x])
     i range(3,-1,-1) range 3 -1 -1 dp[i][x+1]=max(dp[i][x+1],dp[i][x]) dp[i][x+1] [i] dp i x+1 x 1 max(dp[i][x+1],dp[i][x]) max dp[i][x+1] [i] dp i x+1 x 1 dp[i][x] [i] dp i x if y+1<R:
        MAX=0
        for x in range(C):
            for i in range(4):
                MAX=max(MAX,dp[i][x])
                dp[i][x]=0
            dp[0][x]=MAX y+1<R y+1 y 1 R MAX=0 MAX 0 for x in range(C):
            for i in range(4):
                MAX=max(MAX,dp[i][x])
                dp[i][x]=0
            dp[0][x]=MAX x range(C) range C for i in range(4):
                MAX=max(MAX,dp[i][x])
                dp[i][x]=0
             i range(4) range 4 MAX=max(MAX,dp[i][x]) MAX max(MAX,dp[i][x]) max MAX dp[i][x] [i] dp i x dp[i][x]=0 dp[i][x] [i] dp i x 0 dp[0][x]=MAX dp[0][x] [0] dp 0 x MAX print(max(dp[0][-1],dp[1][-1],dp[2][-1],dp[3][-1])) print max(dp[0][-1],dp[1][-1],dp[2][-1],dp[3][-1]) max dp[0][-1] [0] dp 0 -1 dp[1][-1] [1] dp 1 -1 dp[2][-1] [2] dp 2 -1 dp[3][-1] [3] dp 3 -1 c-=1 1 c r,c,v=map(int,input().split()) map(int,input().split()) r YesNo=lambda b: bool([print('Yes')] if b else print('No')) lambda b: bool([print('Yes')] if b else print('No')) YesNo MAX=0 0 MAX R,C,K=map(int,input().split()) map(int,input().split()) R MOD=10**9+7 10**9+7 MOD dp=[[0]*C for _ in range(4)] [[0]*C for _ in range(4)] dp INF=10**18 10**18 INF K=map(int,input().split()) map(int,input().split()) K V=[[0]*C for _ in range(R)] [[0]*C for _ in range(R)] V c,v=map(int,input().split()) map(int,input().split()) c v=map(int,input().split()) map(int,input().split()) v C,K=map(int,input().split()) map(int,input().split()) C YESNO=lambda b: bool([print('YES')] if b else print('NO')) lambda b: bool([print('YES')] if b else print('NO')) YESNO MAX=max(MAX,dp[i][x]) max(MAX,dp[i][x]) MAX int1=lambda x:int(x)-1 lambda x:int(x)-1 int1 r-=1 1 r input=lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

R,C,K=map(int,input().split())
V=[[0]*C for _ in range(R)]
for i in range(K):
    r,c,v=map(int,input().split())
    r-=1
    c-=1
    V[r][c]=v
dp=[[0]*C for _ in range(4)]
for y in range(R):
    for x in range(C):
        for i in range(2,-1,-1):
            dp[i+1][x]=max(dp[i+1][x],dp[i][x]+V[y][x])
        if x<C-1:
            for i in range(3,-1,-1):
                dp[i][x+1]=max(dp[i][x+1],dp[i][x])
    if y+1<R:
        MAX=0
        for x in range(C):
            for i in range(4):
                MAX=max(MAX,dp[i][x])
                dp[i][x]=0
            dp[0][x]=MAX
print(max(dp[0][-1],dp[1][-1],dp[2][-1],dp[3][-1]))