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

dp = [[0, 0, 0, 0] for _ in range(C)]
for r in range(R):
    for c in range(C):
        if c > 0:
            dp[c][0] = max(dp[c])
            dp[c][1] = dp[c - 1][1]
            dp[c][2] = dp[c - 1][2]
            dp[c][3] = dp[c - 1][3]
        else:
            dp[c][0] = max(dp[c])
            dp[c][1] = 0
            dp[c][2] = 0
            dp[c][3] = 0
        if v_list[r][c] > 0:
            v = v_list[r][c]
            dp[c][3] = max(dp[c][2] + v, dp[c][3])
            dp[c][2] = max(dp[c][1] + v, dp[c][2])
            dp[c][1] = max(dp[c][0] + v, dp[c][1])            
print(max(dp[-1])) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K inf = float('inf') inf float('inf') float 'inf' [0 for _ in range(C)] for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] v_list = [[0 for _ in range(C)] for _ in range(R)] v_list [[0 for _ in range(C)] for _ in range(R)] for _ in range(K):
    r, c, v = map(int, input().split())
    v_list[r - 1][c - 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_list[r - 1][c - 1] = v v_list[r - 1][c - 1] [r - 1] v_list r - 1 r 1 c - 1 c 1 v [0, 0, 0, 0] for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0, 0, 0, 0] 0 0 0 0 dp = [[0, 0, 0, 0] for _ in range(C)] dp [[0, 0, 0, 0] for _ in range(C)] for r in range(R):
    for c in range(C):
        if c > 0:
            dp[c][0] = max(dp[c])
            dp[c][1] = dp[c - 1][1]
            dp[c][2] = dp[c - 1][2]
            dp[c][3] = dp[c - 1][3]
        else:
            dp[c][0] = max(dp[c])
            dp[c][1] = 0
            dp[c][2] = 0
            dp[c][3] = 0
        if v_list[r][c] > 0:
            v = v_list[r][c]
            dp[c][3] = max(dp[c][2] + v, dp[c][3])
            dp[c][2] = max(dp[c][1] + v, dp[c][2])
            dp[c][1] = max(dp[c][0] + v, dp[c][1])             r range(R) range R for c in range(C):
        if c > 0:
            dp[c][0] = max(dp[c])
            dp[c][1] = dp[c - 1][1]
            dp[c][2] = dp[c - 1][2]
            dp[c][3] = dp[c - 1][3]
        else:
            dp[c][0] = max(dp[c])
            dp[c][1] = 0
            dp[c][2] = 0
            dp[c][3] = 0
        if v_list[r][c] > 0:
            v = v_list[r][c]
            dp[c][3] = max(dp[c][2] + v, dp[c][3])
            dp[c][2] = max(dp[c][1] + v, dp[c][2])
            dp[c][1] = max(dp[c][0] + v, dp[c][1])             c range(C) range C if c > 0:
            dp[c][0] = max(dp[c])
            dp[c][1] = dp[c - 1][1]
            dp[c][2] = dp[c - 1][2]
            dp[c][3] = dp[c - 1][3]
        else:
            dp[c][0] = max(dp[c])
            dp[c][1] = 0
            dp[c][2] = 0
            dp[c][3] = 0
         c > 0 c 0 dp[c][0] = max(dp[c]) dp[c][0] [c] dp c 0 max(dp[c]) max dp[c] dp c dp[c][1] = dp[c - 1][1] dp[c][1] [c] dp c 1 dp[c - 1][1] [c - 1] dp c - 1 c 1 1 dp[c][2] = dp[c - 1][2] dp[c][2] [c] dp c 2 dp[c - 1][2] [c - 1] dp c - 1 c 1 2 dp[c][3] = dp[c - 1][3] dp[c][3] [c] dp c 3 dp[c - 1][3] [c - 1] dp c - 1 c 1 3 dp[c][0] = max(dp[c]) dp[c][0] [c] dp c 0 max(dp[c]) max dp[c] dp c dp[c][1] = 0 dp[c][1] [c] dp c 1 0 dp[c][2] = 0 dp[c][2] [c] dp c 2 0 dp[c][3] = 0 dp[c][3] [c] dp c 3 0 if v_list[r][c] > 0:
            v = v_list[r][c]
            dp[c][3] = max(dp[c][2] + v, dp[c][3])
            dp[c][2] = max(dp[c][1] + v, dp[c][2])
            dp[c][1] = max(dp[c][0] + v, dp[c][1])             v_list[r][c] > 0 v_list[r][c] [r] v_list r c 0 v = v_list[r][c] v v_list[r][c] [r] v_list r c dp[c][3] = max(dp[c][2] + v, dp[c][3]) dp[c][3] [c] dp c 3 max(dp[c][2] + v, dp[c][3]) max dp[c][2] + v dp[c][2] [c] dp c 2 v dp[c][3] [c] dp c 3 dp[c][2] = max(dp[c][1] + v, dp[c][2]) dp[c][2] [c] dp c 2 max(dp[c][1] + v, dp[c][2]) max dp[c][1] + v dp[c][1] [c] dp c 1 v dp[c][2] [c] dp c 2 dp[c][1] = max(dp[c][0] + v, dp[c][1]) dp[c][1] [c] dp c 1 max(dp[c][0] + v, dp[c][1]) max dp[c][0] + v dp[c][0] [c] dp c 0 v dp[c][1] [c] dp c 1 print(max(dp[-1])) print max(dp[-1]) max dp[-1] dp -1 K = map(int, input().split()) map(int, input().split()) K inf = float('inf') float('inf') inf R, C, K = map(int, input().split()) map(int, input().split()) R v = map(int, input().split()) map(int, input().split()) v C, K = map(int, input().split()) map(int, input().split()) C v = v_list[r][c] v_list[r][c] v v_list = [[0 for _ in range(C)] for _ in range(R)] [[0 for _ in range(C)] for _ in range(R)] v_list dp = [[0, 0, 0, 0] for _ in range(C)] [[0, 0, 0, 0] for _ in range(C)] dp r, c, v = map(int, input().split()) map(int, input().split()) r c, v = map(int, input().split()) map(int, input().split()) c
R, C, K = map(int, input().split())
inf = float('inf')
v_list = [[0 for _ in range(C)] for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    v_list[r - 1][c - 1] = v

dp = [[0, 0, 0, 0] for _ in range(C)]
for r in range(R):
    for c in range(C):
        if c > 0:
            dp[c][0] = max(dp[c])
            dp[c][1] = dp[c - 1][1]
            dp[c][2] = dp[c - 1][2]
            dp[c][3] = dp[c - 1][3]
        else:
            dp[c][0] = max(dp[c])
            dp[c][1] = 0
            dp[c][2] = 0
            dp[c][3] = 0
        if v_list[r][c] > 0:
            v = v_list[r][c]
            dp[c][3] = max(dp[c][2] + v, dp[c][3])
            dp[c][2] = max(dp[c][1] + v, dp[c][2])
            dp[c][1] = max(dp[c][0] + v, dp[c][1])            
print(max(dp[-1]))