R, C, K = map(int, input().split())
# dp = [[[0] * 4 for _ in range(C + 1)]for _ in range(R + 1)]
dp2 = [[[0] * (C + 1) for _ in range(R + 1)]for _ in range(4)]

grid = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    grid[r - 1][c - 1] = v
for i in range(R):
    for j in range(C):
        for k in range(2, -1, -1):
            # chmax(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            # dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            dp2[k + 1][i][j] = max(dp2[k + 1][i][j], dp2[k][i][j] + grid[i][j])
        for k in range(4):
            # dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k])
            dp2[0][i + 1][j] = max(dp2[0][i + 1][j], dp2[k][i][j])
            # dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k])
            dp2[k][i][j + 1] = max(dp2[k][i][j + 1], dp2[k][i][j])
ans = 0
for k in range(4):
    # ans = max(ans, dp[R - 1][C - 1][k])
    ans = max(ans, dp2[k][R - 1][C - 1])
print(ans)

# print(dp[R - 1][C - 1][3]) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [[0] * (C + 1) for _ in range(R + 1)]for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0] * (C + 1) for _ in range(R + 1)] dp2 = [[[0] * (C + 1) for _ in range(R + 1)]for _ in range(4)] dp2 [[[0] * (C + 1) for _ in range(R + 1)]for _ in range(4)] [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):
    r, c, v = map(int, input().split())
    grid[r - 1][c - 1] = v _ 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 grid[r - 1][c - 1] = v grid[r - 1][c - 1] [r - 1] grid r - 1 r 1 c - 1 c 1 v for i in range(R):
    for j in range(C):
        for k in range(2, -1, -1):
            # chmax(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            # dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            dp2[k + 1][i][j] = max(dp2[k + 1][i][j], dp2[k][i][j] + grid[i][j])
        for k in range(4):
            # dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k])
            dp2[0][i + 1][j] = max(dp2[0][i + 1][j], dp2[k][i][j])
            # dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k])
            dp2[k][i][j + 1] = max(dp2[k][i][j + 1], dp2[k][i][j]) i range(R) range R for j in range(C):
        for k in range(2, -1, -1):
            # chmax(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            # dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            dp2[k + 1][i][j] = max(dp2[k + 1][i][j], dp2[k][i][j] + grid[i][j])
        for k in range(4):
            # dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k])
            dp2[0][i + 1][j] = max(dp2[0][i + 1][j], dp2[k][i][j])
            # dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k])
            dp2[k][i][j + 1] = max(dp2[k][i][j + 1], dp2[k][i][j]) j range(C) range C for k in range(2, -1, -1):
            # chmax(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            # dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            dp2[k + 1][i][j] = max(dp2[k + 1][i][j], dp2[k][i][j] + grid[i][j])
         k range(2, -1, -1) range 2 -1 -1 dp2[k + 1][i][j] = max(dp2[k + 1][i][j], dp2[k][i][j] + grid[i][j]) dp2[k + 1][i][j] [i] [k + 1] dp2 k + 1 k 1 i j max(dp2[k + 1][i][j], dp2[k][i][j] + grid[i][j]) max dp2[k + 1][i][j] [i] [k + 1] dp2 k + 1 k 1 i j dp2[k][i][j] + grid[i][j] dp2[k][i][j] [i] [k] dp2 k i j grid[i][j] [i] grid i j for k in range(4):
            # dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k])
            dp2[0][i + 1][j] = max(dp2[0][i + 1][j], dp2[k][i][j])
            # dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k])
            dp2[k][i][j + 1] = max(dp2[k][i][j + 1], dp2[k][i][j]) k range(4) range 4 dp2[0][i + 1][j] = max(dp2[0][i + 1][j], dp2[k][i][j]) dp2[0][i + 1][j] [i + 1] [0] dp2 0 i + 1 i 1 j max(dp2[0][i + 1][j], dp2[k][i][j]) max dp2[0][i + 1][j] [i + 1] [0] dp2 0 i + 1 i 1 j dp2[k][i][j] [i] [k] dp2 k i j dp2[k][i][j + 1] = max(dp2[k][i][j + 1], dp2[k][i][j]) dp2[k][i][j + 1] [i] [k] dp2 k i j + 1 j 1 max(dp2[k][i][j + 1], dp2[k][i][j]) max dp2[k][i][j + 1] [i] [k] dp2 k i j + 1 j 1 dp2[k][i][j] [i] [k] dp2 k i j ans = 0 ans 0 for k in range(4):
    # ans = max(ans, dp[R - 1][C - 1][k])
    ans = max(ans, dp2[k][R - 1][C - 1]) k range(4) range 4 ans = max(ans, dp2[k][R - 1][C - 1]) ans max(ans, dp2[k][R - 1][C - 1]) max ans dp2[k][R - 1][C - 1] [R - 1] [k] dp2 k R - 1 R 1 C - 1 C 1 print(ans) print ans grid = [[0] * C for _ in range(R)] [[0] * C for _ in range(R)] grid R, C, K = map(int, input().split()) map(int, input().split()) R C, K = map(int, input().split()) map(int, input().split()) C K = map(int, input().split()) map(int, input().split()) K c, v = map(int, input().split()) map(int, input().split()) c ans = 0 0 ans r, c, v = map(int, input().split()) map(int, input().split()) r dp2 = [[[0] * (C + 1) for _ in range(R + 1)]for _ in range(4)] [[[0] * (C + 1) for _ in range(R + 1)]for _ in range(4)] dp2 ans = max(ans, dp2[k][R - 1][C - 1]) max(ans, dp2[k][R - 1][C - 1]) ans v = map(int, input().split()) map(int, input().split()) v
R, C, K = map(int, input().split())
# dp = [[[0] * 4 for _ in range(C + 1)]for _ in range(R + 1)]
dp2 = [[[0] * (C + 1) for _ in range(R + 1)]for _ in range(4)]

grid = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    grid[r - 1][c - 1] = v
for i in range(R):
    for j in range(C):
        for k in range(2, -1, -1):
            # chmax(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            # dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + grid[i][j])
            dp2[k + 1][i][j] = max(dp2[k + 1][i][j], dp2[k][i][j] + grid[i][j])
        for k in range(4):
            # dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k])
            dp2[0][i + 1][j] = max(dp2[0][i + 1][j], dp2[k][i][j])
            # dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k])
            dp2[k][i][j + 1] = max(dp2[k][i][j + 1], dp2[k][i][j])
ans = 0
for k in range(4):
    # ans = max(ans, dp[R - 1][C - 1][k])
    ans = max(ans, dp2[k][R - 1][C - 1])
print(ans)

# print(dp[R - 1][C - 1][3])
