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



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

for _ in range(K):

    r, c, v = list(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 = list(map(int, input().split()))



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

for _ in range(K):

    r, c, v = list(map(int, input().split()))

    V[r][c] = v



pre0 = [0]*(C+1)

pre1 = [0]*(C+1)

pre2 = [0]*(C+1)

pre3 = [0]*(C+1)

for i in range(R+1):

    now0 = [0]*(C+1)

    now1 = [0]*(C+1)

    now2 = [0]*(C+1)

    now3 = [0]*(C+1)

    for j in range(C+1):

        v = V[i][j]

        la = lb = 0

        if j > 0:

            la = now0[j-1]

            lb = now1[j-1]

            now2[j] = max(now2[j], now2[j-1], lb + v)

            now3[j] = max(now3[j], now3[j-1], now2[j-1] + v)

        if i > 0:

            max_p = max(pre0[j], pre1[j], pre2[j], pre3[j])

            now0[j] = max(now0[j], max_p, la)

            now1[j] = max(now1[j], max_p + v, la + v, lb)

    pre0 = now0

    pre1 = now1

    pre2 = now2

    pre3 = now3



print((max(now0[C], now1[C], now2[C], now3[C])))

R, C, K = list(map(int, input().split()))
V = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K):
    r, c, v = list(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 = list(map(int, input().split()))
V = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K):
    r, c, v = list(map(int, input().split()))
    V[r][c] = v
pre0 = [0] * (C + 1)
pre1 = [0] * (C + 1)
pre2 = [0] * (C + 1)
pre3 = [0] * (C + 1)
for i in range(R + 1):
    now0 = [0] * (C + 1)
    now1 = [0] * (C + 1)
    now2 = [0] * (C + 1)
    now3 = [0] * (C + 1)
    for j in range(C + 1):
        v = V[i][j]
        la = lb = 0
        if j > 0:
            la = now0[j - 1]
            lb = now1[j - 1]
            now2[j] = max(now2[j], now2[j - 1], lb + v)
            now3[j] = max(now3[j], now3[j - 1], now2[j - 1] + v)
        if i > 0:
            max_p = max(pre0[j], pre1[j], pre2[j], pre3[j])
            now0[j] = max(now0[j], max_p, la)
            now1[j] = max(now1[j], max_p + v, la + v, lb)
    pre0 = now0
    pre1 = now1
    pre2 = now2
    pre3 = now3
print((max(now0[C], now1[C], now2[C], now3[C])))

-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)] +pre0 = [0] * (C + 1) +pre1 = [0] * (C + 1) +pre2 = [0] * (C + 1) +pre3 = [0] * (C + 1) +    now0 = [0] * (C + 1) +    now1 = [0] * (C + 1) +    now2 = [0] * (C + 1) +    now3 = [0] * (C + 1) -        la = lb = lc = ld = 0 +        la = lb = 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) +            la = now0[j - 1] +            lb = now1[j - 1] +            now2[j] = max(now2[j], now2[j - 1], lb + v) +            now3[j] = max(now3[j], now3[j - 1], now2[j - 1] + v) -            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]))) +            max_p = max(pre0[j], pre1[j], pre2[j], pre3[j]) +            now0[j] = max(now0[j], max_p, la) +            now1[j] = max(now1[j], max_p + v, la + v, lb) +    pre0 = now0 +    pre1 = now1 +    pre2 = now2 +    pre3 = now3 +print((max(now0[C], now1[C], now2[C], now3[C])))