H,W,k = map(int, input().split())
# アイテムが何処に何個あるか
fs = [[0]*(W+1) for i in range(H+1)]
for i in range(k):
    h, w, v = map(int, input().split())
    h -= 1
    w -= 1
    fs[h][w] = v

mvs = [(0,1),(1,0)]
dp = [[[-1<<50 for i in range(W+1)] for j in range(H+1)] for k in range(4)]
# dp[n][i][j] n個取ったときの、i,jにおけるアイテム価値の最大値
from collections import deque
q = deque([])
q.append((0,0))
dp[0][0][0] = 0
dp[1][0][0] = fs[0][0]
for h in range(H):
    for w in range(W):
        dp[0][h][w+1] = max(dp[0][h][w+1], dp[0][h][w])
        dp[1][h][w+1] = max(dp[1][h][w+1], dp[1][h][w], dp[0][h][w] + fs[h][w+1])
        dp[2][h][w+1] = max(dp[2][h][w+1], dp[2][h][w], dp[1][h][w] + fs[h][w+1])
        dp[3][h][w+1] = max(dp[3][h][w+1], dp[3][h][w], dp[2][h][w] + fs[h][w+1])
    for w in range(W):
        mx = 0
        for i in range(4):
            # print("fe",i,h,w,"dp",dp[i][h][w])
            mx = max(mx,dp[i][h][w])
        dp[0][h+1][w] = mx
        dp[1][h+1][w] = mx + fs[h+1][w]

H -= 1
W -= 1
ans0 = dp[0][H][W]
ans1 = dp[1][H][W]
ans2 = dp[2][H][W]
ans3 = dp[3][H][W]
# print(fs)
# for i in range(3):
#     d = dp[i]
#     for r in d:
#         print(*r)
#     print("----------")
print(max(ans1,ans2,ans3)) H,W,k = map(int, input().split()) H map(int, input().split()) map int input().split() ().split () input split W k [0]*(W+1) for i in range(H+1) for i in range(H+1) i range(H+1) range H+1 H 1 for i in range(H+1) [0]*(W+1) [0] 0 W+1 W 1 fs = [[0]*(W+1) for i in range(H+1)] fs [[0]*(W+1) for i in range(H+1)] for i in range(k):
    h, w, v = map(int, input().split())
    h -= 1
    w -= 1
    fs[h][w] = v i range(k) range k h, w, v = map(int, input().split()) h map(int, input().split()) map int input().split() ().split () input split w v h -= 1 h 1 w -= 1 w 1 fs[h][w] = v fs[h][w] [h] fs h w v mvs = [(0,1),(1,0)] mvs [(0,1),(1,0)] (0,1) 0 1 (1,0) 1 0 [[-1<<50 for i in range(W+1)] for j in range(H+1)] for k in range(4) for k in range(4) k range(4) range 4 for k in range(4) [[-1<<50 for i in range(W+1)] for j in range(H+1)] dp = [[[-1<<50 for i in range(W+1)] for j in range(H+1)] for k in range(4)] dp [[[-1<<50 for i in range(W+1)] for j in range(H+1)] for k in range(4)] from collections import deque q = deque([]) q deque([]) deque [] q.append((0,0)) q.append q append (0,0) 0 0 dp[0][0][0] = 0 dp[0][0][0] [0] [0] dp 0 0 0 0 dp[1][0][0] = fs[0][0] dp[1][0][0] [0] [1] dp 1 0 0 fs[0][0] [0] fs 0 0 for h in range(H):
    for w in range(W):
        dp[0][h][w+1] = max(dp[0][h][w+1], dp[0][h][w])
        dp[1][h][w+1] = max(dp[1][h][w+1], dp[1][h][w], dp[0][h][w] + fs[h][w+1])
        dp[2][h][w+1] = max(dp[2][h][w+1], dp[2][h][w], dp[1][h][w] + fs[h][w+1])
        dp[3][h][w+1] = max(dp[3][h][w+1], dp[3][h][w], dp[2][h][w] + fs[h][w+1])
    for w in range(W):
        mx = 0
        for i in range(4):
            # print("fe",i,h,w,"dp",dp[i][h][w])
            mx = max(mx,dp[i][h][w])
        dp[0][h+1][w] = mx
        dp[1][h+1][w] = mx + fs[h+1][w] h range(H) range H for w in range(W):
        dp[0][h][w+1] = max(dp[0][h][w+1], dp[0][h][w])
        dp[1][h][w+1] = max(dp[1][h][w+1], dp[1][h][w], dp[0][h][w] + fs[h][w+1])
        dp[2][h][w+1] = max(dp[2][h][w+1], dp[2][h][w], dp[1][h][w] + fs[h][w+1])
        dp[3][h][w+1] = max(dp[3][h][w+1], dp[3][h][w], dp[2][h][w] + fs[h][w+1])
     w range(W) range W dp[0][h][w+1] = max(dp[0][h][w+1], dp[0][h][w]) dp[0][h][w+1] [h] [0] dp 0 h w+1 w 1 max(dp[0][h][w+1], dp[0][h][w]) max dp[0][h][w+1] [h] [0] dp 0 h w+1 w 1 dp[0][h][w] [h] [0] dp 0 h w dp[1][h][w+1] = max(dp[1][h][w+1], dp[1][h][w], dp[0][h][w] + fs[h][w+1]) dp[1][h][w+1] [h] [1] dp 1 h w+1 w 1 max(dp[1][h][w+1], dp[1][h][w], dp[0][h][w] + fs[h][w+1]) max dp[1][h][w+1] [h] [1] dp 1 h w+1 w 1 dp[1][h][w] [h] [1] dp 1 h w dp[0][h][w] + fs[h][w+1] dp[0][h][w] [h] [0] dp 0 h w fs[h][w+1] [h] fs h w+1 w 1 dp[2][h][w+1] = max(dp[2][h][w+1], dp[2][h][w], dp[1][h][w] + fs[h][w+1]) dp[2][h][w+1] [h] [2] dp 2 h w+1 w 1 max(dp[2][h][w+1], dp[2][h][w], dp[1][h][w] + fs[h][w+1]) max dp[2][h][w+1] [h] [2] dp 2 h w+1 w 1 dp[2][h][w] [h] [2] dp 2 h w dp[1][h][w] + fs[h][w+1] dp[1][h][w] [h] [1] dp 1 h w fs[h][w+1] [h] fs h w+1 w 1 dp[3][h][w+1] = max(dp[3][h][w+1], dp[3][h][w], dp[2][h][w] + fs[h][w+1]) dp[3][h][w+1] [h] [3] dp 3 h w+1 w 1 max(dp[3][h][w+1], dp[3][h][w], dp[2][h][w] + fs[h][w+1]) max dp[3][h][w+1] [h] [3] dp 3 h w+1 w 1 dp[3][h][w] [h] [3] dp 3 h w dp[2][h][w] + fs[h][w+1] dp[2][h][w] [h] [2] dp 2 h w fs[h][w+1] [h] fs h w+1 w 1 for w in range(W):
        mx = 0
        for i in range(4):
            # print("fe",i,h,w,"dp",dp[i][h][w])
            mx = max(mx,dp[i][h][w])
        dp[0][h+1][w] = mx
        dp[1][h+1][w] = mx + fs[h+1][w] w range(W) range W mx = 0 mx 0 for i in range(4):
            # print("fe",i,h,w,"dp",dp[i][h][w])
            mx = max(mx,dp[i][h][w])
         i range(4) range 4 mx = max(mx,dp[i][h][w]) mx max(mx,dp[i][h][w]) max mx dp[i][h][w] [h] [i] dp i h w dp[0][h+1][w] = mx dp[0][h+1][w] [h+1] [0] dp 0 h+1 h 1 w mx dp[1][h+1][w] = mx + fs[h+1][w] dp[1][h+1][w] [h+1] [1] dp 1 h+1 h 1 w mx + fs[h+1][w] mx fs[h+1][w] [h+1] fs h+1 h 1 w H -= 1 H 1 W -= 1 W 1 ans0 = dp[0][H][W] ans0 dp[0][H][W] [H] [0] dp 0 H W ans1 = dp[1][H][W] ans1 dp[1][H][W] [H] [1] dp 1 H W ans2 = dp[2][H][W] ans2 dp[2][H][W] [H] [2] dp 2 H W ans3 = dp[3][H][W] ans3 dp[3][H][W] [H] [3] dp 3 H W print(max(ans1,ans2,ans3)) print max(ans1,ans2,ans3) max ans1 ans2 ans3 k = map(int, input().split()) map(int, input().split()) k fs = [[0]*(W+1) for i in range(H+1)] [[0]*(W+1) for i in range(H+1)] fs ans1 = dp[1][H][W] dp[1][H][W] ans1 ans2 = dp[2][H][W] dp[2][H][W] ans2 v = map(int, input().split()) map(int, input().split()) v w -= 1 1 w ans0 = dp[0][H][W] dp[0][H][W] ans0 H,W,k = map(int, input().split()) map(int, input().split()) H mx = 0 0 mx W,k = map(int, input().split()) map(int, input().split()) W w, v = map(int, input().split()) map(int, input().split()) w q = deque([]) deque([]) q ans3 = dp[3][H][W] dp[3][H][W] ans3 H -= 1 1 H mvs = [(0,1),(1,0)] [(0,1),(1,0)] mvs W -= 1 1 W h, w, v = map(int, input().split()) map(int, input().split()) h h -= 1 1 h dp = [[[-1<<50 for i in range(W+1)] for j in range(H+1)] for k in range(4)] [[[-1<<50 for i in range(W+1)] for j in range(H+1)] for k in range(4)] dp mx = max(mx,dp[i][h][w]) max(mx,dp[i][h][w]) mx
H,W,k = map(int, input().split())
# アイテムが何処に何個あるか
fs = [[0]*(W+1) for i in range(H+1)]
for i in range(k):
    h, w, v = map(int, input().split())
    h -= 1
    w -= 1
    fs[h][w] = v

mvs = [(0,1),(1,0)]
dp = [[[-1<<50 for i in range(W+1)] for j in range(H+1)] for k in range(4)]
# dp[n][i][j] n個取ったときの、i,jにおけるアイテム価値の最大値
from collections import deque
q = deque([])
q.append((0,0))
dp[0][0][0] = 0
dp[1][0][0] = fs[0][0]
for h in range(H):
    for w in range(W):
        dp[0][h][w+1] = max(dp[0][h][w+1], dp[0][h][w])
        dp[1][h][w+1] = max(dp[1][h][w+1], dp[1][h][w], dp[0][h][w] + fs[h][w+1])
        dp[2][h][w+1] = max(dp[2][h][w+1], dp[2][h][w], dp[1][h][w] + fs[h][w+1])
        dp[3][h][w+1] = max(dp[3][h][w+1], dp[3][h][w], dp[2][h][w] + fs[h][w+1])
    for w in range(W):
        mx = 0
        for i in range(4):
            # print("fe",i,h,w,"dp",dp[i][h][w])
            mx = max(mx,dp[i][h][w])
        dp[0][h+1][w] = mx
        dp[1][h+1][w] = mx + fs[h+1][w]

H -= 1
W -= 1
ans0 = dp[0][H][W]
ans1 = dp[1][H][W]
ans2 = dp[2][H][W]
ans3 = dp[3][H][W]
# print(fs)
# for i in range(3):
#     d = dp[i]
#     for r in d:
#         print(*r)
#     print("----------")
print(max(ans1,ans2,ans3))