from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,k = inpl()
value = [[0 for _ in range(m)] for i in range(n)]
for _ in range(k):
    a,b,c = inpl()
    value[a-1][b-1] = c
dp = [0] * (4*(m+1)*(n+1))
def ind(i,j,k): 
    return 4*(m+1)*i + 4*j + k
for i in range(n):
    for j in range(m):
        for k in range(3)[::-1]:
            dp[ind(i,j,k+1)] = max(dp[ind(i,j,k+1)], dp[ind(i,j,k)] + value[i][j])
        for k in range(4):
            dp[ind(i+1,j,0)] = max(dp[ind(i+1,j,0)], dp[ind(i,j,k)])
            dp[ind(i,j+1,k)] = max(dp[ind(i,j+1,k)], dp[ind(i,j,k)])
# print(dp)
mx = 0
for k in range(4):
    mx = max(mx, dp[ind(n-1,m-1,k)])
print(mx) from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys math itertools fractions pprint sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 INF = float('inf') INF float('inf') float 'inf' def inp(): return int(sys.stdin.readline()) inp def inpl(): return list(map(int, sys.stdin.readline().split())) inpl n,m,k = inpl() n inpl() inpl m k [0 for _ in range(m)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0 for _ in range(m)] value = [[0 for _ in range(m)] for i in range(n)] value [[0 for _ in range(m)] for i in range(n)] for _ in range(k):
    a,b,c = inpl()
    value[a-1][b-1] = c _ range(k) range k a,b,c = inpl() a inpl() inpl b c value[a-1][b-1] = c value[a-1][b-1] [a-1] value a-1 a 1 b-1 b 1 c dp = [0] * (4*(m+1)*(n+1)) dp [0] * (4*(m+1)*(n+1)) [0] 0 4*(m+1)*(n+1) 4*(m+1) 4 m+1 m 1 n+1 n 1 def ind(i,j,k): 
    return 4*(m+1)*i + 4*j + k ind return 4*(m+1)*i + 4*j + k 4*(m+1)*i + 4*j + k 4*(m+1)*i + 4*j 4*(m+1)*i 4*(m+1) 4 m+1 m 1 i 4*j 4 j k i i j j k k for i in range(n):
    for j in range(m):
        for k in range(3)[::-1]:
            dp[ind(i,j,k+1)] = max(dp[ind(i,j,k+1)], dp[ind(i,j,k)] + value[i][j])
        for k in range(4):
            dp[ind(i+1,j,0)] = max(dp[ind(i+1,j,0)], dp[ind(i,j,k)])
            dp[ind(i,j+1,k)] = max(dp[ind(i,j+1,k)], dp[ind(i,j,k)])
# print(dp) i range(n) range n for j in range(m):
        for k in range(3)[::-1]:
            dp[ind(i,j,k+1)] = max(dp[ind(i,j,k+1)], dp[ind(i,j,k)] + value[i][j])
        for k in range(4):
            dp[ind(i+1,j,0)] = max(dp[ind(i+1,j,0)], dp[ind(i,j,k)])
            dp[ind(i,j+1,k)] = max(dp[ind(i,j+1,k)], dp[ind(i,j,k)])
# print(dp) j range(m) range m for k in range(3)[::-1]:
            dp[ind(i,j,k+1)] = max(dp[ind(i,j,k+1)], dp[ind(i,j,k)] + value[i][j])
         k range(3)[::-1] (3) range 3 ::-1 -1 dp[ind(i,j,k+1)] = max(dp[ind(i,j,k+1)], dp[ind(i,j,k)] + value[i][j]) dp[ind(i,j,k+1)] dp ind(i,j,k+1) ind i j k+1 k 1 max(dp[ind(i,j,k+1)], dp[ind(i,j,k)] + value[i][j]) max dp[ind(i,j,k+1)] dp ind(i,j,k+1) ind i j k+1 k 1 dp[ind(i,j,k)] + value[i][j] dp[ind(i,j,k)] dp ind(i,j,k) ind i j k value[i][j] [i] value i j for k in range(4):
            dp[ind(i+1,j,0)] = max(dp[ind(i+1,j,0)], dp[ind(i,j,k)])
            dp[ind(i,j+1,k)] = max(dp[ind(i,j+1,k)], dp[ind(i,j,k)])
# print(dp) k range(4) range 4 dp[ind(i+1,j,0)] = max(dp[ind(i+1,j,0)], dp[ind(i,j,k)]) dp[ind(i+1,j,0)] dp ind(i+1,j,0) ind i+1 i 1 j 0 max(dp[ind(i+1,j,0)], dp[ind(i,j,k)]) max dp[ind(i+1,j,0)] dp ind(i+1,j,0) ind i+1 i 1 j 0 dp[ind(i,j,k)] dp ind(i,j,k) ind i j k dp[ind(i,j+1,k)] = max(dp[ind(i,j+1,k)], dp[ind(i,j,k)]) dp[ind(i,j+1,k)] dp ind(i,j+1,k) ind i j+1 j 1 k max(dp[ind(i,j+1,k)], dp[ind(i,j,k)]) max dp[ind(i,j+1,k)] dp ind(i,j+1,k) ind i j+1 j 1 k dp[ind(i,j,k)] dp ind(i,j,k) ind i j k mx = 0 mx 0 for k in range(4):
    mx = max(mx, dp[ind(n-1,m-1,k)]) k range(4) range 4 mx = max(mx, dp[ind(n-1,m-1,k)]) mx max(mx, dp[ind(n-1,m-1,k)]) max mx dp[ind(n-1,m-1,k)] dp ind(n-1,m-1,k) ind n-1 n 1 m-1 m 1 k print(mx) print mx dp = [0] * (4*(m+1)*(n+1)) [0] * (4*(m+1)*(n+1)) dp mx = max(mx, dp[ind(n-1,m-1,k)]) max(mx, dp[ind(n-1,m-1,k)]) mx value = [[0 for _ in range(m)] for i in range(n)] [[0 for _ in range(m)] for i in range(n)] value m,k = inpl() inpl() m a,b,c = inpl() inpl() a INF = float('inf') float('inf') INF n,m,k = inpl() inpl() n b,c = inpl() inpl() b def ind(i,j,k): 
    return 4*(m+1)*i + 4*j + k def ind(i,j,k): 
    return 4*(m+1)*i + 4*j + k ind mx = 0 0 mx def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl(): return list(map(int, sys.stdin.readline().split())) inpl k = inpl() inpl() k def inp(): return int(sys.stdin.readline()) def inp(): return int(sys.stdin.readline()) inp c = inpl() inpl() c mod = 10**9+7 10**9+7 mod
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,k = inpl()
value = [[0 for _ in range(m)] for i in range(n)]
for _ in range(k):
    a,b,c = inpl()
    value[a-1][b-1] = c
dp = [0] * (4*(m+1)*(n+1))
def ind(i,j,k): 
    return 4*(m+1)*i + 4*j + k
for i in range(n):
    for j in range(m):
        for k in range(3)[::-1]:
            dp[ind(i,j,k+1)] = max(dp[ind(i,j,k+1)], dp[ind(i,j,k)] + value[i][j])
        for k in range(4):
            dp[ind(i+1,j,0)] = max(dp[ind(i+1,j,0)], dp[ind(i,j,k)])
            dp[ind(i,j+1,k)] = max(dp[ind(i,j+1,k)], dp[ind(i,j,k)])
# print(dp)
mx = 0
for k in range(4):
    mx = max(mx, dp[ind(n-1,m-1,k)])
print(mx)