import sys
input = sys.stdin.readline
from collections import defaultdict


def read():
    R, C, K = map(int, input().strip().split())
    # アイテムの価値V[r][c]
    V = [defaultdict(int) for i in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().strip().split())
        V[r][c] = v
    return R, C, K, V


def solve(R, C, K, V, INF=10**9):
    # dp[c][s]: c列目までにs個のアイテムを拾った時の、価値の最大値
    dp = [[-INF for s in range(4)] for c in range(C+1)]
    # 次の行に移るときに使うキャッシュ
    before = [0 for c in range(C+1)]
    for r in range(1, R+1):
        # s=0, s=1, s>1で処理を分ける
        for c in range(1, C+1):
            dp[c][0] = max(dp[c-1][0], before[c])
            dp[c][1] = max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c])
            for s in range(2, 4):
                dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c])
        # 次の行へ移る
        for c in range(1, C+1):
            before[c] = max(dp[c])
        # dpを初期化
        for c in range(C+1):  
            for s in range(4):
                dp[c][s] = 0
    ans = before[-1]
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from collections import defaultdict def read():
    R, C, K = map(int, input().strip().split())
    # アイテムの価値V[r][c]
    V = [defaultdict(int) for i in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().strip().split())
        V[r][c] = v
    return R, C, K, V read R, C, K = map(int, input().strip().split()) R map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split C K defaultdict(int) for i in range(R+1) for i in range(R+1) i range(R+1) range R+1 R 1 for i in range(R+1) defaultdict(int) defaultdict int V = [defaultdict(int) for i in range(R+1)] V [defaultdict(int) for i in range(R+1)] for i in range(K):
        r, c, v = map(int, input().strip().split())
        V[r][c] = v
     i range(K) range K r, c, v = map(int, input().strip().split()) r map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split c v V[r][c] = v V[r][c] [r] V r c v return R, C, K, V return R, C, K, V R C K V def solve(R, C, K, V, INF=10**9):
    # dp[c][s]: c列目までにs個のアイテムを拾った時の、価値の最大値
    dp = [[-INF for s in range(4)] for c in range(C+1)]
    # 次の行に移るときに使うキャッシュ
    before = [0 for c in range(C+1)]
    for r in range(1, R+1):
        # s=0, s=1, s>1で処理を分ける
        for c in range(1, C+1):
            dp[c][0] = max(dp[c-1][0], before[c])
            dp[c][1] = max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c])
            for s in range(2, 4):
                dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c])
        # 次の行へ移る
        for c in range(1, C+1):
            before[c] = max(dp[c])
        # dpを初期化
        for c in range(C+1):  
            for s in range(4):
                dp[c][s] = 0
    ans = before[-1]
    return ans solve [-INF for s in range(4)] for c in range(C+1) for c in range(C+1) c range(C+1) range C+1 C 1 for c in range(C+1) [-INF for s in range(4)] dp = [[-INF for s in range(4)] for c in range(C+1)] dp [[-INF for s in range(4)] for c in range(C+1)] 0 for c in range(C+1) for c in range(C+1) c range(C+1) range C+1 C 1 for c in range(C+1) 0 before = [0 for c in range(C+1)] before [0 for c in range(C+1)] for r in range(1, R+1):
        # s=0, s=1, s>1で処理を分ける
        for c in range(1, C+1):
            dp[c][0] = max(dp[c-1][0], before[c])
            dp[c][1] = max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c])
            for s in range(2, 4):
                dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c])
        # 次の行へ移る
        for c in range(1, C+1):
            before[c] = max(dp[c])
        # dpを初期化
        for c in range(C+1):  
            for s in range(4):
                dp[c][s] = 0
     r range(1, R+1) range 1 R+1 R 1 for c in range(1, C+1):
            dp[c][0] = max(dp[c-1][0], before[c])
            dp[c][1] = max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c])
            for s in range(2, 4):
                dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c])
        # 次の行へ移る
         c range(1, C+1) range 1 C+1 C 1 dp[c][0] = max(dp[c-1][0], before[c]) dp[c][0] [c] dp c 0 max(dp[c-1][0], before[c]) max dp[c-1][0] [c-1] dp c-1 c 1 0 before[c] before c dp[c][1] = max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c]) dp[c][1] [c] dp c 1 max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c]) max dp[c-1][1] [c-1] dp c-1 c 1 1 dp[c-1][0] + V[r][c] dp[c-1][0] [c-1] dp c-1 c 1 0 V[r][c] [r] V r c before[c] + V[r][c] before[c] before c V[r][c] [r] V r c for s in range(2, 4):
                dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c])
        # 次の行へ移る
         s range(2, 4) range 2 4 dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c]) dp[c][s] [c] dp c s max(dp[c-1][s], dp[c-1][s-1] + V[r][c]) max dp[c-1][s] [c-1] dp c-1 c 1 s dp[c-1][s-1] + V[r][c] dp[c-1][s-1] [c-1] dp c-1 c 1 s-1 s 1 V[r][c] [r] V r c for c in range(1, C+1):
            before[c] = max(dp[c])
        # dpを初期化
         c range(1, C+1) range 1 C+1 C 1 before[c] = max(dp[c]) before[c] before c max(dp[c]) max dp[c] dp c for c in range(C+1):  
            for s in range(4):
                dp[c][s] = 0
     c range(C+1) range C+1 C 1 for s in range(4):
                dp[c][s] = 0
     s range(4) range 4 dp[c][s] = 0 dp[c][s] [c] dp c s 0 ans = before[-1] ans before[-1] before -1 return ans ans R R C C K K V V INF=10**9 INF 10**9 10 9 if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs)) __name__ == '__main__' __name__ '__main__' inputs = read() inputs read() read outputs = solve(*inputs) outputs solve(*inputs) solve *inputs inputs if outputs is not None:
        print("%s" % str(outputs)) outputs is not None outputs None print("%s" % str(outputs)) print "%s" % str(outputs) "%s" str(outputs) str outputs input = sys.stdin.readline sys.stdin.readline input outputs = solve(*inputs) solve(*inputs) outputs def read():
    R, C, K = map(int, input().strip().split())
    # アイテムの価値V[r][c]
    V = [defaultdict(int) for i in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().strip().split())
        V[r][c] = v
    return R, C, K, V def read():
    R, C, K = map(int, input().strip().split())
    # アイテムの価値V[r][c]
    V = [defaultdict(int) for i in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().strip().split())
        V[r][c] = v
    return R, C, K, V read def solve(R, C, K, V, INF=10**9):
    # dp[c][s]: c列目までにs個のアイテムを拾った時の、価値の最大値
    dp = [[-INF for s in range(4)] for c in range(C+1)]
    # 次の行に移るときに使うキャッシュ
    before = [0 for c in range(C+1)]
    for r in range(1, R+1):
        # s=0, s=1, s>1で処理を分ける
        for c in range(1, C+1):
            dp[c][0] = max(dp[c-1][0], before[c])
            dp[c][1] = max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c])
            for s in range(2, 4):
                dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c])
        # 次の行へ移る
        for c in range(1, C+1):
            before[c] = max(dp[c])
        # dpを初期化
        for c in range(C+1):  
            for s in range(4):
                dp[c][s] = 0
    ans = before[-1]
    return ans def solve(R, C, K, V, INF=10**9):
    # dp[c][s]: c列目までにs個のアイテムを拾った時の、価値の最大値
    dp = [[-INF for s in range(4)] for c in range(C+1)]
    # 次の行に移るときに使うキャッシュ
    before = [0 for c in range(C+1)]
    for r in range(1, R+1):
        # s=0, s=1, s>1で処理を分ける
        for c in range(1, C+1):
            dp[c][0] = max(dp[c-1][0], before[c])
            dp[c][1] = max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c])
            for s in range(2, 4):
                dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c])
        # 次の行へ移る
        for c in range(1, C+1):
            before[c] = max(dp[c])
        # dpを初期化
        for c in range(C+1):  
            for s in range(4):
                dp[c][s] = 0
    ans = before[-1]
    return ans solve inputs = read() read() inputs
import sys
input = sys.stdin.readline
from collections import defaultdict


def read():
    R, C, K = map(int, input().strip().split())
    # アイテムの価値V[r][c]
    V = [defaultdict(int) for i in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().strip().split())
        V[r][c] = v
    return R, C, K, V


def solve(R, C, K, V, INF=10**9):
    # dp[c][s]: c列目までにs個のアイテムを拾った時の、価値の最大値
    dp = [[-INF for s in range(4)] for c in range(C+1)]
    # 次の行に移るときに使うキャッシュ
    before = [0 for c in range(C+1)]
    for r in range(1, R+1):
        # s=0, s=1, s>1で処理を分ける
        for c in range(1, C+1):
            dp[c][0] = max(dp[c-1][0], before[c])
            dp[c][1] = max(dp[c-1][1], dp[c-1][0] + V[r][c], before[c] + V[r][c])
            for s in range(2, 4):
                dp[c][s] = max(dp[c-1][s], dp[c-1][s-1] + V[r][c])
        # 次の行へ移る
        for c in range(1, C+1):
            before[c] = max(dp[c])
        # dpを初期化
        for c in range(C+1):  
            for s in range(4):
                dp[c][s] = 0
    ans = before[-1]
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
