import numpy as np
from numba import jit

R, C, K = map(int, input().split())
G = np.zeros((R+1, C+1), np.int64)
for i in range(K):
    [r, c, v] = list(map(int, input().split()))
    G[r-1][c-1] = v

@jit
def main(G, R, C):
    dp = np.full((R+1, C+1, 4), -1)
    dp[0][0][0] = 0
    if G[0][0] != None: dp[0][0][1] = G[0][0]
    for r in range(R):
        for c in range(C):
            for k in range(4):
                if dp[r][c][k] == -1: continue
                if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
    return(max(dp[r][c]))

ret = main(G, R, C)
print(ret)             import numpy as np numpy from numba import jit R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K G = np.zeros((R+1, C+1), np.int64) G np.zeros((R+1, C+1), np.int64) np.zeros np zeros (R+1, C+1) R+1 R 1 C+1 C 1 np.int64 np int64 for i in range(K):
    [r, c, v] = list(map(int, input().split()))
    G[r-1][c-1] = v i range(K) range K [r, c, v] = list(map(int, input().split())) [r, c, v] r c v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split G[r-1][c-1] = v G[r-1][c-1] [r-1] G r-1 r 1 c-1 c 1 v def main(G, R, C):
    dp = np.full((R+1, C+1, 4), -1)
    dp[0][0][0] = 0
    if G[0][0] != None: dp[0][0][1] = G[0][0]
    for r in range(R):
        for c in range(C):
            for k in range(4):
                if dp[r][c][k] == -1: continue
                if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
    return(max(dp[r][c])) main dp = np.full((R+1, C+1, 4), -1) dp np.full((R+1, C+1, 4), -1) np.full np full (R+1, C+1, 4) R+1 R 1 C+1 C 1 4 -1 dp[0][0][0] = 0 dp[0][0][0] [0] [0] dp 0 0 0 0 if G[0][0] != None: dp[0][0][1] = G[0][0]
     G[0][0] != None G[0][0] [0] G 0 0 None for r in range(R):
        for c in range(C):
            for k in range(4):
                if dp[r][c][k] == -1: continue
                if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
     r range(R) range R for c in range(C):
            for k in range(4):
                if dp[r][c][k] == -1: continue
                if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
     c range(C) range C for k in range(4):
                if dp[r][c][k] == -1: continue
                if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
     k range(4) range 4 if dp[r][c][k] == -1: continue
                 dp[r][c][k] == -1 dp[r][c][k] [c] [r] dp r c k -1 if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                 k < 3 k 3 if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                 dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1] dp[r][c+1][k+1] [c+1] [r] dp r c+1 c 1 k+1 k 1 dp[r][c][k] + G[r][c+1] dp[r][c][k] [c] [r] dp r c k G[r][c+1] [r] G r c+1 c 1 dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1] dp[r][c+1][k+1] [c+1] [r] dp r c+1 c 1 k+1 k 1 dp[r][c][k] + G[r][c+1] dp[r][c][k] [c] [r] dp r c k G[r][c+1] [r] G r c+1 c 1 if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                 dp[r][c+1][k] < dp[r][c][k] dp[r][c+1][k] [c+1] [r] dp r c+1 c 1 k dp[r][c][k] [c] [r] dp r c k dp[r][c+1][k] = dp[r][c][k] dp[r][c+1][k] [c+1] [r] dp r c+1 c 1 k dp[r][c][k] [c] [r] dp r c k if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                 dp[r+1][c][0] < dp[r][c][k] dp[r+1][c][0] [c] [r+1] dp r+1 r 1 c 0 dp[r][c][k] [c] [r] dp r c k dp[r+1][c][0] = dp[r][c][k] dp[r+1][c][0] [c] [r+1] dp r+1 r 1 c 0 dp[r][c][k] [c] [r] dp r c k if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
     dp[r+1][c][1] < dp[r][c][k] + G[r+1][c] dp[r+1][c][1] [c] [r+1] dp r+1 r 1 c 1 dp[r][c][k] + G[r+1][c] dp[r][c][k] [c] [r] dp r c k G[r+1][c] [r+1] G r+1 r 1 c dp[r+1][c][1] = dp[r][c][k] + G[r+1][c] dp[r+1][c][1] [c] [r+1] dp r+1 r 1 c 1 dp[r][c][k] + G[r+1][c] dp[r][c][k] [c] [r] dp r c k G[r+1][c] [r+1] G r+1 r 1 c return(max(dp[r][c])) max(dp[r][c]) max dp[r][c] [r] dp r c G G R R C C @jit main jit main ret = main(G, R, C) ret main(G, R, C) main G R C print(ret) print ret G = np.zeros((R+1, C+1), np.int64) np.zeros((R+1, C+1), np.int64) G ret = main(G, R, C) main(G, R, C) ret def main(G, R, C):
    dp = np.full((R+1, C+1, 4), -1)
    dp[0][0][0] = 0
    if G[0][0] != None: dp[0][0][1] = G[0][0]
    for r in range(R):
        for c in range(C):
            for k in range(4):
                if dp[r][c][k] == -1: continue
                if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
    return(max(dp[r][c])) def main(G, R, C):
    dp = np.full((R+1, C+1, 4), -1)
    dp[0][0][0] = 0
    if G[0][0] != None: dp[0][0][1] = G[0][0]
    for r in range(R):
        for c in range(C):
            for k in range(4):
                if dp[r][c][k] == -1: continue
                if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
    return(max(dp[r][c])) main R, C, K = map(int, input().split()) map(int, input().split()) R K = map(int, input().split()) map(int, input().split()) K C, K = map(int, input().split()) map(int, input().split()) C
import numpy as np
from numba import jit

R, C, K = map(int, input().split())
G = np.zeros((R+1, C+1), np.int64)
for i in range(K):
    [r, c, v] = list(map(int, input().split()))
    G[r-1][c-1] = v

@jit
def main(G, R, C):
    dp = np.full((R+1, C+1, 4), -1)
    dp[0][0][0] = 0
    if G[0][0] != None: dp[0][0][1] = G[0][0]
    for r in range(R):
        for c in range(C):
            for k in range(4):
                if dp[r][c][k] == -1: continue
                if k < 3: # can go right and pick up
                    if dp[r][c+1][k+1] < dp[r][c][k] + G[r][c+1]:
                        dp[r][c+1][k+1] = dp[r][c][k] + G[r][c+1]
                if dp[r][c+1][k] < dp[r][c][k]:
                    dp[r][c+1][k] = dp[r][c][k]
                if dp[r+1][c][0] < dp[r][c][k]:
                    dp[r+1][c][0] = dp[r][c][k]
                if dp[r+1][c][1] < dp[r][c][k] + G[r+1][c]:
                    dp[r+1][c][1] = dp[r][c][k] + G[r+1][c]
    return(max(dp[r][c]))

ret = main(G, R, C)
print(ret)            
