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

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

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]))
