import sys
import numpy as np
from numba import njit, void, i8

def main():
    R, C, K = map(int, readline().split())
    items = np.array(read().split(), dtype=np.int64)
    print(calc(R, C, K, items))

@njit(i8(i8, i8, i8, i8[:]), cache=True)
def calc(R, C, K, items):
    cell = np.zeros((R, C), dtype=np.int64)
    for i in range(0, K*3, 3):
        x, y, c = items[i:i+3]
        cell[x-1, y-1] = 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__":
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline

    if __file__=="test.py":
        f = open("./in_out/input.txt", "r", encoding="utf-8")
        read = f.read
        readline = f.readline

    main() import sys sys import numpy as np numpy from numba import njit, void, i8 def main():
    R, C, K = map(int, readline().split())
    items = np.array(read().split(), dtype=np.int64)
    print(calc(R, C, K, items)) main R, C, K = map(int, readline().split()) R map(int, readline().split()) map int readline().split() ().split () readline split C K items = np.array(read().split(), dtype=np.int64) items np.array(read().split(), dtype=np.int64) np.array np array read().split() ().split () read split dtype=np.int64 dtype np.int64 np int64 print(calc(R, C, K, items)) print calc(R, C, K, items) calc R C K items def calc(R, C, K, items):
    cell = np.zeros((R, C), dtype=np.int64)
    for i in range(0, K*3, 3):
        x, y, c = items[i:i+3]
        cell[x-1, y-1] = 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 cell = np.zeros((R, C), dtype=np.int64) cell np.zeros((R, C), dtype=np.int64) np.zeros np zeros (R, C) R C dtype=np.int64 dtype np.int64 np int64 for i in range(0, K*3, 3):
        x, y, c = items[i:i+3]
        cell[x-1, y-1] = c
     i range(0, K*3, 3) range 0 K*3 K 3 3 x, y, c = items[i:i+3] x items[i:i+3] items i:i+3 i i+3 i 3 y c cell[x-1, y-1] = c cell[x-1, y-1] cell x-1 x 1 c 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 R R C C K K items items @njit(i8(i8, i8, i8, i8[:]), cache=True) calc i8(i8, i8, i8, i8[:]), cache=True @njit(i8(i8, i8, i8, i8[:]), cache=True) njit i8(i8, i8, i8, i8[:]) i8 i8 i8 i8 i8[:] i8 : cache=True cache True calc if __name__ == "__main__":
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline

    if __file__=="test.py":
        f = open("./in_out/input.txt", "r", encoding="utf-8")
        read = f.read
        readline = f.readline

    main() __name__ == "__main__" __name__ "__main__" read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline if __file__=="test.py":
        f = open("./in_out/input.txt", "r", encoding="utf-8")
        read = f.read
        readline = f.readline

     __file__=="test.py" __file__ "test.py" f = open("./in_out/input.txt", "r", encoding="utf-8") f open("./in_out/input.txt", "r", encoding="utf-8") open "./in_out/input.txt" "r" encoding="utf-8" encoding "utf-8" read = f.read read f.read f read readline = f.readline readline f.readline f readline main() main def main():
    R, C, K = map(int, readline().split())
    items = np.array(read().split(), dtype=np.int64)
    print(calc(R, C, K, items)) def main():
    R, C, K = map(int, readline().split())
    items = np.array(read().split(), dtype=np.int64)
    print(calc(R, C, K, items)) main read = f.read f.read read def calc(R, C, K, items):
    cell = np.zeros((R, C), dtype=np.int64)
    for i in range(0, K*3, 3):
        x, y, c = items[i:i+3]
        cell[x-1, y-1] = 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(R, C, K, items):
    cell = np.zeros((R, C), dtype=np.int64)
    for i in range(0, K*3, 3):
        x, y, c = items[i:i+3]
        cell[x-1, y-1] = 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 read = sys.stdin.buffer.read sys.stdin.buffer.read read readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline f = open("./in_out/input.txt", "r", encoding="utf-8") open("./in_out/input.txt", "r", encoding="utf-8") f readline = f.readline f.readline readline
import sys
import numpy as np
from numba import njit, void, i8

def main():
    R, C, K = map(int, readline().split())
    items = np.array(read().split(), dtype=np.int64)
    print(calc(R, C, K, items))

@njit(i8(i8, i8, i8, i8[:]), cache=True)
def calc(R, C, K, items):
    cell = np.zeros((R, C), dtype=np.int64)
    for i in range(0, K*3, 3):
        x, y, c = items[i:i+3]
        cell[x-1, y-1] = 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__":
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline

    if __file__=="test.py":
        f = open("./in_out/input.txt", "r", encoding="utf-8")
        read = f.read
        readline = f.readline

    main()
