import sys
import numpy as np
from numba import njit, void, i8
input = sys.stdin.buffer.readline

def main():
    R, C, K = map(int, input().split())

    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    cell = np.full((R+1, C+1), 0, dtype=np.int64)

    for i in range(K):
        x, y, c = map(int, input().split())
        cell[x-1][y-1] = c

    f(dp, cell, R, C)

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

@njit(void(i8[:,:,:],i8[:,:],i8,i8))
def f(dp, cell, R, C):
    dp[0][1][0] = dp[1][0][0] = 0
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1])

if __name__ == "__main__":
    main() import sys sys import numpy as np numpy from numba import njit, void, i8 input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def main():
    R, C, K = map(int, input().split())

    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    cell = np.full((R+1, C+1), 0, dtype=np.int64)

    for i in range(K):
        x, y, c = map(int, input().split())
        cell[x-1][y-1] = c

    f(dp, cell, R, C)

    print(dp[R][C][3]) main R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K L_INF = int(1e17) L_INF int(1e17) int 1e17 dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64) dp np.full((R+1, C+1, 4), -L_INF, dtype=np.int64) np.full np full (R+1, C+1, 4) R+1 R 1 C+1 C 1 4 -L_INF L_INF dtype=np.int64 dtype np.int64 np int64 cell = np.full((R+1, C+1), 0, dtype=np.int64) cell np.full((R+1, C+1), 0, dtype=np.int64) np.full np full (R+1, C+1) R+1 R 1 C+1 C 1 0 dtype=np.int64 dtype np.int64 np int64 for i in range(K):
        x, y, c = map(int, input().split())
        cell[x-1][y-1] = c

     i range(K) range K x, y, c = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y c cell[x-1][y-1] = c cell[x-1][y-1] [x-1] cell x-1 x 1 y-1 y 1 c f(dp, cell, R, C) f dp cell R C print(dp[R][C][3]) print dp[R][C][3] [C] [R] dp R C 3 def f(dp, cell, R, C):
    dp[0][1][0] = dp[1][0][0] = 0
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1]) f dp[0][1][0] = dp[1][0][0] = 0 dp[0][1][0] [1] [0] dp 0 1 0 0 = dp[1][0][0] = 0 dp[1][0][0] [0] [1] dp 1 0 0 0 for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1]) i range(1, R + 1) range 1 R + 1 R 1 for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1]) j range(1, C + 1) range 1 C + 1 C 1 for k in range(4):
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1]) k range(4) range 4 if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                 k > 0 k 0 dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1]) dp[i][j][k] [j] [i] dp i j k max(dp[i][j][k], dp[i][j][k-1]) max dp[i][j][k] [j] [i] dp i j k dp[i][j][k-1] [j] [i] dp i j k-1 k 1 dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k]) dp[i][j][k] [j] [i] dp i j k max(dp[i][j][k], dp[i][j-1][k]) max dp[i][j][k] [j] [i] dp i j k dp[i][j-1][k] [j-1] [i] dp i j-1 j 1 k if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                 k > 0 k 0 dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1]) dp[i][j][k] [j] [i] dp i j k max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1]) max dp[i][j][k] [j] [i] dp i j k dp[i][j-1][k-1] + cell[i-1][j-1] dp[i][j-1][k-1] [j-1] [i] dp i j-1 j 1 k-1 k 1 cell[i-1][j-1] [i-1] cell i-1 i 1 j-1 j 1 if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1]) k == 1 k 1 dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1]) dp[i][j][k] [j] [i] dp i j k max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1]) max dp[i][j][1] [j] [i] dp i j 1 dp[i-1][j][3] + cell[i-1][j-1] dp[i-1][j][3] [j] [i-1] dp i-1 i 1 j 3 cell[i-1][j-1] [i-1] cell i-1 i 1 j-1 j 1 dp dp cell cell R R C C @njit(void(i8[:,:,:],i8[:,:],i8,i8)) f void(i8[:,:,:],i8[:,:],i8,i8) @njit(void(i8[:,:,:],i8[:,:],i8,i8)) njit void(i8[:,:,:],i8[:,:],i8,i8) void i8[:,:,:] i8 : i8[:,:] i8 : i8 i8 f if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def f(dp, cell, R, C):
    dp[0][1][0] = dp[1][0][0] = 0
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1]) def f(dp, cell, R, C):
    dp[0][1][0] = dp[1][0][0] = 0
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1]) f input = sys.stdin.buffer.readline sys.stdin.buffer.readline input def main():
    R, C, K = map(int, input().split())

    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    cell = np.full((R+1, C+1), 0, dtype=np.int64)

    for i in range(K):
        x, y, c = map(int, input().split())
        cell[x-1][y-1] = c

    f(dp, cell, R, C)

    print(dp[R][C][3]) def main():
    R, C, K = map(int, input().split())

    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    cell = np.full((R+1, C+1), 0, dtype=np.int64)

    for i in range(K):
        x, y, c = map(int, input().split())
        cell[x-1][y-1] = c

    f(dp, cell, R, C)

    print(dp[R][C][3]) main
import sys
import numpy as np
from numba import njit, void, i8
input = sys.stdin.buffer.readline

def main():
    R, C, K = map(int, input().split())

    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    cell = np.full((R+1, C+1), 0, dtype=np.int64)

    for i in range(K):
        x, y, c = map(int, input().split())
        cell[x-1][y-1] = c

    f(dp, cell, R, C)

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

@njit(void(i8[:,:,:],i8[:,:],i8,i8))
def f(dp, cell, R, C):
    dp[0][1][0] = dp[1][0][0] = 0
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j][k-1])
                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if k > 0:
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + cell[i-1][j-1])
                if k == 1:
                    dp[i][j][k] = max(dp[i][j][1], dp[i-1][j][3] + cell[i-1][j-1])

if __name__ == "__main__":
    main()
