R, C, K = map(int, input().split())

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

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

for i in range(R):
    dp2 = [[0] * 4 for _ in range(C)]
    for j in range(C):
        if j != 0:
            dp2[j] = dp2[j-1][:]

        dp2[j][0] = max(dp2[j][0], max(dp[j]))

        for k in range(3, 0, -1):
            dp2[j][k] = max(dp2[j][k], dp2[j][k-1] + items[i][j])

    dp = dp2

print(max(dp[-1])) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0] * C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0] * C [0] 0 C items = [[0] * C for _ in range(R)] items [[0] * C for _ in range(R)] for i in range(K):
    r, c, v = map(int, input().split())
    items[r-1][c-1] = v i 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 items[r-1][c-1] = v items[r-1][c-1] [r-1] items r-1 r 1 c-1 c 1 v [0] * 4 for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0] * 4 [0] 0 4 dp = [[0] * 4 for _ in range(C)] dp [[0] * 4 for _ in range(C)] for i in range(R):
    dp2 = [[0] * 4 for _ in range(C)]
    for j in range(C):
        if j != 0:
            dp2[j] = dp2[j-1][:]

        dp2[j][0] = max(dp2[j][0], max(dp[j]))

        for k in range(3, 0, -1):
            dp2[j][k] = max(dp2[j][k], dp2[j][k-1] + items[i][j])

    dp = dp2 i range(R) range R [0] * 4 for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0] * 4 [0] 0 4 dp2 = [[0] * 4 for _ in range(C)] dp2 [[0] * 4 for _ in range(C)] for j in range(C):
        if j != 0:
            dp2[j] = dp2[j-1][:]

        dp2[j][0] = max(dp2[j][0], max(dp[j]))

        for k in range(3, 0, -1):
            dp2[j][k] = max(dp2[j][k], dp2[j][k-1] + items[i][j])

     j range(C) range C if j != 0:
            dp2[j] = dp2[j-1][:]

         j != 0 j 0 dp2[j] = dp2[j-1][:] dp2[j] dp2 j dp2[j-1][:] [j-1] dp2 j-1 j 1 : dp2[j][0] = max(dp2[j][0], max(dp[j])) dp2[j][0] [j] dp2 j 0 max(dp2[j][0], max(dp[j])) max dp2[j][0] [j] dp2 j 0 max(dp[j]) max dp[j] dp j for k in range(3, 0, -1):
            dp2[j][k] = max(dp2[j][k], dp2[j][k-1] + items[i][j])

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

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

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

for i in range(R):
    dp2 = [[0] * 4 for _ in range(C)]
    for j in range(C):
        if j != 0:
            dp2[j] = dp2[j-1][:]

        dp2[j][0] = max(dp2[j][0], max(dp[j]))

        for k in range(3, 0, -1):
            dp2[j][k] = max(dp2[j][k], dp2[j][k-1] + items[i][j])

    dp = dp2

print(max(dp[-1]))
