R, C, K = map(int, input().split())
rcv = [list(map(int, input().split())) for _ in range(K)]

board = [[0] * (C + 1) for _ in range(R + 1)]
for r, c, v in rcv:
    board[r][c] = v

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

for r in range(1, R + 1):
    for c in range(1, C + 1):
        v = board[r][c]
        for i in range(4):
            dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
            dp[1][r][c] = max(dp[1][r][c], dp[i][r-1][c] + v)

            dp[i][r][c] = max(dp[i][r][c], dp[i][r][c-1])
            if i > 0:
                dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v)

ans = 0
for i in range(4):
    ans = max(ans, dp[i][R][C])

print(ans) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K list(map(int, input().split())) for _ in range(K) for _ in range(K) _ range(K) range K for _ in range(K) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split rcv = [list(map(int, input().split())) for _ in range(K)] rcv [list(map(int, input().split())) for _ in range(K)] [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 board = [[0] * (C + 1) for _ in range(R + 1)] board [[0] * (C + 1) for _ in range(R + 1)] for r, c, v in rcv:
    board[r][c] = v r c v rcv board[r][c] = v board[r][c] [r] board r c v [[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)] dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] dp [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] for r in range(1, R + 1):
    for c in range(1, C + 1):
        v = board[r][c]
        for i in range(4):
            dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
            dp[1][r][c] = max(dp[1][r][c], dp[i][r-1][c] + v)

            dp[i][r][c] = max(dp[i][r][c], dp[i][r][c-1])
            if i > 0:
                dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v) r range(1, R + 1) range 1 R + 1 R 1 for c in range(1, C + 1):
        v = board[r][c]
        for i in range(4):
            dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
            dp[1][r][c] = max(dp[1][r][c], dp[i][r-1][c] + v)

            dp[i][r][c] = max(dp[i][r][c], dp[i][r][c-1])
            if i > 0:
                dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v) c range(1, C + 1) range 1 C + 1 C 1 v = board[r][c] v board[r][c] [r] board r c for i in range(4):
            dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
            dp[1][r][c] = max(dp[1][r][c], dp[i][r-1][c] + v)

            dp[i][r][c] = max(dp[i][r][c], dp[i][r][c-1])
            if i > 0:
                dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v) i range(4) range 4 dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c]) dp[0][r][c] [r] [0] dp 0 r c max(dp[0][r][c], dp[i][r-1][c]) max dp[0][r][c] [r] [0] dp 0 r c dp[i][r-1][c] [r-1] [i] dp i r-1 r 1 c dp[1][r][c] = max(dp[1][r][c], dp[i][r-1][c] + v) dp[1][r][c] [r] [1] dp 1 r c max(dp[1][r][c], dp[i][r-1][c] + v) max dp[1][r][c] [r] [1] dp 1 r c dp[i][r-1][c] + v dp[i][r-1][c] [r-1] [i] dp i r-1 r 1 c v dp[i][r][c] = max(dp[i][r][c], dp[i][r][c-1]) dp[i][r][c] [r] [i] dp i r c max(dp[i][r][c], dp[i][r][c-1]) max dp[i][r][c] [r] [i] dp i r c dp[i][r][c-1] [r] [i] dp i r c-1 c 1 if i > 0:
                dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v) i > 0 i 0 dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v) dp[i][r][c] [r] [i] dp i r c max(dp[i][r][c], dp[i-1][r][c-1] + v) max dp[i][r][c] [r] [i] dp i r c dp[i-1][r][c-1] + v dp[i-1][r][c-1] [r] [i-1] dp i-1 i 1 r c-1 c 1 v ans = 0 ans 0 for i in range(4):
    ans = max(ans, dp[i][R][C]) i range(4) range 4 ans = max(ans, dp[i][R][C]) ans max(ans, dp[i][R][C]) max ans dp[i][R][C] [R] [i] dp i R C print(ans) print ans R, C, K = map(int, input().split()) map(int, input().split()) R rcv = [list(map(int, input().split())) for _ in range(K)] [list(map(int, input().split())) for _ in range(K)] rcv v = board[r][c] board[r][c] v ans = 0 0 ans C, K = map(int, input().split()) map(int, input().split()) C board = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] board dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] dp K = map(int, input().split()) map(int, input().split()) K ans = max(ans, dp[i][R][C]) max(ans, dp[i][R][C]) ans
R, C, K = map(int, input().split())
rcv = [list(map(int, input().split())) for _ in range(K)]

board = [[0] * (C + 1) for _ in range(R + 1)]
for r, c, v in rcv:
    board[r][c] = v

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

for r in range(1, R + 1):
    for c in range(1, C + 1):
        v = board[r][c]
        for i in range(4):
            dp[0][r][c] = max(dp[0][r][c], dp[i][r-1][c])
            dp[1][r][c] = max(dp[1][r][c], dp[i][r-1][c] + v)

            dp[i][r][c] = max(dp[i][r][c], dp[i][r][c-1])
            if i > 0:
                dp[i][r][c] = max(dp[i][r][c], dp[i-1][r][c-1] + v)

ans = 0
for i in range(4):
    ans = max(ans, dp[i][R][C])

print(ans)
