R,C,K=map(int, input().split())
M=[[0 for i in range(C)]for i in range(R)]
for i in range(K):
  r,c,v=map(int, input().split())
  r-=1
  c-=1
  M[r][c]=v
dp0=[[0 for j in range(C)] for i in range(R)]
dp1=[[0 for j in range(C)] for i in range(R)]
dp2=[[0 for j in range(C)] for i in range(R)]
dp3=[[0 for j in range(C)] for i in range(R)]
dp1[0][0]+=M[0][0]
for r in range(R):
  for c in range(C):
    if 0<r:
      dp1[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c],dp1[r][c])
      dp0[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]),dp0[r][c])
    if 0<c:
      dp3[r][c]=max(dp2[r][c-1]+M[r][c],dp3[r][c],dp3[r][c-1])
      dp2[r][c]=max(dp1[r][c-1]+M[r][c],dp2[r][c],dp2[r][c-1])
      dp1[r][c]=max(dp0[r][c-1]+M[r][c],dp1[r][c],dp1[r][c-1])
      dp0[r][c]=max(dp0[r][c-1],dp0[r][c])
print(max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1])) R,C,K=map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0 for i in range(C)]for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0 for i in range(C)] M=[[0 for i in range(C)]for i in range(R)] M [[0 for i in range(C)]for i in range(R)] for i in range(K):
  r,c,v=map(int, input().split())
  r-=1
  c-=1
  M[r][c]=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 r-=1 r 1 c-=1 c 1 M[r][c]=v M[r][c] [r] M r c v [0 for j in range(C)] for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0 for j in range(C)] dp0=[[0 for j in range(C)] for i in range(R)] dp0 [[0 for j in range(C)] for i in range(R)] [0 for j in range(C)] for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0 for j in range(C)] dp1=[[0 for j in range(C)] for i in range(R)] dp1 [[0 for j in range(C)] for i in range(R)] [0 for j in range(C)] for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0 for j in range(C)] dp2=[[0 for j in range(C)] for i in range(R)] dp2 [[0 for j in range(C)] for i in range(R)] [0 for j in range(C)] for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0 for j in range(C)] dp3=[[0 for j in range(C)] for i in range(R)] dp3 [[0 for j in range(C)] for i in range(R)] dp1[0][0]+=M[0][0] dp1[0][0] [0] dp1 0 0 M[0][0] [0] M 0 0 for r in range(R):
  for c in range(C):
    if 0<r:
      dp1[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c],dp1[r][c])
      dp0[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]),dp0[r][c])
    if 0<c:
      dp3[r][c]=max(dp2[r][c-1]+M[r][c],dp3[r][c],dp3[r][c-1])
      dp2[r][c]=max(dp1[r][c-1]+M[r][c],dp2[r][c],dp2[r][c-1])
      dp1[r][c]=max(dp0[r][c-1]+M[r][c],dp1[r][c],dp1[r][c-1])
      dp0[r][c]=max(dp0[r][c-1],dp0[r][c]) r range(R) range R for c in range(C):
    if 0<r:
      dp1[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c],dp1[r][c])
      dp0[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]),dp0[r][c])
    if 0<c:
      dp3[r][c]=max(dp2[r][c-1]+M[r][c],dp3[r][c],dp3[r][c-1])
      dp2[r][c]=max(dp1[r][c-1]+M[r][c],dp2[r][c],dp2[r][c-1])
      dp1[r][c]=max(dp0[r][c-1]+M[r][c],dp1[r][c],dp1[r][c-1])
      dp0[r][c]=max(dp0[r][c-1],dp0[r][c]) c range(C) range C if 0<r:
      dp1[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c],dp1[r][c])
      dp0[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]),dp0[r][c])
     0<r 0 r dp1[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c],dp1[r][c]) dp1[r][c] [r] dp1 r c max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c],dp1[r][c]) max max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c] max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]) max dp1[r-1][c] [r-1] dp1 r-1 r 1 c dp2[r-1][c] [r-1] dp2 r-1 r 1 c dp3[r-1][c] [r-1] dp3 r-1 r 1 c M[r][c] [r] M r c dp1[r][c] [r] dp1 r c dp0[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]),dp0[r][c]) dp0[r][c] [r] dp0 r c max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]),dp0[r][c]) max max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]) max dp1[r-1][c] [r-1] dp1 r-1 r 1 c dp2[r-1][c] [r-1] dp2 r-1 r 1 c dp3[r-1][c] [r-1] dp3 r-1 r 1 c dp0[r][c] [r] dp0 r c if 0<c:
      dp3[r][c]=max(dp2[r][c-1]+M[r][c],dp3[r][c],dp3[r][c-1])
      dp2[r][c]=max(dp1[r][c-1]+M[r][c],dp2[r][c],dp2[r][c-1])
      dp1[r][c]=max(dp0[r][c-1]+M[r][c],dp1[r][c],dp1[r][c-1])
      dp0[r][c]=max(dp0[r][c-1],dp0[r][c]) 0<c 0 c dp3[r][c]=max(dp2[r][c-1]+M[r][c],dp3[r][c],dp3[r][c-1]) dp3[r][c] [r] dp3 r c max(dp2[r][c-1]+M[r][c],dp3[r][c],dp3[r][c-1]) max dp2[r][c-1]+M[r][c] dp2[r][c-1] [r] dp2 r c-1 c 1 M[r][c] [r] M r c dp3[r][c] [r] dp3 r c dp3[r][c-1] [r] dp3 r c-1 c 1 dp2[r][c]=max(dp1[r][c-1]+M[r][c],dp2[r][c],dp2[r][c-1]) dp2[r][c] [r] dp2 r c max(dp1[r][c-1]+M[r][c],dp2[r][c],dp2[r][c-1]) max dp1[r][c-1]+M[r][c] dp1[r][c-1] [r] dp1 r c-1 c 1 M[r][c] [r] M r c dp2[r][c] [r] dp2 r c dp2[r][c-1] [r] dp2 r c-1 c 1 dp1[r][c]=max(dp0[r][c-1]+M[r][c],dp1[r][c],dp1[r][c-1]) dp1[r][c] [r] dp1 r c max(dp0[r][c-1]+M[r][c],dp1[r][c],dp1[r][c-1]) max dp0[r][c-1]+M[r][c] dp0[r][c-1] [r] dp0 r c-1 c 1 M[r][c] [r] M r c dp1[r][c] [r] dp1 r c dp1[r][c-1] [r] dp1 r c-1 c 1 dp0[r][c]=max(dp0[r][c-1],dp0[r][c]) dp0[r][c] [r] dp0 r c max(dp0[r][c-1],dp0[r][c]) max dp0[r][c-1] [r] dp0 r c-1 c 1 dp0[r][c] [r] dp0 r c print(max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1])) print max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]) max dp1[-1][-1] [-1] dp1 -1 -1 dp2[-1][-1] [-1] dp2 -1 -1 dp3[-1][-1] [-1] dp3 -1 -1 R,C,K=map(int, input().split()) map(int, input().split()) R dp1=[[0 for j in range(C)] for i in range(R)] [[0 for j in range(C)] for i in range(R)] dp1 C,K=map(int, input().split()) map(int, input().split()) C dp0=[[0 for j in range(C)] for i in range(R)] [[0 for j in range(C)] for i in range(R)] dp0 dp3=[[0 for j in range(C)] for i in range(R)] [[0 for j in range(C)] for i in range(R)] dp3 r,c,v=map(int, input().split()) map(int, input().split()) r v=map(int, input().split()) map(int, input().split()) v dp2=[[0 for j in range(C)] for i in range(R)] [[0 for j in range(C)] for i in range(R)] dp2 r-=1 1 r K=map(int, input().split()) map(int, input().split()) K M=[[0 for i in range(C)]for i in range(R)] [[0 for i in range(C)]for i in range(R)] M c,v=map(int, input().split()) map(int, input().split()) c c-=1 1 c
R,C,K=map(int, input().split())
M=[[0 for i in range(C)]for i in range(R)]
for i in range(K):
  r,c,v=map(int, input().split())
  r-=1
  c-=1
  M[r][c]=v
dp0=[[0 for j in range(C)] for i in range(R)]
dp1=[[0 for j in range(C)] for i in range(R)]
dp2=[[0 for j in range(C)] for i in range(R)]
dp3=[[0 for j in range(C)] for i in range(R)]
dp1[0][0]+=M[0][0]
for r in range(R):
  for c in range(C):
    if 0<r:
      dp1[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c])+M[r][c],dp1[r][c])
      dp0[r][c]=max(max(dp1[r-1][c],dp2[r-1][c],dp3[r-1][c]),dp0[r][c])
    if 0<c:
      dp3[r][c]=max(dp2[r][c-1]+M[r][c],dp3[r][c],dp3[r][c-1])
      dp2[r][c]=max(dp1[r][c-1]+M[r][c],dp2[r][c],dp2[r][c-1])
      dp1[r][c]=max(dp0[r][c-1]+M[r][c],dp1[r][c],dp1[r][c-1])
      dp0[r][c]=max(dp0[r][c-1],dp0[r][c])
print(max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))