R,C,K = map(int, input().split())
a = [[0] * (C+1) for i in range(R+1)]
dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]

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

for i in range(K):
  r,c,v = map(int, input().split())
  r -= 1
  c -= 1
  a[r][c] = v 
  
for i in range(R):
  for j in range(C):
    for k in range(2,-1,-1):
      dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + a[i][j])
    for k in range(4):
      dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])
      dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
ans = 0
for k in range(4):
  ans = max(ans, dp[k][R-1][C-1])
  
print(ans)
  
