import sys
input=sys.stdin.readline
R,C,k=map(int,input().split())
A=[[0]*C for i in range(R)]
for i in range(k):
  r,c,v=map(int,input().split())
  A[r-1][c-1]=v
dp0=[[0]*(C+1) for i in range(R+1)]
dp1=[[0]*(C+1) for i in range(R+1)]
dp2=[[0]*(C+1) for i in range(R+1)]
dp3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    V=A[i-1][j-1]
    dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1])
    dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1])
    dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1])
    dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1])) import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline R,C,k=map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C k [0]*C for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0]*C [0] 0 C A=[[0]*C for i in range(R)] A [[0]*C for i in range(R)] for i in range(k):
  r,c,v=map(int,input().split())
  A[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 A[r-1][c-1]=v A[r-1][c-1] [r-1] A r-1 r 1 c-1 c 1 v [0]*(C+1) for i in range(R+1) for i in range(R+1) i range(R+1) range R+1 R 1 for i in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 dp0=[[0]*(C+1) for i in range(R+1)] dp0 [[0]*(C+1) for i in range(R+1)] [0]*(C+1) for i in range(R+1) for i in range(R+1) i range(R+1) range R+1 R 1 for i in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 dp1=[[0]*(C+1) for i in range(R+1)] dp1 [[0]*(C+1) for i in range(R+1)] [0]*(C+1) for i in range(R+1) for i in range(R+1) i range(R+1) range R+1 R 1 for i in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 dp2=[[0]*(C+1) for i in range(R+1)] dp2 [[0]*(C+1) for i in range(R+1)] [0]*(C+1) for i in range(R+1) for i in range(R+1) i range(R+1) range R+1 R 1 for i in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 dp3=[[0]*(C+1) for i in range(R+1)] dp3 [[0]*(C+1) for i in range(R+1)] for i in range(1,R+1):
  for j in range(1,C+1):
    V=A[i-1][j-1]
    dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1])
    dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1])
    dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1])
    dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1]) i range(1,R+1) range 1 R+1 R 1 for j in range(1,C+1):
    V=A[i-1][j-1]
    dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1])
    dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1])
    dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1])
    dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1]) j range(1,C+1) range 1 C+1 C 1 V=A[i-1][j-1] V A[i-1][j-1] [i-1] A i-1 i 1 j-1 j 1 dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1]) dp0[i][j] [i] dp0 i j max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1]) max dp0[i-1][j] [i-1] dp0 i-1 i 1 j dp1[i-1][j] [i-1] dp1 i-1 i 1 j dp2[i-1][j] [i-1] dp2 i-1 i 1 j dp3[i-1][j] [i-1] dp3 i-1 i 1 j dp0[i][j-1] [i] dp0 i j-1 j 1 dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1]) dp1[i][j] [i] dp1 i j max(dp0[i][j]+V,dp1[i][j-1]) max dp0[i][j]+V dp0[i][j] [i] dp0 i j V dp1[i][j-1] [i] dp1 i j-1 j 1 dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1]) dp2[i][j] [i] dp2 i j max(dp1[i][j-1]+V,dp2[i][j-1]) max dp1[i][j-1]+V dp1[i][j-1] [i] dp1 i j-1 j 1 V dp2[i][j-1] [i] dp2 i j-1 j 1 dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1]) dp3[i][j] [i] dp3 i j max(dp2[i][j-1]+V,dp3[i][j-1]) max dp2[i][j-1]+V dp2[i][j-1] [i] dp2 i j-1 j 1 V dp3[i][j-1] [i] dp3 i j-1 j 1 print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1])) print max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]) max dp0[-1][-1] [-1] dp0 -1 -1 dp1[-1][-1] [-1] dp1 -1 -1 dp2[-1][-1] [-1] dp2 -1 -1 dp3[-1][-1] [-1] dp3 -1 -1 dp0=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] dp0 input=sys.stdin.readline sys.stdin.readline input R,C,k=map(int,input().split()) map(int,input().split()) R v=map(int,input().split()) map(int,input().split()) v r,c,v=map(int,input().split()) map(int,input().split()) r dp3=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] dp3 dp2=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] dp2 dp1=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] dp1 V=A[i-1][j-1] A[i-1][j-1] V k=map(int,input().split()) map(int,input().split()) k C,k=map(int,input().split()) map(int,input().split()) C A=[[0]*C for i in range(R)] [[0]*C for i in range(R)] A c,v=map(int,input().split()) map(int,input().split()) c
import sys
input=sys.stdin.readline
R,C,k=map(int,input().split())
A=[[0]*C for i in range(R)]
for i in range(k):
  r,c,v=map(int,input().split())
  A[r-1][c-1]=v
dp0=[[0]*(C+1) for i in range(R+1)]
dp1=[[0]*(C+1) for i in range(R+1)]
dp2=[[0]*(C+1) for i in range(R+1)]
dp3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    V=A[i-1][j-1]
    dp0[i][j]=max(dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j],dp0[i][j-1])
    dp1[i][j]=max(dp0[i][j]+V,dp1[i][j-1])
    dp2[i][j]=max(dp1[i][j-1]+V,dp2[i][j-1])
    dp3[i][j]=max(dp2[i][j-1]+V,dp3[i][j-1])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))