import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9+7

R,C,K = map(int,input().split())

item = [[0]*C for _ in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    item[r-1][c-1] = v
#print(item)

dp = [[0]*4 for _ in range(C)]
preview = [[0]*4 for _ in range(C)]

for i in range(R):
    for j in range(C):
        for k in range(1,4):
            #print(i,j,k)
            if k == 1:
                if i != 0:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j], max(preview[j]) + item[i][j])
                else:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j])


            else:
                if j != 0:
                    dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                else:
                    dp[j][k] = max(0, 0 + item[i][j])

            #print(dp)
    preview = dp
print(max(dp[C-1])) import bisect bisect import collections collections import copy copy import functools functools import heapq heapq import math math import sys sys from collections import deque from collections import defaultdict input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 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 item = [[0]*C for _ in range(R)] item [[0]*C for _ in range(R)] for i in range(K):
    r,c,v = map(int,input().split())
    item[r-1][c-1] = v
#print(item) 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 item[r-1][c-1] = v item[r-1][c-1] [r-1] item r-1 r 1 c-1 c 1 v [0]*4 for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0]*4 [0] 0 4 dp = [[0]*4 for _ in range(C)] dp [[0]*4 for _ in range(C)] [0]*4 for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0]*4 [0] 0 4 preview = [[0]*4 for _ in range(C)] preview [[0]*4 for _ in range(C)] for i in range(R):
    for j in range(C):
        for k in range(1,4):
            #print(i,j,k)
            if k == 1:
                if i != 0:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j], max(preview[j]) + item[i][j])
                else:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j])


            else:
                if j != 0:
                    dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                else:
                    dp[j][k] = max(0, 0 + item[i][j])

            #print(dp)
    preview = dp i range(R) range R for j in range(C):
        for k in range(1,4):
            #print(i,j,k)
            if k == 1:
                if i != 0:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j], max(preview[j]) + item[i][j])
                else:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j])


            else:
                if j != 0:
                    dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                else:
                    dp[j][k] = max(0, 0 + item[i][j])

            #print(dp)
     j range(C) range C for k in range(1,4):
            #print(i,j,k)
            if k == 1:
                if i != 0:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j], max(preview[j]) + item[i][j])
                else:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j])


            else:
                if j != 0:
                    dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                else:
                    dp[j][k] = max(0, 0 + item[i][j])

            #print(dp)
     k range(1,4) range 1 4 if k == 1:
                if i != 0:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j], max(preview[j]) + item[i][j])
                else:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j])


            else:
                if j != 0:
                    dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                else:
                    dp[j][k] = max(0, 0 + item[i][j])

            #print(dp)
     k == 1 k 1 if i != 0:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j], max(preview[j]) + item[i][j])
                else:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j])


             i != 0 i 0 if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j], max(preview[j]) + item[i][j])
                 j != 0 j 0 dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j]) dp[j][k] [j] dp j k max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j]) max dp[j-1][k] [j-1] dp j-1 j 1 k dp[j-1][k-1] + item[i][j] dp[j-1][k-1] [j-1] dp j-1 j 1 k-1 k 1 item[i][j] [i] item i j max(preview[j]) + item[i][j] max(preview[j]) max preview[j] preview j item[i][j] [i] item i j dp[j][k] = max(0, 0 + item[i][j], max(preview[j]) + item[i][j]) dp[j][k] [j] dp j k max(0, 0 + item[i][j], max(preview[j]) + item[i][j]) max 0 0 + item[i][j] 0 item[i][j] [i] item i j max(preview[j]) + item[i][j] max(preview[j]) max preview[j] preview j item[i][j] [i] item i j if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j])


             j != 0 j 0 dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j]) dp[j][k] [j] dp j k max(dp[j-1][k], dp[j-1][k-1] + item[i][j]) max dp[j-1][k] [j-1] dp j-1 j 1 k dp[j-1][k-1] + item[i][j] dp[j-1][k-1] [j-1] dp j-1 j 1 k-1 k 1 item[i][j] [i] item i j dp[j][k] = max(0, 0 + item[i][j]) dp[j][k] [j] dp j k max(0, 0 + item[i][j]) max 0 0 + item[i][j] 0 item[i][j] [i] item i j if j != 0:
                    dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                else:
                    dp[j][k] = max(0, 0 + item[i][j])

            #print(dp)
     j != 0 j 0 dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j]) dp[j][k] [j] dp j k max(dp[j-1][k], dp[j-1][k-1] + item[i][j]) max dp[j-1][k] [j-1] dp j-1 j 1 k dp[j-1][k-1] + item[i][j] dp[j-1][k-1] [j-1] dp j-1 j 1 k-1 k 1 item[i][j] [i] item i j dp[j][k] = max(0, 0 + item[i][j]) dp[j][k] [j] dp j k max(0, 0 + item[i][j]) max 0 0 + item[i][j] 0 item[i][j] [i] item i j preview = dp preview dp print(max(dp[C-1])) print max(dp[C-1]) max dp[C-1] dp C-1 C 1 item = [[0]*C for _ in range(R)] [[0]*C for _ in range(R)] item preview = dp dp preview MOD = 10**9+7 10**9+7 MOD C,K = map(int,input().split()) map(int,input().split()) C v = map(int,input().split()) map(int,input().split()) v K = map(int,input().split()) map(int,input().split()) K r,c,v = map(int,input().split()) map(int,input().split()) r c,v = map(int,input().split()) map(int,input().split()) c dp = [[0]*4 for _ in range(C)] [[0]*4 for _ in range(C)] dp R,C,K = map(int,input().split()) map(int,input().split()) R preview = [[0]*4 for _ in range(C)] [[0]*4 for _ in range(C)] preview input = sys.stdin.readline sys.stdin.readline input
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9+7

R,C,K = map(int,input().split())

item = [[0]*C for _ in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    item[r-1][c-1] = v
#print(item)

dp = [[0]*4 for _ in range(C)]
preview = [[0]*4 for _ in range(C)]

for i in range(R):
    for j in range(C):
        for k in range(1,4):
            #print(i,j,k)
            if k == 1:
                if i != 0:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j], max(preview[j]) + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j], max(preview[j]) + item[i][j])
                else:
                    if j != 0:
                        dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                    else:
                        dp[j][k] = max(0, 0 + item[i][j])


            else:
                if j != 0:
                    dp[j][k] = max(dp[j-1][k], dp[j-1][k-1] + item[i][j])
                else:
                    dp[j][k] = max(0, 0 + item[i][j])

            #print(dp)
    preview = dp
print(max(dp[C-1]))