def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  last_dp = [[0]*5 for _ in range(C+1)]
  for i in range(1,R+1):
    dp = [[0]*5 for _ in range(C+1)]
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[j][k] = dp[j-1][k]
      #上から取らない
      dp[j][0] = max(dp[j][0],last_dp[j][-1])
      if item[i-1][j-1]>0:
        #上からとる
        dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
      dp[j][4] = max(dp[j][:4])
    last_dp = dp
  ans = max(last_dp[-1])
  return ans
print(solve()) def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  last_dp = [[0]*5 for _ in range(C+1)]
  for i in range(1,R+1):
    dp = [[0]*5 for _ in range(C+1)]
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[j][k] = dp[j-1][k]
      #上から取らない
      dp[j][0] = max(dp[j][0],last_dp[j][-1])
      if item[i-1][j-1]>0:
        #上からとる
        dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
      dp[j][4] = max(dp[j][:4])
    last_dp = dp
  ans = max(last_dp[-1])
  return ans solve R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C item = [[0]*C for _ in range(R)] item [[0]*C for _ in range(R)] for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = 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 item[r-1][c-1] = v item[r-1][c-1] [r-1] item r-1 r 1 c-1 c 1 v [0]*5 for _ in range(C+1) for _ in range(C+1) _ range(C+1) range C+1 C 1 for _ in range(C+1) [0]*5 [0] 0 5 last_dp = [[0]*5 for _ in range(C+1)] last_dp [[0]*5 for _ in range(C+1)] for i in range(1,R+1):
    dp = [[0]*5 for _ in range(C+1)]
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[j][k] = dp[j-1][k]
      #上から取らない
      dp[j][0] = max(dp[j][0],last_dp[j][-1])
      if item[i-1][j-1]>0:
        #上からとる
        dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
      dp[j][4] = max(dp[j][:4])
    last_dp = dp
   i range(1,R+1) range 1 R+1 R 1 [0]*5 for _ in range(C+1) for _ in range(C+1) _ range(C+1) range C+1 C 1 for _ in range(C+1) [0]*5 [0] 0 5 dp = [[0]*5 for _ in range(C+1)] dp [[0]*5 for _ in range(C+1)] for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[j][k] = dp[j-1][k]
      #上から取らない
      dp[j][0] = max(dp[j][0],last_dp[j][-1])
      if item[i-1][j-1]>0:
        #上からとる
        dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
      dp[j][4] = max(dp[j][:4])
     j range(1,C+1) range 1 C+1 C 1 for k in range(4): #横から取らない
        dp[j][k] = dp[j-1][k]
      #上から取らない
       k range(4) range 4 dp[j][k] = dp[j-1][k] dp[j][k] [j] dp j k dp[j-1][k] [j-1] dp j-1 j 1 k dp[j][0] = max(dp[j][0],last_dp[j][-1]) dp[j][0] [j] dp j 0 max(dp[j][0],last_dp[j][-1]) max dp[j][0] [j] dp j 0 last_dp[j][-1] [j] last_dp j -1 if item[i-1][j-1]>0:
        #上からとる
        dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
       item[i-1][j-1]>0 item[i-1][j-1] [i-1] item i-1 i 1 j-1 j 1 0 dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1]) dp[j][1] [j] dp j 1 max(dp[j][1],last_dp[j][-1]+item[i-1][j-1]) max dp[j][1] [j] dp j 1 last_dp[j][-1]+item[i-1][j-1] last_dp[j][-1] [j] last_dp j -1 item[i-1][j-1] [i-1] item i-1 i 1 j-1 j 1 for k in range(1,4): #横から取る
          dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
       k range(1,4) range 1 4 dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1]) dp[j][k] [j] dp j k max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1]) max dp[j][k] [j] dp j k dp[j-1][k-1]+item[i-1][j-1] dp[j-1][k-1] [j-1] dp j-1 j 1 k-1 k 1 item[i-1][j-1] [i-1] item i-1 i 1 j-1 j 1 dp[j][4] = max(dp[j][:4]) dp[j][4] [j] dp j 4 max(dp[j][:4]) max dp[j][:4] [j] dp j :4 4 last_dp = dp last_dp dp ans = max(last_dp[-1]) ans max(last_dp[-1]) max last_dp[-1] last_dp -1 return ans ans print(solve()) print solve() solve def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  last_dp = [[0]*5 for _ in range(C+1)]
  for i in range(1,R+1):
    dp = [[0]*5 for _ in range(C+1)]
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[j][k] = dp[j-1][k]
      #上から取らない
      dp[j][0] = max(dp[j][0],last_dp[j][-1])
      if item[i-1][j-1]>0:
        #上からとる
        dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
      dp[j][4] = max(dp[j][:4])
    last_dp = dp
  ans = max(last_dp[-1])
  return ans def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  last_dp = [[0]*5 for _ in range(C+1)]
  for i in range(1,R+1):
    dp = [[0]*5 for _ in range(C+1)]
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[j][k] = dp[j-1][k]
      #上から取らない
      dp[j][0] = max(dp[j][0],last_dp[j][-1])
      if item[i-1][j-1]>0:
        #上からとる
        dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
      dp[j][4] = max(dp[j][:4])
    last_dp = dp
  ans = max(last_dp[-1])
  return ans solve
def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  last_dp = [[0]*5 for _ in range(C+1)]
  for i in range(1,R+1):
    dp = [[0]*5 for _ in range(C+1)]
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[j][k] = dp[j-1][k]
      #上から取らない
      dp[j][0] = max(dp[j][0],last_dp[j][-1])
      if item[i-1][j-1]>0:
        #上からとる
        dp[j][1] = max(dp[j][1],last_dp[j][-1]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[j][k] = max(dp[j][k],dp[j-1][k-1]+item[i-1][j-1])
      dp[j][4] = max(dp[j][:4])
    last_dp = dp
  ans = max(last_dp[-1])
  return ans
print(solve())