import sys
input=sys.stdin.readline
def main():
  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])
  ans=0
  for i in range(R):
    for j in range(C):
      ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j])
  print(ans)
if __name__ == '__main__':
    main() import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
  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])
  ans=0
  for i in range(R):
    for j in range(C):
      ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j])
  print(ans) main 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 ans=0 ans 0 for i in range(R):
    for j in range(C):
      ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j])
   i range(R) range R for j in range(C):
      ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j])
   j range(C) range C ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j]) ans max(ans,dp1[i][j],dp2[i][j],dp3[i][j]) max ans dp1[i][j] [i] dp1 i j dp2[i][j] [i] dp2 i j dp3[i][j] [i] dp3 i j print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main input=sys.stdin.readline sys.stdin.readline input def main():
  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])
  ans=0
  for i in range(R):
    for j in range(C):
      ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j])
  print(ans) def main():
  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])
  ans=0
  for i in range(R):
    for j in range(C):
      ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j])
  print(ans) main
import sys
input=sys.stdin.readline
def main():
  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])
  ans=0
  for i in range(R):
    for j in range(C):
      ans=max(ans,dp1[i][j],dp2[i][j],dp3[i][j])
  print(ans)
if __name__ == '__main__':
    main()