def max2(x,y):
    return x if x > y else y

R, L, K = map(int, input().split())
V = [[0]*R for _ in range(L)]
for _ in range(K):
    r, c, v = map(int, input().split())
    V[c-1][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][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])) def max2(x,y):
    return x if x > y else y max2 return x if x > y else y x if x > y else y x > y x y x y x x y y R, L, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split L K [0]*R for _ in range(L) for _ in range(L) _ range(L) range L for _ in range(L) [0]*R [0] 0 R V = [[0]*R for _ in range(L)] V [[0]*R for _ in range(L)] for _ in range(K):
    r, c, v = map(int, input().split())
    V[c-1][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-1] = v V[c-1][r-1] [c-1] V c-1 c 1 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][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][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][j] v V[i][j] [i] V i 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 A, B, C, D = [[0]*(R+1) for _ in range(4)] [[0]*(R+1) for _ in range(4)] A def max2(x,y):
    return x if x > y else y def max2(x,y):
    return x if x > y else y max2 K = map(int, input().split()) map(int, input().split()) K V = [[0]*R for _ in range(L)] [[0]*R for _ in range(L)] V v = V[i][j] V[i][j] v v = map(int, input().split()) map(int, input().split()) v r, c, v = map(int, input().split()) map(int, input().split()) r c, v = map(int, input().split()) map(int, input().split()) c C, D = [[0]*(R+1) for _ in range(4)] [[0]*(R+1) for _ in range(4)] C B, C, D = [[0]*(R+1) for _ in range(4)] [[0]*(R+1) for _ in range(4)] B R, L, K = map(int, input().split()) map(int, input().split()) R L, K = map(int, input().split()) map(int, input().split()) L D = [[0]*(R+1) for _ in range(4)] [[0]*(R+1) for _ in range(4)] D
def max2(x,y):
    return x if x > y else y

R, L, K = map(int, input().split())
V = [[0]*R for _ in range(L)]
for _ in range(K):
    r, c, v = map(int, input().split())
    V[c-1][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][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]))