# pypy
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

R, C, K = map(int, readline().split())
rcv = list(map(int, read().split()))
rc2v = {}
for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]):
    rc2v[(rr, cc)] = vv

dp = [[0]*4 for c in range(C+1)]
for r in range(1, R+1):
  for c in range(1, C+1):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    dp[c][0] = max(dp[c-1][0], max(dp[c]))
    dp[c][1] = max(dp[c-1][1], dp[c][0] + v)
    dp[c][2] = max(dp[c-1][2], dp[c-1][1] + v)
    dp[c][3] = max(dp[c-1][3], dp[c-1][2] + v)

print(max(dp[-1])) import sys sys read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines R, C, K = map(int, readline().split()) R map(int, readline().split()) map int readline().split() ().split () readline split C K rcv = list(map(int, read().split())) rcv list(map(int, read().split())) list map(int, read().split()) map int read().split() ().split () read split rc2v = {} rc2v {} for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]):
    rc2v[(rr, cc)] = vv rr cc vv zip(rcv[::3], rcv[1::3], rcv[2::3]) zip rcv[::3] rcv ::3 3 rcv[1::3] rcv 1::3 1 3 rcv[2::3] rcv 2::3 2 3 rc2v[(rr, cc)] = vv rc2v[(rr, cc)] rc2v (rr, cc) rr cc vv [0]*4 for c in range(C+1) for c in range(C+1) c range(C+1) range C+1 C 1 for c in range(C+1) [0]*4 [0] 0 4 dp = [[0]*4 for c in range(C+1)] dp [[0]*4 for c in range(C+1)] for r in range(1, R+1):
  for c in range(1, C+1):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    dp[c][0] = max(dp[c-1][0], max(dp[c]))
    dp[c][1] = max(dp[c-1][1], dp[c][0] + v)
    dp[c][2] = max(dp[c-1][2], dp[c-1][1] + v)
    dp[c][3] = max(dp[c-1][3], dp[c-1][2] + v) r range(1, R+1) range 1 R+1 R 1 for c in range(1, C+1):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    dp[c][0] = max(dp[c-1][0], max(dp[c]))
    dp[c][1] = max(dp[c-1][1], dp[c][0] + v)
    dp[c][2] = max(dp[c-1][2], dp[c-1][1] + v)
    dp[c][3] = max(dp[c-1][3], dp[c-1][2] + v) c range(1, C+1) range 1 C+1 C 1 v = rc2v[(r, c)] if (r, c) in rc2v else 0 v rc2v[(r, c)] if (r, c) in rc2v else 0 (r, c) in rc2v (r, c) r c rc2v rc2v[(r, c)] rc2v (r, c) r c 0 dp[c][0] = max(dp[c-1][0], max(dp[c])) dp[c][0] [c] dp c 0 max(dp[c-1][0], max(dp[c])) max dp[c-1][0] [c-1] dp c-1 c 1 0 max(dp[c]) max dp[c] dp c dp[c][1] = max(dp[c-1][1], dp[c][0] + v) dp[c][1] [c] dp c 1 max(dp[c-1][1], dp[c][0] + v) max dp[c-1][1] [c-1] dp c-1 c 1 1 dp[c][0] + v dp[c][0] [c] dp c 0 v dp[c][2] = max(dp[c-1][2], dp[c-1][1] + v) dp[c][2] [c] dp c 2 max(dp[c-1][2], dp[c-1][1] + v) max dp[c-1][2] [c-1] dp c-1 c 1 2 dp[c-1][1] + v dp[c-1][1] [c-1] dp c-1 c 1 1 v dp[c][3] = max(dp[c-1][3], dp[c-1][2] + v) dp[c][3] [c] dp c 3 max(dp[c-1][3], dp[c-1][2] + v) max dp[c-1][3] [c-1] dp c-1 c 1 3 dp[c-1][2] + v dp[c-1][2] [c-1] dp c-1 c 1 2 v print(max(dp[-1])) print max(dp[-1]) max dp[-1] dp -1 readlines = sys.stdin.readlines sys.stdin.readlines readlines v = rc2v[(r, c)] if (r, c) in rc2v else 0 rc2v[(r, c)] if (r, c) in rc2v else 0 v R, C, K = map(int, readline().split()) map(int, readline().split()) R rc2v = {} {} rc2v read = sys.stdin.read sys.stdin.read read readline = sys.stdin.readline sys.stdin.readline readline C, K = map(int, readline().split()) map(int, readline().split()) C dp = [[0]*4 for c in range(C+1)] [[0]*4 for c in range(C+1)] dp K = map(int, readline().split()) map(int, readline().split()) K rcv = list(map(int, read().split())) list(map(int, read().split())) rcv
# pypy
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

R, C, K = map(int, readline().split())
rcv = list(map(int, read().split()))
rc2v = {}
for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]):
    rc2v[(rr, cc)] = vv

dp = [[0]*4 for c in range(C+1)]
for r in range(1, R+1):
  for c in range(1, C+1):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    dp[c][0] = max(dp[c-1][0], max(dp[c]))
    dp[c][1] = max(dp[c-1][1], dp[c][0] + v)
    dp[c][2] = max(dp[c-1][2], dp[c-1][1] + v)
    dp[c][3] = max(dp[c-1][3], dp[c-1][2] + v)

print(max(dp[-1]))