import sys
input = sys.stdin.readline
R,C,K = map(int,input().split())
RCV = [tuple(map(int,input().split())) for i in range(K)]

goods = [dict() for _ in range(R)]
for r,c,v in RCV:
    r,c = r-1,c-1
    goods[r][c] = v

dp0 = [[0]*4 for _ in range(C)]
dp1 = [[0]*4 for _ in range(C)]
if 0 in goods[0]:
    dp1[0][1] = goods[0][0]
for i in range(R):
    for j in range(C):
        if i:
            pre = max(dp0[j])
            dp1[j][0] = pre
            if j in goods[i]:
                dp1[j][1] = pre + goods[i][j]
        if j:
            for k in range(4):
                dp1[j][k] = max(dp1[j][k], dp1[j-1][k])
            if j in goods[i]:
                for k in reversed(range(3)):
                    dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j])
    dp0 = dp1
    dp1 = [[0]*4 for _ in range(C)]
print(max(dp0[-1])) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline R,C,K = map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K tuple(map(int,input().split())) for i in range(K) for i in range(K) i range(K) range K for i in range(K) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split RCV = [tuple(map(int,input().split())) for i in range(K)] RCV [tuple(map(int,input().split())) for i in range(K)] dict() for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) dict() dict goods = [dict() for _ in range(R)] goods [dict() for _ in range(R)] for r,c,v in RCV:
    r,c = r-1,c-1
    goods[r][c] = v r c v RCV r,c = r-1,c-1 r r-1 r 1 c c-1 c 1 goods[r][c] = v goods[r][c] [r] goods r c v [0]*4 for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0]*4 [0] 0 4 dp0 = [[0]*4 for _ in range(C)] dp0 [[0]*4 for _ in range(C)] [0]*4 for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0]*4 [0] 0 4 dp1 = [[0]*4 for _ in range(C)] dp1 [[0]*4 for _ in range(C)] if 0 in goods[0]:
    dp1[0][1] = goods[0][0] 0 in goods[0] 0 goods[0] goods 0 dp1[0][1] = goods[0][0] dp1[0][1] [0] dp1 0 1 goods[0][0] [0] goods 0 0 for i in range(R):
    for j in range(C):
        if i:
            pre = max(dp0[j])
            dp1[j][0] = pre
            if j in goods[i]:
                dp1[j][1] = pre + goods[i][j]
        if j:
            for k in range(4):
                dp1[j][k] = max(dp1[j][k], dp1[j-1][k])
            if j in goods[i]:
                for k in reversed(range(3)):
                    dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j])
    dp0 = dp1
    dp1 = [[0]*4 for _ in range(C)] i range(R) range R for j in range(C):
        if i:
            pre = max(dp0[j])
            dp1[j][0] = pre
            if j in goods[i]:
                dp1[j][1] = pre + goods[i][j]
        if j:
            for k in range(4):
                dp1[j][k] = max(dp1[j][k], dp1[j-1][k])
            if j in goods[i]:
                for k in reversed(range(3)):
                    dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j])
     j range(C) range C if i:
            pre = max(dp0[j])
            dp1[j][0] = pre
            if j in goods[i]:
                dp1[j][1] = pre + goods[i][j]
         i pre = max(dp0[j]) pre max(dp0[j]) max dp0[j] dp0 j dp1[j][0] = pre dp1[j][0] [j] dp1 j 0 pre if j in goods[i]:
                dp1[j][1] = pre + goods[i][j]
         j in goods[i] j goods[i] goods i dp1[j][1] = pre + goods[i][j] dp1[j][1] [j] dp1 j 1 pre + goods[i][j] pre goods[i][j] [i] goods i j if j:
            for k in range(4):
                dp1[j][k] = max(dp1[j][k], dp1[j-1][k])
            if j in goods[i]:
                for k in reversed(range(3)):
                    dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j])
     j for k in range(4):
                dp1[j][k] = max(dp1[j][k], dp1[j-1][k])
             k range(4) range 4 dp1[j][k] = max(dp1[j][k], dp1[j-1][k]) dp1[j][k] [j] dp1 j k max(dp1[j][k], dp1[j-1][k]) max dp1[j][k] [j] dp1 j k dp1[j-1][k] [j-1] dp1 j-1 j 1 k if j in goods[i]:
                for k in reversed(range(3)):
                    dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j])
     j in goods[i] j goods[i] goods i for k in reversed(range(3)):
                    dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j])
     k reversed(range(3)) reversed range(3) range 3 dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j]) dp1[j][k+1] [j] dp1 j k+1 k 1 max(dp1[j][k+1], dp1[j-1][k] + goods[i][j]) max dp1[j][k+1] [j] dp1 j k+1 k 1 dp1[j-1][k] + goods[i][j] dp1[j-1][k] [j-1] dp1 j-1 j 1 k goods[i][j] [i] goods i j dp0 = dp1 dp0 dp1 [0]*4 for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0]*4 [0] 0 4 dp1 = [[0]*4 for _ in range(C)] dp1 [[0]*4 for _ in range(C)] print(max(dp0[-1])) print max(dp0[-1]) max dp0[-1] dp0 -1 dp1 = [[0]*4 for _ in range(C)] [[0]*4 for _ in range(C)] dp1 RCV = [tuple(map(int,input().split())) for i in range(K)] [tuple(map(int,input().split())) for i in range(K)] RCV dp0 = [[0]*4 for _ in range(C)] [[0]*4 for _ in range(C)] dp0 pre = max(dp0[j]) max(dp0[j]) pre dp1 = [[0]*4 for _ in range(C)] [[0]*4 for _ in range(C)] dp1 input = sys.stdin.readline sys.stdin.readline input goods = [dict() for _ in range(R)] [dict() for _ in range(R)] goods K = map(int,input().split()) map(int,input().split()) K dp0 = dp1 dp1 dp0 r,c = r-1,c-1 r-1 r c = r-1,c-1 c-1 c R,C,K = map(int,input().split()) map(int,input().split()) R C,K = map(int,input().split()) map(int,input().split()) C
import sys
input = sys.stdin.readline
R,C,K = map(int,input().split())
RCV = [tuple(map(int,input().split())) for i in range(K)]

goods = [dict() for _ in range(R)]
for r,c,v in RCV:
    r,c = r-1,c-1
    goods[r][c] = v

dp0 = [[0]*4 for _ in range(C)]
dp1 = [[0]*4 for _ in range(C)]
if 0 in goods[0]:
    dp1[0][1] = goods[0][0]
for i in range(R):
    for j in range(C):
        if i:
            pre = max(dp0[j])
            dp1[j][0] = pre
            if j in goods[i]:
                dp1[j][1] = pre + goods[i][j]
        if j:
            for k in range(4):
                dp1[j][k] = max(dp1[j][k], dp1[j-1][k])
            if j in goods[i]:
                for k in reversed(range(3)):
                    dp1[j][k+1] = max(dp1[j][k+1], dp1[j-1][k] + goods[i][j])
    dp0 = dp1
    dp1 = [[0]*4 for _ in range(C)]
print(max(dp0[-1]))