import sys
input = sys.stdin.buffer.readline

R, C, K = map(int, input().split())
G = [[None for j in range(C)] for i in range(R)]

for _ in range(K):
    r, c, v = map(int, input().split())
    G[r - 1][c - 1] = v

dp = [[0, 0, 0, 0] for _ in range(C)]

for i in range(R):
    for j in range(C):
        if G[i][j] is not None:
            dp[j][0], dp[j][1] = max(dp[j]), max(dp[j]) + G[i][j]
            dp[j][2], dp[j][3] = 0, 0
        else:
            dp[j][0] = max(dp[j])
            dp[j][1], dp[j][2], dp[j][3] = 0, 0, 0
    for j in range(1, C):
        if G[i][j] is not None:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1])
            if dp[j - 1][1] != 0:
                dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2])
            if dp[j - 1][2] != 0:
                dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3])
        else:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j][1])
            dp[j][2] = max(dp[j - 1][2], dp[j][2])
            dp[j][3] = max(dp[j - 1][3], dp[j][3])

print(max(dp[-1])) 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 [None for j in range(C)] for i in range(R) for i in range(R) i range(R) range R for i in range(R) [None for j in range(C)] G = [[None for j in range(C)] for i in range(R)] G [[None for j in range(C)] for i in range(R)] for _ in range(K):
    r, c, v = map(int, input().split())
    G[r - 1][c - 1] = v _ 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 G[r - 1][c - 1] = v G[r - 1][c - 1] [r - 1] G r - 1 r 1 c - 1 c 1 v [0, 0, 0, 0] for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0, 0, 0, 0] 0 0 0 0 dp = [[0, 0, 0, 0] for _ in range(C)] dp [[0, 0, 0, 0] for _ in range(C)] for i in range(R):
    for j in range(C):
        if G[i][j] is not None:
            dp[j][0], dp[j][1] = max(dp[j]), max(dp[j]) + G[i][j]
            dp[j][2], dp[j][3] = 0, 0
        else:
            dp[j][0] = max(dp[j])
            dp[j][1], dp[j][2], dp[j][3] = 0, 0, 0
    for j in range(1, C):
        if G[i][j] is not None:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1])
            if dp[j - 1][1] != 0:
                dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2])
            if dp[j - 1][2] != 0:
                dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3])
        else:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j][1])
            dp[j][2] = max(dp[j - 1][2], dp[j][2])
            dp[j][3] = max(dp[j - 1][3], dp[j][3]) i range(R) range R for j in range(C):
        if G[i][j] is not None:
            dp[j][0], dp[j][1] = max(dp[j]), max(dp[j]) + G[i][j]
            dp[j][2], dp[j][3] = 0, 0
        else:
            dp[j][0] = max(dp[j])
            dp[j][1], dp[j][2], dp[j][3] = 0, 0, 0
     j range(C) range C if G[i][j] is not None:
            dp[j][0], dp[j][1] = max(dp[j]), max(dp[j]) + G[i][j]
            dp[j][2], dp[j][3] = 0, 0
        else:
            dp[j][0] = max(dp[j])
            dp[j][1], dp[j][2], dp[j][3] = 0, 0, 0
     G[i][j] is not None G[i][j] [i] G i j None dp[j][0], dp[j][1] = max(dp[j]), max(dp[j]) + G[i][j] dp[j][0] [j] dp j 0 max(dp[j]) max dp[j] dp j dp[j][1] [j] dp j 1 max(dp[j]) + G[i][j] max(dp[j]) max dp[j] dp j G[i][j] [i] G i j dp[j][2], dp[j][3] = 0, 0 dp[j][2] [j] dp j 2 0 dp[j][3] [j] dp j 3 0 dp[j][0] = max(dp[j]) dp[j][0] [j] dp j 0 max(dp[j]) max dp[j] dp j dp[j][1], dp[j][2], dp[j][3] = 0, 0, 0 dp[j][1] [j] dp j 1 0 dp[j][2] [j] dp j 2 0 dp[j][3] [j] dp j 3 0 for j in range(1, C):
        if G[i][j] is not None:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1])
            if dp[j - 1][1] != 0:
                dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2])
            if dp[j - 1][2] != 0:
                dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3])
        else:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j][1])
            dp[j][2] = max(dp[j - 1][2], dp[j][2])
            dp[j][3] = max(dp[j - 1][3], dp[j][3]) j range(1, C) range 1 C if G[i][j] is not None:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1])
            if dp[j - 1][1] != 0:
                dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2])
            if dp[j - 1][2] != 0:
                dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3])
        else:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j][1])
            dp[j][2] = max(dp[j - 1][2], dp[j][2])
            dp[j][3] = max(dp[j - 1][3], dp[j][3]) G[i][j] is not None G[i][j] [i] G i j None dp[j][0] = max(dp[j - 1][0], dp[j][0]) dp[j][0] [j] dp j 0 max(dp[j - 1][0], dp[j][0]) max dp[j - 1][0] [j - 1] dp j - 1 j 1 0 dp[j][0] [j] dp j 0 dp[j][1] = max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1]) dp[j][1] [j] dp j 1 max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1]) max dp[j - 1][1] [j - 1] dp j - 1 j 1 1 dp[j - 1][0] + G[i][j] dp[j - 1][0] [j - 1] dp j - 1 j 1 0 G[i][j] [i] G i j dp[j][1] [j] dp j 1 if dp[j - 1][1] != 0:
                dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2])
             dp[j - 1][1] != 0 dp[j - 1][1] [j - 1] dp j - 1 j 1 1 0 dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2]) dp[j][2] [j] dp j 2 max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2]) max dp[j - 1][2] [j - 1] dp j - 1 j 1 2 dp[j - 1][1] + G[i][j] dp[j - 1][1] [j - 1] dp j - 1 j 1 1 G[i][j] [i] G i j dp[j][2] [j] dp j 2 if dp[j - 1][2] != 0:
                dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3])
         dp[j - 1][2] != 0 dp[j - 1][2] [j - 1] dp j - 1 j 1 2 0 dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3]) dp[j][3] [j] dp j 3 max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3]) max dp[j - 1][3] [j - 1] dp j - 1 j 1 3 dp[j - 1][2] + G[i][j] dp[j - 1][2] [j - 1] dp j - 1 j 1 2 G[i][j] [i] G i j dp[j][3] [j] dp j 3 dp[j][0] = max(dp[j - 1][0], dp[j][0]) dp[j][0] [j] dp j 0 max(dp[j - 1][0], dp[j][0]) max dp[j - 1][0] [j - 1] dp j - 1 j 1 0 dp[j][0] [j] dp j 0 dp[j][1] = max(dp[j - 1][1], dp[j][1]) dp[j][1] [j] dp j 1 max(dp[j - 1][1], dp[j][1]) max dp[j - 1][1] [j - 1] dp j - 1 j 1 1 dp[j][1] [j] dp j 1 dp[j][2] = max(dp[j - 1][2], dp[j][2]) dp[j][2] [j] dp j 2 max(dp[j - 1][2], dp[j][2]) max dp[j - 1][2] [j - 1] dp j - 1 j 1 2 dp[j][2] [j] dp j 2 dp[j][3] = max(dp[j - 1][3], dp[j][3]) dp[j][3] [j] dp j 3 max(dp[j - 1][3], dp[j][3]) max dp[j - 1][3] [j - 1] dp j - 1 j 1 3 dp[j][3] [j] dp j 3 print(max(dp[-1])) print max(dp[-1]) max dp[-1] dp -1 r, c, v = map(int, input().split()) map(int, input().split()) r v = map(int, input().split()) map(int, input().split()) v G = [[None for j in range(C)] for i in range(R)] [[None for j in range(C)] for i in range(R)] G C, K = map(int, input().split()) map(int, input().split()) C dp = [[0, 0, 0, 0] for _ in range(C)] [[0, 0, 0, 0] for _ in range(C)] dp c, v = map(int, input().split()) map(int, input().split()) c R, C, K = map(int, input().split()) map(int, input().split()) R K = map(int, input().split()) map(int, input().split()) K input = sys.stdin.buffer.readline sys.stdin.buffer.readline input
import sys
input = sys.stdin.buffer.readline

R, C, K = map(int, input().split())
G = [[None for j in range(C)] for i in range(R)]

for _ in range(K):
    r, c, v = map(int, input().split())
    G[r - 1][c - 1] = v

dp = [[0, 0, 0, 0] for _ in range(C)]

for i in range(R):
    for j in range(C):
        if G[i][j] is not None:
            dp[j][0], dp[j][1] = max(dp[j]), max(dp[j]) + G[i][j]
            dp[j][2], dp[j][3] = 0, 0
        else:
            dp[j][0] = max(dp[j])
            dp[j][1], dp[j][2], dp[j][3] = 0, 0, 0
    for j in range(1, C):
        if G[i][j] is not None:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j - 1][0] + G[i][j], dp[j][1])
            if dp[j - 1][1] != 0:
                dp[j][2] = max(dp[j - 1][2], dp[j - 1][1] + G[i][j], dp[j][2])
            if dp[j - 1][2] != 0:
                dp[j][3] = max(dp[j - 1][3], dp[j - 1][2] + G[i][j], dp[j][3])
        else:
            dp[j][0] = max(dp[j - 1][0], dp[j][0])
            dp[j][1] = max(dp[j - 1][1], dp[j][1])
            dp[j][2] = max(dp[j - 1][2], dp[j][2])
            dp[j][3] = max(dp[j - 1][3], dp[j][3])

print(max(dp[-1]))