from collections import defaultdict
import sys


def input(): return sys.stdin.readline().rstrip()


r, c, K = map(int, input().split())

dp = [[[0]*(c+1) for _ in range(r+1)] for i in range(4)]

# dp[N][i][j] := (i,j) にN個目でたどりつく方法
d = [[0 for i in range(c+1)] for j in range(r+1)]

for _ in range(K):
    r_, c_, v = map(int, input().split())
    d[r_][c_] = v
for i in range(1, r+1):
    for j in range(1, c+1):
        v = d[i][j]
        if v > 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(maxi, dp[0][i][j-1])
            dp[1][i][j] = max(dp[1][i][j-1], dp[0][i][j-1]+v, maxi+v)
            dp[2][i][j] = max(dp[2][i][j-1], dp[1][i][j-1]+v)
            dp[3][i][j] = max(dp[3][i][j-1], dp[2][i][j-1]+v)

        elif v == 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], maxi)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1]


ans = max(dp[k][r][c] for k in range(4))

print(ans) from collections import defaultdict import sys sys def input(): return sys.stdin.readline().rstrip() input 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 i in range(4) for i in range(4) i range(4) range 4 for i in range(4) [[0]*(c+1) for _ in range(r+1)] dp = [[[0]*(c+1) for _ in range(r+1)] for i in range(4)] dp [[[0]*(c+1) for _ in range(r+1)] for i in range(4)] [0 for i in range(c+1)] for j in range(r+1) for j in range(r+1) j range(r+1) range r+1 r 1 for j in range(r+1) [0 for i in range(c+1)] d = [[0 for i in range(c+1)] for j in range(r+1)] d [[0 for i in range(c+1)] for j in range(r+1)] for _ in range(K):
    r_, c_, v = map(int, input().split())
    d[r_][c_] = 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 d[r_][c_] = v d[r_][c_] [r_] d r_ c_ v for i in range(1, r+1):
    for j in range(1, c+1):
        v = d[i][j]
        if v > 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(maxi, dp[0][i][j-1])
            dp[1][i][j] = max(dp[1][i][j-1], dp[0][i][j-1]+v, maxi+v)
            dp[2][i][j] = max(dp[2][i][j-1], dp[1][i][j-1]+v)
            dp[3][i][j] = max(dp[3][i][j-1], dp[2][i][j-1]+v)

        elif v == 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], maxi)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1] i range(1, r+1) range 1 r+1 r 1 for j in range(1, c+1):
        v = d[i][j]
        if v > 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(maxi, dp[0][i][j-1])
            dp[1][i][j] = max(dp[1][i][j-1], dp[0][i][j-1]+v, maxi+v)
            dp[2][i][j] = max(dp[2][i][j-1], dp[1][i][j-1]+v)
            dp[3][i][j] = max(dp[3][i][j-1], dp[2][i][j-1]+v)

        elif v == 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], maxi)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1] j range(1, c+1) range 1 c+1 c 1 v = d[i][j] v d[i][j] [i] d i j if v > 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(maxi, dp[0][i][j-1])
            dp[1][i][j] = max(dp[1][i][j-1], dp[0][i][j-1]+v, maxi+v)
            dp[2][i][j] = max(dp[2][i][j-1], dp[1][i][j-1]+v)
            dp[3][i][j] = max(dp[3][i][j-1], dp[2][i][j-1]+v)

        elif v == 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], maxi)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1] v > 0 v 0 maxi = max(dp[k][i-1][j] for k in range(4)) maxi max(dp[k][i-1][j] for k in range(4)) max dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j dp[0][i][j] = max(maxi, dp[0][i][j-1]) dp[0][i][j] [i] [0] dp 0 i j max(maxi, dp[0][i][j-1]) max maxi dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 dp[1][i][j] = max(dp[1][i][j-1], dp[0][i][j-1]+v, maxi+v) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j-1], dp[0][i][j-1]+v, maxi+v) max dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 dp[0][i][j-1]+v dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 v maxi+v maxi v dp[2][i][j] = max(dp[2][i][j-1], dp[1][i][j-1]+v) dp[2][i][j] [i] [2] dp 2 i j max(dp[2][i][j-1], dp[1][i][j-1]+v) max dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 dp[1][i][j-1]+v dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 v dp[3][i][j] = max(dp[3][i][j-1], dp[2][i][j-1]+v) dp[3][i][j] [i] [3] dp 3 i j max(dp[3][i][j-1], dp[2][i][j-1]+v) max dp[3][i][j-1] [i] [3] dp 3 i j-1 j 1 dp[2][i][j-1]+v dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 v elif v == 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], maxi)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1] v == 0 v 0 maxi = max(dp[k][i-1][j] for k in range(4)) maxi max(dp[k][i-1][j] for k in range(4)) max dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j dp[0][i][j] = max(dp[0][i][j-1], maxi) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j-1], maxi) max dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 maxi dp[1][i][j] = dp[1][i][j-1] dp[1][i][j] [i] [1] dp 1 i j dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 dp[2][i][j] = dp[2][i][j-1] dp[2][i][j] [i] [2] dp 2 i j dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 dp[3][i][j] = dp[3][i][j-1] dp[3][i][j] [i] [3] dp 3 i j dp[3][i][j-1] [i] [3] dp 3 i j-1 j 1 ans = max(dp[k][r][c] for k in range(4)) ans max(dp[k][r][c] for k in range(4)) max dp[k][r][c] [r] [k] dp k r c print(ans) print ans ans = max(dp[k][r][c] for k in range(4)) max(dp[k][r][c] for k in range(4)) ans dp = [[[0]*(c+1) for _ in range(r+1)] for i in range(4)] [[[0]*(c+1) for _ in range(r+1)] for i in range(4)] dp v = d[i][j] d[i][j] v v = map(int, input().split()) map(int, input().split()) v c, K = map(int, input().split()) map(int, input().split()) c d = [[0 for i in range(c+1)] for j in range(r+1)] [[0 for i in range(c+1)] for j in range(r+1)] d maxi = max(dp[k][i-1][j] for k in range(4)) max(dp[k][i-1][j] for k in range(4)) maxi K = map(int, input().split()) map(int, input().split()) K maxi = max(dp[k][i-1][j] for k in range(4)) max(dp[k][i-1][j] for k in range(4)) maxi r_, c_, v = map(int, input().split()) map(int, input().split()) r_ r, c, K = map(int, input().split()) map(int, input().split()) r c_, v = map(int, input().split()) map(int, input().split()) c_ def input(): return sys.stdin.readline().rstrip() def input(): return sys.stdin.readline().rstrip() input
from collections import defaultdict
import sys


def input(): return sys.stdin.readline().rstrip()


r, c, K = map(int, input().split())

dp = [[[0]*(c+1) for _ in range(r+1)] for i in range(4)]

# dp[N][i][j] := (i,j) にN個目でたどりつく方法
d = [[0 for i in range(c+1)] for j in range(r+1)]

for _ in range(K):
    r_, c_, v = map(int, input().split())
    d[r_][c_] = v
for i in range(1, r+1):
    for j in range(1, c+1):
        v = d[i][j]
        if v > 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(maxi, dp[0][i][j-1])
            dp[1][i][j] = max(dp[1][i][j-1], dp[0][i][j-1]+v, maxi+v)
            dp[2][i][j] = max(dp[2][i][j-1], dp[1][i][j-1]+v)
            dp[3][i][j] = max(dp[3][i][j-1], dp[2][i][j-1]+v)

        elif v == 0:
            maxi = max(dp[k][i-1][j] for k in range(4))
            dp[0][i][j] = max(dp[0][i][j-1], maxi)
            dp[1][i][j] = dp[1][i][j-1]
            dp[2][i][j] = dp[2][i][j-1]
            dp[3][i][j] = dp[3][i][j-1]


ans = max(dp[k][r][c] for k in range(4))

print(ans)