import sys
input = sys.stdin.buffer.readline

r, c, k = map(int, input().split())
v = [[0]*(c+1) for i in range(r+1)]
for i in range(k):
    cr, cc, cv = map(int, input().split())
    v[cr][cc] = cv

dp = [[0]*4 for _ in range(c+1)]
last = [[0]*4 for _ in range(c+1)]
for cr in range(1, r+1):
    for cc in range(1, c+1):
        upper = max(last[cc][0], last[cc][1], last[cc][2], last[cc][3])
        dp[cc][0] = max(upper, dp[cc-1][0], dp[cc][0])
        dp[cc][1] = max(dp[cc-1][1], dp[cc-1][0]+v[cr][cc], upper+v[cr][cc])
        dp[cc][2] = max(dp[cc-1][2], dp[cc-1][1]+v[cr][cc])
        dp[cc][3] = max(dp[cc-1][3], dp[cc-1][2]+v[cr][cc])
        last = dp
print(max(dp[c])) import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline r, c, k = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c k [0]*(c+1) for i in range(r+1) for i in range(r+1) i range(r+1) range r+1 r 1 for i in range(r+1) [0]*(c+1) [0] 0 c+1 c 1 v = [[0]*(c+1) for i in range(r+1)] v [[0]*(c+1) for i in range(r+1)] for i in range(k):
    cr, cc, cv = map(int, input().split())
    v[cr][cc] = cv i range(k) range k cr, cc, cv = map(int, input().split()) cr map(int, input().split()) map int input().split() ().split () input split cc cv v[cr][cc] = cv v[cr][cc] [cr] v cr cc cv [0]*4 for _ in range(c+1) for _ in range(c+1) _ range(c+1) range c+1 c 1 for _ in range(c+1) [0]*4 [0] 0 4 dp = [[0]*4 for _ in range(c+1)] dp [[0]*4 for _ in range(c+1)] [0]*4 for _ in range(c+1) for _ in range(c+1) _ range(c+1) range c+1 c 1 for _ in range(c+1) [0]*4 [0] 0 4 last = [[0]*4 for _ in range(c+1)] last [[0]*4 for _ in range(c+1)] for cr in range(1, r+1):
    for cc in range(1, c+1):
        upper = max(last[cc][0], last[cc][1], last[cc][2], last[cc][3])
        dp[cc][0] = max(upper, dp[cc-1][0], dp[cc][0])
        dp[cc][1] = max(dp[cc-1][1], dp[cc-1][0]+v[cr][cc], upper+v[cr][cc])
        dp[cc][2] = max(dp[cc-1][2], dp[cc-1][1]+v[cr][cc])
        dp[cc][3] = max(dp[cc-1][3], dp[cc-1][2]+v[cr][cc])
        last = dp cr range(1, r+1) range 1 r+1 r 1 for cc in range(1, c+1):
        upper = max(last[cc][0], last[cc][1], last[cc][2], last[cc][3])
        dp[cc][0] = max(upper, dp[cc-1][0], dp[cc][0])
        dp[cc][1] = max(dp[cc-1][1], dp[cc-1][0]+v[cr][cc], upper+v[cr][cc])
        dp[cc][2] = max(dp[cc-1][2], dp[cc-1][1]+v[cr][cc])
        dp[cc][3] = max(dp[cc-1][3], dp[cc-1][2]+v[cr][cc])
        last = dp cc range(1, c+1) range 1 c+1 c 1 upper = max(last[cc][0], last[cc][1], last[cc][2], last[cc][3]) upper max(last[cc][0], last[cc][1], last[cc][2], last[cc][3]) max last[cc][0] [cc] last cc 0 last[cc][1] [cc] last cc 1 last[cc][2] [cc] last cc 2 last[cc][3] [cc] last cc 3 dp[cc][0] = max(upper, dp[cc-1][0], dp[cc][0]) dp[cc][0] [cc] dp cc 0 max(upper, dp[cc-1][0], dp[cc][0]) max upper dp[cc-1][0] [cc-1] dp cc-1 cc 1 0 dp[cc][0] [cc] dp cc 0 dp[cc][1] = max(dp[cc-1][1], dp[cc-1][0]+v[cr][cc], upper+v[cr][cc]) dp[cc][1] [cc] dp cc 1 max(dp[cc-1][1], dp[cc-1][0]+v[cr][cc], upper+v[cr][cc]) max dp[cc-1][1] [cc-1] dp cc-1 cc 1 1 dp[cc-1][0]+v[cr][cc] dp[cc-1][0] [cc-1] dp cc-1 cc 1 0 v[cr][cc] [cr] v cr cc upper+v[cr][cc] upper v[cr][cc] [cr] v cr cc dp[cc][2] = max(dp[cc-1][2], dp[cc-1][1]+v[cr][cc]) dp[cc][2] [cc] dp cc 2 max(dp[cc-1][2], dp[cc-1][1]+v[cr][cc]) max dp[cc-1][2] [cc-1] dp cc-1 cc 1 2 dp[cc-1][1]+v[cr][cc] dp[cc-1][1] [cc-1] dp cc-1 cc 1 1 v[cr][cc] [cr] v cr cc dp[cc][3] = max(dp[cc-1][3], dp[cc-1][2]+v[cr][cc]) dp[cc][3] [cc] dp cc 3 max(dp[cc-1][3], dp[cc-1][2]+v[cr][cc]) max dp[cc-1][3] [cc-1] dp cc-1 cc 1 3 dp[cc-1][2]+v[cr][cc] dp[cc-1][2] [cc-1] dp cc-1 cc 1 2 v[cr][cc] [cr] v cr cc last = dp last dp print(max(dp[c])) print max(dp[c]) max dp[c] dp c last = [[0]*4 for _ in range(c+1)] [[0]*4 for _ in range(c+1)] last cv = map(int, input().split()) map(int, input().split()) cv cc, cv = map(int, input().split()) map(int, input().split()) cc v = [[0]*(c+1) for i in range(r+1)] [[0]*(c+1) for i in range(r+1)] v dp = [[0]*4 for _ in range(c+1)] [[0]*4 for _ in range(c+1)] dp upper = max(last[cc][0], last[cc][1], last[cc][2], last[cc][3]) max(last[cc][0], last[cc][1], last[cc][2], last[cc][3]) upper r, c, k = map(int, input().split()) map(int, input().split()) r cr, cc, cv = map(int, input().split()) map(int, input().split()) cr last = dp dp last k = map(int, input().split()) map(int, input().split()) k input = sys.stdin.buffer.readline sys.stdin.buffer.readline input c, k = map(int, input().split()) map(int, input().split()) c
import sys
input = sys.stdin.buffer.readline

r, c, k = map(int, input().split())
v = [[0]*(c+1) for i in range(r+1)]
for i in range(k):
    cr, cc, cv = map(int, input().split())
    v[cr][cc] = cv

dp = [[0]*4 for _ in range(c+1)]
last = [[0]*4 for _ in range(c+1)]
for cr in range(1, r+1):
    for cc in range(1, c+1):
        upper = max(last[cc][0], last[cc][1], last[cc][2], last[cc][3])
        dp[cc][0] = max(upper, dp[cc-1][0], dp[cc][0])
        dp[cc][1] = max(dp[cc-1][1], dp[cc-1][0]+v[cr][cc], upper+v[cr][cc])
        dp[cc][2] = max(dp[cc-1][2], dp[cc-1][1]+v[cr][cc])
        dp[cc][3] = max(dp[cc-1][3], dp[cc-1][2]+v[cr][cc])
        last = dp
print(max(dp[c]))