# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

R, C, K = map(int, readline().split())
data = [[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r,c,k = map(int,readline().split())
    data[r][c] = k
    
dp = [0]*(C+1)

for i in range(1,R+1):
    di = data[i]
    ndp = [0]*(C+1)
    kdp = [0]*4
    for j in range(1,C+1):
        kdp[0] = max(kdp[0],dp[j])
        for k in range(2,-1,-1):
            kdp[k+1] = max(kdp[k+1],kdp[k]+di[j])
        ndp[j] = max(kdp)
    dp = ndp
print(dp[C]) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines R, C, K = map(int, readline().split()) R map(int, readline().split()) map int readline().split() ().split () readline split C K [0]*(C+1) for _ in range(R+1) for _ in range(R+1) _ range(R+1) range R+1 R 1 for _ in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 data = [[0]*(C+1) for _ in range(R+1)] data [[0]*(C+1) for _ in range(R+1)] for _ in range(K):
    r,c,k = map(int,readline().split())
    data[r][c] = k
     _ range(K) range K r,c,k = map(int,readline().split()) r map(int,readline().split()) map int readline().split() ().split () readline split c k data[r][c] = k data[r][c] [r] data r c k dp = [0]*(C+1) dp [0]*(C+1) [0] 0 C+1 C 1 for i in range(1,R+1):
    di = data[i]
    ndp = [0]*(C+1)
    kdp = [0]*4
    for j in range(1,C+1):
        kdp[0] = max(kdp[0],dp[j])
        for k in range(2,-1,-1):
            kdp[k+1] = max(kdp[k+1],kdp[k]+di[j])
        ndp[j] = max(kdp)
    dp = ndp i range(1,R+1) range 1 R+1 R 1 di = data[i] di data[i] data i ndp = [0]*(C+1) ndp [0]*(C+1) [0] 0 C+1 C 1 kdp = [0]*4 kdp [0]*4 [0] 0 4 for j in range(1,C+1):
        kdp[0] = max(kdp[0],dp[j])
        for k in range(2,-1,-1):
            kdp[k+1] = max(kdp[k+1],kdp[k]+di[j])
        ndp[j] = max(kdp)
     j range(1,C+1) range 1 C+1 C 1 kdp[0] = max(kdp[0],dp[j]) kdp[0] kdp 0 max(kdp[0],dp[j]) max kdp[0] kdp 0 dp[j] dp j for k in range(2,-1,-1):
            kdp[k+1] = max(kdp[k+1],kdp[k]+di[j])
         k range(2,-1,-1) range 2 -1 -1 kdp[k+1] = max(kdp[k+1],kdp[k]+di[j]) kdp[k+1] kdp k+1 k 1 max(kdp[k+1],kdp[k]+di[j]) max kdp[k+1] kdp k+1 k 1 kdp[k]+di[j] kdp[k] kdp k di[j] di j ndp[j] = max(kdp) ndp[j] ndp j max(kdp) max kdp dp = ndp dp ndp print(dp[C]) print dp[C] dp C k = map(int,readline().split()) map(int,readline().split()) k read = sys.stdin.buffer.read sys.stdin.buffer.read read dp = [0]*(C+1) [0]*(C+1) dp C, K = map(int, readline().split()) map(int, readline().split()) C c,k = map(int,readline().split()) map(int,readline().split()) c readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline dp = ndp ndp dp kdp = [0]*4 [0]*4 kdp r,c,k = map(int,readline().split()) map(int,readline().split()) r readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines data = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] data K = map(int, readline().split()) map(int, readline().split()) K di = data[i] data[i] di ndp = [0]*(C+1) [0]*(C+1) ndp R, C, K = map(int, readline().split()) map(int, readline().split()) R
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

R, C, K = map(int, readline().split())
data = [[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r,c,k = map(int,readline().split())
    data[r][c] = k
    
dp = [0]*(C+1)

for i in range(1,R+1):
    di = data[i]
    ndp = [0]*(C+1)
    kdp = [0]*4
    for j in range(1,C+1):
        kdp[0] = max(kdp[0],dp[j])
        for k in range(2,-1,-1):
            kdp[k+1] = max(kdp[k+1],kdp[k]+di[j])
        ndp[j] = max(kdp)
    dp = ndp
print(dp[C])