# Date [ 2020-08-15 21:54:45 ]
# Problem [ e.py ]
# Author Koki_tkg

import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 6 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

from numba import njit, i8
import numpy as np

@njit(i8(i8, i8, i8[:,:]))
def dp(R, C, grid):
    dp = np.zeros((R+1, C+1, 4), np.int64)
    for y in range(1, R+1):
        for x in range(1, C+1):
            for i in range(4):
                dp[y][x][i] = max(dp[y][x - 1][i], dp[y - 1][x][3])
            for i in range(3, 0, -1):
                dp[y][x][i] = max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1])
    return dp[R][C][3]

def Main():
    R, C, k = read_ints()
    item = [read_int_list() for _ in range(k)]
    grid = np.zeros((R, C), np.int64)
    for r, c, v in item:
        grid[r - 1][c - 1] = v
    print(dp(R, C, grid))

if __name__ ==  '__main__':
    Main() import sys sys from decimal import Decimal import math math from itertools import combinations, product import bisect bisect from collections import Counter, deque, defaultdict MOD = 10 ** 6 + 7 MOD 10 ** 6 + 7 10 ** 6 10 6 7 INF = 10 ** 9 INF 10 ** 9 10 9 PI = 3.14159265358979323846 PI 3.14159265358979323846 def read_str():      return sys.stdin.readline().strip() read_str def read_int():      return int(sys.stdin.readline().strip()) read_int def read_ints():     return map(int, sys.stdin.readline().strip().split()) read_ints def read_str_list(): return list(sys.stdin.readline().strip().split()) read_str_list def read_int_list(): return list(map(int, sys.stdin.readline().strip().split())) read_int_list def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b) lcm a: int a b: int b from numba import njit, i8 import numpy as np numpy def dp(R, C, grid):
    dp = np.zeros((R+1, C+1, 4), np.int64)
    for y in range(1, R+1):
        for x in range(1, C+1):
            for i in range(4):
                dp[y][x][i] = max(dp[y][x - 1][i], dp[y - 1][x][3])
            for i in range(3, 0, -1):
                dp[y][x][i] = max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1])
    return dp[R][C][3] dp dp = np.zeros((R+1, C+1, 4), np.int64) dp np.zeros((R+1, C+1, 4), np.int64) np.zeros np zeros (R+1, C+1, 4) R+1 R 1 C+1 C 1 4 np.int64 np int64 for y in range(1, R+1):
        for x in range(1, C+1):
            for i in range(4):
                dp[y][x][i] = max(dp[y][x - 1][i], dp[y - 1][x][3])
            for i in range(3, 0, -1):
                dp[y][x][i] = max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1])
     y range(1, R+1) range 1 R+1 R 1 for x in range(1, C+1):
            for i in range(4):
                dp[y][x][i] = max(dp[y][x - 1][i], dp[y - 1][x][3])
            for i in range(3, 0, -1):
                dp[y][x][i] = max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1])
     x range(1, C+1) range 1 C+1 C 1 for i in range(4):
                dp[y][x][i] = max(dp[y][x - 1][i], dp[y - 1][x][3])
             i range(4) range 4 dp[y][x][i] = max(dp[y][x - 1][i], dp[y - 1][x][3]) dp[y][x][i] [x] [y] dp y x i max(dp[y][x - 1][i], dp[y - 1][x][3]) max dp[y][x - 1][i] [x - 1] [y] dp y x - 1 x 1 i dp[y - 1][x][3] [x] [y - 1] dp y - 1 y 1 x 3 for i in range(3, 0, -1):
                dp[y][x][i] = max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1])
     i range(3, 0, -1) range 3 0 -1 dp[y][x][i] = max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1]) dp[y][x][i] [x] [y] dp y x i max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1]) max dp[y][x][i] [x] [y] dp y x i dp[y][x][i - 1] + grid[y-1][x-1] dp[y][x][i - 1] [x] [y] dp y x i - 1 i 1 grid[y-1][x-1] [y-1] grid y-1 y 1 x-1 x 1 return dp[R][C][3] dp[R][C][3] [C] [R] dp R C 3 R R C C grid grid @njit(i8(i8, i8, i8[:,:])) dp i8(i8, i8, i8[:,:]) @njit(i8(i8, i8, i8[:,:])) njit i8(i8, i8, i8[:,:]) i8 i8 i8 i8[:,:] i8 : dp def Main():
    R, C, k = read_ints()
    item = [read_int_list() for _ in range(k)]
    grid = np.zeros((R, C), np.int64)
    for r, c, v in item:
        grid[r - 1][c - 1] = v
    print(dp(R, C, grid)) Main R, C, k = read_ints() R read_ints() read_ints C k read_int_list() for _ in range(k) for _ in range(k) _ range(k) range k for _ in range(k) read_int_list() read_int_list item = [read_int_list() for _ in range(k)] item [read_int_list() for _ in range(k)] grid = np.zeros((R, C), np.int64) grid np.zeros((R, C), np.int64) np.zeros np zeros (R, C) R C np.int64 np int64 for r, c, v in item:
        grid[r - 1][c - 1] = v
     r c v item grid[r - 1][c - 1] = v grid[r - 1][c - 1] [r - 1] grid r - 1 r 1 c - 1 c 1 v print(dp(R, C, grid)) print dp(R, C, grid) dp R C grid if __name__ ==  '__main__':
    Main() __name__ ==  '__main__' __name__ '__main__' Main() Main def read_ints():     return map(int, sys.stdin.readline().strip().split()) def read_ints():     return map(int, sys.stdin.readline().strip().split()) read_ints def read_str_list(): return list(sys.stdin.readline().strip().split()) def read_str_list(): return list(sys.stdin.readline().strip().split()) read_str_list MOD = 10 ** 6 + 7 10 ** 6 + 7 MOD def dp(R, C, grid):
    dp = np.zeros((R+1, C+1, 4), np.int64)
    for y in range(1, R+1):
        for x in range(1, C+1):
            for i in range(4):
                dp[y][x][i] = max(dp[y][x - 1][i], dp[y - 1][x][3])
            for i in range(3, 0, -1):
                dp[y][x][i] = max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1])
    return dp[R][C][3] def dp(R, C, grid):
    dp = np.zeros((R+1, C+1, 4), np.int64)
    for y in range(1, R+1):
        for x in range(1, C+1):
            for i in range(4):
                dp[y][x][i] = max(dp[y][x - 1][i], dp[y - 1][x][3])
            for i in range(3, 0, -1):
                dp[y][x][i] = max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1])
    return dp[R][C][3] dp PI = 3.14159265358979323846 3.14159265358979323846 PI INF = 10 ** 9 10 ** 9 INF def read_int():      return int(sys.stdin.readline().strip()) def read_int():      return int(sys.stdin.readline().strip()) read_int def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b) def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b) lcm def read_str():      return sys.stdin.readline().strip() def read_str():      return sys.stdin.readline().strip() read_str def read_int_list(): return list(map(int, sys.stdin.readline().strip().split())) def read_int_list(): return list(map(int, sys.stdin.readline().strip().split())) read_int_list def Main():
    R, C, k = read_ints()
    item = [read_int_list() for _ in range(k)]
    grid = np.zeros((R, C), np.int64)
    for r, c, v in item:
        grid[r - 1][c - 1] = v
    print(dp(R, C, grid)) def Main():
    R, C, k = read_ints()
    item = [read_int_list() for _ in range(k)]
    grid = np.zeros((R, C), np.int64)
    for r, c, v in item:
        grid[r - 1][c - 1] = v
    print(dp(R, C, grid)) Main
# Date [ 2020-08-15 21:54:45 ]
# Problem [ e.py ]
# Author Koki_tkg

import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 6 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

from numba import njit, i8
import numpy as np

@njit(i8(i8, i8, i8[:,:]))
def dp(R, C, grid):
    dp = np.zeros((R+1, C+1, 4), np.int64)
    for y in range(1, R+1):
        for x in range(1, C+1):
            for i in range(4):
                dp[y][x][i] = max(dp[y][x - 1][i], dp[y - 1][x][3])
            for i in range(3, 0, -1):
                dp[y][x][i] = max(dp[y][x][i], dp[y][x][i - 1] + grid[y-1][x-1])
    return dp[R][C][3]

def Main():
    R, C, k = read_ints()
    item = [read_int_list() for _ in range(k)]
    grid = np.zeros((R, C), np.int64)
    for r, c, v in item:
        grid[r - 1][c - 1] = v
    print(dp(R, C, grid))

if __name__ ==  '__main__':
    Main()