f=lambda:map(int,input().split())
R,C,K=f()
g=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
  r,c,v=f()
  g[r][c]=v
dp=[[[0]*(C+2) for _ in range(R+2)] for _ in range(4)]
for i in range(1,R+1):
  for j in range(1,C+1):
    for k in range(3,-1,-1):
      if k: dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+g[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
print(max(dp[k][R][C] for k in range(4))) f=lambda:map(int,input().split()) f lambda:map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split R,C,K=f() R f() f 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 g=[[0]*(C+1) for _ in range(R+1)] g [[0]*(C+1) for _ in range(R+1)] for _ in range(K):
  r,c,v=f()
  g[r][c]=v _ range(K) range K r,c,v=f() r f() f c v g[r][c]=v g[r][c] [r] g r c v [[0]*(C+2) for _ in range(R+2)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*(C+2) for _ in range(R+2)] dp=[[[0]*(C+2) for _ in range(R+2)] for _ in range(4)] dp [[[0]*(C+2) for _ in range(R+2)] for _ in range(4)] for i in range(1,R+1):
  for j in range(1,C+1):
    for k in range(3,-1,-1):
      if k: dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+g[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) i range(1,R+1) range 1 R+1 R 1 for j in range(1,C+1):
    for k in range(3,-1,-1):
      if k: dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+g[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) j range(1,C+1) range 1 C+1 C 1 for k in range(3,-1,-1):
      if k: dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+g[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) k range(3,-1,-1) range 3 -1 -1 if k: dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+g[i][j])
       k dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j]) dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j max(dp[0][i+1][j],dp[k][i][j]) max dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j dp[k][i][j] [i] [k] dp k i j dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) dp[k][i][j+1] [i] [k] dp k i j+1 j 1 max(dp[k][i][j+1],dp[k][i][j]) max dp[k][i][j+1] [i] [k] dp k i j+1 j 1 dp[k][i][j] [i] [k] dp k i j print(max(dp[k][R][C] for k in range(4))) print max(dp[k][R][C] for k in range(4)) max dp[k][R][C] [R] [k] dp k R C R,C,K=f() f() R g=[[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] g v=f() f() v C,K=f() f() C f=lambda:map(int,input().split()) lambda:map(int,input().split()) f r,c,v=f() f() r c,v=f() f() c K=f() f() K dp=[[[0]*(C+2) for _ in range(R+2)] for _ in range(4)] [[[0]*(C+2) for _ in range(R+2)] for _ in range(4)] dp
f=lambda:map(int,input().split())
R,C,K=f()
g=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
  r,c,v=f()
  g[r][c]=v
dp=[[[0]*(C+2) for _ in range(R+2)] for _ in range(4)]
for i in range(1,R+1):
  for j in range(1,C+1):
    for k in range(3,-1,-1):
      if k: dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+g[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
print(max(dp[k][R][C] for k in range(4)))