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,4), dtype=np.int64)
  for i in range(1,R+1):
    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-1][j-1])
  ans = dp[-1].max()
  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,4), dtype=np.int64)
  for i in range(1,R+1):
    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-1][j-1])
  ans = dp[-1].max()
  return ans solve 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(1,R+1):
    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-1][j-1])
   i range(1,R+1) range 1 R+1 R 1 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-1][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] [j] new_dp j k 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-1][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-1][j-1]) dp[j,k+1] dp j np.maximum(dp[j,k+1],dp[j,k]+item[i-1][j-1]) np.maximum np maximum dp[j,k+1] dp j dp[j,k]+item[i-1][j-1] dp[j,k] dp j item[i-1][j-1] [i-1] item i-1 i 1 j-1 j 1 ans = dp[-1].max() ans dp[-1].max() [-1].max [-1] dp -1 max 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 K = map(int, input().split()) map(int, input().split()) K v = map(int, input().split()) map(int, input().split()) v def solve(R,C,K,item):
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(1,R+1):
    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-1][j-1])
  ans = dp[-1].max()
  return ans def solve(R,C,K,item):
  dp = np.zeros((C+1,4), dtype=np.int64)
  for i in range(1,R+1):
    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-1][j-1])
  ans = dp[-1].max()
  return ans solve c,v = map(int, input().split()) map(int, input().split()) c R, C, K = map(int, input().split()) map(int, input().split()) R item = np.zeros((R,C), dtype=np.int64) np.zeros((R,C), dtype=np.int64) item r,c,v = map(int, input().split()) map(int, input().split()) r C, K = map(int, input().split()) map(int, input().split()) C
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,4), dtype=np.int64)
  for i in range(1,R+1):
    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-1][j-1])
  ans = dp[-1].max()
  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))
