# 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()))
rr = rcv[::3]
cc = rcv[1::3]
vv = rcv[2::3]
rc2v = {}
for _r, _c, _v in zip(rr, cc, vv):
    rc2v[(_r-1, _c-1)] = _v

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

for r in range(R):
    for c in range(C):
        if(c!=0):
            dp[c][0] = max(dp[c-1][0], max(dp[c]))
        else:
            dp[c][0] = max(dp[c])

        v = 0
        if (r, c) in rc2v:
            v = rc2v[(r, c)]
        for k in range(1,4):
            if(c!=0):
                dp[c][k] = max(dp[c-1][k], dp[c-1][k-1] + v, dp[c][0] + v)
            else:
                dp[c][k] = dp[c][0] + 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 rr = rcv[::3] rr rcv[::3] rcv ::3 3 cc = rcv[1::3] cc rcv[1::3] rcv 1::3 1 3 vv = rcv[2::3] vv rcv[2::3] rcv 2::3 2 3 rc2v = {} rc2v {} for _r, _c, _v in zip(rr, cc, vv):
    rc2v[(_r-1, _c-1)] = _v _r _c _v zip(rr, cc, vv) zip rr cc vv rc2v[(_r-1, _c-1)] = _v rc2v[(_r-1, _c-1)] rc2v (_r-1, _c-1) _r-1 _r 1 _c-1 _c 1 _v [0]*4 for c in range(C) for c in range(C) c range(C) range C for c in range(C) [0]*4 [0] 0 4 dp = [[0]*4 for c in range(C)] dp [[0]*4 for c in range(C)] for r in range(R):
    for c in range(C):
        if(c!=0):
            dp[c][0] = max(dp[c-1][0], max(dp[c]))
        else:
            dp[c][0] = max(dp[c])

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

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

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

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

for r in range(R):
    for c in range(C):
        if(c!=0):
            dp[c][0] = max(dp[c-1][0], max(dp[c]))
        else:
            dp[c][0] = max(dp[c])

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

print(max(dp[-1]))