r, c, k = map(int, input().split())
rcv = [list(map(int, input().split())) for i in range(k)]

area = [[0] * (c+1) for i in range(r+1)]
for a, b, v in rcv:
    area[a-1][b-1] = v

# dp[i][j][k]: その行でiまで拾っており、
# j行k列目に到達時点の最大スコア
dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)]
dp[0][0][0] = 0

for rr in range(r+1):
    for cc in range(c+1):
        for i in range(4):
            # 取って右
            if i+1<4 and cc<c and area[rr][cc]>0:
                dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc])
            # 取って下
            if i+1<4 and rr<r and area[rr][cc]>0:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc])
            # 取らずに右
            if cc<c:
                dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
                                      dp[i][rr][cc])
            # 取らずに下
            if rr<r:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc])
# ans: r行c列目の最大値（iは問わず）
ans = max([dp[i][r][c] for i in range(4)])
print(ans)


 r, c, k = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c k list(map(int, input().split())) for i in range(k) for i in range(k) i range(k) range k for i in range(k) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split rcv = [list(map(int, input().split())) for i in range(k)] rcv [list(map(int, input().split())) for i in range(k)] [0] * (c+1) for i in range(r+1) for i in range(r+1) i range(r+1) range r+1 r 1 for i in range(r+1) [0] * (c+1) [0] 0 c+1 c 1 area = [[0] * (c+1) for i in range(r+1)] area [[0] * (c+1) for i in range(r+1)] for a, b, v in rcv:
    area[a-1][b-1] = v

# dp[i][j][k]: その行でiまで拾っており、
# j行k列目に到達時点の最大スコア a b v rcv area[a-1][b-1] = v area[a-1][b-1] [a-1] area a-1 a 1 b-1 b 1 v [[-1] * (c+1) for i in range(r+1)] for j in range(4) for j in range(4) j range(4) range 4 for j in range(4) [[-1] * (c+1) for i in range(r+1)] dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)] dp [[[-1] * (c+1) for i in range(r+1)] for j in range(4)] dp[0][0][0] = 0 dp[0][0][0] [0] [0] dp 0 0 0 0 for rr in range(r+1):
    for cc in range(c+1):
        for i in range(4):
            # 取って右
            if i+1<4 and cc<c and area[rr][cc]>0:
                dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc])
            # 取って下
            if i+1<4 and rr<r and area[rr][cc]>0:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc])
            # 取らずに右
            if cc<c:
                dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
                                      dp[i][rr][cc])
            # 取らずに下
            if rr<r:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc])
# ans: r行c列目の最大値（iは問わず） rr range(r+1) range r+1 r 1 for cc in range(c+1):
        for i in range(4):
            # 取って右
            if i+1<4 and cc<c and area[rr][cc]>0:
                dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc])
            # 取って下
            if i+1<4 and rr<r and area[rr][cc]>0:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc])
            # 取らずに右
            if cc<c:
                dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
                                      dp[i][rr][cc])
            # 取らずに下
            if rr<r:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc])
# ans: r行c列目の最大値（iは問わず） cc range(c+1) range c+1 c 1 for i in range(4):
            # 取って右
            if i+1<4 and cc<c and area[rr][cc]>0:
                dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc])
            # 取って下
            if i+1<4 and rr<r and area[rr][cc]>0:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc])
            # 取らずに右
            if cc<c:
                dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
                                      dp[i][rr][cc])
            # 取らずに下
            if rr<r:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc])
# ans: r行c列目の最大値（iは問わず） i range(4) range 4 if i+1<4 and cc<c and area[rr][cc]>0:
                dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc])
            # 取って下
             i+1<4 and cc<c and area[rr][cc]>0 i+1<4 and cc<c i+1<4 i+1 i 1 4 cc<c cc c area[rr][cc]>0 area[rr][cc] [rr] area rr cc 0 dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc]) dp[i+1][rr][cc+1] [rr] [i+1] dp i+1 i 1 rr cc+1 cc 1 max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc]) max dp[i+1][rr][cc+1] [rr] [i+1] dp i+1 i 1 rr cc+1 cc 1 dp[i][rr][cc]+area[rr][cc] dp[i][rr][cc] [rr] [i] dp i rr cc area[rr][cc] [rr] area rr cc if i+1<4 and rr<r and area[rr][cc]>0:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc])
            # 取らずに右
             i+1<4 and rr<r and area[rr][cc]>0 i+1<4 and rr<r i+1<4 i+1 i 1 4 rr<r rr r area[rr][cc]>0 area[rr][cc] [rr] area rr cc 0 dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc]) dp[0][rr+1][cc] [rr+1] [0] dp 0 rr+1 rr 1 cc max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc]) max dp[0][rr+1][cc] [rr+1] [0] dp 0 rr+1 rr 1 cc dp[i][rr][cc]+area[rr][cc] dp[i][rr][cc] [rr] [i] dp i rr cc area[rr][cc] [rr] area rr cc if cc<c:
                dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
                                      dp[i][rr][cc])
            # 取らずに下
             cc<c cc c dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
                                      dp[i][rr][cc]) dp[i][rr][cc+1] [rr] [i] dp i rr cc+1 cc 1 max(dp[i][rr][cc+1],
                                      dp[i][rr][cc]) max dp[i][rr][cc+1] [rr] [i] dp i rr cc+1 cc 1 dp[i][rr][cc] [rr] [i] dp i rr cc if rr<r:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc])
# ans: r行c列目の最大値（iは問わず） rr<r rr r dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]) dp[0][rr+1][cc] [rr+1] [0] dp 0 rr+1 rr 1 cc max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]) max dp[0][rr+1][cc] [rr+1] [0] dp 0 rr+1 rr 1 cc dp[i][rr][cc] [rr] [i] dp i rr cc dp[i][r][c] for i in range(4) for i in range(4) i range(4) range 4 for i in range(4) dp[i][r][c] [r] [i] dp i r c ans = max([dp[i][r][c] for i in range(4)]) ans max([dp[i][r][c] for i in range(4)]) max [dp[i][r][c] for i in range(4)] print(ans) print ans r, c, k = map(int, input().split()) map(int, input().split()) r dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)] [[[-1] * (c+1) for i in range(r+1)] for j in range(4)] dp rcv = [list(map(int, input().split())) for i in range(k)] [list(map(int, input().split())) for i in range(k)] rcv ans = max([dp[i][r][c] for i in range(4)]) max([dp[i][r][c] for i in range(4)]) ans area = [[0] * (c+1) for i in range(r+1)] [[0] * (c+1) for i in range(r+1)] area k = map(int, input().split()) map(int, input().split()) k c, k = map(int, input().split()) map(int, input().split()) c
r, c, k = map(int, input().split())
rcv = [list(map(int, input().split())) for i in range(k)]

area = [[0] * (c+1) for i in range(r+1)]
for a, b, v in rcv:
    area[a-1][b-1] = v

# dp[i][j][k]: その行でiまで拾っており、
# j行k列目に到達時点の最大スコア
dp = [[[-1] * (c+1) for i in range(r+1)] for j in range(4)]
dp[0][0][0] = 0

for rr in range(r+1):
    for cc in range(c+1):
        for i in range(4):
            # 取って右
            if i+1<4 and cc<c and area[rr][cc]>0:
                dp[i+1][rr][cc+1] = max(dp[i+1][rr][cc+1],
                                        dp[i][rr][cc]+area[rr][cc])
            # 取って下
            if i+1<4 and rr<r and area[rr][cc]>0:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc]+area[rr][cc])
            # 取らずに右
            if cc<c:
                dp[i][rr][cc+1] = max(dp[i][rr][cc+1],
                                      dp[i][rr][cc])
            # 取らずに下
            if rr<r:
                dp[0][rr+1][cc] = max(dp[0][rr+1][cc],
                                      dp[i][rr][cc])
# ans: r行c列目の最大値（iは問わず）
ans = max([dp[i][r][c] for i in range(4)])
print(ans)



