import sys
import time
s1 = time.time()
*data, = map(int, sys.stdin.read().split()[::-1])

def inp():
    global data
    return data.pop()
R, C, k = inp(), inp(), inp()
grid = [[0] * C for _ in range(R)]

for _ in range(k):
    ri, ci, v = inp(), inp(), inp()
    grid[ri - 1][ci - 1] = v


dp = []
for _ in range(4):
    dp.append([[0] * (C + 1) for _ in range(R + 1)])

# print(time.time() - s1)
mx = 0
for row in range(1, R + 1):
    for col in range(1, C + 1):
        level = 0
        dp[1][row][col] = max(dp[1][row][col], dp[3][row - 1][col] + grid[row - 1][col - 1])
        dp[0][row][col] = max(dp[0][row][col], dp[3][row - 1][col])
        level = 1
        v = grid[row - 1][col - 1]
        while level < 4:
            dp[level][row][col] = max(
                dp[level - 1][row][col],
                dp[level][row][col],
                dp[level][row][col - 1],
                dp[level - 1][row][col - 1] + v,
            )
            mx = max(mx, dp[level][row][col])
            level += 1

# print(time.time() - s1)
print(mx) import sys sys import time time s1 = time.time() s1 time.time() time.time time time *data, = map(int, sys.stdin.read().split()[::-1]) *data data map(int, sys.stdin.read().split()[::-1]) map int sys.stdin.read().split()[::-1] sys.stdin.read().split() sys.stdin.read().split sys.stdin.read() sys.stdin.read sys.stdin sys stdin read split ::-1 -1 def inp():
    global data
    return data.pop() inp global data return data.pop() data.pop() data.pop data pop R, C, k = inp(), inp(), inp() R inp() inp C inp() inp k inp() inp [0] * C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0] * C [0] 0 C grid = [[0] * C for _ in range(R)] grid [[0] * C for _ in range(R)] for _ in range(k):
    ri, ci, v = inp(), inp(), inp()
    grid[ri - 1][ci - 1] = v _ range(k) range k ri, ci, v = inp(), inp(), inp() ri inp() inp ci inp() inp v inp() inp grid[ri - 1][ci - 1] = v grid[ri - 1][ci - 1] [ri - 1] grid ri - 1 ri 1 ci - 1 ci 1 v dp = [] dp [] for _ in range(4):
    dp.append([[0] * (C + 1) for _ in range(R + 1)])

# print(time.time() - s1) _ range(4) range 4 [0] * (C + 1) for _ in range(R + 1) for _ in range(R + 1) _ range(R + 1) range R + 1 R 1 for _ in range(R + 1) [0] * (C + 1) [0] 0 C + 1 C 1 dp.append([[0] * (C + 1) for _ in range(R + 1)]) dp.append dp append [[0] * (C + 1) for _ in range(R + 1)] mx = 0 mx 0 for row in range(1, R + 1):
    for col in range(1, C + 1):
        level = 0
        dp[1][row][col] = max(dp[1][row][col], dp[3][row - 1][col] + grid[row - 1][col - 1])
        dp[0][row][col] = max(dp[0][row][col], dp[3][row - 1][col])
        level = 1
        v = grid[row - 1][col - 1]
        while level < 4:
            dp[level][row][col] = max(
                dp[level - 1][row][col],
                dp[level][row][col],
                dp[level][row][col - 1],
                dp[level - 1][row][col - 1] + v,
            )
            mx = max(mx, dp[level][row][col])
            level += 1

# print(time.time() - s1) row range(1, R + 1) range 1 R + 1 R 1 for col in range(1, C + 1):
        level = 0
        dp[1][row][col] = max(dp[1][row][col], dp[3][row - 1][col] + grid[row - 1][col - 1])
        dp[0][row][col] = max(dp[0][row][col], dp[3][row - 1][col])
        level = 1
        v = grid[row - 1][col - 1]
        while level < 4:
            dp[level][row][col] = max(
                dp[level - 1][row][col],
                dp[level][row][col],
                dp[level][row][col - 1],
                dp[level - 1][row][col - 1] + v,
            )
            mx = max(mx, dp[level][row][col])
            level += 1

# print(time.time() - s1) col range(1, C + 1) range 1 C + 1 C 1 level = 0 level 0 dp[1][row][col] = max(dp[1][row][col], dp[3][row - 1][col] + grid[row - 1][col - 1]) dp[1][row][col] [row] [1] dp 1 row col max(dp[1][row][col], dp[3][row - 1][col] + grid[row - 1][col - 1]) max dp[1][row][col] [row] [1] dp 1 row col dp[3][row - 1][col] + grid[row - 1][col - 1] dp[3][row - 1][col] [row - 1] [3] dp 3 row - 1 row 1 col grid[row - 1][col - 1] [row - 1] grid row - 1 row 1 col - 1 col 1 dp[0][row][col] = max(dp[0][row][col], dp[3][row - 1][col]) dp[0][row][col] [row] [0] dp 0 row col max(dp[0][row][col], dp[3][row - 1][col]) max dp[0][row][col] [row] [0] dp 0 row col dp[3][row - 1][col] [row - 1] [3] dp 3 row - 1 row 1 col level = 1 level 1 v = grid[row - 1][col - 1] v grid[row - 1][col - 1] [row - 1] grid row - 1 row 1 col - 1 col 1 while level < 4:
            dp[level][row][col] = max(
                dp[level - 1][row][col],
                dp[level][row][col],
                dp[level][row][col - 1],
                dp[level - 1][row][col - 1] + v,
            )
            mx = max(mx, dp[level][row][col])
            level += 1

# print(time.time() - s1) level < 4 level 4 dp[level][row][col] = max(
                dp[level - 1][row][col],
                dp[level][row][col],
                dp[level][row][col - 1],
                dp[level - 1][row][col - 1] + v,
            ) dp[level][row][col] [row] [level] dp level row col max(
                dp[level - 1][row][col],
                dp[level][row][col],
                dp[level][row][col - 1],
                dp[level - 1][row][col - 1] + v,
            ) max dp[level - 1][row][col] [row] [level - 1] dp level - 1 level 1 row col dp[level][row][col] [row] [level] dp level row col dp[level][row][col - 1] [row] [level] dp level row col - 1 col 1 dp[level - 1][row][col - 1] + v dp[level - 1][row][col - 1] [row] [level - 1] dp level - 1 level 1 row col - 1 col 1 v mx = max(mx, dp[level][row][col]) mx max(mx, dp[level][row][col]) max mx dp[level][row][col] [row] [level] dp level row col level += 1 level 1 print(mx) print mx mx = 0 0 mx ci, v = inp(), inp(), inp() inp() ci k = inp(), inp(), inp() inp() k grid = [[0] * C for _ in range(R)] [[0] * C for _ in range(R)] grid v = inp(), inp(), inp() inp() v level += 1 1 level def inp():
    global data
    return data.pop() def inp():
    global data
    return data.pop() inp R, C, k = inp(), inp(), inp() inp() R level = 0 0 level ri, ci, v = inp(), inp(), inp() inp() ri s1 = time.time() time.time() s1 level = 1 1 level dp = [] [] dp v = grid[row - 1][col - 1] grid[row - 1][col - 1] v C, k = inp(), inp(), inp() inp() C mx = max(mx, dp[level][row][col]) max(mx, dp[level][row][col]) mx
import sys
import time
s1 = time.time()
*data, = map(int, sys.stdin.read().split()[::-1])

def inp():
    global data
    return data.pop()
R, C, k = inp(), inp(), inp()
grid = [[0] * C for _ in range(R)]

for _ in range(k):
    ri, ci, v = inp(), inp(), inp()
    grid[ri - 1][ci - 1] = v


dp = []
for _ in range(4):
    dp.append([[0] * (C + 1) for _ in range(R + 1)])

# print(time.time() - s1)
mx = 0
for row in range(1, R + 1):
    for col in range(1, C + 1):
        level = 0
        dp[1][row][col] = max(dp[1][row][col], dp[3][row - 1][col] + grid[row - 1][col - 1])
        dp[0][row][col] = max(dp[0][row][col], dp[3][row - 1][col])
        level = 1
        v = grid[row - 1][col - 1]
        while level < 4:
            dp[level][row][col] = max(
                dp[level - 1][row][col],
                dp[level][row][col],
                dp[level][row][col - 1],
                dp[level - 1][row][col - 1] + v,
            )
            mx = max(mx, dp[level][row][col])
            level += 1

# print(time.time() - s1)
print(mx)
