import sys
input = sys.stdin.readline

r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]

for i in range(k):
    rr, cc, vv = map(int, input().split())
    rr, cc = rr - 1, cc - 1
    v[rr][cc] = vv

dp = [[0 for _ in range(c + 1)] for _ in range(4)]
for y in range(r):
    tmp = [[0 for _ in range(c + 1)] for _ in range(4)]
    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])
        for i in range(4):
            tmp[0][x] = max(tmp[0][x], dp[i][x])
            dp[i][x + 1] = max(dp[i][x + 1], dp[i][x])
    dp = tmp
print(dp[0][c - 1]) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline r, c, k = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c k [0 for _ in range(c)] for _ in range(r) for _ in range(r) _ range(r) range r for _ in range(r) [0 for _ in range(c)] v = [[0 for _ in range(c)] for _ in range(r)] v [[0 for _ in range(c)] for _ in range(r)] for i in range(k):
    rr, cc, vv = map(int, input().split())
    rr, cc = rr - 1, cc - 1
    v[rr][cc] = vv i range(k) range k rr, cc, vv = map(int, input().split()) rr map(int, input().split()) map int input().split() ().split () input split cc vv rr, cc = rr - 1, cc - 1 rr rr - 1 rr 1 cc cc - 1 cc 1 v[rr][cc] = vv v[rr][cc] [rr] v rr cc vv [0 for _ in range(c + 1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [0 for _ in range(c + 1)] dp = [[0 for _ in range(c + 1)] for _ in range(4)] dp [[0 for _ in range(c + 1)] for _ in range(4)] for y in range(r):
    tmp = [[0 for _ in range(c + 1)] for _ in range(4)]
    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])
        for i in range(4):
            tmp[0][x] = max(tmp[0][x], dp[i][x])
            dp[i][x + 1] = max(dp[i][x + 1], dp[i][x])
    dp = tmp y range(r) range r [0 for _ in range(c + 1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [0 for _ in range(c + 1)] tmp = [[0 for _ in range(c + 1)] for _ in range(4)] tmp [[0 for _ in range(c + 1)] for _ in range(4)] 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])
        for i in range(4):
            tmp[0][x] = max(tmp[0][x], dp[i][x])
            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 for i in range(4):
            tmp[0][x] = max(tmp[0][x], dp[i][x])
            dp[i][x + 1] = max(dp[i][x + 1], dp[i][x])
     i range(4) range 4 tmp[0][x] = max(tmp[0][x], dp[i][x]) tmp[0][x] [0] tmp 0 x max(tmp[0][x], dp[i][x]) max tmp[0][x] [0] tmp 0 x dp[i][x] [i] dp i x 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 dp = tmp dp tmp print(dp[0][c - 1]) print dp[0][c - 1] [0] dp 0 c - 1 c 1 r, c, k = map(int, input().split()) map(int, input().split()) r vv = map(int, input().split()) map(int, input().split()) vv v = [[0 for _ in range(c)] for _ in range(r)] [[0 for _ in range(c)] for _ in range(r)] v input = sys.stdin.readline sys.stdin.readline input dp = [[0 for _ in range(c + 1)] for _ in range(4)] [[0 for _ in range(c + 1)] for _ in range(4)] dp rr, cc, vv = map(int, input().split()) map(int, input().split()) rr dp = tmp tmp dp tmp = [[0 for _ in range(c + 1)] for _ in range(4)] [[0 for _ in range(c + 1)] for _ in range(4)] tmp rr, cc = rr - 1, cc - 1 rr - 1 rr cc, vv = map(int, input().split()) map(int, input().split()) cc c, k = map(int, input().split()) map(int, input().split()) c k = map(int, input().split()) map(int, input().split()) k cc = rr - 1, cc - 1 cc - 1 cc
import sys
input = sys.stdin.readline

r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]

for i in range(k):
    rr, cc, vv = map(int, input().split())
    rr, cc = rr - 1, cc - 1
    v[rr][cc] = vv

dp = [[0 for _ in range(c + 1)] for _ in range(4)]
for y in range(r):
    tmp = [[0 for _ in range(c + 1)] for _ in range(4)]
    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])
        for i in range(4):
            tmp[0][x] = max(tmp[0][x], dp[i][x])
            dp[i][x + 1] = max(dp[i][x + 1], dp[i][x])
    dp = tmp
print(dp[0][c - 1])
