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())
    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
    print(calc(cell, R, C))

@njit(i8(i8[:,:],i8,i8))
def calc(cell, R, C):
    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    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):
                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, k-1])
                    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, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])
    return dp[R, C, 3]

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())
    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
    print(calc(cell, R, C)) main R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K 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] cell x-1 x 1 c print(calc(cell, R, C)) print calc(cell, R, C) calc cell R C def calc(cell, R, C):
    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    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):
                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, k-1])
                    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, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])
    return dp[R, C, 3] calc 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 dp[0, 1, 0] = dp[1, 0, 0] = 0 dp[0, 1, 0] dp 0 0 = dp[1, 0, 0] = 0 dp[1, 0, 0] dp 1 0 for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                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, k-1])
                    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, 1] = 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):
                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, k-1])
                    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, 1] = 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):
                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, k-1])
                    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, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])
     k range(4) range 4 dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k]) dp[i, j, k] dp i max(dp[i, j, k], dp[i, j-1, k]) max dp[i, j, k] dp i dp[i, j-1, k] dp i 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-1] + cell[i-1, j-1])
                 k > 0 k 0 dp[i, j, k] = max(dp[i, j, k], dp[i, j, k-1]) dp[i, j, k] dp i max(dp[i, j, k], dp[i, j, k-1]) max dp[i, j, k] dp i dp[i, j, k-1] dp i dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k-1] + cell[i-1, j-1]) dp[i, j, k] dp i max(dp[i, j, k], dp[i, j-1, k-1] + cell[i-1, j-1]) max dp[i, j, k] dp i dp[i, j-1, k-1] + cell[i-1, j-1] dp[i, j-1, k-1] dp i cell[i-1, j-1] cell i-1 i 1 if k == 1:
                    dp[i, j, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])
     k == 1 k 1 dp[i, j, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1]) dp[i, j, 1] dp i max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1]) max dp[i, j, 1] dp i dp[i-1, j, 3] + cell[i-1, j-1] dp[i-1, j, 3] dp i-1 i 1 cell[i-1, j-1] cell i-1 i 1 return dp[R, C, 3] dp[R, C, 3] dp R cell cell R R C C @njit(i8(i8[:,:],i8,i8)) calc i8(i8[:,:],i8,i8) @njit(i8(i8[:,:],i8,i8)) njit i8(i8[:,:],i8,i8) i8 i8[:,:] i8 : i8 i8 calc if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    R, C, K = map(int, input().split())
    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
    print(calc(cell, R, C)) def main():
    R, C, K = map(int, input().split())
    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
    print(calc(cell, R, C)) main def calc(cell, R, C):
    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    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):
                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, k-1])
                    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, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])
    return dp[R, C, 3] def calc(cell, R, C):
    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    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):
                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, k-1])
                    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, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])
    return dp[R, C, 3] calc input = sys.stdin.buffer.readline sys.stdin.buffer.readline input
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())
    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
    print(calc(cell, R, C))

@njit(i8(i8[:,:],i8,i8))
def calc(cell, R, C):
    L_INF = int(1e17)
    dp = np.full((R+1, C+1, 4), -L_INF, dtype=np.int64)
    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):
                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, k-1])
                    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, 1] = max(dp[i, j, 1], dp[i-1, j, 3] + cell[i-1, j-1])
    return dp[R, C, 3]

if __name__ == "__main__":
    main()
