from numpy import zeros, int64
from numba import njit

R, C, K, *RCV = map(int64, open(0).read().split())
V = zeros((R + 1, C + 1), int64)
for r, c, v in zip(*[iter(RCV)] * 3):
    V[r][c] = v

@njit
def main():
    dp = zeros((R + 1, C + 1, 4), int64)
    for i in range(1, R + 1):
        for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

    print(dp[R][C][3])

main() from numpy import zeros, int64 from numba import njit R, C, K, *RCV = map(int64, open(0).read().split()) R map(int64, open(0).read().split()) map int64 open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split C K *RCV RCV V = zeros((R + 1, C + 1), int64) V zeros((R + 1, C + 1), int64) zeros (R + 1, C + 1) R + 1 R 1 C + 1 C 1 int64 for r, c, v in zip(*[iter(RCV)] * 3):
    V[r][c] = v r c v zip(*[iter(RCV)] * 3) zip *[iter(RCV)] * 3 [iter(RCV)] * 3 [iter(RCV)] iter(RCV) iter RCV 3 V[r][c] = v V[r][c] [r] V r c v def main():
    dp = zeros((R + 1, C + 1, 4), int64)
    for i in range(1, R + 1):
        for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

    print(dp[R][C][3]) main dp = zeros((R + 1, C + 1, 4), int64) dp zeros((R + 1, C + 1, 4), int64) zeros (R + 1, C + 1, 4) R + 1 R 1 C + 1 C 1 4 int64 for i in range(1, R + 1):
        for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

     i range(1, R + 1) range 1 R + 1 R 1 for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

     j range(1, C + 1) range 1 C + 1 C 1 vij = V[i][j] vij V[i][j] [i] V i j for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
             k range(4) range 4 dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                ) dp[i][j][k] [j] [i] dp i j k max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                ) max dp[i][j - 1][k] [j - 1] [i] dp i j - 1 j 1 k dp[i - 1][j][3] [j] [i - 1] dp i - 1 i 1 j 3 for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

     k range(3, 0, -1) range 3 0 -1 dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                ) dp[i][j][k] [j] [i] dp i j k max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                ) max dp[i][j][k] [j] [i] dp i j k vij + dp[i][j][k - 1] vij dp[i][j][k - 1] [j] [i] dp i j k - 1 k 1 print(dp[R][C][3]) print dp[R][C][3] [C] [R] dp R C 3 @njit main njit main main() main V = zeros((R + 1, C + 1), int64) zeros((R + 1, C + 1), int64) V C, K, *RCV = map(int64, open(0).read().split()) map(int64, open(0).read().split()) C R, C, K, *RCV = map(int64, open(0).read().split()) map(int64, open(0).read().split()) R K, *RCV = map(int64, open(0).read().split()) map(int64, open(0).read().split()) K def main():
    dp = zeros((R + 1, C + 1, 4), int64)
    for i in range(1, R + 1):
        for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

    print(dp[R][C][3]) def main():
    dp = zeros((R + 1, C + 1, 4), int64)
    for i in range(1, R + 1):
        for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

    print(dp[R][C][3]) main
from numpy import zeros, int64
from numba import njit

R, C, K, *RCV = map(int64, open(0).read().split())
V = zeros((R + 1, C + 1), int64)
for r, c, v in zip(*[iter(RCV)] * 3):
    V[r][c] = v

@njit
def main():
    dp = zeros((R + 1, C + 1, 4), int64)
    for i in range(1, R + 1):
        for j in range(1, C + 1):

            vij = V[i][j]

            for k in range(4):
                dp[i][j][k] = max(
                    dp[i][j - 1][k],
                    dp[i - 1][j][3]
                )
            for k in range(3, 0, -1):
                dp[i][j][k] = max(
                    dp[i][j][k],
                    vij + dp[i][j][k - 1]
                )

    print(dp[R][C][3])

main()