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_pre = [0]*(C+1)
for i in range(R+1):
    now = [[0]*(3+1) for _ in range(C+1)]
    for j in range(C+1):
        v = V[i][j]
        la = lb = 0
        if j > 0:
            la = now[j-1][0]
            lb = now[j-1][1]
            now[j][2] = max(now[j][2], now[j-1][2], lb + v)
            now[j][3] = max(now[j][3], now[j-1][3], now[j-1][2] + v)
        if i > 0:
            now[j][0] = max(now[j][0], max_pre[j], la)
            now[j][1] = max(now[j][1], max_pre[j] + v, la + v, lb)
        max_pre[j] = max(now[j])

print(max(now[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_pre = [0]*(C+1) max_pre [0]*(C+1) [0] 0 C+1 C 1 for i in range(R+1):
    now = [[0]*(3+1) for _ in range(C+1)]
    for j in range(C+1):
        v = V[i][j]
        la = lb = 0
        if j > 0:
            la = now[j-1][0]
            lb = now[j-1][1]
            now[j][2] = max(now[j][2], now[j-1][2], lb + v)
            now[j][3] = max(now[j][3], now[j-1][3], now[j-1][2] + v)
        if i > 0:
            now[j][0] = max(now[j][0], max_pre[j], la)
            now[j][1] = max(now[j][1], max_pre[j] + v, la + v, lb)
        max_pre[j] = max(now[j]) i range(R+1) range R+1 R 1 [0]*(3+1) for _ in range(C+1) for _ in range(C+1) _ range(C+1) range C+1 C 1 for _ in range(C+1) [0]*(3+1) [0] 0 3+1 3 1 now = [[0]*(3+1) for _ in range(C+1)] now [[0]*(3+1) for _ in range(C+1)] for j in range(C+1):
        v = V[i][j]
        la = lb = 0
        if j > 0:
            la = now[j-1][0]
            lb = now[j-1][1]
            now[j][2] = max(now[j][2], now[j-1][2], lb + v)
            now[j][3] = max(now[j][3], now[j-1][3], now[j-1][2] + v)
        if i > 0:
            now[j][0] = max(now[j][0], max_pre[j], la)
            now[j][1] = max(now[j][1], max_pre[j] + v, la + v, lb)
        max_pre[j] = max(now[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 = now[j-1][0]
            lb = now[j-1][1]
            now[j][2] = max(now[j][2], now[j-1][2], lb + v)
            now[j][3] = max(now[j][3], now[j-1][3], now[j-1][2] + v)
         j > 0 j 0 la = now[j-1][0] la now[j-1][0] [j-1] now j-1 j 1 0 lb = now[j-1][1] lb now[j-1][1] [j-1] now j-1 j 1 1 now[j][2] = max(now[j][2], now[j-1][2], lb + v) now[j][2] [j] now j 2 max(now[j][2], now[j-1][2], lb + v) max now[j][2] [j] now j 2 now[j-1][2] [j-1] now j-1 j 1 2 lb + v lb v now[j][3] = max(now[j][3], now[j-1][3], now[j-1][2] + v) now[j][3] [j] now j 3 max(now[j][3], now[j-1][3], now[j-1][2] + v) max now[j][3] [j] now j 3 now[j-1][3] [j-1] now j-1 j 1 3 now[j-1][2] + v now[j-1][2] [j-1] now j-1 j 1 2 v if i > 0:
            now[j][0] = max(now[j][0], max_pre[j], la)
            now[j][1] = max(now[j][1], max_pre[j] + v, la + v, lb)
         i > 0 i 0 now[j][0] = max(now[j][0], max_pre[j], la) now[j][0] [j] now j 0 max(now[j][0], max_pre[j], la) max now[j][0] [j] now j 0 max_pre[j] max_pre j la now[j][1] = max(now[j][1], max_pre[j] + v, la + v, lb) now[j][1] [j] now j 1 max(now[j][1], max_pre[j] + v, la + v, lb) max now[j][1] [j] now j 1 max_pre[j] + v max_pre[j] max_pre j v la + v la v lb max_pre[j] = max(now[j]) max_pre[j] max_pre j max(now[j]) max now[j] now j print(max(now[C])) print max(now[C]) max now[C] now C la = now[j-1][0] now[j-1][0] la C, K = map(int, input().split()) map(int, input().split()) C c, v = map(int, input().split()) map(int, input().split()) c lb = 0 0 lb r, c, v = map(int, input().split()) map(int, input().split()) r now = [[0]*(3+1) for _ in range(C+1)] [[0]*(3+1) for _ in range(C+1)] now max_pre = [0]*(C+1) [0]*(C+1) max_pre V = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] V la = lb = 0 0 la K = map(int, input().split()) map(int, input().split()) K v = map(int, input().split()) map(int, input().split()) v lb = now[j-1][1] now[j-1][1] lb v = V[i][j] V[i][j] v R, C, K = map(int, input().split()) map(int, input().split()) R
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_pre = [0]*(C+1)
for i in range(R+1):
    now = [[0]*(3+1) for _ in range(C+1)]
    for j in range(C+1):
        v = V[i][j]
        la = lb = 0
        if j > 0:
            la = now[j-1][0]
            lb = now[j-1][1]
            now[j][2] = max(now[j][2], now[j-1][2], lb + v)
            now[j][3] = max(now[j][3], now[j-1][3], now[j-1][2] + v)
        if i > 0:
            now[j][0] = max(now[j][0], max_pre[j], la)
            now[j][1] = max(now[j][1], max_pre[j] + v, la + v, lb)
        max_pre[j] = max(now[j])

print(max(now[C]))
