import sys
input=lambda:sys.stdin.readline().rstrip()
r,c,k=map(int,input().split())
dp=[[(c+1)*[0]for _ in range(r+1)]for _ in range(4)]
p=[c*[0]for _ in range(r)]
for _ in range(k):
  rr,cc,u=map(int,input().split())
  rr-=1
  cc-=1
  p[rr][cc]=u
ans=0
for j in range(1,r+1):
  for k in range(1,c+1):
    dp[0][j][k]=max(dp[0][j-1][k],dp[0][j][k-1])
    t=max(dp[0][j-1][k],dp[1][j-1][k],dp[2][j-1][k],dp[3][j-1][k])
    for i in range(1,4):
      dp[i][j][k]=max(dp[i][j][k],t,dp[i][j][k-1])
      if p[j-1][k-1]:
        dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k-1]+p[j-1][k-1],t+p[j-1][k-1])
      ans=max(ans,dp[i][j][k])
print(ans) import sys sys input=lambda:sys.stdin.readline().rstrip() input lambda:sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip r,c,k=map(int,input().split()) r map(int,input().split()) map int input().split() ().split () input split c k [(c+1)*[0]for _ in range(r+1)]for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [(c+1)*[0]for _ in range(r+1)] dp=[[(c+1)*[0]for _ in range(r+1)]for _ in range(4)] dp [[(c+1)*[0]for _ in range(r+1)]for _ in range(4)] c*[0]for _ in range(r) for _ in range(r) _ range(r) range r for _ in range(r) c*[0] c [0] 0 p=[c*[0]for _ in range(r)] p [c*[0]for _ in range(r)] for _ in range(k):
  rr,cc,u=map(int,input().split())
  rr-=1
  cc-=1
  p[rr][cc]=u _ range(k) range k rr,cc,u=map(int,input().split()) rr map(int,input().split()) map int input().split() ().split () input split cc u rr-=1 rr 1 cc-=1 cc 1 p[rr][cc]=u p[rr][cc] [rr] p rr cc u ans=0 ans 0 for j in range(1,r+1):
  for k in range(1,c+1):
    dp[0][j][k]=max(dp[0][j-1][k],dp[0][j][k-1])
    t=max(dp[0][j-1][k],dp[1][j-1][k],dp[2][j-1][k],dp[3][j-1][k])
    for i in range(1,4):
      dp[i][j][k]=max(dp[i][j][k],t,dp[i][j][k-1])
      if p[j-1][k-1]:
        dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k-1]+p[j-1][k-1],t+p[j-1][k-1])
      ans=max(ans,dp[i][j][k]) j range(1,r+1) range 1 r+1 r 1 for k in range(1,c+1):
    dp[0][j][k]=max(dp[0][j-1][k],dp[0][j][k-1])
    t=max(dp[0][j-1][k],dp[1][j-1][k],dp[2][j-1][k],dp[3][j-1][k])
    for i in range(1,4):
      dp[i][j][k]=max(dp[i][j][k],t,dp[i][j][k-1])
      if p[j-1][k-1]:
        dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k-1]+p[j-1][k-1],t+p[j-1][k-1])
      ans=max(ans,dp[i][j][k]) k range(1,c+1) range 1 c+1 c 1 dp[0][j][k]=max(dp[0][j-1][k],dp[0][j][k-1]) dp[0][j][k] [j] [0] dp 0 j k max(dp[0][j-1][k],dp[0][j][k-1]) max dp[0][j-1][k] [j-1] [0] dp 0 j-1 j 1 k dp[0][j][k-1] [j] [0] dp 0 j k-1 k 1 t=max(dp[0][j-1][k],dp[1][j-1][k],dp[2][j-1][k],dp[3][j-1][k]) t max(dp[0][j-1][k],dp[1][j-1][k],dp[2][j-1][k],dp[3][j-1][k]) max dp[0][j-1][k] [j-1] [0] dp 0 j-1 j 1 k dp[1][j-1][k] [j-1] [1] dp 1 j-1 j 1 k dp[2][j-1][k] [j-1] [2] dp 2 j-1 j 1 k dp[3][j-1][k] [j-1] [3] dp 3 j-1 j 1 k for i in range(1,4):
      dp[i][j][k]=max(dp[i][j][k],t,dp[i][j][k-1])
      if p[j-1][k-1]:
        dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k-1]+p[j-1][k-1],t+p[j-1][k-1])
      ans=max(ans,dp[i][j][k]) i range(1,4) range 1 4 dp[i][j][k]=max(dp[i][j][k],t,dp[i][j][k-1]) dp[i][j][k] [j] [i] dp i j k max(dp[i][j][k],t,dp[i][j][k-1]) max dp[i][j][k] [j] [i] dp i j k t dp[i][j][k-1] [j] [i] dp i j k-1 k 1 if p[j-1][k-1]:
        dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k-1]+p[j-1][k-1],t+p[j-1][k-1])
       p[j-1][k-1] [j-1] p j-1 j 1 k-1 k 1 dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k-1]+p[j-1][k-1],t+p[j-1][k-1]) dp[i][j][k] [j] [i] dp i j k max(dp[i][j][k],dp[i-1][j][k-1]+p[j-1][k-1],t+p[j-1][k-1]) max dp[i][j][k] [j] [i] dp i j k dp[i-1][j][k-1]+p[j-1][k-1] dp[i-1][j][k-1] [j] [i-1] dp i-1 i 1 j k-1 k 1 p[j-1][k-1] [j-1] p j-1 j 1 k-1 k 1 t+p[j-1][k-1] t p[j-1][k-1] [j-1] p j-1 j 1 k-1 k 1 ans=max(ans,dp[i][j][k]) ans max(ans,dp[i][j][k]) max ans dp[i][j][k] [j] [i] dp i j k print(ans) print ans input=lambda:sys.stdin.readline().rstrip() lambda:sys.stdin.readline().rstrip() input p=[c*[0]for _ in range(r)] [c*[0]for _ in range(r)] p cc,u=map(int,input().split()) map(int,input().split()) cc rr,cc,u=map(int,input().split()) map(int,input().split()) rr dp=[[(c+1)*[0]for _ in range(r+1)]for _ in range(4)] [[(c+1)*[0]for _ in range(r+1)]for _ in range(4)] dp t=max(dp[0][j-1][k],dp[1][j-1][k],dp[2][j-1][k],dp[3][j-1][k]) max(dp[0][j-1][k],dp[1][j-1][k],dp[2][j-1][k],dp[3][j-1][k]) t c,k=map(int,input().split()) map(int,input().split()) c k=map(int,input().split()) map(int,input().split()) k u=map(int,input().split()) map(int,input().split()) u cc-=1 1 cc rr-=1 1 rr ans=max(ans,dp[i][j][k]) max(ans,dp[i][j][k]) ans ans=0 0 ans r,c,k=map(int,input().split()) map(int,input().split()) r
import sys
input=lambda:sys.stdin.readline().rstrip()
r,c,k=map(int,input().split())
dp=[[(c+1)*[0]for _ in range(r+1)]for _ in range(4)]
p=[c*[0]for _ in range(r)]
for _ in range(k):
  rr,cc,u=map(int,input().split())
  rr-=1
  cc-=1
  p[rr][cc]=u
ans=0
for j in range(1,r+1):
  for k in range(1,c+1):
    dp[0][j][k]=max(dp[0][j-1][k],dp[0][j][k-1])
    t=max(dp[0][j-1][k],dp[1][j-1][k],dp[2][j-1][k],dp[3][j-1][k])
    for i in range(1,4):
      dp[i][j][k]=max(dp[i][j][k],t,dp[i][j][k-1])
      if p[j-1][k-1]:
        dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][k-1]+p[j-1][k-1],t+p[j-1][k-1])
      ans=max(ans,dp[i][j][k])
print(ans)
