import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

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

R, C, K = map(int, input().split())
item = np.zeros((R,C), dtype=np.int64)
for i in range(K):
  r,c,v = map(int, input().split())
  item[r-1,c-1] = v
print(solve(R,C,K,item)) import numpy as np numpy import numba numba from numba import njit, b1, i4, i8, f8 def solve(R,C,K,item):
  dp = np.zeros((C+1,5), dtype=np.int64)
  for i in range(1,R+1):
    new_dp = np.zeros((C+1,5), dtype=np.int64)
    #上からアイテムを取らずに移動
    new_dp[:,0] = dp[:,-1]
    #上からアイテムを取って移動
    new_dp[1:,1] = np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1])
    for j in range(1,C+1):
      #横からアイテムを取らずに移動
      new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
      #横からアイテムを取って移動
      for k in range(1,4):
        new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1])
    for k in range(4):
      new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k])
    dp = new_dp
  ans = dp[-1,-1]
  return ans solve dp = np.zeros((C+1,5), dtype=np.int64) dp np.zeros((C+1,5), dtype=np.int64) np.zeros np zeros (C+1,5) C+1 C 1 5 dtype=np.int64 dtype np.int64 np int64 for i in range(1,R+1):
    new_dp = np.zeros((C+1,5), dtype=np.int64)
    #上からアイテムを取らずに移動
    new_dp[:,0] = dp[:,-1]
    #上からアイテムを取って移動
    new_dp[1:,1] = np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1])
    for j in range(1,C+1):
      #横からアイテムを取らずに移動
      new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
      #横からアイテムを取って移動
      for k in range(1,4):
        new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1])
    for k in range(4):
      new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k])
    dp = new_dp
   i range(1,R+1) range 1 R+1 R 1 new_dp = np.zeros((C+1,5), dtype=np.int64) new_dp np.zeros((C+1,5), dtype=np.int64) np.zeros np zeros (C+1,5) C+1 C 1 5 dtype=np.int64 dtype np.int64 np int64 new_dp[:,0] = dp[:,-1] new_dp[:,0] new_dp : dp[:,-1] dp : new_dp[1:,1] = np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1]) new_dp[1:,1] new_dp 1: 1 np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1]) np.maximum np maximum new_dp[1:,1] new_dp 1: 1 dp[1:,-1]+item[i-1] dp[1:,-1] dp 1: 1 item[i-1] item i-1 i 1 for j in range(1,C+1):
      #横からアイテムを取らずに移動
      new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
      #横からアイテムを取って移動
      for k in range(1,4):
        new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1])
     j range(1,C+1) range 1 C+1 C 1 new_dp[j] = np.maximum(new_dp[j],new_dp[j-1]) new_dp[j] new_dp j np.maximum(new_dp[j],new_dp[j-1]) np.maximum np maximum new_dp[j] new_dp j new_dp[j-1] new_dp j-1 j 1 for k in range(1,4):
        new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1])
     k range(1,4) range 1 4 new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1]) new_dp[j,k] new_dp j max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1]) max new_dp[j,k] new_dp j new_dp[j-1,k-1]+item[i-1,j-1] new_dp[j-1,k-1] new_dp j-1 j 1 item[i-1,j-1] item i-1 i 1 for k in range(4):
      new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k])
     k range(4) range 4 new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k]) new_dp[:,-1] new_dp : np.maximum(new_dp[:,-1],new_dp[:,k]) np.maximum np maximum new_dp[:,-1] new_dp : new_dp[:,k] new_dp : dp = new_dp dp new_dp ans = dp[-1,-1] ans dp[-1,-1] dp -1 return ans ans R R C C K K item item @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, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K item = np.zeros((R,C), dtype=np.int64) item np.zeros((R,C), dtype=np.int64) np.zeros np zeros (R,C) R C dtype=np.int64 dtype np.int64 np int64 for i in range(K):
  r,c,v = map(int, input().split())
  item[r-1,c-1] = v i 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 item[r-1,c-1] = v item[r-1,c-1] item r-1 r 1 v print(solve(R,C,K,item)) print solve(R,C,K,item) solve R C K item R, C, K = map(int, input().split()) map(int, input().split()) R v = map(int, input().split()) map(int, input().split()) v def solve(R,C,K,item):
  dp = np.zeros((C+1,5), dtype=np.int64)
  for i in range(1,R+1):
    new_dp = np.zeros((C+1,5), dtype=np.int64)
    #上からアイテムを取らずに移動
    new_dp[:,0] = dp[:,-1]
    #上からアイテムを取って移動
    new_dp[1:,1] = np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1])
    for j in range(1,C+1):
      #横からアイテムを取らずに移動
      new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
      #横からアイテムを取って移動
      for k in range(1,4):
        new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1])
    for k in range(4):
      new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k])
    dp = new_dp
  ans = dp[-1,-1]
  return ans def solve(R,C,K,item):
  dp = np.zeros((C+1,5), dtype=np.int64)
  for i in range(1,R+1):
    new_dp = np.zeros((C+1,5), dtype=np.int64)
    #上からアイテムを取らずに移動
    new_dp[:,0] = dp[:,-1]
    #上からアイテムを取って移動
    new_dp[1:,1] = np.maximum(new_dp[1:,1],dp[1:,-1]+item[i-1])
    for j in range(1,C+1):
      #横からアイテムを取らずに移動
      new_dp[j] = np.maximum(new_dp[j],new_dp[j-1])
      #横からアイテムを取って移動
      for k in range(1,4):
        new_dp[j,k] = max(new_dp[j,k],new_dp[j-1,k-1]+item[i-1,j-1])
    for k in range(4):
      new_dp[:,-1] = np.maximum(new_dp[:,-1],new_dp[:,k])
    dp = new_dp
  ans = dp[-1,-1]
  return ans solve r,c,v = map(int, input().split()) map(int, input().split()) r c,v = map(int, input().split()) map(int, input().split()) c K = map(int, input().split()) map(int, input().split()) K C, K = map(int, input().split()) map(int, input().split()) C item = np.zeros((R,C), dtype=np.int64) np.zeros((R,C), dtype=np.int64) item
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

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

R, C, K = map(int, input().split())
item = np.zeros((R,C), dtype=np.int64)
for i in range(K):
  r,c,v = map(int, input().split())
  item[r-1,c-1] = v
print(solve(R,C,K,item))