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

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

for y in range(R+1):
    for x in range(C+1):
        for i in range(4):
            position = dp[i][y][x]
            if y+1 <= R:
                dp[0][y+1][x] = max(dp[0][y+1][x], position)
                dp[1][y+1][x] = max(dp[1][y+1][x], position+items[y+1][x])
            if x+1 <= C:
                dp[i][y][x+1] = max(dp[i][y][x+1], position)
                if i < 3:
                    dp[i+1][y][x+1] = max(dp[i+1][y][x+1], position+items[y][x+1])

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

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

for y in range(R+1):
    for x in range(C+1):
        for i in range(4):
            position = dp[i][y][x]
            if y+1 <= R:
                dp[0][y+1][x] = max(dp[0][y+1][x], position)
                dp[1][y+1][x] = max(dp[1][y+1][x], position+items[y+1][x])
            if x+1 <= C:
                dp[i][y][x+1] = max(dp[i][y][x+1], position)
                if i < 3:
                    dp[i+1][y][x+1] = max(dp[i+1][y][x+1], position+items[y][x+1])

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