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

max_p = [0]*(C+1)
for i in range(R+1):
    now0, now1, now2, now3 = [[0]*(C+1) for _ in range(4)]
    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:
            now0[j] = max(now0[j], max_p[j], la)
            now1[j] = max(now1[j], max_p[j] + v, la + v, lb)
        max_p[j] = max(now0[j], now1[j], now2[j], now3[j])

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

max_p = [0]*(C+1)
for i in range(R+1):
    now0, now1, now2, now3 = [[0]*(C+1) for _ in range(4)]
    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:
            now0[j] = max(now0[j], max_p[j], la)
            now1[j] = max(now1[j], max_p[j] + v, la + v, lb)
        max_p[j] = max(now0[j], now1[j], now2[j], now3[j])

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