import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
 
R, C, K = rl()
I = [[0]*(C+2) for _ in range(R+2)]
for i in range(K):
	r, c, v = rl()
	I[r][c] = v
 
dp = [[0]*4 for _ in range(C+2)]
dp2 = [[0]*4 for _ in range(C+2)]
 
for i in range(R+1):
	for j in range(C+1):
		for m in range(4):
			ni, nj = i, j+1
			dp[nj][m] = max(dp[nj][m], dp[j][m])
			if m < 3:
				dp[nj][m+1] = max(dp[nj][m+1], dp[j][m]+I[ni][nj])
			ni, nj = i+1, j
			dp2[nj][0] = max(dp2[nj][0], dp[j][m])
			dp2[nj][1] = max(dp2[nj][1], dp[j][m]+I[ni][nj])
	dp = dp2
	dp2 = [[0]*4 for _ in range(C+2)]
ans = 0
for m in range(4):
	ans = max(ans, dp[C][m])
print(ans) import sys, math sys math from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from itertools import combinations, permutations, product from heapq import heappush, heappop from functools import lru_cache input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline rs = lambda: input().strip() rs lambda: input().strip() input().strip() ().strip () input strip ri = lambda: int(input()) ri lambda: int(input()) int(input()) int input() input rl = lambda: list(map(int, input().split())) rl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split mod = 1000000007 mod 1000000007 sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 R, C, K = rl() R rl() rl C K [0]*(C+2) for _ in range(R+2) for _ in range(R+2) _ range(R+2) range R+2 R 2 for _ in range(R+2) [0]*(C+2) [0] 0 C+2 C 2 I = [[0]*(C+2) for _ in range(R+2)] I [[0]*(C+2) for _ in range(R+2)] for i in range(K):
	r, c, v = rl()
	I[r][c] = v
  i range(K) range K r, c, v = rl() r rl() rl c v I[r][c] = v I[r][c] [r] I r c v [0]*4 for _ in range(C+2) for _ in range(C+2) _ range(C+2) range C+2 C 2 for _ in range(C+2) [0]*4 [0] 0 4 dp = [[0]*4 for _ in range(C+2)] dp [[0]*4 for _ in range(C+2)] [0]*4 for _ in range(C+2) for _ in range(C+2) _ range(C+2) range C+2 C 2 for _ in range(C+2) [0]*4 [0] 0 4 dp2 = [[0]*4 for _ in range(C+2)] dp2 [[0]*4 for _ in range(C+2)] for i in range(R+1):
	for j in range(C+1):
		for m in range(4):
			ni, nj = i, j+1
			dp[nj][m] = max(dp[nj][m], dp[j][m])
			if m < 3:
				dp[nj][m+1] = max(dp[nj][m+1], dp[j][m]+I[ni][nj])
			ni, nj = i+1, j
			dp2[nj][0] = max(dp2[nj][0], dp[j][m])
			dp2[nj][1] = max(dp2[nj][1], dp[j][m]+I[ni][nj])
	dp = dp2
	dp2 = [[0]*4 for _ in range(C+2)] i range(R+1) range R+1 R 1 for j in range(C+1):
		for m in range(4):
			ni, nj = i, j+1
			dp[nj][m] = max(dp[nj][m], dp[j][m])
			if m < 3:
				dp[nj][m+1] = max(dp[nj][m+1], dp[j][m]+I[ni][nj])
			ni, nj = i+1, j
			dp2[nj][0] = max(dp2[nj][0], dp[j][m])
			dp2[nj][1] = max(dp2[nj][1], dp[j][m]+I[ni][nj])
	 j range(C+1) range C+1 C 1 for m in range(4):
			ni, nj = i, j+1
			dp[nj][m] = max(dp[nj][m], dp[j][m])
			if m < 3:
				dp[nj][m+1] = max(dp[nj][m+1], dp[j][m]+I[ni][nj])
			ni, nj = i+1, j
			dp2[nj][0] = max(dp2[nj][0], dp[j][m])
			dp2[nj][1] = max(dp2[nj][1], dp[j][m]+I[ni][nj])
	 m range(4) range 4 ni, nj = i, j+1 ni i nj j+1 j 1 dp[nj][m] = max(dp[nj][m], dp[j][m]) dp[nj][m] [nj] dp nj m max(dp[nj][m], dp[j][m]) max dp[nj][m] [nj] dp nj m dp[j][m] [j] dp j m if m < 3:
				dp[nj][m+1] = max(dp[nj][m+1], dp[j][m]+I[ni][nj])
			 m < 3 m 3 dp[nj][m+1] = max(dp[nj][m+1], dp[j][m]+I[ni][nj]) dp[nj][m+1] [nj] dp nj m+1 m 1 max(dp[nj][m+1], dp[j][m]+I[ni][nj]) max dp[nj][m+1] [nj] dp nj m+1 m 1 dp[j][m]+I[ni][nj] dp[j][m] [j] dp j m I[ni][nj] [ni] I ni nj ni, nj = i+1, j ni i+1 i 1 nj j dp2[nj][0] = max(dp2[nj][0], dp[j][m]) dp2[nj][0] [nj] dp2 nj 0 max(dp2[nj][0], dp[j][m]) max dp2[nj][0] [nj] dp2 nj 0 dp[j][m] [j] dp j m dp2[nj][1] = max(dp2[nj][1], dp[j][m]+I[ni][nj]) dp2[nj][1] [nj] dp2 nj 1 max(dp2[nj][1], dp[j][m]+I[ni][nj]) max dp2[nj][1] [nj] dp2 nj 1 dp[j][m]+I[ni][nj] dp[j][m] [j] dp j m I[ni][nj] [ni] I ni nj dp = dp2 dp dp2 [0]*4 for _ in range(C+2) for _ in range(C+2) _ range(C+2) range C+2 C 2 for _ in range(C+2) [0]*4 [0] 0 4 dp2 = [[0]*4 for _ in range(C+2)] dp2 [[0]*4 for _ in range(C+2)] ans = 0 ans 0 for m in range(4):
	ans = max(ans, dp[C][m]) m range(4) range 4 ans = max(ans, dp[C][m]) ans max(ans, dp[C][m]) max ans dp[C][m] [C] dp C m print(ans) print ans dp2 = [[0]*4 for _ in range(C+2)] [[0]*4 for _ in range(C+2)] dp2 K = rl() rl() K R, C, K = rl() rl() R dp = [[0]*4 for _ in range(C+2)] [[0]*4 for _ in range(C+2)] dp ans = 0 0 ans rs = lambda: input().strip() lambda: input().strip() rs dp = dp2 dp2 dp c, v = rl() rl() c dp2 = [[0]*4 for _ in range(C+2)] [[0]*4 for _ in range(C+2)] dp2 ni, nj = i, j+1 i ni v = rl() rl() v ans = max(ans, dp[C][m]) max(ans, dp[C][m]) ans r, c, v = rl() rl() r nj = i, j+1 j+1 nj input = sys.stdin.readline sys.stdin.readline input C, K = rl() rl() C I = [[0]*(C+2) for _ in range(R+2)] [[0]*(C+2) for _ in range(R+2)] I mod = 1000000007 1000000007 mod ni, nj = i+1, j i+1 ni ri = lambda: int(input()) lambda: int(input()) ri rl = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) rl nj = i+1, j j nj
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)
 
R, C, K = rl()
I = [[0]*(C+2) for _ in range(R+2)]
for i in range(K):
	r, c, v = rl()
	I[r][c] = v
 
dp = [[0]*4 for _ in range(C+2)]
dp2 = [[0]*4 for _ in range(C+2)]
 
for i in range(R+1):
	for j in range(C+1):
		for m in range(4):
			ni, nj = i, j+1
			dp[nj][m] = max(dp[nj][m], dp[j][m])
			if m < 3:
				dp[nj][m+1] = max(dp[nj][m+1], dp[j][m]+I[ni][nj])
			ni, nj = i+1, j
			dp2[nj][0] = max(dp2[nj][0], dp[j][m])
			dp2[nj][1] = max(dp2[nj][1], dp[j][m]+I[ni][nj])
	dp = dp2
	dp2 = [[0]*4 for _ in range(C+2)]
ans = 0
for m in range(4):
	ans = max(ans, dp[C][m])
print(ans)
