import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [0 for _ in range(R * C * 4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])

            # take 
            for k in range(3):
                dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0))

    print(res)


if __name__ == "__main__":
    main() import sys sys from collections import deque import bisect bisect import copy copy import heapq heapq import itertools itertools import math math input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def read_values(): return map(int, input().split()) read_values def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index def read_list(): return list(read_values()) read_list read_list() for n in range(N) for n in range(N) n range(N) range N for n in range(N) read_list() read_list def read_lists(N): return [read_list() for n in range(N)] read_lists N N def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [0 for _ in range(R * C * 4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])

            # take 
            for k in range(3):
                dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0))

    print(res) main R, C, K = read_values() R read_values() read_values C K V = [0] * (R * C) V [0] * (R * C) [0] 0 R * C R C for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
     _ range(K) range K r, c, v = read_values() r read_values() read_values c v r -= 1 r 1 c -= 1 c 1 V[r * C + c] = v V[r * C + c] V r * C + c r * C r C c v 0 for _ in range(R * C * 4) for _ in range(R * C * 4) _ range(R * C * 4) range R * C * 4 R * C R C 4 for _ in range(R * C * 4) 0 dp = [0 for _ in range(R * C * 4)] dp [0 for _ in range(R * C * 4)] for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])

            # take 
            for k in range(3):
                dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))

     i range(R * C) range R * C R C r = i // C r i // C i C c = i % C c i % C i C if c + 1 < C:
            # not take
            for k in range(4):
                dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])

            # take 
            for k in range(3):
                dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])

        # next r
         c + 1 < C c + 1 c 1 C for k in range(4):
                dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])

            # take 
             k range(4) range 4 dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k]) dp[4 * (i + 1) + k] dp 4 * (i + 1) + k 4 * (i + 1) 4 i + 1 i 1 k max(dp[4 * (i + 1) + k], dp[4 * i + k]) max dp[4 * (i + 1) + k] dp 4 * (i + 1) + k 4 * (i + 1) 4 i + 1 i 1 k dp[4 * i + k] dp 4 * i + k 4 * i 4 i k for k in range(3):
                dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])

        # next r
         k range(3) range 3 dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i]) dp[4 * (i + 1) + k + 1] dp 4 * (i + 1) + k + 1 4 * (i + 1) + k 4 * (i + 1) 4 i + 1 i 1 k 1 max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i]) max dp[4 * (i + 1) + k + 1] dp 4 * (i + 1) + k + 1 4 * (i + 1) + k 4 * (i + 1) 4 i + 1 i 1 k 1 dp[4 * i + k] + V[i] dp[4 * i + k] dp 4 * i + k 4 * i 4 i k V[i] V i if r + 1 < R:
            for k in range(4):
                dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))

     r + 1 < R r + 1 r 1 R for k in range(4):
                dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))

     k range(4) range 4 dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0)) dp[4 * (i + C)] dp 4 * (i + C) 4 i + C i C max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0)) max dp[4 * (i + C)] dp 4 * (i + C) 4 i + C i C dp[4 * i + k] + (V[i] if k < 3 else 0) dp[4 * i + k] dp 4 * i + k 4 * i 4 i k V[i] if k < 3 else 0 k < 3 k 3 V[i] V i 0 res = 0 res 0 for k in range(4):
        res = max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0))

     k range(4) range 4 res = max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0)) res max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0)) max res dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0) dp[4 * (R * C - 1) + k] dp 4 * (R * C - 1) + k 4 * (R * C - 1) 4 R * C - 1 R * C R C 1 k V[-1] if k < 3 else 0 k < 3 k 3 V[-1] V -1 0 print(res) print res if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def read_values(): return map(int, input().split()) def read_values(): return map(int, input().split()) read_values input = sys.stdin.readline sys.stdin.readline input def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [0 for _ in range(R * C * 4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])

            # take 
            for k in range(3):
                dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0))

    print(res) def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [0 for _ in range(R * C * 4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])

            # take 
            for k in range(3):
                dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0))

    print(res) main def read_list(): return list(read_values()) def read_list(): return list(read_values()) read_list mod = 10 ** 9 + 7 10 ** 9 + 7 mod def read_lists(N): return [read_list() for n in range(N)] def read_lists(N): return [read_list() for n in range(N)] read_lists def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [0 for _ in range(R * C * 4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])

            # take 
            for k in range(3):
                dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0))

    print(res)


if __name__ == "__main__":
    main()
