r, c, k = map(int, input().split())

atlas = [[0]*c for i in range(r)]
dp = [[[0]*c for i in range(r)] for j in range(4)]

for i in range(k):
  x, y, v = map(int, input().split())
  atlas[x-1][y-1] = v
  
def max_sum(r, c, atlas):
  global dp

  if atlas[0][0] > 0:
    dp[1][0][0] = atlas[0][0]
    
  for i in range(r):
    for j in range(c):
      for h in range(4):
        
        if j+1 < c:
          dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
          if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
        if i+1 < r:
          dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
          if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
  return dp

max_sum(r, c, atlas)

ans = 0
for i in range(4):
  ans = max(ans, dp[i][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 for i in range(r) for i in range(r) i range(r) range r for i in range(r) [0]*c [0] 0 c atlas = [[0]*c for i in range(r)] atlas [[0]*c for i in range(r)] [[0]*c for i in range(r)] for j in range(4) for j in range(4) j range(4) range 4 for j in range(4) [[0]*c for i in range(r)] dp = [[[0]*c for i in range(r)] for j in range(4)] dp [[[0]*c for i in range(r)] for j in range(4)] for i in range(k):
  x, y, v = map(int, input().split())
  atlas[x-1][y-1] = v
   i range(k) range k x, y, v = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y v atlas[x-1][y-1] = v atlas[x-1][y-1] [x-1] atlas x-1 x 1 y-1 y 1 v def max_sum(r, c, atlas):
  global dp

  if atlas[0][0] > 0:
    dp[1][0][0] = atlas[0][0]
    
  for i in range(r):
    for j in range(c):
      for h in range(4):
        
        if j+1 < c:
          dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
          if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
        if i+1 < r:
          dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
          if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
  return dp max_sum global dp if atlas[0][0] > 0:
    dp[1][0][0] = atlas[0][0]
    
   atlas[0][0] > 0 atlas[0][0] [0] atlas 0 0 0 dp[1][0][0] = atlas[0][0] dp[1][0][0] [0] [1] dp 1 0 0 atlas[0][0] [0] atlas 0 0 for i in range(r):
    for j in range(c):
      for h in range(4):
        
        if j+1 < c:
          dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
          if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
        if i+1 < r:
          dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
          if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
   i range(r) range r for j in range(c):
      for h in range(4):
        
        if j+1 < c:
          dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
          if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
        if i+1 < r:
          dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
          if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
   j range(c) range c for h in range(4):
        
        if j+1 < c:
          dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
          if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
        if i+1 < r:
          dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
          if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
   h range(4) range 4 if j+1 < c:
          dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
          if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
         j+1 < c j+1 j 1 c dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j]) dp[h][i][j+1] [i] [h] dp h i j+1 j 1 max(dp[h][i][j+1], dp[h][i][j]) max dp[h][i][j+1] [i] [h] dp h i j+1 j 1 dp[h][i][j] [i] [h] dp h i j if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
         atlas[i][j+1] > 0 and h < 3 atlas[i][j+1] > 0 atlas[i][j+1] [i] atlas i j+1 j 1 0 h < 3 h 3 dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1]) dp[h+1][i][j+1] [i] [h+1] dp h+1 h 1 i j+1 j 1 max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1]) max dp[h+1][i][j+1] [i] [h+1] dp h+1 h 1 i j+1 j 1 dp[h][i][j]+atlas[i][j+1] dp[h][i][j] [i] [h] dp h i j atlas[i][j+1] [i] atlas i j+1 j 1 if i+1 < r:
          dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
          if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
   i+1 < r i+1 i 1 r dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j]) dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j max(dp[0][i+1][j], dp[h][i][j]) max dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j dp[h][i][j] [i] [h] dp h i j if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
   atlas[i+1][j] > 0 atlas[i+1][j] [i+1] atlas i+1 i 1 j 0 dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j]) dp[1][i+1][j] [i+1] [1] dp 1 i+1 i 1 j max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j]) max dp[1][i+1][j] [i+1] [1] dp 1 i+1 i 1 j dp[h][i][j]+atlas[i+1][j] dp[h][i][j] [i] [h] dp h i j atlas[i+1][j] [i+1] atlas i+1 i 1 j return dp dp r r c c atlas atlas max_sum(r, c, atlas) max_sum r c atlas ans = 0 ans 0 for i in range(4):
  ans = max(ans, dp[i][r-1][c-1])
   i range(4) range 4 ans = max(ans, dp[i][r-1][c-1]) ans max(ans, dp[i][r-1][c-1]) max ans dp[i][r-1][c-1] [r-1] [i] dp i r-1 r 1 c-1 c 1 print(ans) print ans x, y, v = map(int, input().split()) map(int, input().split()) x def max_sum(r, c, atlas):
  global dp

  if atlas[0][0] > 0:
    dp[1][0][0] = atlas[0][0]
    
  for i in range(r):
    for j in range(c):
      for h in range(4):
        
        if j+1 < c:
          dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
          if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
        if i+1 < r:
          dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
          if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
  return dp def max_sum(r, c, atlas):
  global dp

  if atlas[0][0] > 0:
    dp[1][0][0] = atlas[0][0]
    
  for i in range(r):
    for j in range(c):
      for h in range(4):
        
        if j+1 < c:
          dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
          if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
        if i+1 < r:
          dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
          if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
  return dp max_sum ans = 0 0 ans v = map(int, input().split()) map(int, input().split()) v k = map(int, input().split()) map(int, input().split()) k r, c, k = map(int, input().split()) map(int, input().split()) r y, v = map(int, input().split()) map(int, input().split()) y c, k = map(int, input().split()) map(int, input().split()) c dp = [[[0]*c for i in range(r)] for j in range(4)] [[[0]*c for i in range(r)] for j in range(4)] dp atlas = [[0]*c for i in range(r)] [[0]*c for i in range(r)] atlas ans = max(ans, dp[i][r-1][c-1]) max(ans, dp[i][r-1][c-1]) ans
r, c, k = map(int, input().split())

atlas = [[0]*c for i in range(r)]
dp = [[[0]*c for i in range(r)] for j in range(4)]

for i in range(k):
  x, y, v = map(int, input().split())
  atlas[x-1][y-1] = v
  
def max_sum(r, c, atlas):
  global dp

  if atlas[0][0] > 0:
    dp[1][0][0] = atlas[0][0]
    
  for i in range(r):
    for j in range(c):
      for h in range(4):
        
        if j+1 < c:
          dp[h][i][j+1] = max(dp[h][i][j+1], dp[h][i][j])
          if atlas[i][j+1] > 0 and h < 3:
            dp[h+1][i][j+1] = max(dp[h+1][i][j+1], dp[h][i][j]+atlas[i][j+1])
            
        if i+1 < r:
          dp[0][i+1][j] = max(dp[0][i+1][j], dp[h][i][j])
          if atlas[i+1][j] > 0:
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[h][i][j]+atlas[i+1][j])
          
            
  return dp

max_sum(r, c, atlas)

ans = 0
for i in range(4):
  ans = max(ans, dp[i][r-1][c-1])
  
print(ans)