H, W, K = map(int, input().split())
Map = [[0] * (W + 1) for _ in range(H + 1)]
for _ in range(K):
    h, w, k = map(int, input().split())
    Map[h][w] = k

DP = [[[0] * (H + 1) for _ in range(W + 1)] for __ in range(4)]


for i in range(1, H + 1):
    for j in range(1, W + 1):
        x = Map[i][j]
        if Map:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = max(DP[1][j - 1][i], DP[0][j-1][i] + x, DP[0][j][i-1] + x, DP[1][j][i-1] + x, DP[2][j][i-1] + x, DP[3][j][i-1] + x)
            DP[2][j][i] = max(DP[2][j - 1][i], DP[1][j-1][i] + x)
            DP[3][j][i] = max(DP[3][j - 1][i], DP[2][j-1][i] + x)

        else:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = DP[1][j-1][i]
            DP[2][j][i] = DP[2][j-1][i]
            DP[3][j][i] = DP[3][j-1][i]

print(max(DP[0][W][H], DP[1][W][H], DP[2][W][H], DP[3][W][H])) H, W, K = map(int, input().split()) H map(int, input().split()) map int input().split() ().split () input split W K [0] * (W + 1) for _ in range(H + 1) for _ in range(H + 1) _ range(H + 1) range H + 1 H 1 for _ in range(H + 1) [0] * (W + 1) [0] 0 W + 1 W 1 Map = [[0] * (W + 1) for _ in range(H + 1)] Map [[0] * (W + 1) for _ in range(H + 1)] for _ in range(K):
    h, w, k = map(int, input().split())
    Map[h][w] = k _ range(K) range K h, w, k = map(int, input().split()) h map(int, input().split()) map int input().split() ().split () input split w k Map[h][w] = k Map[h][w] [h] Map h w k [[0] * (H + 1) for _ in range(W + 1)] for __ in range(4) for __ in range(4) __ range(4) range 4 for __ in range(4) [[0] * (H + 1) for _ in range(W + 1)] DP = [[[0] * (H + 1) for _ in range(W + 1)] for __ in range(4)] DP [[[0] * (H + 1) for _ in range(W + 1)] for __ in range(4)] for i in range(1, H + 1):
    for j in range(1, W + 1):
        x = Map[i][j]
        if Map:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = max(DP[1][j - 1][i], DP[0][j-1][i] + x, DP[0][j][i-1] + x, DP[1][j][i-1] + x, DP[2][j][i-1] + x, DP[3][j][i-1] + x)
            DP[2][j][i] = max(DP[2][j - 1][i], DP[1][j-1][i] + x)
            DP[3][j][i] = max(DP[3][j - 1][i], DP[2][j-1][i] + x)

        else:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = DP[1][j-1][i]
            DP[2][j][i] = DP[2][j-1][i]
            DP[3][j][i] = DP[3][j-1][i] i range(1, H + 1) range 1 H + 1 H 1 for j in range(1, W + 1):
        x = Map[i][j]
        if Map:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = max(DP[1][j - 1][i], DP[0][j-1][i] + x, DP[0][j][i-1] + x, DP[1][j][i-1] + x, DP[2][j][i-1] + x, DP[3][j][i-1] + x)
            DP[2][j][i] = max(DP[2][j - 1][i], DP[1][j-1][i] + x)
            DP[3][j][i] = max(DP[3][j - 1][i], DP[2][j-1][i] + x)

        else:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = DP[1][j-1][i]
            DP[2][j][i] = DP[2][j-1][i]
            DP[3][j][i] = DP[3][j-1][i] j range(1, W + 1) range 1 W + 1 W 1 x = Map[i][j] x Map[i][j] [i] Map i j if Map:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = max(DP[1][j - 1][i], DP[0][j-1][i] + x, DP[0][j][i-1] + x, DP[1][j][i-1] + x, DP[2][j][i-1] + x, DP[3][j][i-1] + x)
            DP[2][j][i] = max(DP[2][j - 1][i], DP[1][j-1][i] + x)
            DP[3][j][i] = max(DP[3][j - 1][i], DP[2][j-1][i] + x)

        else:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = DP[1][j-1][i]
            DP[2][j][i] = DP[2][j-1][i]
            DP[3][j][i] = DP[3][j-1][i] Map DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i]) DP[0][j][i] [j] [0] DP 0 j i max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i]) max DP[0][j][i-1] [j] [0] DP 0 j i-1 i 1 DP[1][j][i-1] [j] [1] DP 1 j i-1 i 1 DP[2][j][i-1] [j] [2] DP 2 j i-1 i 1 DP[3][j][i-1] [j] [3] DP 3 j i-1 i 1 DP[0][j-1][i] [j-1] [0] DP 0 j-1 j 1 i DP[1][j][i] = max(DP[1][j - 1][i], DP[0][j-1][i] + x, DP[0][j][i-1] + x, DP[1][j][i-1] + x, DP[2][j][i-1] + x, DP[3][j][i-1] + x) DP[1][j][i] [j] [1] DP 1 j i max(DP[1][j - 1][i], DP[0][j-1][i] + x, DP[0][j][i-1] + x, DP[1][j][i-1] + x, DP[2][j][i-1] + x, DP[3][j][i-1] + x) max DP[1][j - 1][i] [j - 1] [1] DP 1 j - 1 j 1 i DP[0][j-1][i] + x DP[0][j-1][i] [j-1] [0] DP 0 j-1 j 1 i x DP[0][j][i-1] + x DP[0][j][i-1] [j] [0] DP 0 j i-1 i 1 x DP[1][j][i-1] + x DP[1][j][i-1] [j] [1] DP 1 j i-1 i 1 x DP[2][j][i-1] + x DP[2][j][i-1] [j] [2] DP 2 j i-1 i 1 x DP[3][j][i-1] + x DP[3][j][i-1] [j] [3] DP 3 j i-1 i 1 x DP[2][j][i] = max(DP[2][j - 1][i], DP[1][j-1][i] + x) DP[2][j][i] [j] [2] DP 2 j i max(DP[2][j - 1][i], DP[1][j-1][i] + x) max DP[2][j - 1][i] [j - 1] [2] DP 2 j - 1 j 1 i DP[1][j-1][i] + x DP[1][j-1][i] [j-1] [1] DP 1 j-1 j 1 i x DP[3][j][i] = max(DP[3][j - 1][i], DP[2][j-1][i] + x) DP[3][j][i] [j] [3] DP 3 j i max(DP[3][j - 1][i], DP[2][j-1][i] + x) max DP[3][j - 1][i] [j - 1] [3] DP 3 j - 1 j 1 i DP[2][j-1][i] + x DP[2][j-1][i] [j-1] [2] DP 2 j-1 j 1 i x DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i]) DP[0][j][i] [j] [0] DP 0 j i max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i]) max DP[0][j][i-1] [j] [0] DP 0 j i-1 i 1 DP[1][j][i-1] [j] [1] DP 1 j i-1 i 1 DP[2][j][i-1] [j] [2] DP 2 j i-1 i 1 DP[3][j][i-1] [j] [3] DP 3 j i-1 i 1 DP[0][j-1][i] [j-1] [0] DP 0 j-1 j 1 i DP[1][j][i] = DP[1][j-1][i] DP[1][j][i] [j] [1] DP 1 j i DP[1][j-1][i] [j-1] [1] DP 1 j-1 j 1 i DP[2][j][i] = DP[2][j-1][i] DP[2][j][i] [j] [2] DP 2 j i DP[2][j-1][i] [j-1] [2] DP 2 j-1 j 1 i DP[3][j][i] = DP[3][j-1][i] DP[3][j][i] [j] [3] DP 3 j i DP[3][j-1][i] [j-1] [3] DP 3 j-1 j 1 i print(max(DP[0][W][H], DP[1][W][H], DP[2][W][H], DP[3][W][H])) print max(DP[0][W][H], DP[1][W][H], DP[2][W][H], DP[3][W][H]) max DP[0][W][H] [W] [0] DP 0 W H DP[1][W][H] [W] [1] DP 1 W H DP[2][W][H] [W] [2] DP 2 W H DP[3][W][H] [W] [3] DP 3 W H H, W, K = map(int, input().split()) map(int, input().split()) H w, k = map(int, input().split()) map(int, input().split()) w W, K = map(int, input().split()) map(int, input().split()) W h, w, k = map(int, input().split()) map(int, input().split()) h K = map(int, input().split()) map(int, input().split()) K Map = [[0] * (W + 1) for _ in range(H + 1)] [[0] * (W + 1) for _ in range(H + 1)] Map k = map(int, input().split()) map(int, input().split()) k DP = [[[0] * (H + 1) for _ in range(W + 1)] for __ in range(4)] [[[0] * (H + 1) for _ in range(W + 1)] for __ in range(4)] DP x = Map[i][j] Map[i][j] x
H, W, K = map(int, input().split())
Map = [[0] * (W + 1) for _ in range(H + 1)]
for _ in range(K):
    h, w, k = map(int, input().split())
    Map[h][w] = k

DP = [[[0] * (H + 1) for _ in range(W + 1)] for __ in range(4)]


for i in range(1, H + 1):
    for j in range(1, W + 1):
        x = Map[i][j]
        if Map:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = max(DP[1][j - 1][i], DP[0][j-1][i] + x, DP[0][j][i-1] + x, DP[1][j][i-1] + x, DP[2][j][i-1] + x, DP[3][j][i-1] + x)
            DP[2][j][i] = max(DP[2][j - 1][i], DP[1][j-1][i] + x)
            DP[3][j][i] = max(DP[3][j - 1][i], DP[2][j-1][i] + x)

        else:
            DP[0][j][i] = max(DP[0][j][i-1], DP[1][j][i-1], DP[2][j][i-1], DP[3][j][i-1], DP[0][j-1][i])
            DP[1][j][i] = DP[1][j-1][i]
            DP[2][j][i] = DP[2][j-1][i]
            DP[3][j][i] = DP[3][j-1][i]

print(max(DP[0][W][H], DP[1][W][H], DP[2][W][H], DP[3][W][H]))