import numpy as np
from numba import njit, i8


@njit(i8[:](i8[:]), cache=True)
def max_acc(li):
    res = li.copy()
    cur_max = res[0]
    for i in range(len(li)):
        if res[i] > cur_max:
            cur_max = res[i]
        res[i] = cur_max
    return res


@njit(i8(i8, i8, i8[:, :]), cache=True)
def solve(R, C, goods):
    dp = np.zeros(C + 1, dtype=np.int64)
    for i in range(R):
        dp[1:] += goods[i]
        dp = max_acc(dp)
        for _ in range(2):
            dp[1:] = np.maximum(dp[:-1] + goods[i], dp[1:])
            dp = max_acc(dp)
    return dp[-1]


R, C, K, *rcv = map(int, open(0).read().split())
goods = np.zeros((R, C), dtype=np.int64)
for r, c, v in zip(*[iter(rcv)] * 3):
    goods[r - 1][c - 1] = v
print(solve(R, C, goods)) import numpy as np numpy from numba import njit, i8 def max_acc(li):
    res = li.copy()
    cur_max = res[0]
    for i in range(len(li)):
        if res[i] > cur_max:
            cur_max = res[i]
        res[i] = cur_max
    return res max_acc res = li.copy() res li.copy() li.copy li copy cur_max = res[0] cur_max res[0] res 0 for i in range(len(li)):
        if res[i] > cur_max:
            cur_max = res[i]
        res[i] = cur_max
     i range(len(li)) range len(li) len li if res[i] > cur_max:
            cur_max = res[i]
         res[i] > cur_max res[i] res i cur_max cur_max = res[i] cur_max res[i] res i res[i] = cur_max res[i] res i cur_max return res res li li @njit(i8[:](i8[:]), cache=True) max_acc i8[:](i8[:]), cache=True @njit(i8[:](i8[:]), cache=True) njit i8[:](i8[:]) [:] i8 : i8[:] i8 : cache=True cache True max_acc def solve(R, C, goods):
    dp = np.zeros(C + 1, dtype=np.int64)
    for i in range(R):
        dp[1:] += goods[i]
        dp = max_acc(dp)
        for _ in range(2):
            dp[1:] = np.maximum(dp[:-1] + goods[i], dp[1:])
            dp = max_acc(dp)
    return dp[-1] solve dp = np.zeros(C + 1, dtype=np.int64) dp np.zeros(C + 1, dtype=np.int64) np.zeros np zeros C + 1 C 1 dtype=np.int64 dtype np.int64 np int64 for i in range(R):
        dp[1:] += goods[i]
        dp = max_acc(dp)
        for _ in range(2):
            dp[1:] = np.maximum(dp[:-1] + goods[i], dp[1:])
            dp = max_acc(dp)
     i range(R) range R dp[1:] += goods[i] dp[1:] dp 1: 1 goods[i] goods i dp = max_acc(dp) dp max_acc(dp) max_acc dp for _ in range(2):
            dp[1:] = np.maximum(dp[:-1] + goods[i], dp[1:])
            dp = max_acc(dp)
     _ range(2) range 2 dp[1:] = np.maximum(dp[:-1] + goods[i], dp[1:]) dp[1:] dp 1: 1 np.maximum(dp[:-1] + goods[i], dp[1:]) np.maximum np maximum dp[:-1] + goods[i] dp[:-1] dp :-1 -1 goods[i] goods i dp[1:] dp 1: 1 dp = max_acc(dp) dp max_acc(dp) max_acc dp return dp[-1] dp[-1] dp -1 R R C C goods goods @njit(i8(i8, i8, i8[:, :]), cache=True) solve i8(i8, i8, i8[:, :]), cache=True @njit(i8(i8, i8, i8[:, :]), cache=True) njit i8(i8, i8, i8[:, :]) i8 i8 i8 i8[:, :] i8 : cache=True cache True solve R, C, K, *rcv = map(int, open(0).read().split()) R map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split C K *rcv rcv goods = np.zeros((R, C), dtype=np.int64) goods np.zeros((R, C), dtype=np.int64) np.zeros np zeros (R, C) R C dtype=np.int64 dtype np.int64 np int64 for r, c, v in zip(*[iter(rcv)] * 3):
    goods[r - 1][c - 1] = v r c v zip(*[iter(rcv)] * 3) zip *[iter(rcv)] * 3 [iter(rcv)] * 3 [iter(rcv)] iter(rcv) iter rcv 3 goods[r - 1][c - 1] = v goods[r - 1][c - 1] [r - 1] goods r - 1 r 1 c - 1 c 1 v print(solve(R, C, goods)) print solve(R, C, goods) solve R C goods def max_acc(li):
    res = li.copy()
    cur_max = res[0]
    for i in range(len(li)):
        if res[i] > cur_max:
            cur_max = res[i]
        res[i] = cur_max
    return res def max_acc(li):
    res = li.copy()
    cur_max = res[0]
    for i in range(len(li)):
        if res[i] > cur_max:
            cur_max = res[i]
        res[i] = cur_max
    return res max_acc K, *rcv = map(int, open(0).read().split()) map(int, open(0).read().split()) K R, C, K, *rcv = map(int, open(0).read().split()) map(int, open(0).read().split()) R goods = np.zeros((R, C), dtype=np.int64) np.zeros((R, C), dtype=np.int64) goods def solve(R, C, goods):
    dp = np.zeros(C + 1, dtype=np.int64)
    for i in range(R):
        dp[1:] += goods[i]
        dp = max_acc(dp)
        for _ in range(2):
            dp[1:] = np.maximum(dp[:-1] + goods[i], dp[1:])
            dp = max_acc(dp)
    return dp[-1] def solve(R, C, goods):
    dp = np.zeros(C + 1, dtype=np.int64)
    for i in range(R):
        dp[1:] += goods[i]
        dp = max_acc(dp)
        for _ in range(2):
            dp[1:] = np.maximum(dp[:-1] + goods[i], dp[1:])
            dp = max_acc(dp)
    return dp[-1] solve C, K, *rcv = map(int, open(0).read().split()) map(int, open(0).read().split()) C
import numpy as np
from numba import njit, i8


@njit(i8[:](i8[:]), cache=True)
def max_acc(li):
    res = li.copy()
    cur_max = res[0]
    for i in range(len(li)):
        if res[i] > cur_max:
            cur_max = res[i]
        res[i] = cur_max
    return res


@njit(i8(i8, i8, i8[:, :]), cache=True)
def solve(R, C, goods):
    dp = np.zeros(C + 1, dtype=np.int64)
    for i in range(R):
        dp[1:] += goods[i]
        dp = max_acc(dp)
        for _ in range(2):
            dp[1:] = np.maximum(dp[:-1] + goods[i], dp[1:])
            dp = max_acc(dp)
    return dp[-1]


R, C, K, *rcv = map(int, open(0).read().split())
goods = np.zeros((R, C), dtype=np.int64)
for r, c, v in zip(*[iter(rcv)] * 3):
    goods[r - 1][c - 1] = v
print(solve(R, C, goods))
