# from sys import stdin
# input = stdin.readline
(R,C,K) = map(int, input().split())
rcv = [list(map(int, input().split())) for _ in range(K)]
 
grids = [[0]*C for _ in range(R)]
 
for r,c,v in rcv:
    grids[r-1][c-1] = v
 
dp = [0] * C

for r in range(R):
#     print(dp)
    ndp = [0] * C
    elm = [0] * 4
    for c in range(C):
        elm[0] = max(elm[0], dp[c])
        value = grids[r][c]
        if value:
            nelm = [0] * 4
            nelm[0] = elm[0]
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            for i in range(3)[::-1]:
                nelm[i + 1] = max(elm[i + 1], elm[i] + value)
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            elm = nelm
        ndp[c] = max(elm)
    dp = ndp
 

print(dp[-1]) (R,C,K) = map(int, input().split()) (R,C,K) R C K map(int, input().split()) map int input().split() ().split () input split list(map(int, input().split())) for _ in range(K) for _ in range(K) _ range(K) range K for _ in range(K) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split rcv = [list(map(int, input().split())) for _ in range(K)] rcv [list(map(int, input().split())) for _ in range(K)] [0]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C grids = [[0]*C for _ in range(R)] grids [[0]*C for _ in range(R)] for r,c,v in rcv:
    grids[r-1][c-1] = v
  r c v rcv grids[r-1][c-1] = v grids[r-1][c-1] [r-1] grids r-1 r 1 c-1 c 1 v dp = [0] * C dp [0] * C [0] 0 C for r in range(R):
#     print(dp)
    ndp = [0] * C
    elm = [0] * 4
    for c in range(C):
        elm[0] = max(elm[0], dp[c])
        value = grids[r][c]
        if value:
            nelm = [0] * 4
            nelm[0] = elm[0]
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            for i in range(3)[::-1]:
                nelm[i + 1] = max(elm[i + 1], elm[i] + value)
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            elm = nelm
        ndp[c] = max(elm)
    dp = ndp
  r range(R) range R ndp = [0] * C ndp [0] * C [0] 0 C elm = [0] * 4 elm [0] * 4 [0] 0 4 for c in range(C):
        elm[0] = max(elm[0], dp[c])
        value = grids[r][c]
        if value:
            nelm = [0] * 4
            nelm[0] = elm[0]
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            for i in range(3)[::-1]:
                nelm[i + 1] = max(elm[i + 1], elm[i] + value)
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            elm = nelm
        ndp[c] = max(elm)
     c range(C) range C elm[0] = max(elm[0], dp[c]) elm[0] elm 0 max(elm[0], dp[c]) max elm[0] elm 0 dp[c] dp c value = grids[r][c] value grids[r][c] [r] grids r c if value:
            nelm = [0] * 4
            nelm[0] = elm[0]
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            for i in range(3)[::-1]:
                nelm[i + 1] = max(elm[i + 1], elm[i] + value)
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            elm = nelm
         value nelm = [0] * 4 nelm [0] * 4 [0] 0 4 nelm[0] = elm[0] nelm[0] nelm 0 elm[0] elm 0 for i in range(3)[::-1]:
                nelm[i + 1] = max(elm[i + 1], elm[i] + value)
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
             i range(3)[::-1] (3) range 3 ::-1 -1 nelm[i + 1] = max(elm[i + 1], elm[i] + value) nelm[i + 1] nelm i + 1 i 1 max(elm[i + 1], elm[i] + value) max elm[i + 1] elm i + 1 i 1 elm[i] + value elm[i] elm i value elm = nelm elm nelm ndp[c] = max(elm) ndp[c] ndp c max(elm) max elm dp = ndp dp ndp print(dp[-1]) print dp[-1] dp -1 nelm = [0] * 4 [0] * 4 nelm dp = [0] * C [0] * C dp dp = ndp ndp dp elm = nelm nelm elm value = grids[r][c] grids[r][c] value grids = [[0]*C for _ in range(R)] [[0]*C for _ in range(R)] grids elm = [0] * 4 [0] * 4 elm ndp = [0] * C [0] * C ndp rcv = [list(map(int, input().split())) for _ in range(K)] [list(map(int, input().split())) for _ in range(K)] rcv
# from sys import stdin
# input = stdin.readline
(R,C,K) = map(int, input().split())
rcv = [list(map(int, input().split())) for _ in range(K)]
 
grids = [[0]*C for _ in range(R)]
 
for r,c,v in rcv:
    grids[r-1][c-1] = v
 
dp = [0] * C

for r in range(R):
#     print(dp)
    ndp = [0] * C
    elm = [0] * 4
    for c in range(C):
        elm[0] = max(elm[0], dp[c])
        value = grids[r][c]
        if value:
            nelm = [0] * 4
            nelm[0] = elm[0]
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            for i in range(3)[::-1]:
                nelm[i + 1] = max(elm[i + 1], elm[i] + value)
#             print(f'{value=}')
#             print(f'{ elm=}')
#             print(f'{nelm=}')
            elm = nelm
        ndp[c] = max(elm)
    dp = ndp
 

print(dp[-1])