from sys import stdin
readline = stdin.readline

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

goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, readline().split())
    goods[r - 1][c - 1] = v

dp = [0] * (C + 1)
for i in range(R):
    cur = [0] * 4
    cur[0] = dp[0]
    for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                cur[k + 1] = max(cur[k + 1], cur[k] + goods[i][j])
        dp[j] = max(cur)
        cur[0] = max(cur[0], dp[j + 1])

print(max(cur)) from sys import stdin readline = stdin.readline readline stdin.readline stdin readline R, C, K = map(int, readline().split()) R map(int, readline().split()) map int readline().split() ().split () readline 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 goods = [[0] * C for _ in range(R)] goods [[0] * C for _ in range(R)] for _ in range(K):
    r, c, v = map(int, readline().split())
    goods[r - 1][c - 1] = v _ range(K) range K r, c, v = map(int, readline().split()) r map(int, readline().split()) map int readline().split() ().split () readline split c v goods[r - 1][c - 1] = v goods[r - 1][c - 1] [r - 1] goods r - 1 r 1 c - 1 c 1 v dp = [0] * (C + 1) dp [0] * (C + 1) [0] 0 C + 1 C 1 for i in range(R):
    cur = [0] * 4
    cur[0] = dp[0]
    for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                cur[k + 1] = max(cur[k + 1], cur[k] + goods[i][j])
        dp[j] = max(cur)
        cur[0] = max(cur[0], dp[j + 1]) i range(R) range R cur = [0] * 4 cur [0] * 4 [0] 0 4 cur[0] = dp[0] cur[0] cur 0 dp[0] dp 0 for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                cur[k + 1] = max(cur[k + 1], cur[k] + goods[i][j])
        dp[j] = max(cur)
        cur[0] = max(cur[0], dp[j + 1]) j range(C) range C if goods[i][j] != 0:
            for k in range(2, -1, -1):
                cur[k + 1] = max(cur[k + 1], cur[k] + goods[i][j])
         goods[i][j] != 0 goods[i][j] [i] goods i j 0 for k in range(2, -1, -1):
                cur[k + 1] = max(cur[k + 1], cur[k] + goods[i][j])
         k range(2, -1, -1) range 2 -1 -1 cur[k + 1] = max(cur[k + 1], cur[k] + goods[i][j]) cur[k + 1] cur k + 1 k 1 max(cur[k + 1], cur[k] + goods[i][j]) max cur[k + 1] cur k + 1 k 1 cur[k] + goods[i][j] cur[k] cur k goods[i][j] [i] goods i j dp[j] = max(cur) dp[j] dp j max(cur) max cur cur[0] = max(cur[0], dp[j + 1]) cur[0] cur 0 max(cur[0], dp[j + 1]) max cur[0] cur 0 dp[j + 1] dp j + 1 j 1 print(max(cur)) print max(cur) max cur r, c, v = map(int, readline().split()) map(int, readline().split()) r c, v = map(int, readline().split()) map(int, readline().split()) c K = map(int, readline().split()) map(int, readline().split()) K v = map(int, readline().split()) map(int, readline().split()) v goods = [[0] * C for _ in range(R)] [[0] * C for _ in range(R)] goods dp = [0] * (C + 1) [0] * (C + 1) dp readline = stdin.readline stdin.readline readline cur = [0] * 4 [0] * 4 cur C, K = map(int, readline().split()) map(int, readline().split()) C R, C, K = map(int, readline().split()) map(int, readline().split()) R
from sys import stdin
readline = stdin.readline

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

goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, readline().split())
    goods[r - 1][c - 1] = v

dp = [0] * (C + 1)
for i in range(R):
    cur = [0] * 4
    cur[0] = dp[0]
    for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                cur[k + 1] = max(cur[k + 1], cur[k] + goods[i][j])
        dp[j] = max(cur)
        cur[0] = max(cur[0], dp[j + 1])

print(max(cur))
