def max2(x,y):

    return x if x > y else y



R, C, K = list(map(int, input().split()))

V = [[0]*R for _ in range(C)]

for _ in range(K):

    r, c, v = list(map(int, input().split()))

    V[c-1][r-1] = v



dp = [[0]*4 for _ in range(R)]

for j in range(R):

    if V[0][j] != 0:

        dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j]

    if j != 0:

        dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0])

for i in range(1,C):

    for j in range(R):

        v = V[i][j]

        if v != 0:

            if dp[j][2] != 0:

                dp[j][3] = max2(dp[j][2] + v, dp[j][3])

            if dp[j][1] != 0:

                dp[j][2] = max2(dp[j][1] + v, dp[j][2])

            dp[j][1] = max2(v, dp[j][1])

        if j != 0:

            if v != 0:

                dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])

            dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0])

print((max(dp[-1])))

R, L, K = list(map(int, input().split()))

V = [[0]*R for _ in range(L)]

for _ in range(K):

    r, c, v = list(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] = max(C[j] + v, D[j]), max(B[j] + v, C[j]), max(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


R, C, K = list(map(int, input().split()))
V = [[0] * R for _ in range(C)]
for _ in range(K):
    r, c, v = list(map(int, input().split()))
    V[c - 1][r - 1] = v
dp = [[0] * 4 for _ in range(R)]
for j in range(R):
    if V[0][j] != 0:
        dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j]
    if j != 0:
        dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0])
for i in range(1, C):
    for j in range(R):
        v = V[i][j]
        if v != 0:
            if dp[j][2] != 0:
                dp[j][3] = max2(dp[j][2] + v, dp[j][3])
            if dp[j][1] != 0:
                dp[j][2] = max2(dp[j][1] + v, dp[j][2])
            dp[j][1] = max2(v, dp[j][1])
        if j != 0:
            if v != 0:
                dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])
            dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0])
print((max(dp[-1])))

R, L, K = list(map(int, input().split()))
V = [[0] * R for _ in range(L)]
for _ in range(K):
    r, c, v = list(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] = (
                max(C[j] + v, D[j]),
                max(B[j] + v, C[j]),
                max(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 - - -R, C, K = list(map(int, input().split())) -V = [[0] * R for _ in range(C)] +R, L, K = list(map(int, input().split())) +V = [[0] * R for _ in range(L)] -dp = [[0] * 4 for _ in range(R)] -for j in range(R): -    if V[0][j] != 0: -        dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j] -    if j != 0: -        dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0]) -for i in range(1, C): +A, B, C, D = [[0] * (R + 1) for _ in range(4)] +for i in range(L): +        A[j] = max(A[j - 1], B[j - 1], C[j - 1], D[j - 1]) -            if dp[j][2] != 0: -                dp[j][3] = max2(dp[j][2] + v, dp[j][3]) -            if dp[j][1] != 0: -                dp[j][2] = max2(dp[j][1] + v, dp[j][2]) -            dp[j][1] = max2(v, dp[j][1]) -        if j != 0: -            if v != 0: -                dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1]) -            dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0]) -print((max(dp[-1]))) +            D[j], C[j], B[j] = ( +                max(C[j] + v, D[j]), +                max(B[j] + v, C[j]), +                max(A[j] + v, B[j]), +            ) +print((max(A[-2], B[-2], C[-2], D[-2])))