r, c, k = map(int, input().split())
dp = [[[0] * (c+1) for _ in range(r+1)] for _ in range(4)]

v_dict = dict()
for _ in range(k):
    y, x, v = map(int, input().split())
    v_dict[(y, x)] = v

for y in range(1, r+1):
    for x in range(1, c+1):
        prev_y_max = 0
        for i in range(4):
            prev_y_max = max(dp[i][y-1][x], prev_y_max)
        dp[0][y][x] = max(prev_y_max, dp[0][y][x-1])
        if (y, x) in v_dict:
            v = v_dict[(y, x)]
            dp[1][y][x] = max(prev_y_max + v, dp[0][y][x-1] + v, dp[1][y][x-1])
            dp[2][y][x] = max(dp[1][y][x-1] + v, dp[2][y][x-1])
            dp[3][y][x] = max(dp[2][y][x-1] + v, dp[3][y][x-1])
        else:
            for i in range(1, 4):
                dp[i][y][x] = dp[i][y][x-1]
ans = 0
for i in range(4):
    ans = max(dp[i][r][c], ans)
print(ans) 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(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0] * (c+1) for _ in range(r+1)] dp = [[[0] * (c+1) for _ in range(r+1)] for _ in range(4)] dp [[[0] * (c+1) for _ in range(r+1)] for _ in range(4)] v_dict = dict() v_dict dict() dict for _ in range(k):
    y, x, v = map(int, input().split())
    v_dict[(y, x)] = v _ range(k) range k y, x, v = map(int, input().split()) y map(int, input().split()) map int input().split() ().split () input split x v v_dict[(y, x)] = v v_dict[(y, x)] v_dict (y, x) y x v for y in range(1, r+1):
    for x in range(1, c+1):
        prev_y_max = 0
        for i in range(4):
            prev_y_max = max(dp[i][y-1][x], prev_y_max)
        dp[0][y][x] = max(prev_y_max, dp[0][y][x-1])
        if (y, x) in v_dict:
            v = v_dict[(y, x)]
            dp[1][y][x] = max(prev_y_max + v, dp[0][y][x-1] + v, dp[1][y][x-1])
            dp[2][y][x] = max(dp[1][y][x-1] + v, dp[2][y][x-1])
            dp[3][y][x] = max(dp[2][y][x-1] + v, dp[3][y][x-1])
        else:
            for i in range(1, 4):
                dp[i][y][x] = dp[i][y][x-1] y range(1, r+1) range 1 r+1 r 1 for x in range(1, c+1):
        prev_y_max = 0
        for i in range(4):
            prev_y_max = max(dp[i][y-1][x], prev_y_max)
        dp[0][y][x] = max(prev_y_max, dp[0][y][x-1])
        if (y, x) in v_dict:
            v = v_dict[(y, x)]
            dp[1][y][x] = max(prev_y_max + v, dp[0][y][x-1] + v, dp[1][y][x-1])
            dp[2][y][x] = max(dp[1][y][x-1] + v, dp[2][y][x-1])
            dp[3][y][x] = max(dp[2][y][x-1] + v, dp[3][y][x-1])
        else:
            for i in range(1, 4):
                dp[i][y][x] = dp[i][y][x-1] x range(1, c+1) range 1 c+1 c 1 prev_y_max = 0 prev_y_max 0 for i in range(4):
            prev_y_max = max(dp[i][y-1][x], prev_y_max)
         i range(4) range 4 prev_y_max = max(dp[i][y-1][x], prev_y_max) prev_y_max max(dp[i][y-1][x], prev_y_max) max dp[i][y-1][x] [y-1] [i] dp i y-1 y 1 x prev_y_max dp[0][y][x] = max(prev_y_max, dp[0][y][x-1]) dp[0][y][x] [y] [0] dp 0 y x max(prev_y_max, dp[0][y][x-1]) max prev_y_max dp[0][y][x-1] [y] [0] dp 0 y x-1 x 1 if (y, x) in v_dict:
            v = v_dict[(y, x)]
            dp[1][y][x] = max(prev_y_max + v, dp[0][y][x-1] + v, dp[1][y][x-1])
            dp[2][y][x] = max(dp[1][y][x-1] + v, dp[2][y][x-1])
            dp[3][y][x] = max(dp[2][y][x-1] + v, dp[3][y][x-1])
        else:
            for i in range(1, 4):
                dp[i][y][x] = dp[i][y][x-1] (y, x) in v_dict (y, x) y x v_dict v = v_dict[(y, x)] v v_dict[(y, x)] v_dict (y, x) y x dp[1][y][x] = max(prev_y_max + v, dp[0][y][x-1] + v, dp[1][y][x-1]) dp[1][y][x] [y] [1] dp 1 y x max(prev_y_max + v, dp[0][y][x-1] + v, dp[1][y][x-1]) max prev_y_max + v prev_y_max v dp[0][y][x-1] + v dp[0][y][x-1] [y] [0] dp 0 y x-1 x 1 v dp[1][y][x-1] [y] [1] dp 1 y x-1 x 1 dp[2][y][x] = max(dp[1][y][x-1] + v, dp[2][y][x-1]) dp[2][y][x] [y] [2] dp 2 y x max(dp[1][y][x-1] + v, dp[2][y][x-1]) max dp[1][y][x-1] + v dp[1][y][x-1] [y] [1] dp 1 y x-1 x 1 v dp[2][y][x-1] [y] [2] dp 2 y x-1 x 1 dp[3][y][x] = max(dp[2][y][x-1] + v, dp[3][y][x-1]) dp[3][y][x] [y] [3] dp 3 y x max(dp[2][y][x-1] + v, dp[3][y][x-1]) max dp[2][y][x-1] + v dp[2][y][x-1] [y] [2] dp 2 y x-1 x 1 v dp[3][y][x-1] [y] [3] dp 3 y x-1 x 1 for i in range(1, 4):
                dp[i][y][x] = dp[i][y][x-1] i range(1, 4) range 1 4 dp[i][y][x] = dp[i][y][x-1] dp[i][y][x] [y] [i] dp i y x dp[i][y][x-1] [y] [i] dp i y x-1 x 1 ans = 0 ans 0 for i in range(4):
    ans = max(dp[i][r][c], ans) i range(4) range 4 ans = max(dp[i][r][c], ans) ans max(dp[i][r][c], ans) max dp[i][r][c] [r] [i] dp i r c ans print(ans) print ans prev_y_max = max(dp[i][y-1][x], prev_y_max) max(dp[i][y-1][x], prev_y_max) prev_y_max v_dict = dict() dict() v_dict c, k = map(int, input().split()) map(int, input().split()) c y, x, v = map(int, input().split()) map(int, input().split()) y v = v_dict[(y, x)] v_dict[(y, x)] v r, c, k = map(int, input().split()) map(int, input().split()) r ans = 0 0 ans v = map(int, input().split()) map(int, input().split()) v prev_y_max = 0 0 prev_y_max k = map(int, input().split()) map(int, input().split()) k dp = [[[0] * (c+1) for _ in range(r+1)] for _ in range(4)] [[[0] * (c+1) for _ in range(r+1)] for _ in range(4)] dp x, v = map(int, input().split()) map(int, input().split()) x ans = max(dp[i][r][c], ans) max(dp[i][r][c], ans) ans
r, c, k = map(int, input().split())
dp = [[[0] * (c+1) for _ in range(r+1)] for _ in range(4)]

v_dict = dict()
for _ in range(k):
    y, x, v = map(int, input().split())
    v_dict[(y, x)] = v

for y in range(1, r+1):
    for x in range(1, c+1):
        prev_y_max = 0
        for i in range(4):
            prev_y_max = max(dp[i][y-1][x], prev_y_max)
        dp[0][y][x] = max(prev_y_max, dp[0][y][x-1])
        if (y, x) in v_dict:
            v = v_dict[(y, x)]
            dp[1][y][x] = max(prev_y_max + v, dp[0][y][x-1] + v, dp[1][y][x-1])
            dp[2][y][x] = max(dp[1][y][x-1] + v, dp[2][y][x-1])
            dp[3][y][x] = max(dp[2][y][x-1] + v, dp[3][y][x-1])
        else:
            for i in range(1, 4):
                dp[i][y][x] = dp[i][y][x-1]
ans = 0
for i in range(4):
    ans = max(dp[i][r][c], ans)
print(ans)
