import os
import sys

import numpy as np


def solve(inp):
    r, c, k = inp[:3]
    items = np.zeros((r + 1, c + 1), dtype=np.int64)
    rrr = inp[3::3]
    ccc = inp[4::3]
    vvv = inp[5::3]
    for r_, c_, v in zip(rrr, ccc, vvv):
        items[r_, c_] = v

    dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64)

    for i in range(1, r + 1):
        for j in range(1, c + 1):
            v = items[i, j]
            dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3])
            if v > 0:
                dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)

    return dp[-1, -1, -1]


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(ans) import os os import sys sys import numpy as np numpy def solve(inp):
    r, c, k = inp[:3]
    items = np.zeros((r + 1, c + 1), dtype=np.int64)
    rrr = inp[3::3]
    ccc = inp[4::3]
    vvv = inp[5::3]
    for r_, c_, v in zip(rrr, ccc, vvv):
        items[r_, c_] = v

    dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64)

    for i in range(1, r + 1):
        for j in range(1, c + 1):
            v = items[i, j]
            dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3])
            if v > 0:
                dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)

    return dp[-1, -1, -1] solve r, c, k = inp[:3] r inp[:3] inp :3 3 c k items = np.zeros((r + 1, c + 1), dtype=np.int64) items np.zeros((r + 1, c + 1), dtype=np.int64) np.zeros np zeros (r + 1, c + 1) r + 1 r 1 c + 1 c 1 dtype=np.int64 dtype np.int64 np int64 rrr = inp[3::3] rrr inp[3::3] inp 3::3 3 3 ccc = inp[4::3] ccc inp[4::3] inp 4::3 4 3 vvv = inp[5::3] vvv inp[5::3] inp 5::3 5 3 for r_, c_, v in zip(rrr, ccc, vvv):
        items[r_, c_] = v

     r_ c_ v zip(rrr, ccc, vvv) zip rrr ccc vvv items[r_, c_] = v items[r_, c_] items r_ v dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64) dp np.zeros((r + 1, c + 1, 4), dtype=np.int64) np.zeros np zeros (r + 1, c + 1, 4) r + 1 r 1 c + 1 c 1 4 dtype=np.int64 dtype np.int64 np int64 for i in range(1, r + 1):
        for j in range(1, c + 1):
            v = items[i, j]
            dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3])
            if v > 0:
                dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)

     i range(1, r + 1) range 1 r + 1 r 1 for j in range(1, c + 1):
            v = items[i, j]
            dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3])
            if v > 0:
                dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)

     j range(1, c + 1) range 1 c + 1 c 1 v = items[i, j] v items[i, j] items i dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3]) dp[i, j] dp i np.maximum(dp[i, j - 1], dp[i - 1, j, 3]) np.maximum np maximum dp[i, j - 1] dp i dp[i - 1, j, 3] dp i - 1 i 1 if v > 0:
                dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)

     v > 0 v 0 dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v) dp[i, j, 1:] dp i np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v) np.maximum np maximum dp[i, j, 1:] dp i dp[i, j, :-1] + v dp[i, j, :-1] dp i v return dp[-1, -1, -1] dp[-1, -1, -1] dp -1 inp inp if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit() sys.argv[-1] == 'ONLINE_JUDGE' sys.argv[-1] sys.argv sys argv -1 'ONLINE_JUDGE' from numba.pycc import CC cc = CC('my_module') cc CC('my_module') CC 'my_module' cc.export('solve', '(i8[:],)')(solve) cc.export('solve', '(i8[:],)') cc.export cc export 'solve' '(i8[:],)' solve cc.compile() cc.compile cc compile exit() exit if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr) os.name == 'posix' os.name os name 'posix' from my_module import solve from numba import njit solve = njit('(i8[:],)', cache=True)(solve) solve njit('(i8[:],)', cache=True)(solve) ('(i8[:],)', cache=True) njit '(i8[:],)' cache=True cache True solve print('compiled', file=sys.stderr) print 'compiled' file=sys.stderr file sys.stderr sys stderr inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ') inp np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ') np.fromstring np fromstring sys.stdin.read() sys.stdin.read sys.stdin sys stdin read dtype=np.int64 dtype np.int64 np int64 sep=' ' sep ' ' ans = solve(inp) ans solve(inp) solve inp print(ans) print ans def solve(inp):
    r, c, k = inp[:3]
    items = np.zeros((r + 1, c + 1), dtype=np.int64)
    rrr = inp[3::3]
    ccc = inp[4::3]
    vvv = inp[5::3]
    for r_, c_, v in zip(rrr, ccc, vvv):
        items[r_, c_] = v

    dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64)

    for i in range(1, r + 1):
        for j in range(1, c + 1):
            v = items[i, j]
            dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3])
            if v > 0:
                dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)

    return dp[-1, -1, -1] def solve(inp):
    r, c, k = inp[:3]
    items = np.zeros((r + 1, c + 1), dtype=np.int64)
    rrr = inp[3::3]
    ccc = inp[4::3]
    vvv = inp[5::3]
    for r_, c_, v in zip(rrr, ccc, vvv):
        items[r_, c_] = v

    dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64)

    for i in range(1, r + 1):
        for j in range(1, c + 1):
            v = items[i, j]
            dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3])
            if v > 0:
                dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)

    return dp[-1, -1, -1] solve cc = CC('my_module') CC('my_module') cc ans = solve(inp) solve(inp) ans inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ') np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ') inp solve = njit('(i8[:],)', cache=True)(solve) njit('(i8[:],)', cache=True)(solve) solve
import os
import sys

import numpy as np


def solve(inp):
    r, c, k = inp[:3]
    items = np.zeros((r + 1, c + 1), dtype=np.int64)
    rrr = inp[3::3]
    ccc = inp[4::3]
    vvv = inp[5::3]
    for r_, c_, v in zip(rrr, ccc, vvv):
        items[r_, c_] = v

    dp = np.zeros((r + 1, c + 1, 4), dtype=np.int64)

    for i in range(1, r + 1):
        for j in range(1, c + 1):
            v = items[i, j]
            dp[i, j] = np.maximum(dp[i, j - 1], dp[i - 1, j, 3])
            if v > 0:
                dp[i, j, 1:] = np.maximum(dp[i, j, 1:], dp[i, j, :-1] + v)

    return dp[-1, -1, -1]


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(ans)
