import sys
input = sys.stdin.readline
R,C,K = map(int,input().split())
lis = [[0] * (C+1) for i in range(R+1)]
for _ in range(K):
    r,c,v = map(int,input().split())
    lis[r][c] = v

dp = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)]
#print(dp)
for i in range(1,R+1):
    for j in range(1,C+1):
        for k in range(4):
            dp[0][i][j] = max(dp[0][i][j],dp[k][i-1][j])
            dp[1][i][j] = max(dp[1][i][j],dp[k][i-1][j] + lis[i][j])

            dp[k][i][j] = max(dp[k][i][j],dp[k][i][j-1])
            if k > 0:
                dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1] + lis[i][j])
# print(dp[0])
# print(dp[1])
# print(dp[2])
# print(dp[3])
print(max(dp[0][R][C],dp[1][R][C],dp[2][R][C],dp[3][R][C])) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 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 lis = [[0] * (C+1) for i in range(R+1)] lis [[0] * (C+1) for i in range(R+1)] for _ in range(K):
    r,c,v = map(int,input().split())
    lis[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 lis[r][c] = v lis[r][c] [r] lis r c v [[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)] for i in range(1,R+1):
    for j in range(1,C+1):
        for k in range(4):
            dp[0][i][j] = max(dp[0][i][j],dp[k][i-1][j])
            dp[1][i][j] = max(dp[1][i][j],dp[k][i-1][j] + lis[i][j])

            dp[k][i][j] = max(dp[k][i][j],dp[k][i][j-1])
            if k > 0:
                dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1] + lis[i][j])
# print(dp[0])
# print(dp[1])
# print(dp[2])
# print(dp[3]) i range(1,R+1) range 1 R+1 R 1 for j in range(1,C+1):
        for k in range(4):
            dp[0][i][j] = max(dp[0][i][j],dp[k][i-1][j])
            dp[1][i][j] = max(dp[1][i][j],dp[k][i-1][j] + lis[i][j])

            dp[k][i][j] = max(dp[k][i][j],dp[k][i][j-1])
            if k > 0:
                dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1] + lis[i][j])
# print(dp[0])
# print(dp[1])
# print(dp[2])
# print(dp[3]) j range(1,C+1) range 1 C+1 C 1 for k in range(4):
            dp[0][i][j] = max(dp[0][i][j],dp[k][i-1][j])
            dp[1][i][j] = max(dp[1][i][j],dp[k][i-1][j] + lis[i][j])

            dp[k][i][j] = max(dp[k][i][j],dp[k][i][j-1])
            if k > 0:
                dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1] + lis[i][j])
# print(dp[0])
# print(dp[1])
# print(dp[2])
# print(dp[3]) k range(4) range 4 dp[0][i][j] = max(dp[0][i][j],dp[k][i-1][j]) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j],dp[k][i-1][j]) max dp[0][i][j] [i] [0] dp 0 i j dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j dp[1][i][j] = max(dp[1][i][j],dp[k][i-1][j] + lis[i][j]) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j],dp[k][i-1][j] + lis[i][j]) max dp[1][i][j] [i] [1] dp 1 i j dp[k][i-1][j] + lis[i][j] dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j lis[i][j] [i] lis i j dp[k][i][j] = max(dp[k][i][j],dp[k][i][j-1]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j],dp[k][i][j-1]) max dp[k][i][j] [i] [k] dp k i j dp[k][i][j-1] [i] [k] dp k i j-1 j 1 if k > 0:
                dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1] + lis[i][j])
# print(dp[0])
# print(dp[1])
# print(dp[2])
# print(dp[3]) k > 0 k 0 dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1] + lis[i][j]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j],dp[k-1][i][j-1] + lis[i][j]) max dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j-1] + lis[i][j] dp[k-1][i][j-1] [i] [k-1] dp k-1 k 1 i j-1 j 1 lis[i][j] [i] lis i j print(max(dp[0][R][C],dp[1][R][C],dp[2][R][C],dp[3][R][C])) print max(dp[0][R][C],dp[1][R][C],dp[2][R][C],dp[3][R][C]) max dp[0][R][C] [R] [0] dp 0 R C dp[1][R][C] [R] [1] dp 1 R C dp[2][R][C] [R] [2] dp 2 R C dp[3][R][C] [R] [3] dp 3 R C v = map(int,input().split()) map(int,input().split()) v c,v = map(int,input().split()) map(int,input().split()) c lis = [[0] * (C+1) for i in range(R+1)] [[0] * (C+1) for i in range(R+1)] lis r,c,v = map(int,input().split()) map(int,input().split()) r C,K = map(int,input().split()) map(int,input().split()) C K = map(int,input().split()) map(int,input().split()) K R,C,K = map(int,input().split()) map(int,input().split()) R input = sys.stdin.readline sys.stdin.readline input 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
import sys
input = sys.stdin.readline
R,C,K = map(int,input().split())
lis = [[0] * (C+1) for i in range(R+1)]
for _ in range(K):
    r,c,v = map(int,input().split())
    lis[r][c] = v

dp = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)]
#print(dp)
for i in range(1,R+1):
    for j in range(1,C+1):
        for k in range(4):
            dp[0][i][j] = max(dp[0][i][j],dp[k][i-1][j])
            dp[1][i][j] = max(dp[1][i][j],dp[k][i-1][j] + lis[i][j])

            dp[k][i][j] = max(dp[k][i][j],dp[k][i][j-1])
            if k > 0:
                dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1] + lis[i][j])
# print(dp[0])
# print(dp[1])
# print(dp[2])
# print(dp[3])
print(max(dp[0][R][C],dp[1][R][C],dp[2][R][C],dp[3][R][C]))
