r,c,k = list(map(int, input().split()))
import copy
dp=[[[0]*4 for _ in range(c)] for _ in range(2)]


F = [[0]*c for _ in range(r)]

for _ in range(k):
  x,y,v = list(map(int, input().split()))
  x-=1
  y-=1
  F[x][y] = v
  
for nn in range(r):
  for j in range(c):
    i = 1
    val = F[nn][j]
  
      
    mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3])

    dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + val)
    dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + val)
    dp[i][j][1] = max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val)
    dp[i][j][0] = mxv

  dp[0] = dp[1] 
  dp[1] = [[0]*4 for _ in range(c)]

best = 0


for k in range(4):
  best = max(best, dp[0][c-1][k])
    
print(best) r,c,k = list(map(int, input().split())) r list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c k import copy copy [[0]*4 for _ in range(c)] for _ in range(2) for _ in range(2) _ range(2) range 2 for _ in range(2) [[0]*4 for _ in range(c)] dp=[[[0]*4 for _ in range(c)] for _ in range(2)] dp [[[0]*4 for _ in range(c)] for _ in range(2)] [0]*c for _ in range(r) for _ in range(r) _ range(r) range r for _ in range(r) [0]*c [0] 0 c F = [[0]*c for _ in range(r)] F [[0]*c for _ in range(r)] for _ in range(k):
  x,y,v = list(map(int, input().split()))
  x-=1
  y-=1
  F[x][y] = v
   _ range(k) range k x,y,v = list(map(int, input().split())) x list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split y v x-=1 x 1 y-=1 y 1 F[x][y] = v F[x][y] [x] F x y v for nn in range(r):
  for j in range(c):
    i = 1
    val = F[nn][j]
  
      
    mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3])

    dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + val)
    dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + val)
    dp[i][j][1] = max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val)
    dp[i][j][0] = mxv

  dp[0] = dp[1] 
  dp[1] = [[0]*4 for _ in range(c)] nn range(r) range r for j in range(c):
    i = 1
    val = F[nn][j]
  
      
    mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3])

    dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + val)
    dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + val)
    dp[i][j][1] = max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val)
    dp[i][j][0] = mxv

   j range(c) range c i = 1 i 1 val = F[nn][j] val F[nn][j] [nn] F nn j mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3]) mxv max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3]) max dp[i-1][j][0] [j] [i-1] dp i-1 i 1 j 0 dp[i-1][j][1] [j] [i-1] dp i-1 i 1 j 1 dp[i-1][j][2] [j] [i-1] dp i-1 i 1 j 2 dp[i-1][j][3] [j] [i-1] dp i-1 i 1 j 3 dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + val) dp[i][j][3] [j] [i] dp i j 3 max(dp[i][j-1][3], dp[i][j-1][2] + val) max dp[i][j-1][3] [j-1] [i] dp i j-1 j 1 3 dp[i][j-1][2] + val dp[i][j-1][2] [j-1] [i] dp i j-1 j 1 2 val dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + val) dp[i][j][2] [j] [i] dp i j 2 max(dp[i][j-1][2], dp[i][j-1][1] + val) max dp[i][j-1][2] [j-1] [i] dp i j-1 j 1 2 dp[i][j-1][1] + val dp[i][j-1][1] [j-1] [i] dp i j-1 j 1 1 val dp[i][j][1] = max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val) dp[i][j][1] [j] [i] dp i j 1 max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val) max dp[i][j-1][1] [j-1] [i] dp i j-1 j 1 1 dp[i][j-1][0] + val dp[i][j-1][0] [j-1] [i] dp i j-1 j 1 0 val mxv + val mxv val dp[i][j][0] = mxv dp[i][j][0] [j] [i] dp i j 0 mxv dp[0] = dp[1] dp[0] dp 0 dp[1] dp 1 [0]*4 for _ in range(c) for _ in range(c) _ range(c) range c for _ in range(c) [0]*4 [0] 0 4 dp[1] = [[0]*4 for _ in range(c)] dp[1] dp 1 [[0]*4 for _ in range(c)] best = 0 best 0 for k in range(4):
  best = max(best, dp[0][c-1][k])
     k range(4) range 4 best = max(best, dp[0][c-1][k]) best max(best, dp[0][c-1][k]) max best dp[0][c-1][k] [c-1] [0] dp 0 c-1 c 1 k print(best) print best k = list(map(int, input().split())) list(map(int, input().split())) k best = max(best, dp[0][c-1][k]) max(best, dp[0][c-1][k]) best x-=1 1 x best = 0 0 best dp=[[[0]*4 for _ in range(c)] for _ in range(2)] [[[0]*4 for _ in range(c)] for _ in range(2)] dp F = [[0]*c for _ in range(r)] [[0]*c for _ in range(r)] F y-=1 1 y x,y,v = list(map(int, input().split())) list(map(int, input().split())) x y,v = list(map(int, input().split())) list(map(int, input().split())) y r,c,k = list(map(int, input().split())) list(map(int, input().split())) r i = 1 1 i c,k = list(map(int, input().split())) list(map(int, input().split())) c v = list(map(int, input().split())) list(map(int, input().split())) v mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3]) max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3]) mxv val = F[nn][j] F[nn][j] val
r,c,k = list(map(int, input().split()))
import copy
dp=[[[0]*4 for _ in range(c)] for _ in range(2)]


F = [[0]*c for _ in range(r)]

for _ in range(k):
  x,y,v = list(map(int, input().split()))
  x-=1
  y-=1
  F[x][y] = v
  
for nn in range(r):
  for j in range(c):
    i = 1
    val = F[nn][j]
  
      
    mxv = max(dp[i-1][j][0], dp[i-1][j][1], dp[i-1][j][2], dp[i-1][j][3])

    dp[i][j][3] = max(dp[i][j-1][3], dp[i][j-1][2] + val)
    dp[i][j][2] = max(dp[i][j-1][2], dp[i][j-1][1] + val)
    dp[i][j][1] = max(dp[i][j-1][1], dp[i][j-1][0] + val, mxv + val)
    dp[i][j][0] = mxv

  dp[0] = dp[1] 
  dp[1] = [[0]*4 for _ in range(c)]

best = 0


for k in range(4):
  best = max(best, dp[0][c-1][k])
    
print(best)
