# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        r, c = r - 1, c - 1
        V[r][c] = v
    dp = [[[0] * C for _ in range(R)] for __ in range(4)]
    dp[1][0][0] = V[0][0]
    for i in range(R):
        for j in range(C):
            for k in range(4):
                if j > 0:
                    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] + V[i][j])
                if i > 0:
                    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] + V[i][j])
    print(max(dp[k][R - 1][C - 1] for k in range(4)))

if __name__ == '__main__':
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    RCV = [list(map(int, input().split())) for _ in range(K)]
    main(R, C, K, RCV) import sys sys def main(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        r, c = r - 1, c - 1
        V[r][c] = v
    dp = [[[0] * C for _ in range(R)] for __ in range(4)]
    dp[1][0][0] = V[0][0]
    for i in range(R):
        for j in range(C):
            for k in range(4):
                if j > 0:
                    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] + V[i][j])
                if i > 0:
                    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] + V[i][j])
    print(max(dp[k][R - 1][C - 1] for k in range(4))) main [0] * C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0] * C [0] 0 C V = [[0] * C for _ in range(R)] V [[0] * C for _ in range(R)] for r, c, v in RCV:
        r, c = r - 1, c - 1
        V[r][c] = v
     r c v RCV r, c = r - 1, c - 1 r r - 1 r 1 c c - 1 c 1 V[r][c] = v V[r][c] [r] V r c v [[0] * C for _ in range(R)] for __ in range(4) for __ in range(4) __ range(4) range 4 for __ in range(4) [[0] * C for _ in range(R)] dp = [[[0] * C for _ in range(R)] for __ in range(4)] dp [[[0] * C for _ in range(R)] for __ in range(4)] dp[1][0][0] = V[0][0] dp[1][0][0] [0] [1] dp 1 0 0 V[0][0] [0] V 0 0 for i in range(R):
        for j in range(C):
            for k in range(4):
                if j > 0:
                    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] + V[i][j])
                if i > 0:
                    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] + V[i][j])
     i range(R) range R for j in range(C):
            for k in range(4):
                if j > 0:
                    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] + V[i][j])
                if i > 0:
                    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] + V[i][j])
     j range(C) range C for k in range(4):
                if j > 0:
                    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] + V[i][j])
                if i > 0:
                    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] + V[i][j])
     k range(4) range 4 if j > 0:
                    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] + V[i][j])
                 j > 0 j 0 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] + V[i][j])
                 k > 0 k 0 dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + V[i][j]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k - 1][i][j - 1] + V[i][j]) max dp[k][i][j] [i] [k] dp k i j dp[k - 1][i][j - 1] + V[i][j] dp[k - 1][i][j - 1] [i] [k - 1] dp k - 1 k 1 i j - 1 j 1 V[i][j] [i] V i j if i > 0:
                    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] + V[i][j])
     i > 0 i 0 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] + V[i][j]) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j], dp[k][i - 1][j] + V[i][j]) max dp[1][i][j] [i] [1] dp 1 i j dp[k][i - 1][j] + V[i][j] dp[k][i - 1][j] [i - 1] [k] dp k i - 1 i 1 j V[i][j] [i] V i j print(max(dp[k][R - 1][C - 1] for k in range(4))) print max(dp[k][R - 1][C - 1] for k in range(4)) max dp[k][R - 1][C - 1] [R - 1] [k] dp k R - 1 R 1 C - 1 C 1 R R C C K K RCV RCV if __name__ == '__main__':
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    RCV = [list(map(int, input().split())) for _ in range(K)]
    main(R, C, K, RCV) __name__ == '__main__' __name__ '__main__' 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 list(map(int, input().split())) for _ in range(K) for _ in range(K) _ range(K) range K for _ 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 _ in range(K)] RCV [list(map(int, input().split())) for _ in range(K)] main(R, C, K, RCV) main R C K RCV def main(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        r, c = r - 1, c - 1
        V[r][c] = v
    dp = [[[0] * C for _ in range(R)] for __ in range(4)]
    dp[1][0][0] = V[0][0]
    for i in range(R):
        for j in range(C):
            for k in range(4):
                if j > 0:
                    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] + V[i][j])
                if i > 0:
                    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] + V[i][j])
    print(max(dp[k][R - 1][C - 1] for k in range(4))) def main(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        r, c = r - 1, c - 1
        V[r][c] = v
    dp = [[[0] * C for _ in range(R)] for __ in range(4)]
    dp[1][0][0] = V[0][0]
    for i in range(R):
        for j in range(C):
            for k in range(4):
                if j > 0:
                    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] + V[i][j])
                if i > 0:
                    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] + V[i][j])
    print(max(dp[k][R - 1][C - 1] for k in range(4))) main K = map(int, input().split()) map(int, input().split()) K input = sys.stdin.readline sys.stdin.readline input R, C, K = map(int, input().split()) map(int, input().split()) R RCV = [list(map(int, input().split())) for _ in range(K)] [list(map(int, input().split())) for _ in range(K)] RCV C, K = map(int, input().split()) map(int, input().split()) C
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        r, c = r - 1, c - 1
        V[r][c] = v
    dp = [[[0] * C for _ in range(R)] for __ in range(4)]
    dp[1][0][0] = V[0][0]
    for i in range(R):
        for j in range(C):
            for k in range(4):
                if j > 0:
                    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] + V[i][j])
                if i > 0:
                    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] + V[i][j])
    print(max(dp[k][R - 1][C - 1] for k in range(4)))

if __name__ == '__main__':
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    RCV = [list(map(int, input().split())) for _ in range(K)]
    main(R, C, K, RCV)
