import sys

R, C, K = map(int, sys.stdin.readline().split())

grid = [[0 for _ in range(C)] for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, sys.stdin.readline().split())
    grid[r-1][c-1] = v

# r行目、c列目にいるときに、その行でアイテムをi個取得している場合の最大価値
dp0 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp1 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp2 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp3 = [[0 for _ in range(C+1)] for _ in range(R+1)]
# print(dp)
for r in range(R):
    for c in range(C):
        # 取らない
        dp0[r+1][c] = max((dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]))
        dp1[r][c+1] = max(dp1[r][c], dp1[r][c])
        dp2[r][c+1] = max(dp2[r][c], dp2[r][c])
        dp3[r][c+1] = max(dp3[r][c], dp3[r][c])

        if grid[r][c] == 0:
            continue
        # 取る
        dp0[r+1][c] = max(dp0[r][c] + grid[r][c], dp0[r+1][c])
        dp0[r+1][c] = max(dp1[r][c] + grid[r][c], dp0[r+1][c])
        dp0[r+1][c] = max(dp2[r][c] + grid[r][c], dp0[r+1][c])

        dp1[r][c+1] = max(dp0[r][c] + grid[r][c], dp1[r][c+1])
        dp2[r][c+1] = max(dp1[r][c] + grid[r][c], dp2[r][c+1])
        dp3[r][c+1] = max(dp2[r][c] + grid[r][c], dp3[r][c+1])

# print(dp0)
# print(dp1)
# print(dp2)
# print(dp3)
# print(max((dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])))
print(dp0[R][C-1]) import sys sys R, C, K = map(int, sys.stdin.readline().split()) R map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split C K [0 for _ in range(C)] for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] grid = [[0 for _ in range(C)] for _ in range(R)] grid [[0 for _ in range(C)] for _ in range(R)] for _ in range(K):
    r, c, v = map(int, sys.stdin.readline().split())
    grid[r-1][c-1] = v

# r行目、c列目にいるときに、その行でアイテムをi個取得している場合の最大価値 _ range(K) range K r, c, v = map(int, sys.stdin.readline().split()) r map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split c v grid[r-1][c-1] = v grid[r-1][c-1] [r-1] grid r-1 r 1 c-1 c 1 v [0 for _ in range(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 for _ in range(C+1)] dp0 = [[0 for _ in range(C+1)] for _ in range(R+1)] dp0 [[0 for _ in range(C+1)] for _ in range(R+1)] [0 for _ in range(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 for _ in range(C+1)] dp1 = [[0 for _ in range(C+1)] for _ in range(R+1)] dp1 [[0 for _ in range(C+1)] for _ in range(R+1)] [0 for _ in range(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 for _ in range(C+1)] dp2 = [[0 for _ in range(C+1)] for _ in range(R+1)] dp2 [[0 for _ in range(C+1)] for _ in range(R+1)] [0 for _ in range(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 for _ in range(C+1)] dp3 = [[0 for _ in range(C+1)] for _ in range(R+1)] dp3 [[0 for _ in range(C+1)] for _ in range(R+1)] for r in range(R):
    for c in range(C):
        # 取らない
        dp0[r+1][c] = max((dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]))
        dp1[r][c+1] = max(dp1[r][c], dp1[r][c])
        dp2[r][c+1] = max(dp2[r][c], dp2[r][c])
        dp3[r][c+1] = max(dp3[r][c], dp3[r][c])

        if grid[r][c] == 0:
            continue
        # 取る
        dp0[r+1][c] = max(dp0[r][c] + grid[r][c], dp0[r+1][c])
        dp0[r+1][c] = max(dp1[r][c] + grid[r][c], dp0[r+1][c])
        dp0[r+1][c] = max(dp2[r][c] + grid[r][c], dp0[r+1][c])

        dp1[r][c+1] = max(dp0[r][c] + grid[r][c], dp1[r][c+1])
        dp2[r][c+1] = max(dp1[r][c] + grid[r][c], dp2[r][c+1])
        dp3[r][c+1] = max(dp2[r][c] + grid[r][c], dp3[r][c+1])

# print(dp0)
# print(dp1)
# print(dp2)
# print(dp3)
# print(max((dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))) r range(R) range R for c in range(C):
        # 取らない
        dp0[r+1][c] = max((dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]))
        dp1[r][c+1] = max(dp1[r][c], dp1[r][c])
        dp2[r][c+1] = max(dp2[r][c], dp2[r][c])
        dp3[r][c+1] = max(dp3[r][c], dp3[r][c])

        if grid[r][c] == 0:
            continue
        # 取る
        dp0[r+1][c] = max(dp0[r][c] + grid[r][c], dp0[r+1][c])
        dp0[r+1][c] = max(dp1[r][c] + grid[r][c], dp0[r+1][c])
        dp0[r+1][c] = max(dp2[r][c] + grid[r][c], dp0[r+1][c])

        dp1[r][c+1] = max(dp0[r][c] + grid[r][c], dp1[r][c+1])
        dp2[r][c+1] = max(dp1[r][c] + grid[r][c], dp2[r][c+1])
        dp3[r][c+1] = max(dp2[r][c] + grid[r][c], dp3[r][c+1])

# print(dp0)
# print(dp1)
# print(dp2)
# print(dp3)
# print(max((dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))) c range(C) range C dp0[r+1][c] = max((dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c])) dp0[r+1][c] [r+1] dp0 r+1 r 1 c max((dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c])) max (dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]) dp0[r][c] [r] dp0 r c dp1[r][c] [r] dp1 r c dp2[r][c] [r] dp2 r c dp3[r][c] [r] dp3 r c dp1[r][c+1] = max(dp1[r][c], dp1[r][c]) dp1[r][c+1] [r] dp1 r c+1 c 1 max(dp1[r][c], dp1[r][c]) max dp1[r][c] [r] dp1 r c dp1[r][c] [r] dp1 r c dp2[r][c+1] = max(dp2[r][c], dp2[r][c]) dp2[r][c+1] [r] dp2 r c+1 c 1 max(dp2[r][c], dp2[r][c]) max dp2[r][c] [r] dp2 r c dp2[r][c] [r] dp2 r c dp3[r][c+1] = max(dp3[r][c], dp3[r][c]) dp3[r][c+1] [r] dp3 r c+1 c 1 max(dp3[r][c], dp3[r][c]) max dp3[r][c] [r] dp3 r c dp3[r][c] [r] dp3 r c if grid[r][c] == 0:
            continue
        # 取る
         grid[r][c] == 0 grid[r][c] [r] grid r c 0 continue dp0[r+1][c] = max(dp0[r][c] + grid[r][c], dp0[r+1][c]) dp0[r+1][c] [r+1] dp0 r+1 r 1 c max(dp0[r][c] + grid[r][c], dp0[r+1][c]) max dp0[r][c] + grid[r][c] dp0[r][c] [r] dp0 r c grid[r][c] [r] grid r c dp0[r+1][c] [r+1] dp0 r+1 r 1 c dp0[r+1][c] = max(dp1[r][c] + grid[r][c], dp0[r+1][c]) dp0[r+1][c] [r+1] dp0 r+1 r 1 c max(dp1[r][c] + grid[r][c], dp0[r+1][c]) max dp1[r][c] + grid[r][c] dp1[r][c] [r] dp1 r c grid[r][c] [r] grid r c dp0[r+1][c] [r+1] dp0 r+1 r 1 c dp0[r+1][c] = max(dp2[r][c] + grid[r][c], dp0[r+1][c]) dp0[r+1][c] [r+1] dp0 r+1 r 1 c max(dp2[r][c] + grid[r][c], dp0[r+1][c]) max dp2[r][c] + grid[r][c] dp2[r][c] [r] dp2 r c grid[r][c] [r] grid r c dp0[r+1][c] [r+1] dp0 r+1 r 1 c dp1[r][c+1] = max(dp0[r][c] + grid[r][c], dp1[r][c+1]) dp1[r][c+1] [r] dp1 r c+1 c 1 max(dp0[r][c] + grid[r][c], dp1[r][c+1]) max dp0[r][c] + grid[r][c] dp0[r][c] [r] dp0 r c grid[r][c] [r] grid r c dp1[r][c+1] [r] dp1 r c+1 c 1 dp2[r][c+1] = max(dp1[r][c] + grid[r][c], dp2[r][c+1]) dp2[r][c+1] [r] dp2 r c+1 c 1 max(dp1[r][c] + grid[r][c], dp2[r][c+1]) max dp1[r][c] + grid[r][c] dp1[r][c] [r] dp1 r c grid[r][c] [r] grid r c dp2[r][c+1] [r] dp2 r c+1 c 1 dp3[r][c+1] = max(dp2[r][c] + grid[r][c], dp3[r][c+1]) dp3[r][c+1] [r] dp3 r c+1 c 1 max(dp2[r][c] + grid[r][c], dp3[r][c+1]) max dp2[r][c] + grid[r][c] dp2[r][c] [r] dp2 r c grid[r][c] [r] grid r c dp3[r][c+1] [r] dp3 r c+1 c 1 print(dp0[R][C-1]) print dp0[R][C-1] [R] dp0 R C-1 C 1 dp1 = [[0 for _ in range(C+1)] for _ in range(R+1)] [[0 for _ in range(C+1)] for _ in range(R+1)] dp1 C, K = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) C grid = [[0 for _ in range(C)] for _ in range(R)] [[0 for _ in range(C)] for _ in range(R)] grid R, C, K = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) R dp3 = [[0 for _ in range(C+1)] for _ in range(R+1)] [[0 for _ in range(C+1)] for _ in range(R+1)] dp3 c, v = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) c dp0 = [[0 for _ in range(C+1)] for _ in range(R+1)] [[0 for _ in range(C+1)] for _ in range(R+1)] dp0 dp2 = [[0 for _ in range(C+1)] for _ in range(R+1)] [[0 for _ in range(C+1)] for _ in range(R+1)] dp2 K = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) K r, c, v = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) r v = map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) v
import sys

R, C, K = map(int, sys.stdin.readline().split())

grid = [[0 for _ in range(C)] for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, sys.stdin.readline().split())
    grid[r-1][c-1] = v

# r行目、c列目にいるときに、その行でアイテムをi個取得している場合の最大価値
dp0 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp1 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp2 = [[0 for _ in range(C+1)] for _ in range(R+1)]
dp3 = [[0 for _ in range(C+1)] for _ in range(R+1)]
# print(dp)
for r in range(R):
    for c in range(C):
        # 取らない
        dp0[r+1][c] = max((dp0[r][c], dp1[r][c], dp2[r][c], dp3[r][c]))
        dp1[r][c+1] = max(dp1[r][c], dp1[r][c])
        dp2[r][c+1] = max(dp2[r][c], dp2[r][c])
        dp3[r][c+1] = max(dp3[r][c], dp3[r][c])

        if grid[r][c] == 0:
            continue
        # 取る
        dp0[r+1][c] = max(dp0[r][c] + grid[r][c], dp0[r+1][c])
        dp0[r+1][c] = max(dp1[r][c] + grid[r][c], dp0[r+1][c])
        dp0[r+1][c] = max(dp2[r][c] + grid[r][c], dp0[r+1][c])

        dp1[r][c+1] = max(dp0[r][c] + grid[r][c], dp1[r][c+1])
        dp2[r][c+1] = max(dp1[r][c] + grid[r][c], dp2[r][c+1])
        dp3[r][c+1] = max(dp2[r][c] + grid[r][c], dp3[r][c+1])

# print(dp0)
# print(dp1)
# print(dp2)
# print(dp3)
# print(max((dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])))
print(dp0[R][C-1])