import sys
input = lambda: sys.stdin.readline().rstrip()
r, c, k = map(int, input().split())
pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)]

for i in range(k):
    r1, c1, v = map(int, input().split())
    pt[r1][c1] = v

memo = [[0] * 4 for _ in range(c + 1)]
prev = [[0] * 4 for _ in range(c + 1)]
for i in range(1, r + 1):
    memo, prev = prev, memo
    for j in range(1, c + 1):
        V = pt[i][j]
        memo[j][0] = max(prev[j][3], memo[j - 1][0])
        memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
        memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
        memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])
print(memo[-1][3]) import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip 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 + 5)] for _ in range(r + 5) for _ in range(r + 5) _ range(r + 5) range r + 5 r 5 for _ in range(r + 5) [0 for _ in range(c + 5)] pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)] pt [[0 for _ in range(c + 5)] for _ in range(r + 5)] for i in range(k):
    r1, c1, v = map(int, input().split())
    pt[r1][c1] = v i range(k) range k r1, c1, v = map(int, input().split()) r1 map(int, input().split()) map int input().split() ().split () input split c1 v pt[r1][c1] = v pt[r1][c1] [r1] pt r1 c1 v [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 memo = [[0] * 4 for _ in range(c + 1)] memo [[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 prev = [[0] * 4 for _ in range(c + 1)] prev [[0] * 4 for _ in range(c + 1)] for i in range(1, r + 1):
    memo, prev = prev, memo
    for j in range(1, c + 1):
        V = pt[i][j]
        memo[j][0] = max(prev[j][3], memo[j - 1][0])
        memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
        memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
        memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3]) i range(1, r + 1) range 1 r + 1 r 1 memo, prev = prev, memo memo prev prev memo for j in range(1, c + 1):
        V = pt[i][j]
        memo[j][0] = max(prev[j][3], memo[j - 1][0])
        memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
        memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
        memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3]) j range(1, c + 1) range 1 c + 1 c 1 V = pt[i][j] V pt[i][j] [i] pt i j memo[j][0] = max(prev[j][3], memo[j - 1][0]) memo[j][0] [j] memo j 0 max(prev[j][3], memo[j - 1][0]) max prev[j][3] [j] prev j 3 memo[j - 1][0] [j - 1] memo j - 1 j 1 0 memo[j][1] = max(memo[j][0] + V, memo[j - 1][1]) memo[j][1] [j] memo j 1 max(memo[j][0] + V, memo[j - 1][1]) max memo[j][0] + V memo[j][0] [j] memo j 0 V memo[j - 1][1] [j - 1] memo j - 1 j 1 1 memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2]) memo[j][2] [j] memo j 2 max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2]) max memo[j][1] [j] memo j 1 memo[j - 1][1] + V memo[j - 1][1] [j - 1] memo j - 1 j 1 1 V memo[j - 1][2] [j - 1] memo j - 1 j 1 2 memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3]) memo[j][3] [j] memo j 3 max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3]) max memo[j][2] [j] memo j 2 memo[j - 1][2] + V memo[j - 1][2] [j - 1] memo j - 1 j 1 2 V memo[j - 1][3] [j - 1] memo j - 1 j 1 3 print(memo[-1][3]) print memo[-1][3] [-1] memo -1 3 memo, prev = prev, memo prev memo V = pt[i][j] pt[i][j] V input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input r1, c1, v = map(int, input().split()) map(int, input().split()) r1 prev = [[0] * 4 for _ in range(c + 1)] [[0] * 4 for _ in range(c + 1)] prev memo = [[0] * 4 for _ in range(c + 1)] [[0] * 4 for _ in range(c + 1)] memo r, c, k = map(int, input().split()) map(int, input().split()) r v = map(int, input().split()) map(int, input().split()) v pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)] [[0 for _ in range(c + 5)] for _ in range(r + 5)] pt k = map(int, input().split()) map(int, input().split()) k c1, v = map(int, input().split()) map(int, input().split()) c1 prev = prev, memo memo prev c, k = map(int, input().split()) map(int, input().split()) c
import sys
input = lambda: sys.stdin.readline().rstrip()
r, c, k = map(int, input().split())
pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)]

for i in range(k):
    r1, c1, v = map(int, input().split())
    pt[r1][c1] = v

memo = [[0] * 4 for _ in range(c + 1)]
prev = [[0] * 4 for _ in range(c + 1)]
for i in range(1, r + 1):
    memo, prev = prev, memo
    for j in range(1, c + 1):
        V = pt[i][j]
        memo[j][0] = max(prev[j][3], memo[j - 1][0])
        memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
        memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
        memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])
print(memo[-1][3])
