def max2(x,y):
    return x if x > y else y

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

dp = [[0]*4 for _ in range(R)]
for j in range(R):
    if V[0][j] != 0:
        dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j]
    if j != 0:
        dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0])
for i in range(1,C):
    for j in range(R):
        v = V[i][j]
        if v != 0:
            if dp[j][2] != 0:
                dp[j][3] = max2(dp[j][2] + v, dp[j][3])
            if dp[j][1] != 0:
                dp[j][2] = max2(dp[j][1] + v, dp[j][2])
            dp[j][1] = max2(v, dp[j][1])
        if j != 0:
            if v != 0:
                dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])
            dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0])
print(max(dp[-1])) def max2(x,y):
    return x if x > y else y max2 return x if x > y else y x if x > y else y x > y x y x y x x y y R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0]*R for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0]*R [0] 0 R V = [[0]*R for _ in range(C)] V [[0]*R for _ in range(C)] for _ in range(K):
    r, c, v = map(int, input().split())
    V[c-1][r-1] = 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[c-1][r-1] = v V[c-1][r-1] [c-1] V c-1 c 1 r-1 r 1 v [0]*4 for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*4 [0] 0 4 dp = [[0]*4 for _ in range(R)] dp [[0]*4 for _ in range(R)] for j in range(R):
    if V[0][j] != 0:
        dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j]
    if j != 0:
        dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0]) j range(R) range R if V[0][j] != 0:
        dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j]
     V[0][j] != 0 V[0][j] [0] V 0 j 0 dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j] dp[j][1] [j] dp j 1 max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j] max2(dp[j - 1][1], dp[j - 1][0]) max2 dp[j - 1][1] [j - 1] dp j - 1 j 1 1 dp[j - 1][0] [j - 1] dp j - 1 j 1 0 V[0][j] [0] V 0 j if j != 0:
        dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0]) j != 0 j 0 dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0]) dp[j][0] [j] dp j 0 max2(dp[j - 1][1], dp[j - 1][0]) max2 dp[j - 1][1] [j - 1] dp j - 1 j 1 1 dp[j - 1][0] [j - 1] dp j - 1 j 1 0 for i in range(1,C):
    for j in range(R):
        v = V[i][j]
        if v != 0:
            if dp[j][2] != 0:
                dp[j][3] = max2(dp[j][2] + v, dp[j][3])
            if dp[j][1] != 0:
                dp[j][2] = max2(dp[j][1] + v, dp[j][2])
            dp[j][1] = max2(v, dp[j][1])
        if j != 0:
            if v != 0:
                dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])
            dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0]) i range(1,C) range 1 C for j in range(R):
        v = V[i][j]
        if v != 0:
            if dp[j][2] != 0:
                dp[j][3] = max2(dp[j][2] + v, dp[j][3])
            if dp[j][1] != 0:
                dp[j][2] = max2(dp[j][1] + v, dp[j][2])
            dp[j][1] = max2(v, dp[j][1])
        if j != 0:
            if v != 0:
                dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])
            dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0]) j range(R) range R v = V[i][j] v V[i][j] [i] V i j if v != 0:
            if dp[j][2] != 0:
                dp[j][3] = max2(dp[j][2] + v, dp[j][3])
            if dp[j][1] != 0:
                dp[j][2] = max2(dp[j][1] + v, dp[j][2])
            dp[j][1] = max2(v, dp[j][1])
         v != 0 v 0 if dp[j][2] != 0:
                dp[j][3] = max2(dp[j][2] + v, dp[j][3])
             dp[j][2] != 0 dp[j][2] [j] dp j 2 0 dp[j][3] = max2(dp[j][2] + v, dp[j][3]) dp[j][3] [j] dp j 3 max2(dp[j][2] + v, dp[j][3]) max2 dp[j][2] + v dp[j][2] [j] dp j 2 v dp[j][3] [j] dp j 3 if dp[j][1] != 0:
                dp[j][2] = max2(dp[j][1] + v, dp[j][2])
             dp[j][1] != 0 dp[j][1] [j] dp j 1 0 dp[j][2] = max2(dp[j][1] + v, dp[j][2]) dp[j][2] [j] dp j 2 max2(dp[j][1] + v, dp[j][2]) max2 dp[j][1] + v dp[j][1] [j] dp j 1 v dp[j][2] [j] dp j 2 dp[j][1] = max2(v, dp[j][1]) dp[j][1] [j] dp j 1 max2(v, dp[j][1]) max2 v dp[j][1] [j] dp j 1 if j != 0:
            if v != 0:
                dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])
            dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0]) j != 0 j 0 if v != 0:
                dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])
             v != 0 v 0 dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1]) dp[j][1] [j] dp j 1 max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1]) max2 max(dp[j - 1][k] for k in range(4)) + v max(dp[j - 1][k] for k in range(4)) max dp[j - 1][k] [j - 1] dp j - 1 j 1 k v dp[j][1] [j] dp j 1 dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0]) dp[j][0] [j] dp j 0 max2(max(dp[j - 1][k] for k in range(4)), dp[j][0]) max2 max(dp[j - 1][k] for k in range(4)) max dp[j - 1][k] [j - 1] dp j - 1 j 1 k dp[j][0] [j] dp j 0 print(max(dp[-1])) print max(dp[-1]) max dp[-1] dp -1 v = map(int, input().split()) map(int, input().split()) v C, K = map(int, input().split()) map(int, input().split()) C V = [[0]*R for _ in range(C)] [[0]*R for _ in range(C)] V dp = [[0]*4 for _ in range(R)] [[0]*4 for _ in range(R)] dp r, c, v = map(int, input().split()) map(int, input().split()) r c, v = map(int, input().split()) map(int, input().split()) c v = V[i][j] V[i][j] v R, C, K = map(int, input().split()) map(int, input().split()) R K = map(int, input().split()) map(int, input().split()) K def max2(x,y):
    return x if x > y else y def max2(x,y):
    return x if x > y else y max2
def max2(x,y):
    return x if x > y else y

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

dp = [[0]*4 for _ in range(R)]
for j in range(R):
    if V[0][j] != 0:
        dp[j][1] = max2(dp[j - 1][1], dp[j - 1][0]) + V[0][j]
    if j != 0:
        dp[j][0] = max2(dp[j - 1][1], dp[j - 1][0])
for i in range(1,C):
    for j in range(R):
        v = V[i][j]
        if v != 0:
            if dp[j][2] != 0:
                dp[j][3] = max2(dp[j][2] + v, dp[j][3])
            if dp[j][1] != 0:
                dp[j][2] = max2(dp[j][1] + v, dp[j][2])
            dp[j][1] = max2(v, dp[j][1])
        if j != 0:
            if v != 0:
                dp[j][1] = max2(max(dp[j - 1][k] for k in range(4)) + v, dp[j][1])
            dp[j][0] = max2(max(dp[j - 1][k] for k in range(4)), dp[j][0])
print(max(dp[-1]))
