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

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

dp0 = [[0]*(C+1) for _ in range(R+1)]
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(R+1):
    for j in range(C+1):
        v = V[i][j]

        la = lb = lc = ld = 0
        if j > 0:
            la = dp0[i][j-1]
            lb = dp1[i][j-1]
            lc = dp2[i][j-1]
            ld = dp3[i][j-1]
            dp2[i][j] = max(dp2[i][j], lc, lb + v)
            dp3[i][j] = max(dp3[i][j], ld, lc + v)

        if i > 0:
            max_p = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
            dp0[i][j] = max(dp0[i][j], max_p, la)
            dp1[i][j] = max(dp1[i][j], max_p + v, lb, la + v)

print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])) 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 V = [[0]*(C+1) for _ in range(R+1)] V [[0]*(C+1) for _ in range(R+1)] for _ in range(K):
    r, c, v = map(int, input().split())
    V[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 V[r][c] = v V[r][c] [r] V 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 dp0 = [[0]*(C+1) for _ in range(R+1)] dp0 [[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 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(R+1):
    for j in range(C+1):
        v = V[i][j]

        la = lb = lc = ld = 0
        if j > 0:
            la = dp0[i][j-1]
            lb = dp1[i][j-1]
            lc = dp2[i][j-1]
            ld = dp3[i][j-1]
            dp2[i][j] = max(dp2[i][j], lc, lb + v)
            dp3[i][j] = max(dp3[i][j], ld, lc + v)

        if i > 0:
            max_p = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
            dp0[i][j] = max(dp0[i][j], max_p, la)
            dp1[i][j] = max(dp1[i][j], max_p + v, lb, la + v) i range(R+1) range R+1 R 1 for j in range(C+1):
        v = V[i][j]

        la = lb = lc = ld = 0
        if j > 0:
            la = dp0[i][j-1]
            lb = dp1[i][j-1]
            lc = dp2[i][j-1]
            ld = dp3[i][j-1]
            dp2[i][j] = max(dp2[i][j], lc, lb + v)
            dp3[i][j] = max(dp3[i][j], ld, lc + v)

        if i > 0:
            max_p = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
            dp0[i][j] = max(dp0[i][j], max_p, la)
            dp1[i][j] = max(dp1[i][j], max_p + v, lb, la + v) j range(C+1) range C+1 C 1 v = V[i][j] v V[i][j] [i] V i j la = lb = lc = ld = 0 la 0 = lb = lc = ld = 0 lb 0 lc ld if j > 0:
            la = dp0[i][j-1]
            lb = dp1[i][j-1]
            lc = dp2[i][j-1]
            ld = dp3[i][j-1]
            dp2[i][j] = max(dp2[i][j], lc, lb + v)
            dp3[i][j] = max(dp3[i][j], ld, lc + v)

         j > 0 j 0 la = dp0[i][j-1] la dp0[i][j-1] [i] dp0 i j-1 j 1 lb = dp1[i][j-1] lb dp1[i][j-1] [i] dp1 i j-1 j 1 lc = dp2[i][j-1] lc dp2[i][j-1] [i] dp2 i j-1 j 1 ld = dp3[i][j-1] ld dp3[i][j-1] [i] dp3 i j-1 j 1 dp2[i][j] = max(dp2[i][j], lc, lb + v) dp2[i][j] [i] dp2 i j max(dp2[i][j], lc, lb + v) max dp2[i][j] [i] dp2 i j lc lb + v lb v dp3[i][j] = max(dp3[i][j], ld, lc + v) dp3[i][j] [i] dp3 i j max(dp3[i][j], ld, lc + v) max dp3[i][j] [i] dp3 i j ld lc + v lc v if i > 0:
            max_p = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
            dp0[i][j] = max(dp0[i][j], max_p, la)
            dp1[i][j] = max(dp1[i][j], max_p + v, lb, la + v) i > 0 i 0 max_p = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j]) max_p max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j]) max dp0[i-1][j] [i-1] dp0 i-1 i 1 j dp1[i-1][j] [i-1] dp1 i-1 i 1 j dp2[i-1][j] [i-1] dp2 i-1 i 1 j dp3[i-1][j] [i-1] dp3 i-1 i 1 j dp0[i][j] = max(dp0[i][j], max_p, la) dp0[i][j] [i] dp0 i j max(dp0[i][j], max_p, la) max dp0[i][j] [i] dp0 i j max_p la dp1[i][j] = max(dp1[i][j], max_p + v, lb, la + v) dp1[i][j] [i] dp1 i j max(dp1[i][j], max_p + v, lb, la + v) max dp1[i][j] [i] dp1 i j max_p + v max_p v lb la + v la v print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])) print max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]) max dp0[R][C] [R] dp0 R C dp1[R][C] [R] dp1 R C dp2[R][C] [R] dp2 R C dp3[R][C] [R] dp3 R C r, c, v = map(int, input().split()) map(int, input().split()) r lc = dp2[i][j-1] dp2[i][j-1] lc K = map(int, input().split()) map(int, input().split()) K lc = ld = 0 0 lc R, C, K = map(int, input().split()) map(int, input().split()) R C, K = map(int, input().split()) map(int, input().split()) C V = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] V dp0 = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] dp0 ld = dp3[i][j-1] dp3[i][j-1] ld la = dp0[i][j-1] dp0[i][j-1] la lb = lc = ld = 0 0 lb la = lb = lc = ld = 0 0 la c, v = map(int, input().split()) map(int, input().split()) c lb = dp1[i][j-1] dp1[i][j-1] lb v = V[i][j] V[i][j] v 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 max_p = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j]) max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j]) max_p dp2 = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] dp2 dp1 = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] dp1 ld = 0 0 ld
R, C, K = map(int, input().split())

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

dp0 = [[0]*(C+1) for _ in range(R+1)]
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(R+1):
    for j in range(C+1):
        v = V[i][j]

        la = lb = lc = ld = 0
        if j > 0:
            la = dp0[i][j-1]
            lb = dp1[i][j-1]
            lc = dp2[i][j-1]
            ld = dp3[i][j-1]
            dp2[i][j] = max(dp2[i][j], lc, lb + v)
            dp3[i][j] = max(dp3[i][j], ld, lc + v)

        if i > 0:
            max_p = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
            dp0[i][j] = max(dp0[i][j], max_p, la)
            dp1[i][j] = max(dp1[i][j], max_p + v, lb, la + v)

print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))
