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

d = [[0 for _ in range(C+1)] for _ in range(R+1)]

#dp[行の中でピックした回数][行][列]　この順じゃないとTLEする
dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]

for i in range(K):
    r, c, v = map(int, input().split())
    d[r-1][c-1] = v
for i in range(R):
    for j in range(C):
        # kが大きい方からやらないとダメ。01ナップサックと同じ考え方。書き換えられた値を見ないように。
        for k in range(2, -1, -1):
            # 拾う遷移。d[i][j]を取るかどうかという判定
            dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + d[i][j])
        for k in range(4):
            dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
            dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])
ans = 0

for k in range(4):
    ans = max(ans, dp[k][R-1][C-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 for _ in range(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 for _ in range(C+1)] d = [[0 for _ in range(C+1)] for _ in range(R+1)] d [[0 for _ in range(C+1)] for _ in range(R+1)] [[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0 for _ in range(C+1)] for _ in range(R+1)] dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] dp [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] for i in range(K):
    r, c, v = map(int, input().split())
    d[r-1][c-1] = 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-1][c-1] = v d[r-1][c-1] [r-1] d r-1 r 1 c-1 c 1 v for i in range(R):
    for j in range(C):
        # kが大きい方からやらないとダメ。01ナップサックと同じ考え方。書き換えられた値を見ないように。
        for k in range(2, -1, -1):
            # 拾う遷移。d[i][j]を取るかどうかという判定
            dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + d[i][j])
        for k in range(4):
            dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
            dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j]) i range(R) range R for j in range(C):
        # kが大きい方からやらないとダメ。01ナップサックと同じ考え方。書き換えられた値を見ないように。
        for k in range(2, -1, -1):
            # 拾う遷移。d[i][j]を取るかどうかという判定
            dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + d[i][j])
        for k in range(4):
            dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
            dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j]) j range(C) range C for k in range(2, -1, -1):
            # 拾う遷移。d[i][j]を取るかどうかという判定
            dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + d[i][j])
         k range(2, -1, -1) range 2 -1 -1 dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + d[i][j]) dp[k+1][i][j] [i] [k+1] dp k+1 k 1 i j max(dp[k+1][i][j], dp[k][i][j] + d[i][j]) max dp[k+1][i][j] [i] [k+1] dp k+1 k 1 i j dp[k][i][j] + d[i][j] dp[k][i][j] [i] [k] dp k i j d[i][j] [i] d i j for k in range(4):
            dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
            dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j]) 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[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 ans = 0 ans 0 for k in range(4):
    ans = max(ans, dp[k][R-1][C-1]) k range(4) range 4 ans = max(ans, dp[k][R-1][C-1]) ans max(ans, dp[k][R-1][C-1]) max ans dp[k][R-1][C-1] [R-1] [k] dp k R-1 R 1 C-1 C 1 print(ans) print ans ans = 0 0 ans K = map(int, input().split()) map(int, input().split()) K dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] dp C,K = 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()) map(int, input().split()) R r, c, v = map(int, input().split()) map(int, input().split()) r c, v = map(int, input().split()) map(int, input().split()) c ans = max(ans, dp[k][R-1][C-1]) max(ans, dp[k][R-1][C-1]) ans d = [[0 for _ in range(C+1)] for _ in range(R+1)] [[0 for _ in range(C+1)] for _ in range(R+1)] d
R,C,K = map(int, input().split())

d = [[0 for _ in range(C+1)] for _ in range(R+1)]

#dp[行の中でピックした回数][行][列]　この順じゃないとTLEする
dp = [[[0 for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]

for i in range(K):
    r, c, v = map(int, input().split())
    d[r-1][c-1] = v
for i in range(R):
    for j in range(C):
        # kが大きい方からやらないとダメ。01ナップサックと同じ考え方。書き換えられた値を見ないように。
        for k in range(2, -1, -1):
            # 拾う遷移。d[i][j]を取るかどうかという判定
            dp[k+1][i][j] = max(dp[k+1][i][j], dp[k][i][j] + d[i][j])
        for k in range(4):
            dp[0][i+1][j] = max(dp[0][i+1][j], dp[k][i][j])
            dp[k][i][j+1] = max(dp[k][i][j+1], dp[k][i][j])
ans = 0

for k in range(4):
    ans = max(ans, dp[k][R-1][C-1])
print(ans)    