import sys
input = sys.stdin.readline
R, L, K = map(int, input().split())
V = [0]*(R*L)
max2 = lambda x, y: x if x > y else y
for _ in range(K):
    r, c, v = map(int, input().split())
    V[(c-1)*R+(r-1)] = v
A, B, C, D = [[0]*(R+1) for _ in range(4)]
for i in range(L):
    for j in range(R):
        A[j] = max(A[j-1],B[j-1],C[j-1],D[j-1])
        v = V[i*R+j]
        if v != 0:
            D[j], C[j], B[j] = max2(C[j]+v,D[j]), max2(B[j]+v,C[j]), max2(A[j]+v,B[j])
print(max(A[-2],B[-2],C[-2],D[-2])) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline R, L, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split L K V = [0]*(R*L) V [0]*(R*L) [0] 0 R*L R L max2 = lambda x, y: x if x > y else y max2 lambda x, y: x if x > y else y x if x > y else y x > y x y x y x y for _ in range(K):
    r, c, v = map(int, input().split())
    V[(c-1)*R+(r-1)] = v _ range(K) range K r, c, v = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c v V[(c-1)*R+(r-1)] = v V[(c-1)*R+(r-1)] V (c-1)*R+(r-1) (c-1)*R c-1 c 1 R r-1 r 1 v [0]*(R+1) for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [0]*(R+1) [0] 0 R+1 R 1 A, B, C, D = [[0]*(R+1) for _ in range(4)] A [[0]*(R+1) for _ in range(4)] B C D for i in range(L):
    for j in range(R):
        A[j] = max(A[j-1],B[j-1],C[j-1],D[j-1])
        v = V[i*R+j]
        if v != 0:
            D[j], C[j], B[j] = max2(C[j]+v,D[j]), max2(B[j]+v,C[j]), max2(A[j]+v,B[j]) i range(L) range L for j in range(R):
        A[j] = max(A[j-1],B[j-1],C[j-1],D[j-1])
        v = V[i*R+j]
        if v != 0:
            D[j], C[j], B[j] = max2(C[j]+v,D[j]), max2(B[j]+v,C[j]), max2(A[j]+v,B[j]) j range(R) range R A[j] = max(A[j-1],B[j-1],C[j-1],D[j-1]) A[j] A j max(A[j-1],B[j-1],C[j-1],D[j-1]) max A[j-1] A j-1 j 1 B[j-1] B j-1 j 1 C[j-1] C j-1 j 1 D[j-1] D j-1 j 1 v = V[i*R+j] v V[i*R+j] V i*R+j i*R i R j if v != 0:
            D[j], C[j], B[j] = max2(C[j]+v,D[j]), max2(B[j]+v,C[j]), max2(A[j]+v,B[j]) v != 0 v 0 D[j], C[j], B[j] = max2(C[j]+v,D[j]), max2(B[j]+v,C[j]), max2(A[j]+v,B[j]) D[j] D j max2(C[j]+v,D[j]) max2 C[j]+v C[j] C j v D[j] D j C[j] C j max2(B[j]+v,C[j]) max2 B[j]+v B[j] B j v C[j] C j B[j] B j max2(A[j]+v,B[j]) max2 A[j]+v A[j] A j v B[j] B j print(max(A[-2],B[-2],C[-2],D[-2])) print max(A[-2],B[-2],C[-2],D[-2]) max A[-2] A -2 B[-2] B -2 C[-2] C -2 D[-2] D -2 L, K = map(int, input().split()) map(int, input().split()) L c, v = map(int, input().split()) map(int, input().split()) c V = [0]*(R*L) [0]*(R*L) V C, D = [[0]*(R+1) for _ in range(4)] [[0]*(R+1) for _ in range(4)] C D = [[0]*(R+1) for _ in range(4)] [[0]*(R+1) for _ in range(4)] D v = map(int, input().split()) map(int, input().split()) v r, c, v = map(int, input().split()) map(int, input().split()) r input = sys.stdin.readline sys.stdin.readline input B, C, D = [[0]*(R+1) for _ in range(4)] [[0]*(R+1) for _ in range(4)] B A, B, C, D = [[0]*(R+1) for _ in range(4)] [[0]*(R+1) for _ in range(4)] A K = map(int, input().split()) map(int, input().split()) K max2 = lambda x, y: x if x > y else y lambda x, y: x if x > y else y max2 v = V[i*R+j] V[i*R+j] v R, L, K = map(int, input().split()) map(int, input().split()) R
import sys
input = sys.stdin.readline
R, L, K = map(int, input().split())
V = [0]*(R*L)
max2 = lambda x, y: x if x > y else y
for _ in range(K):
    r, c, v = map(int, input().split())
    V[(c-1)*R+(r-1)] = v
A, B, C, D = [[0]*(R+1) for _ in range(4)]
for i in range(L):
    for j in range(R):
        A[j] = max(A[j-1],B[j-1],C[j-1],D[j-1])
        v = V[i*R+j]
        if v != 0:
            D[j], C[j], B[j] = max2(C[j]+v,D[j]), max2(B[j]+v,C[j]), max2(A[j]+v,B[j])
print(max(A[-2],B[-2],C[-2],D[-2]))