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

item = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    item[r][c] = v

# dp[n][i][j] = その行で取得したアイテムがn個で、(i,j)でのmax_value
dp = [[[0 for _ in range(C + 1)]for _ in range(R + 1)]for _ in range(4)]

for i in range(R + 1):
    for j in range(C + 1):
        # 下に移動
        if i <= R - 1:
            # アイテムを取らない
            dp[0][i + 1][j] = max(dp[0][i + 1][j],
                                  dp[0][i][j],
                                  dp[1][i][j],
                                  dp[2][i][j],
                                  dp[3][i][j])
            # アイテムを取る
            dp[1][i + 1][j] = max(dp[1][i + 1][j],
                                  dp[0][i][j] + item[i + 1][j],
                                  dp[1][i][j] + item[i + 1][j],
                                  dp[2][i][j] + item[i + 1][j],
                                  dp[3][i][j] + item[i + 1][j])

        # 右に移動
        if j <= C - 1:
            # アイテムを取らない
            dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j])
            dp[1][i][j + 1] = max(dp[1][i][j + 1], dp[1][i][j])
            dp[2][i][j + 1] = max(dp[2][i][j + 1], dp[2][i][j])
            dp[3][i][j + 1] = max(dp[3][i][j + 1], dp[3][i][j])
            # アイテムを取る
            dp[1][i][j + 1] = max(dp[1][i][j + 1],
                                  dp[0][i][j] + item[i][j + 1])
            dp[2][i][j + 1] = max(dp[2][i][j + 1],
                                  dp[1][i][j] + item[i][j + 1])
            dp[3][i][j + 1] = max(dp[3][i][j + 1],
                                  dp[2][i][j] + item[i][j + 1])

ans = max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])
print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [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)] item = [[0 for _ in range(C + 1)] for _ in range(R + 1)] item [[0 for _ in range(C + 1)] for _ in range(R + 1)] for _ in range(K):
    r, c, v = map(int, input().split())
    item[r][c] = v

# dp[n][i][j] = その行で取得したアイテムがn個で、(i,j)でのmax_value _ range(K) range K r, c, v = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c v item[r][c] = v item[r][c] [r] item r c v [[0 for _ in range(C + 1)]for _ in range(R + 1)]for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0 for _ in range(C + 1)]for _ in range(R + 1)] dp = [[[0 for _ in range(C + 1)]for _ in range(R + 1)]for _ in range(4)] dp [[[0 for _ in range(C + 1)]for _ in range(R + 1)]for _ in range(4)] for i in range(R + 1):
    for j in range(C + 1):
        # 下に移動
        if i <= R - 1:
            # アイテムを取らない
            dp[0][i + 1][j] = max(dp[0][i + 1][j],
                                  dp[0][i][j],
                                  dp[1][i][j],
                                  dp[2][i][j],
                                  dp[3][i][j])
            # アイテムを取る
            dp[1][i + 1][j] = max(dp[1][i + 1][j],
                                  dp[0][i][j] + item[i + 1][j],
                                  dp[1][i][j] + item[i + 1][j],
                                  dp[2][i][j] + item[i + 1][j],
                                  dp[3][i][j] + item[i + 1][j])

        # 右に移動
        if j <= C - 1:
            # アイテムを取らない
            dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j])
            dp[1][i][j + 1] = max(dp[1][i][j + 1], dp[1][i][j])
            dp[2][i][j + 1] = max(dp[2][i][j + 1], dp[2][i][j])
            dp[3][i][j + 1] = max(dp[3][i][j + 1], dp[3][i][j])
            # アイテムを取る
            dp[1][i][j + 1] = max(dp[1][i][j + 1],
                                  dp[0][i][j] + item[i][j + 1])
            dp[2][i][j + 1] = max(dp[2][i][j + 1],
                                  dp[1][i][j] + item[i][j + 1])
            dp[3][i][j + 1] = max(dp[3][i][j + 1],
                                  dp[2][i][j] + item[i][j + 1]) i range(R + 1) range R + 1 R 1 for j in range(C + 1):
        # 下に移動
        if i <= R - 1:
            # アイテムを取らない
            dp[0][i + 1][j] = max(dp[0][i + 1][j],
                                  dp[0][i][j],
                                  dp[1][i][j],
                                  dp[2][i][j],
                                  dp[3][i][j])
            # アイテムを取る
            dp[1][i + 1][j] = max(dp[1][i + 1][j],
                                  dp[0][i][j] + item[i + 1][j],
                                  dp[1][i][j] + item[i + 1][j],
                                  dp[2][i][j] + item[i + 1][j],
                                  dp[3][i][j] + item[i + 1][j])

        # 右に移動
        if j <= C - 1:
            # アイテムを取らない
            dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j])
            dp[1][i][j + 1] = max(dp[1][i][j + 1], dp[1][i][j])
            dp[2][i][j + 1] = max(dp[2][i][j + 1], dp[2][i][j])
            dp[3][i][j + 1] = max(dp[3][i][j + 1], dp[3][i][j])
            # アイテムを取る
            dp[1][i][j + 1] = max(dp[1][i][j + 1],
                                  dp[0][i][j] + item[i][j + 1])
            dp[2][i][j + 1] = max(dp[2][i][j + 1],
                                  dp[1][i][j] + item[i][j + 1])
            dp[3][i][j + 1] = max(dp[3][i][j + 1],
                                  dp[2][i][j] + item[i][j + 1]) j range(C + 1) range C + 1 C 1 if i <= R - 1:
            # アイテムを取らない
            dp[0][i + 1][j] = max(dp[0][i + 1][j],
                                  dp[0][i][j],
                                  dp[1][i][j],
                                  dp[2][i][j],
                                  dp[3][i][j])
            # アイテムを取る
            dp[1][i + 1][j] = max(dp[1][i + 1][j],
                                  dp[0][i][j] + item[i + 1][j],
                                  dp[1][i][j] + item[i + 1][j],
                                  dp[2][i][j] + item[i + 1][j],
                                  dp[3][i][j] + item[i + 1][j])

        # 右に移動
         i <= R - 1 i R - 1 R 1 dp[0][i + 1][j] = max(dp[0][i + 1][j],
                                  dp[0][i][j],
                                  dp[1][i][j],
                                  dp[2][i][j],
                                  dp[3][i][j]) dp[0][i + 1][j] [i + 1] [0] dp 0 i + 1 i 1 j max(dp[0][i + 1][j],
                                  dp[0][i][j],
                                  dp[1][i][j],
                                  dp[2][i][j],
                                  dp[3][i][j]) max dp[0][i + 1][j] [i + 1] [0] dp 0 i + 1 i 1 j dp[0][i][j] [i] [0] dp 0 i j dp[1][i][j] [i] [1] dp 1 i j dp[2][i][j] [i] [2] dp 2 i j dp[3][i][j] [i] [3] dp 3 i j dp[1][i + 1][j] = max(dp[1][i + 1][j],
                                  dp[0][i][j] + item[i + 1][j],
                                  dp[1][i][j] + item[i + 1][j],
                                  dp[2][i][j] + item[i + 1][j],
                                  dp[3][i][j] + item[i + 1][j]) dp[1][i + 1][j] [i + 1] [1] dp 1 i + 1 i 1 j max(dp[1][i + 1][j],
                                  dp[0][i][j] + item[i + 1][j],
                                  dp[1][i][j] + item[i + 1][j],
                                  dp[2][i][j] + item[i + 1][j],
                                  dp[3][i][j] + item[i + 1][j]) max dp[1][i + 1][j] [i + 1] [1] dp 1 i + 1 i 1 j dp[0][i][j] + item[i + 1][j] dp[0][i][j] [i] [0] dp 0 i j item[i + 1][j] [i + 1] item i + 1 i 1 j dp[1][i][j] + item[i + 1][j] dp[1][i][j] [i] [1] dp 1 i j item[i + 1][j] [i + 1] item i + 1 i 1 j dp[2][i][j] + item[i + 1][j] dp[2][i][j] [i] [2] dp 2 i j item[i + 1][j] [i + 1] item i + 1 i 1 j dp[3][i][j] + item[i + 1][j] dp[3][i][j] [i] [3] dp 3 i j item[i + 1][j] [i + 1] item i + 1 i 1 j if j <= C - 1:
            # アイテムを取らない
            dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j])
            dp[1][i][j + 1] = max(dp[1][i][j + 1], dp[1][i][j])
            dp[2][i][j + 1] = max(dp[2][i][j + 1], dp[2][i][j])
            dp[3][i][j + 1] = max(dp[3][i][j + 1], dp[3][i][j])
            # アイテムを取る
            dp[1][i][j + 1] = max(dp[1][i][j + 1],
                                  dp[0][i][j] + item[i][j + 1])
            dp[2][i][j + 1] = max(dp[2][i][j + 1],
                                  dp[1][i][j] + item[i][j + 1])
            dp[3][i][j + 1] = max(dp[3][i][j + 1],
                                  dp[2][i][j] + item[i][j + 1]) j <= C - 1 j C - 1 C 1 dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j]) dp[0][i][j + 1] [i] [0] dp 0 i j + 1 j 1 max(dp[0][i][j + 1], dp[0][i][j]) max dp[0][i][j + 1] [i] [0] dp 0 i j + 1 j 1 dp[0][i][j] [i] [0] dp 0 i j dp[1][i][j + 1] = max(dp[1][i][j + 1], dp[1][i][j]) dp[1][i][j + 1] [i] [1] dp 1 i j + 1 j 1 max(dp[1][i][j + 1], dp[1][i][j]) max dp[1][i][j + 1] [i] [1] dp 1 i j + 1 j 1 dp[1][i][j] [i] [1] dp 1 i j dp[2][i][j + 1] = max(dp[2][i][j + 1], dp[2][i][j]) dp[2][i][j + 1] [i] [2] dp 2 i j + 1 j 1 max(dp[2][i][j + 1], dp[2][i][j]) max dp[2][i][j + 1] [i] [2] dp 2 i j + 1 j 1 dp[2][i][j] [i] [2] dp 2 i j dp[3][i][j + 1] = max(dp[3][i][j + 1], dp[3][i][j]) dp[3][i][j + 1] [i] [3] dp 3 i j + 1 j 1 max(dp[3][i][j + 1], dp[3][i][j]) max dp[3][i][j + 1] [i] [3] dp 3 i j + 1 j 1 dp[3][i][j] [i] [3] dp 3 i j dp[1][i][j + 1] = max(dp[1][i][j + 1],
                                  dp[0][i][j] + item[i][j + 1]) dp[1][i][j + 1] [i] [1] dp 1 i j + 1 j 1 max(dp[1][i][j + 1],
                                  dp[0][i][j] + item[i][j + 1]) max dp[1][i][j + 1] [i] [1] dp 1 i j + 1 j 1 dp[0][i][j] + item[i][j + 1] dp[0][i][j] [i] [0] dp 0 i j item[i][j + 1] [i] item i j + 1 j 1 dp[2][i][j + 1] = max(dp[2][i][j + 1],
                                  dp[1][i][j] + item[i][j + 1]) dp[2][i][j + 1] [i] [2] dp 2 i j + 1 j 1 max(dp[2][i][j + 1],
                                  dp[1][i][j] + item[i][j + 1]) max dp[2][i][j + 1] [i] [2] dp 2 i j + 1 j 1 dp[1][i][j] + item[i][j + 1] dp[1][i][j] [i] [1] dp 1 i j item[i][j + 1] [i] item i j + 1 j 1 dp[3][i][j + 1] = max(dp[3][i][j + 1],
                                  dp[2][i][j] + item[i][j + 1]) dp[3][i][j + 1] [i] [3] dp 3 i j + 1 j 1 max(dp[3][i][j + 1],
                                  dp[2][i][j] + item[i][j + 1]) max dp[3][i][j + 1] [i] [3] dp 3 i j + 1 j 1 dp[2][i][j] + item[i][j + 1] dp[2][i][j] [i] [2] dp 2 i j item[i][j + 1] [i] item i j + 1 j 1 ans = max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]) ans max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]) max dp[0][R][C] [R] [0] dp 0 R C dp[1][R][C] [R] [1] dp 1 R C dp[2][R][C] [R] [2] dp 2 R C dp[3][R][C] [R] [3] dp 3 R C print(ans) print ans K = map(int, input().split()) map(int, input().split()) K input = sys.stdin.readline sys.stdin.readline input item = [[0 for _ in range(C + 1)] for _ in range(R + 1)] [[0 for _ in range(C + 1)] for _ in range(R + 1)] item c, v = map(int, input().split()) map(int, input().split()) c v = map(int, input().split()) map(int, input().split()) v R, C, K = map(int, input().split()) map(int, input().split()) R ans = max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]) max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]) ans C, K = map(int, input().split()) map(int, input().split()) C r, c, v = map(int, input().split()) map(int, input().split()) r dp = [[[0 for _ in range(C + 1)]for _ in range(R + 1)]for _ in range(4)] [[[0 for _ in range(C + 1)]for _ in range(R + 1)]for _ in range(4)] dp
import sys
input = sys.stdin.readline
R, C, K = map(int, input().split())

item = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    item[r][c] = v

# dp[n][i][j] = その行で取得したアイテムがn個で、(i,j)でのmax_value
dp = [[[0 for _ in range(C + 1)]for _ in range(R + 1)]for _ in range(4)]

for i in range(R + 1):
    for j in range(C + 1):
        # 下に移動
        if i <= R - 1:
            # アイテムを取らない
            dp[0][i + 1][j] = max(dp[0][i + 1][j],
                                  dp[0][i][j],
                                  dp[1][i][j],
                                  dp[2][i][j],
                                  dp[3][i][j])
            # アイテムを取る
            dp[1][i + 1][j] = max(dp[1][i + 1][j],
                                  dp[0][i][j] + item[i + 1][j],
                                  dp[1][i][j] + item[i + 1][j],
                                  dp[2][i][j] + item[i + 1][j],
                                  dp[3][i][j] + item[i + 1][j])

        # 右に移動
        if j <= C - 1:
            # アイテムを取らない
            dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j])
            dp[1][i][j + 1] = max(dp[1][i][j + 1], dp[1][i][j])
            dp[2][i][j + 1] = max(dp[2][i][j + 1], dp[2][i][j])
            dp[3][i][j + 1] = max(dp[3][i][j + 1], dp[3][i][j])
            # アイテムを取る
            dp[1][i][j + 1] = max(dp[1][i][j + 1],
                                  dp[0][i][j] + item[i][j + 1])
            dp[2][i][j + 1] = max(dp[2][i][j + 1],
                                  dp[1][i][j] + item[i][j + 1])
            dp[3][i][j + 1] = max(dp[3][i][j + 1],
                                  dp[2][i][j] + item[i][j + 1])

ans = max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])
print(ans)
