# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
from numba import jit

@jit
def run_dp(MAP, dp, R, C):
    for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i,j,0] = max(dp[i,j,0], dp[i-1,j,k])
                if MAP[i,j]:
                    dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j])

                dp[i,j,k] = max(dp[i,j,k], dp[i,j-1,k])
                if MAP[i][j] and k < 3:
                    dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j])
    return dp[R, C].max()

def run():
    R,C,K = map(int, sysread().split())
    MAP = np.zeros((R + 1, C + 1), dtype=np.int64)
    for i in range(K):
        r, c, v = map(int, sysread().split())
        MAP[r, c] = v

    dp = np.zeros((R+1, C+1, 4), dtype= np.int64)

    run_dp(MAP, dp, R, C)

    #print(dp)
    #for m in MAP:
    #   print(m)
    ans= run_dp(MAP, dp, R, C)

    print(ans)

if __name__ == "__main__":
    run() import sys sys sysread = sys.stdin.buffer.readline sysread sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 import numpy as np numpy from numba import jit def run_dp(MAP, dp, R, C):
    for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i,j,0] = max(dp[i,j,0], dp[i-1,j,k])
                if MAP[i,j]:
                    dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j])

                dp[i,j,k] = max(dp[i,j,k], dp[i,j-1,k])
                if MAP[i][j] and k < 3:
                    dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j])
    return dp[R, C].max() run_dp for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i,j,0] = max(dp[i,j,0], dp[i-1,j,k])
                if MAP[i,j]:
                    dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j])

                dp[i,j,k] = max(dp[i,j,k], dp[i,j-1,k])
                if MAP[i][j] and k < 3:
                    dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j])
     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,0] = max(dp[i,j,0], dp[i-1,j,k])
                if MAP[i,j]:
                    dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j])

                dp[i,j,k] = max(dp[i,j,k], dp[i,j-1,k])
                if MAP[i][j] and k < 3:
                    dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j])
     j range(1, C+1) range 1 C+1 C 1 for k in range(4):
                dp[i,j,0] = max(dp[i,j,0], dp[i-1,j,k])
                if MAP[i,j]:
                    dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j])

                dp[i,j,k] = max(dp[i,j,k], dp[i,j-1,k])
                if MAP[i][j] and k < 3:
                    dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j])
     k range(4) range 4 dp[i,j,0] = max(dp[i,j,0], dp[i-1,j,k]) dp[i,j,0] dp i max(dp[i,j,0], dp[i-1,j,k]) max dp[i,j,0] dp i dp[i-1,j,k] dp i-1 i 1 if MAP[i,j]:
                    dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j])

                 MAP[i,j] MAP i dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j]) dp[i,j,1] dp i max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j]) max dp[i,j,1] dp i dp[i-1,j,k]+MAP[i,j] dp[i-1,j,k] dp i-1 i 1 MAP[i,j] MAP i 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 MAP[i][j] and k < 3:
                    dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j])
     MAP[i][j] and k < 3 MAP[i][j] [i] MAP i j k < 3 k 3 dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j]) dp[i,j,k+1] dp i max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j]) max dp[i,j,k+1] dp i dp[i,j-1,k] + MAP[i,j] dp[i,j-1,k] dp i MAP[i,j] MAP i return dp[R, C].max() dp[R, C].max() [R, C].max [R, C] dp R max MAP MAP dp dp R R C C @jit run_dp jit run_dp def run():
    R,C,K = map(int, sysread().split())
    MAP = np.zeros((R + 1, C + 1), dtype=np.int64)
    for i in range(K):
        r, c, v = map(int, sysread().split())
        MAP[r, c] = v

    dp = np.zeros((R+1, C+1, 4), dtype= np.int64)

    run_dp(MAP, dp, R, C)

    #print(dp)
    #for m in MAP:
    #   print(m)
    ans= run_dp(MAP, dp, R, C)

    print(ans) run R,C,K = map(int, sysread().split()) R map(int, sysread().split()) map int sysread().split() ().split () sysread split C K MAP = np.zeros((R + 1, C + 1), dtype=np.int64) MAP 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 for i in range(K):
        r, c, v = map(int, sysread().split())
        MAP[r, c] = v

     i range(K) range K r, c, v = map(int, sysread().split()) r map(int, sysread().split()) map int sysread().split() ().split () sysread split c v MAP[r, c] = v MAP[r, c] MAP 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 run_dp(MAP, dp, R, C) run_dp MAP dp R C ans= run_dp(MAP, dp, R, C) ans run_dp(MAP, dp, R, C) run_dp MAP dp R C print(ans) print ans if __name__ == "__main__":
    run() __name__ == "__main__" __name__ "__main__" run() run def run():
    R,C,K = map(int, sysread().split())
    MAP = np.zeros((R + 1, C + 1), dtype=np.int64)
    for i in range(K):
        r, c, v = map(int, sysread().split())
        MAP[r, c] = v

    dp = np.zeros((R+1, C+1, 4), dtype= np.int64)

    run_dp(MAP, dp, R, C)

    #print(dp)
    #for m in MAP:
    #   print(m)
    ans= run_dp(MAP, dp, R, C)

    print(ans) def run():
    R,C,K = map(int, sysread().split())
    MAP = np.zeros((R + 1, C + 1), dtype=np.int64)
    for i in range(K):
        r, c, v = map(int, sysread().split())
        MAP[r, c] = v

    dp = np.zeros((R+1, C+1, 4), dtype= np.int64)

    run_dp(MAP, dp, R, C)

    #print(dp)
    #for m in MAP:
    #   print(m)
    ans= run_dp(MAP, dp, R, C)

    print(ans) run def run_dp(MAP, dp, R, C):
    for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i,j,0] = max(dp[i,j,0], dp[i-1,j,k])
                if MAP[i,j]:
                    dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j])

                dp[i,j,k] = max(dp[i,j,k], dp[i,j-1,k])
                if MAP[i][j] and k < 3:
                    dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j])
    return dp[R, C].max() def run_dp(MAP, dp, R, C):
    for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i,j,0] = max(dp[i,j,0], dp[i-1,j,k])
                if MAP[i,j]:
                    dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j])

                dp[i,j,k] = max(dp[i,j,k], dp[i,j-1,k])
                if MAP[i][j] and k < 3:
                    dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j])
    return dp[R, C].max() run_dp read = sys.stdin.buffer.read sys.stdin.buffer.read read sysread = sys.stdin.buffer.readline sys.stdin.buffer.readline sysread
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
from numba import jit

@jit
def run_dp(MAP, dp, R, C):
    for i in range(1, R+1):
        for j in range(1, C+1):
            for k in range(4):
                dp[i,j,0] = max(dp[i,j,0], dp[i-1,j,k])
                if MAP[i,j]:
                    dp[i,j,1] = max(dp[i,j,1], dp[i-1,j,k]+MAP[i,j])

                dp[i,j,k] = max(dp[i,j,k], dp[i,j-1,k])
                if MAP[i][j] and k < 3:
                    dp[i,j,k+1] = max(dp[i,j,k+1], dp[i,j-1,k] + MAP[i,j])
    return dp[R, C].max()

def run():
    R,C,K = map(int, sysread().split())
    MAP = np.zeros((R + 1, C + 1), dtype=np.int64)
    for i in range(K):
        r, c, v = map(int, sysread().split())
        MAP[r, c] = v

    dp = np.zeros((R+1, C+1, 4), dtype= np.int64)

    run_dp(MAP, dp, R, C)

    #print(dp)
    #for m in MAP:
    #   print(m)
    ans= run_dp(MAP, dp, R, C)

    print(ans)

if __name__ == "__main__":
    run()