#!/usr/bin/env python3
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

dp1 = [[0] * (c+1) for _ in range(r+1)]
dp2 = [[0] * (c+1) for _ in range(r+1)]
dp3 = [[0] * (c+1) for _ in range(r+1)]

for i in range(1, r+1):
    for j in range(1, c+1):
        dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + items[i][j], dp2[i-1][j] + items[i][j], dp3[i-1][j] + items[i][j])
        dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1] + items[i][j])
        dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1] + items[i][j])

ans = max(dp1[r][c], dp2[r][c], dp3[r][c])
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 _ 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] * (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 dp1 = [[0] * (c+1) for _ in range(r+1)] dp1 [[0] * (c+1) for _ in range(r+1)] [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 dp2 = [[0] * (c+1) for _ in range(r+1)] dp2 [[0] * (c+1) for _ in range(r+1)] [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 dp3 = [[0] * (c+1) for _ in range(r+1)] dp3 [[0] * (c+1) for _ in range(r+1)] for i in range(1, r+1):
    for j in range(1, c+1):
        dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + items[i][j], dp2[i-1][j] + items[i][j], dp3[i-1][j] + items[i][j])
        dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1] + items[i][j])
        dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1] + items[i][j]) i range(1, r+1) range 1 r+1 r 1 for j in range(1, c+1):
        dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + items[i][j], dp2[i-1][j] + items[i][j], dp3[i-1][j] + items[i][j])
        dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1] + items[i][j])
        dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1] + items[i][j]) j range(1, c+1) range 1 c+1 c 1 dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + items[i][j], dp2[i-1][j] + items[i][j], dp3[i-1][j] + items[i][j]) dp1[i][j] [i] dp1 i j max(dp1[i][j-1], dp1[i-1][j] + items[i][j], dp2[i-1][j] + items[i][j], dp3[i-1][j] + items[i][j]) max dp1[i][j-1] [i] dp1 i j-1 j 1 dp1[i-1][j] + items[i][j] dp1[i-1][j] [i-1] dp1 i-1 i 1 j items[i][j] [i] items i j dp2[i-1][j] + items[i][j] dp2[i-1][j] [i-1] dp2 i-1 i 1 j items[i][j] [i] items i j dp3[i-1][j] + items[i][j] dp3[i-1][j] [i-1] dp3 i-1 i 1 j items[i][j] [i] items i j dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1] + items[i][j]) dp2[i][j] [i] dp2 i j max(dp2[i][j-1], dp1[i][j-1] + items[i][j]) max dp2[i][j-1] [i] dp2 i j-1 j 1 dp1[i][j-1] + items[i][j] dp1[i][j-1] [i] dp1 i j-1 j 1 items[i][j] [i] items i j dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1] + items[i][j]) dp3[i][j] [i] dp3 i j max(dp3[i][j-1], dp2[i][j-1] + items[i][j]) max dp3[i][j-1] [i] dp3 i j-1 j 1 dp2[i][j-1] + items[i][j] dp2[i][j-1] [i] dp2 i j-1 j 1 items[i][j] [i] items i j ans = max(dp1[r][c], dp2[r][c], dp3[r][c]) ans max(dp1[r][c], dp2[r][c], dp3[r][c]) max dp1[r][c] [r] dp1 r c dp2[r][c] [r] dp2 r c dp3[r][c] [r] dp3 r c print(ans) print ans items = [[0] * (c+1) for _ in range(r+1)] [[0] * (c+1) for _ in range(r+1)] items dp2 = [[0] * (c+1) for _ in range(r+1)] [[0] * (c+1) for _ in range(r+1)] dp2 r, c, k = map(int, input().split()) map(int, input().split()) r ans = max(dp1[r][c], dp2[r][c], dp3[r][c]) max(dp1[r][c], dp2[r][c], dp3[r][c]) ans dp1 = [[0] * (c+1) for _ in range(r+1)] [[0] * (c+1) for _ in range(r+1)] dp1 k = map(int, input().split()) map(int, input().split()) k R, C, V = map(int, input().split()) map(int, input().split()) R C, V = map(int, input().split()) map(int, input().split()) C c, k = map(int, input().split()) map(int, input().split()) c V = map(int, input().split()) map(int, input().split()) V dp3 = [[0] * (c+1) for _ in range(r+1)] [[0] * (c+1) for _ in range(r+1)] dp3
#!/usr/bin/env python3
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

dp1 = [[0] * (c+1) for _ in range(r+1)]
dp2 = [[0] * (c+1) for _ in range(r+1)]
dp3 = [[0] * (c+1) for _ in range(r+1)]

for i in range(1, r+1):
    for j in range(1, c+1):
        dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + items[i][j], dp2[i-1][j] + items[i][j], dp3[i-1][j] + items[i][j])
        dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1] + items[i][j])
        dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1] + items[i][j])

ans = max(dp1[r][c], dp2[r][c], dp3[r][c])
print(ans)