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

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


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

for x in range(1, C+1):
    for y in range(1, R+1):
        v = Items[y][x]
        if v:
            DP[y][3] = max(DP[y][3], DP[y][2] + v)
            DP[y][2] = max(DP[y][2], DP[y][1] + v)
            DP[y][1] = max(max(DP[y][1], DP[y][0] + v), max(DP[y-1]) + v)
            DP[y][0] = max(DP[y][0], max(DP[y-1]))
        else:
            DP[y][0] = max(DP[y][0], max(DP[y-1]))

print(max(DP[R])) 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(R + 1) _ range(R + 1) range R + 1 R 1 for _ in range(R + 1) [0] * (C + 1) [0] 0 C + 1 C 1 Items = [[0] * (C + 1) for _ in range(R + 1)] Items [[0] * (C + 1) for _ in range(R + 1)] for _ in range(K):
    r, c, v = map(int, input().split())
    Items[r][c] = 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 Items[r][c] = v Items[r][c] [r] Items r c v [0] * 4 for _ in range(R + 1) for _ in range(R + 1) _ range(R + 1) range R + 1 R 1 for _ in range(R + 1) [0] * 4 [0] 0 4 DP = [[0] * 4 for _ in range(R + 1)] DP [[0] * 4 for _ in range(R + 1)] for x in range(1, C+1):
    for y in range(1, R+1):
        v = Items[y][x]
        if v:
            DP[y][3] = max(DP[y][3], DP[y][2] + v)
            DP[y][2] = max(DP[y][2], DP[y][1] + v)
            DP[y][1] = max(max(DP[y][1], DP[y][0] + v), max(DP[y-1]) + v)
            DP[y][0] = max(DP[y][0], max(DP[y-1]))
        else:
            DP[y][0] = max(DP[y][0], max(DP[y-1])) x range(1, C+1) range 1 C+1 C 1 for y in range(1, R+1):
        v = Items[y][x]
        if v:
            DP[y][3] = max(DP[y][3], DP[y][2] + v)
            DP[y][2] = max(DP[y][2], DP[y][1] + v)
            DP[y][1] = max(max(DP[y][1], DP[y][0] + v), max(DP[y-1]) + v)
            DP[y][0] = max(DP[y][0], max(DP[y-1]))
        else:
            DP[y][0] = max(DP[y][0], max(DP[y-1])) y range(1, R+1) range 1 R+1 R 1 v = Items[y][x] v Items[y][x] [y] Items y x if v:
            DP[y][3] = max(DP[y][3], DP[y][2] + v)
            DP[y][2] = max(DP[y][2], DP[y][1] + v)
            DP[y][1] = max(max(DP[y][1], DP[y][0] + v), max(DP[y-1]) + v)
            DP[y][0] = max(DP[y][0], max(DP[y-1]))
        else:
            DP[y][0] = max(DP[y][0], max(DP[y-1])) v DP[y][3] = max(DP[y][3], DP[y][2] + v) DP[y][3] [y] DP y 3 max(DP[y][3], DP[y][2] + v) max DP[y][3] [y] DP y 3 DP[y][2] + v DP[y][2] [y] DP y 2 v DP[y][2] = max(DP[y][2], DP[y][1] + v) DP[y][2] [y] DP y 2 max(DP[y][2], DP[y][1] + v) max DP[y][2] [y] DP y 2 DP[y][1] + v DP[y][1] [y] DP y 1 v DP[y][1] = max(max(DP[y][1], DP[y][0] + v), max(DP[y-1]) + v) DP[y][1] [y] DP y 1 max(max(DP[y][1], DP[y][0] + v), max(DP[y-1]) + v) max max(DP[y][1], DP[y][0] + v) max DP[y][1] [y] DP y 1 DP[y][0] + v DP[y][0] [y] DP y 0 v max(DP[y-1]) + v max(DP[y-1]) max DP[y-1] DP y-1 y 1 v DP[y][0] = max(DP[y][0], max(DP[y-1])) DP[y][0] [y] DP y 0 max(DP[y][0], max(DP[y-1])) max DP[y][0] [y] DP y 0 max(DP[y-1]) max DP[y-1] DP y-1 y 1 DP[y][0] = max(DP[y][0], max(DP[y-1])) DP[y][0] [y] DP y 0 max(DP[y][0], max(DP[y-1])) max DP[y][0] [y] DP y 0 max(DP[y-1]) max DP[y-1] DP y-1 y 1 print(max(DP[R])) print max(DP[R]) max DP[R] DP R c, v = map(int, input().split()) map(int, input().split()) c v = map(int, input().split()) map(int, input().split()) v v = Items[y][x] Items[y][x] v r, c, v = map(int, input().split()) map(int, input().split()) r DP = [[0] * 4 for _ in range(R + 1)] [[0] * 4 for _ in range(R + 1)] DP Items = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] Items 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
R, C, K = map(int, input().split())

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


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

for x in range(1, C+1):
    for y in range(1, R+1):
        v = Items[y][x]
        if v:
            DP[y][3] = max(DP[y][3], DP[y][2] + v)
            DP[y][2] = max(DP[y][2], DP[y][1] + v)
            DP[y][1] = max(max(DP[y][1], DP[y][0] + v), max(DP[y-1]) + v)
            DP[y][0] = max(DP[y][0], max(DP[y-1]))
        else:
            DP[y][0] = max(DP[y][0], max(DP[y-1]))

print(max(DP[R]))