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

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

for i in range(1, R+1):
    for j in range(1, C+1):
        for k in range(4):
            dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
            dp[1][i+1][j] = max(dp[1][i+1][j], dp[k][i][j] + T[i+1][j])
            dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])
            if k <= 2:
                dp[k+1][i][j+1] = max(dp[k+1][i][j+1], dp[k][i][j] + T[i][j+1])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][R][C])
print(ans)