R, C, K = map(int, input().split())
g = [[-float('inf')]*C for _ in range(R)]
for i in range(K):
    r, c, k = map(int, input().split())
    r -= 1
    c -= 1
    g[r][c] = k

dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
for r in range(R):
    for c in range(C):
        # k[0..3] = 0個拾っている状態から3個拾っている状態
        # indexが大きいほど、小さいアイテムとなるので、小さいものから更新していく
        for k in range(2, -1, -1):
            dp[k+1][r][c] = max(
                dp[k+1][r][c],
                dp[k][r][c]+g[r][c]
            )

        for k in range(4):
            dp[0][r+1][c] = max(dp[0][r+1][c], dp[k][r][c])
            dp[k][r][c+1] = max(dp[k][r][c+1], dp[k][r][c])

ans = 0
for i in range(4):
    ans = max(dp[i][R-1][C-1], ans)
print(ans) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [-float('inf')]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [-float('inf')]*C [-float('inf')] -float('inf') float('inf') float 'inf' C g = [[-float('inf')]*C for _ in range(R)] g [[-float('inf')]*C for _ in range(R)] for i in range(K):
    r, c, k = map(int, input().split())
    r -= 1
    c -= 1
    g[r][c] = k i range(K) range K r, c, k = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c k r -= 1 r 1 c -= 1 c 1 g[r][c] = k g[r][c] [r] g r 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)] 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(R):
    for c in range(C):
        # k[0..3] = 0個拾っている状態から3個拾っている状態
        # indexが大きいほど、小さいアイテムとなるので、小さいものから更新していく
        for k in range(2, -1, -1):
            dp[k+1][r][c] = max(
                dp[k+1][r][c],
                dp[k][r][c]+g[r][c]
            )

        for k in range(4):
            dp[0][r+1][c] = max(dp[0][r+1][c], dp[k][r][c])
            dp[k][r][c+1] = max(dp[k][r][c+1], dp[k][r][c]) r range(R) range R for c in range(C):
        # k[0..3] = 0個拾っている状態から3個拾っている状態
        # indexが大きいほど、小さいアイテムとなるので、小さいものから更新していく
        for k in range(2, -1, -1):
            dp[k+1][r][c] = max(
                dp[k+1][r][c],
                dp[k][r][c]+g[r][c]
            )

        for k in range(4):
            dp[0][r+1][c] = max(dp[0][r+1][c], dp[k][r][c])
            dp[k][r][c+1] = max(dp[k][r][c+1], dp[k][r][c]) c range(C) range C for k in range(2, -1, -1):
            dp[k+1][r][c] = max(
                dp[k+1][r][c],
                dp[k][r][c]+g[r][c]
            )

         k range(2, -1, -1) range 2 -1 -1 dp[k+1][r][c] = max(
                dp[k+1][r][c],
                dp[k][r][c]+g[r][c]
            ) dp[k+1][r][c] [r] [k+1] dp k+1 k 1 r c max(
                dp[k+1][r][c],
                dp[k][r][c]+g[r][c]
            ) max dp[k+1][r][c] [r] [k+1] dp k+1 k 1 r c dp[k][r][c]+g[r][c] dp[k][r][c] [r] [k] dp k r c g[r][c] [r] g r c for k in range(4):
            dp[0][r+1][c] = max(dp[0][r+1][c], dp[k][r][c])
            dp[k][r][c+1] = max(dp[k][r][c+1], dp[k][r][c]) k range(4) range 4 dp[0][r+1][c] = max(dp[0][r+1][c], dp[k][r][c]) dp[0][r+1][c] [r+1] [0] dp 0 r+1 r 1 c max(dp[0][r+1][c], dp[k][r][c]) max dp[0][r+1][c] [r+1] [0] dp 0 r+1 r 1 c dp[k][r][c] [r] [k] dp k r c dp[k][r][c+1] = max(dp[k][r][c+1], dp[k][r][c]) dp[k][r][c+1] [r] [k] dp k r c+1 c 1 max(dp[k][r][c+1], dp[k][r][c]) max dp[k][r][c+1] [r] [k] dp k r c+1 c 1 dp[k][r][c] [r] [k] dp k r c ans = 0 ans 0 for i in range(4):
    ans = max(dp[i][R-1][C-1], ans) i range(4) range 4 ans = max(dp[i][R-1][C-1], ans) ans max(dp[i][R-1][C-1], ans) max dp[i][R-1][C-1] [R-1] [i] dp i R-1 R 1 C-1 C 1 ans print(ans) print ans ans = max(dp[i][R-1][C-1], ans) max(dp[i][R-1][C-1], ans) ans g = [[-float('inf')]*C for _ in range(R)] [[-float('inf')]*C for _ in range(R)] g 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 ans = 0 0 ans c, k = map(int, input().split()) map(int, input().split()) c k = map(int, input().split()) map(int, input().split()) k C, K = map(int, input().split()) map(int, input().split()) C r -= 1 1 r K = map(int, input().split()) map(int, input().split()) K R, C, K = map(int, input().split()) map(int, input().split()) R c -= 1 1 c r, c, k = map(int, input().split()) map(int, input().split()) r
R, C, K = map(int, input().split())
g = [[-float('inf')]*C for _ in range(R)]
for i in range(K):
    r, c, k = map(int, input().split())
    r -= 1
    c -= 1
    g[r][c] = k

dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
for r in range(R):
    for c in range(C):
        # k[0..3] = 0個拾っている状態から3個拾っている状態
        # indexが大きいほど、小さいアイテムとなるので、小さいものから更新していく
        for k in range(2, -1, -1):
            dp[k+1][r][c] = max(
                dp[k+1][r][c],
                dp[k][r][c]+g[r][c]
            )

        for k in range(4):
            dp[0][r+1][c] = max(dp[0][r+1][c], dp[k][r][c])
            dp[k][r][c+1] = max(dp[k][r][c+1], dp[k][r][c])

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