import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

@njit((i8, i8, i8, i8[:]), cache=True)
def solve(R,C,K,XYV):
  item = np.zeros((R + 1, C + 1), dtype=np.int64)
  for i in range(0, 3 * K, 3):
    x, y, v = XYV[i:i + 3]
    item[x - 1, y - 1] = v
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(R):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      for k in range(4):
        new_dp[j,k] = np.maximum(new_dp[j,k],new_dp[j-1,k])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1])
  ans = dp[-1].max()
  return ans

R, C, K = map(int, readline().split())
XYV = np.array(read().split(), np.int64)
print(solve(R,C,K,XYV)) import sys sys import numpy as np numpy import numba numba from numba import njit, b1, i4, i8, f8 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 def solve(R,C,K,XYV):
  item = np.zeros((R + 1, C + 1), dtype=np.int64)
  for i in range(0, 3 * K, 3):
    x, y, v = XYV[i:i + 3]
    item[x - 1, y - 1] = v
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(R):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      for k in range(4):
        new_dp[j,k] = np.maximum(new_dp[j,k],new_dp[j-1,k])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1])
  ans = dp[-1].max()
  return ans solve item = np.zeros((R + 1, C + 1), dtype=np.int64) item np.zeros((R + 1, C + 1), dtype=np.int64) np.zeros np zeros (R + 1, C + 1) R + 1 R 1 C + 1 C 1 dtype=np.int64 dtype np.int64 np int64 for i in range(0, 3 * K, 3):
    x, y, v = XYV[i:i + 3]
    item[x - 1, y - 1] = v
   i range(0, 3 * K, 3) range 0 3 * K 3 K 3 x, y, v = XYV[i:i + 3] x XYV[i:i + 3] XYV i:i + 3 i i + 3 i 3 y v item[x - 1, y - 1] = v item[x - 1, y - 1] item x - 1 x 1 v dp = np.zeros((C+1,4), dtype=np.int64) dp np.zeros((C+1,4), dtype=np.int64) np.zeros np zeros (C+1,4) C+1 C 1 4 dtype=np.int64 dtype np.int64 np int64 for i in range(R):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      for k in range(4):
        new_dp[j,k] = np.maximum(new_dp[j,k],new_dp[j-1,k])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1])
   i range(R) range R new_dp = np.zeros((C+1,4), dtype=np.int64) new_dp np.zeros((C+1,4), dtype=np.int64) np.zeros np zeros (C+1,4) C+1 C 1 4 dtype=np.int64 dtype np.int64 np int64 for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
     k range(4) range 4 new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k]) new_dp[:,0] new_dp : np.maximum(new_dp[:,0], dp[:,k]) np.maximum np maximum new_dp[:,0] new_dp : dp[:,k] dp : dp = new_dp dp new_dp for j in range(1,C+1):
      #横から移動
      for k in range(4):
        new_dp[j,k] = np.maximum(new_dp[j,k],new_dp[j-1,k])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1])
   j range(1,C+1) range 1 C+1 C 1 for k in range(4):
        new_dp[j,k] = np.maximum(new_dp[j,k],new_dp[j-1,k])
      #アイテムを取る
       k range(4) range 4 new_dp[j,k] = np.maximum(new_dp[j,k],new_dp[j-1,k]) new_dp[j,k] new_dp j np.maximum(new_dp[j,k],new_dp[j-1,k]) np.maximum np maximum new_dp[j,k] new_dp j new_dp[j-1,k] new_dp j-1 j 1 for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1])
   k range(2,-1,-1) range 2 -1 -1 dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1]) dp[j,k+1] dp j np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1]) np.maximum np maximum dp[j,k+1] dp j dp[j,k]+item[i,j-1] dp[j,k] dp j item[i,j-1] item i ans = dp[-1].max() ans dp[-1].max() [-1].max [-1] dp -1 max return ans ans R R C C K K XYV XYV @njit((i8, i8, i8, i8[:]), cache=True) solve (i8, i8, i8, i8[:]), cache=True @njit((i8, i8, i8, i8[:]), cache=True) njit (i8, i8, i8, i8[:]) i8 i8 i8 i8[:] i8 : cache=True cache True solve R, C, K = map(int, readline().split()) R map(int, readline().split()) map int readline().split() ().split () readline split C K XYV = np.array(read().split(), np.int64) XYV np.array(read().split(), np.int64) np.array np array read().split() ().split () read split np.int64 np int64 print(solve(R,C,K,XYV)) print solve(R,C,K,XYV) solve R C K XYV read = sys.stdin.buffer.read sys.stdin.buffer.read read XYV = np.array(read().split(), np.int64) np.array(read().split(), np.int64) XYV R, C, K = map(int, readline().split()) map(int, readline().split()) R K = map(int, readline().split()) map(int, readline().split()) K def solve(R,C,K,XYV):
  item = np.zeros((R + 1, C + 1), dtype=np.int64)
  for i in range(0, 3 * K, 3):
    x, y, v = XYV[i:i + 3]
    item[x - 1, y - 1] = v
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(R):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      for k in range(4):
        new_dp[j,k] = np.maximum(new_dp[j,k],new_dp[j-1,k])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1])
  ans = dp[-1].max()
  return ans def solve(R,C,K,XYV):
  item = np.zeros((R + 1, C + 1), dtype=np.int64)
  for i in range(0, 3 * K, 3):
    x, y, v = XYV[i:i + 3]
    item[x - 1, y - 1] = v
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(R):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      for k in range(4):
        new_dp[j,k] = np.maximum(new_dp[j,k],new_dp[j-1,k])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1])
  ans = dp[-1].max()
  return ans solve C, K = map(int, readline().split()) map(int, readline().split()) C readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

@njit((i8, i8, i8, i8[:]), cache=True)
def solve(R,C,K,XYV):
  item = np.zeros((R + 1, C + 1), dtype=np.int64)
  for i in range(0, 3 * K, 3):
    x, y, v = XYV[i:i + 3]
    item[x - 1, y - 1] = v
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(R):
    new_dp = np.zeros((C+1,4), dtype=np.int64)
    #上から移動
    for k in range(4):
      new_dp[:,0] = np.maximum(new_dp[:,0], dp[:,k])
    dp = new_dp
    for j in range(1,C+1):
      #横から移動
      for k in range(4):
        new_dp[j,k] = np.maximum(new_dp[j,k],new_dp[j-1,k])
      #アイテムを取る
      for k in range(2,-1,-1):
        dp[j,k+1] = np.maximum(dp[j,k+1],dp[j,k]+item[i,j-1])
  ans = dp[-1].max()
  return ans

R, C, K = map(int, readline().split())
XYV = np.array(read().split(), np.int64)
print(solve(R,C,K,XYV))
