## 一時間もTLEのために時間を無駄にした　学びもないつまんない問題...

R, C, K = map(int, input().split())
dp = [[[0]*(C+1) for _ in range(R+1)]for __ in range(4)]
# dp[r][c][j] :=r index c columns already j cnt
dp[0][0][0] = 0
D = [[0 for i in range(C+1)] for j in range(R+1)]

for i in range(K):
    r, c, v = map(int, input().split())
    D[r][c] = v

for i in range(R+1):
    for j in range(C+1):
        if D[i][j] > 0:
            v = D[i][j]
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
            dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
            dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])

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

        else:
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1] i range(R+1) range R+1 R 1 for j in range(C+1):
        if D[i][j] > 0:
            v = D[i][j]
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
            dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
            dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])

        else:
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1] j range(C+1) range C+1 C 1 if D[i][j] > 0:
            v = D[i][j]
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
            dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
            dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])

        else:
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1] D[i][j] > 0 D[i][j] [i] D i j 0 v = D[i][j] v D[i][j] [i] D i j M = max(dp[k][i-1][j] for k in range(4)) M max(dp[k][i-1][j] for k in range(4)) max dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j dp[0][i][j] = max(dp[0][i][j-1], M) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j-1], M) max dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 M dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v) dp[1][i][j] [i] [1] dp 1 i j max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v) max dp[0][i][j-1]+v dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 v dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 M+v M v dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1]) dp[2][i][j] [i] [2] dp 2 i j max(dp[1][i][j-1]+v, dp[2][i][j-1]) max dp[1][i][j-1]+v dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 v dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1]) dp[3][i][j] [i] [3] dp 3 i j max(dp[2][i][j-1]+v, dp[3][i][j-1]) max dp[2][i][j-1]+v dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 v dp[3][i][j-1] [i] [3] dp 3 i j-1 j 1 M = max(dp[k][i-1][j] for k in range(4)) M max(dp[k][i-1][j] for k in range(4)) max dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j dp[0][i][j] = max(dp[0][i][j-1], M) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j-1], M) max dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 M dp[1][i][j] = dp[1][i][j-1] dp[1][i][j] [i] [1] dp 1 i j dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 dp[2][i][j] = dp[2][i][j-1] dp[2][i][j] [i] [2] dp 2 i j dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 dp[3][i][j] = dp[3][i][j-1] dp[3][i][j] [i] [3] dp 3 i j dp[3][i][j-1] [i] [3] dp 3 i j-1 j 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 R, C, K = map(int, input().split()) map(int, input().split()) R r, c, v = map(int, input().split()) map(int, input().split()) r M = max(dp[k][i-1][j] for k in range(4)) max(dp[k][i-1][j] for k in range(4)) M D = [[0 for i in range(C+1)] for j in range(R+1)] [[0 for i in range(C+1)] for j in range(R+1)] D v = D[i][j] D[i][j] v v = map(int, input().split()) map(int, input().split()) v 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 C, K = map(int, input().split()) map(int, input().split()) C c, v = map(int, input().split()) map(int, input().split()) c M = max(dp[k][i-1][j] for k in range(4)) max(dp[k][i-1][j] for k in range(4)) M K = map(int, input().split()) map(int, input().split()) K ans = 0 0 ans ans = max(ans, dp[i][-1][-1]) max(ans, dp[i][-1][-1]) ans
## 一時間もTLEのために時間を無駄にした　学びもないつまんない問題...

R, C, K = map(int, input().split())
dp = [[[0]*(C+1) for _ in range(R+1)]for __ in range(4)]
# dp[r][c][j] :=r index c columns already j cnt
dp[0][0][0] = 0
D = [[0 for i in range(C+1)] for j in range(R+1)]

for i in range(K):
    r, c, v = map(int, input().split())
    D[r][c] = v

for i in range(R+1):
    for j in range(C+1):
        if D[i][j] > 0:
            v = D[i][j]
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
            dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
            dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])

        else:
            M = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], M)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1]

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