# 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-1, cc-1)] = vv

dp = [[[0]*4 for c in range(C)] for r in range(2)]
dp[0][0][1] = rc2v[(0, 0)] if (0, 0) in rc2v else 0

for c in range(1, C):
  for k in range(1, 4):
    v = rc2v[(0, c)] if (0, c) in rc2v else 0
    dp[0][c][k] = max(dp[0][c-1][k], dp[0][c-1][k-1]+v)

for r in range(1, R):
  rr = r % 2
  dp[rr][0][0] = max(dp[rr-1][0])
  v = rc2v[(r, 0)] if (r, 0) in rc2v else 0
  dp[rr][0][1] = dp[rr][0][0] + v
  for c in range(1, C):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    temp_max = max(dp[rr-1][c])
    dp[rr][c][1] = max(dp[rr][c-1][1], max(dp[rr][c-1][0], temp_max)+v)
    for k in range(2, 4):
      dp[rr][c][k] = max(dp[rr][c-1][k], dp[rr][c-1][k-1]+v)
    
if R % 2:
  print(max(dp[0][-1]))
else:
  print(max(dp[-1][-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-1, cc-1)] = 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-1, cc-1)] = vv rc2v[(rr-1, cc-1)] rc2v (rr-1, cc-1) rr-1 rr 1 cc-1 cc 1 vv [[0]*4 for c in range(C)] for r in range(2) for r in range(2) r range(2) range 2 for r in range(2) [[0]*4 for c in range(C)] dp = [[[0]*4 for c in range(C)] for r in range(2)] dp [[[0]*4 for c in range(C)] for r in range(2)] dp[0][0][1] = rc2v[(0, 0)] if (0, 0) in rc2v else 0 dp[0][0][1] [0] [0] dp 0 0 1 rc2v[(0, 0)] if (0, 0) in rc2v else 0 (0, 0) in rc2v (0, 0) 0 0 rc2v rc2v[(0, 0)] rc2v (0, 0) 0 0 0 for c in range(1, C):
  for k in range(1, 4):
    v = rc2v[(0, c)] if (0, c) in rc2v else 0
    dp[0][c][k] = max(dp[0][c-1][k], dp[0][c-1][k-1]+v) c range(1, C) range 1 C for k in range(1, 4):
    v = rc2v[(0, c)] if (0, c) in rc2v else 0
    dp[0][c][k] = max(dp[0][c-1][k], dp[0][c-1][k-1]+v) k range(1, 4) range 1 4 v = rc2v[(0, c)] if (0, c) in rc2v else 0 v rc2v[(0, c)] if (0, c) in rc2v else 0 (0, c) in rc2v (0, c) 0 c rc2v rc2v[(0, c)] rc2v (0, c) 0 c 0 dp[0][c][k] = max(dp[0][c-1][k], dp[0][c-1][k-1]+v) dp[0][c][k] [c] [0] dp 0 c k max(dp[0][c-1][k], dp[0][c-1][k-1]+v) max dp[0][c-1][k] [c-1] [0] dp 0 c-1 c 1 k dp[0][c-1][k-1]+v dp[0][c-1][k-1] [c-1] [0] dp 0 c-1 c 1 k-1 k 1 v for r in range(1, R):
  rr = r % 2
  dp[rr][0][0] = max(dp[rr-1][0])
  v = rc2v[(r, 0)] if (r, 0) in rc2v else 0
  dp[rr][0][1] = dp[rr][0][0] + v
  for c in range(1, C):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    temp_max = max(dp[rr-1][c])
    dp[rr][c][1] = max(dp[rr][c-1][1], max(dp[rr][c-1][0], temp_max)+v)
    for k in range(2, 4):
      dp[rr][c][k] = max(dp[rr][c-1][k], dp[rr][c-1][k-1]+v)
     r range(1, R) range 1 R rr = r % 2 rr r % 2 r 2 dp[rr][0][0] = max(dp[rr-1][0]) dp[rr][0][0] [0] [rr] dp rr 0 0 max(dp[rr-1][0]) max dp[rr-1][0] [rr-1] dp rr-1 rr 1 0 v = rc2v[(r, 0)] if (r, 0) in rc2v else 0 v rc2v[(r, 0)] if (r, 0) in rc2v else 0 (r, 0) in rc2v (r, 0) r 0 rc2v rc2v[(r, 0)] rc2v (r, 0) r 0 0 dp[rr][0][1] = dp[rr][0][0] + v dp[rr][0][1] [0] [rr] dp rr 0 1 dp[rr][0][0] + v dp[rr][0][0] [0] [rr] dp rr 0 0 v for c in range(1, C):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    temp_max = max(dp[rr-1][c])
    dp[rr][c][1] = max(dp[rr][c-1][1], max(dp[rr][c-1][0], temp_max)+v)
    for k in range(2, 4):
      dp[rr][c][k] = max(dp[rr][c-1][k], dp[rr][c-1][k-1]+v)
     c range(1, C) range 1 C 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 temp_max = max(dp[rr-1][c]) temp_max max(dp[rr-1][c]) max dp[rr-1][c] [rr-1] dp rr-1 rr 1 c dp[rr][c][1] = max(dp[rr][c-1][1], max(dp[rr][c-1][0], temp_max)+v) dp[rr][c][1] [c] [rr] dp rr c 1 max(dp[rr][c-1][1], max(dp[rr][c-1][0], temp_max)+v) max dp[rr][c-1][1] [c-1] [rr] dp rr c-1 c 1 1 max(dp[rr][c-1][0], temp_max)+v max(dp[rr][c-1][0], temp_max) max dp[rr][c-1][0] [c-1] [rr] dp rr c-1 c 1 0 temp_max v for k in range(2, 4):
      dp[rr][c][k] = max(dp[rr][c-1][k], dp[rr][c-1][k-1]+v)
     k range(2, 4) range 2 4 dp[rr][c][k] = max(dp[rr][c-1][k], dp[rr][c-1][k-1]+v) dp[rr][c][k] [c] [rr] dp rr c k max(dp[rr][c-1][k], dp[rr][c-1][k-1]+v) max dp[rr][c-1][k] [c-1] [rr] dp rr c-1 c 1 k dp[rr][c-1][k-1]+v dp[rr][c-1][k-1] [c-1] [rr] dp rr c-1 c 1 k-1 k 1 v if R % 2:
  print(max(dp[0][-1]))
else:
  print(max(dp[-1][-1])) R % 2 R 2 print(max(dp[0][-1])) print max(dp[0][-1]) max dp[0][-1] [0] dp 0 -1 print(max(dp[-1][-1])) print max(dp[-1][-1]) max dp[-1][-1] [-1] dp -1 -1 K = map(int, readline().split()) map(int, readline().split()) K temp_max = max(dp[rr-1][c]) max(dp[rr-1][c]) temp_max rc2v = {} {} rc2v readline = sys.stdin.readline sys.stdin.readline readline dp = [[[0]*4 for c in range(C)] for r in range(2)] [[[0]*4 for c in range(C)] for r in range(2)] dp v = rc2v[(0, c)] if (0, c) in rc2v else 0 rc2v[(0, c)] if (0, c) in rc2v else 0 v rr = r % 2 r % 2 rr rcv = list(map(int, read().split())) list(map(int, read().split())) rcv R, C, K = map(int, readline().split()) map(int, readline().split()) R read = sys.stdin.read sys.stdin.read read v = rc2v[(r, 0)] if (r, 0) in rc2v else 0 rc2v[(r, 0)] if (r, 0) in rc2v else 0 v C, K = map(int, readline().split()) map(int, readline().split()) C v = rc2v[(r, c)] if (r, c) in rc2v else 0 rc2v[(r, c)] if (r, c) in rc2v else 0 v readlines = sys.stdin.readlines sys.stdin.readlines readlines
# 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-1, cc-1)] = vv

dp = [[[0]*4 for c in range(C)] for r in range(2)]
dp[0][0][1] = rc2v[(0, 0)] if (0, 0) in rc2v else 0

for c in range(1, C):
  for k in range(1, 4):
    v = rc2v[(0, c)] if (0, c) in rc2v else 0
    dp[0][c][k] = max(dp[0][c-1][k], dp[0][c-1][k-1]+v)

for r in range(1, R):
  rr = r % 2
  dp[rr][0][0] = max(dp[rr-1][0])
  v = rc2v[(r, 0)] if (r, 0) in rc2v else 0
  dp[rr][0][1] = dp[rr][0][0] + v
  for c in range(1, C):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    temp_max = max(dp[rr-1][c])
    dp[rr][c][1] = max(dp[rr][c-1][1], max(dp[rr][c-1][0], temp_max)+v)
    for k in range(2, 4):
      dp[rr][c][k] = max(dp[rr][c-1][k], dp[rr][c-1][k-1]+v)
    
if R % 2:
  print(max(dp[0][-1]))
else:
  print(max(dp[-1][-1]))