from sys import stdin
input = stdin.readline
def main():
    R, C, K = map(int, input().split())
    items = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(4)]
    dp[1][0][0] = items[0][0]
    for r in range(R):
        for c in range(C):
            for i in range(4):
                tmp = dp[i][r][c]
                # right
                if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
    ans = 0
    for i in range(4):
        ans = max(ans, dp[i][-1][-1])
    print(ans)


if __name__ == "__main__":
    main() from sys import stdin input = stdin.readline input stdin.readline stdin readline def main():
    R, C, K = map(int, input().split())
    items = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(4)]
    dp[1][0][0] = items[0][0]
    for r in range(R):
        for c in range(C):
            for i in range(4):
                tmp = dp[i][r][c]
                # right
                if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
    ans = 0
    for i in range(4):
        ans = max(ans, dp[i][-1][-1])
    print(ans) main R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0 for _ in range(C)] for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] items = [[0 for _ in range(C)] for _ in range(R)] items [[0 for _ in range(C)] for _ in range(R)] for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = 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 items[r - 1][c - 1] = v items[r - 1][c - 1] [r - 1] items r - 1 r 1 c - 1 c 1 v [[0 for _ in range(C)] for _ in range(R)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0 for _ in range(C)] for _ in range(R)] dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(4)] dp [[[0 for _ in range(C)] for _ in range(R)] for _ in range(4)] dp[1][0][0] = items[0][0] dp[1][0][0] [0] [1] dp 1 0 0 items[0][0] [0] items 0 0 for r in range(R):
        for c in range(C):
            for i in range(4):
                tmp = dp[i][r][c]
                # right
                if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
     r range(R) range R for c in range(C):
            for i in range(4):
                tmp = dp[i][r][c]
                # right
                if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
     c range(C) range C for i in range(4):
                tmp = dp[i][r][c]
                # right
                if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
     i range(4) range 4 tmp = dp[i][r][c] tmp dp[i][r][c] [r] [i] dp i r c if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                 c != C - 1 c C - 1 C 1 dp[i][r][c + 1] = max(dp[i][r][c+1], tmp) dp[i][r][c + 1] [r] [i] dp i r c + 1 c 1 max(dp[i][r][c+1], tmp) max dp[i][r][c+1] [r] [i] dp i r c+1 c 1 tmp if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                 i < 3 i 3 dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1]) dp[i+1][r][c + 1] [r] [i+1] dp i+1 i 1 r c + 1 c 1 max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1]) max dp[i+1][r]
                                                [c + 1] [r] [i+1] dp i+1 i 1 r c + 1 c 1 tmp + items[r][c + 1] tmp items[r][c + 1] [r] items r c + 1 c 1 if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
     r != R - 1 r R - 1 R 1 dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp) dp[0][r + 1][c] [r + 1] [0] dp 0 r + 1 r 1 c max(dp[0][r + 1][c], tmp) max dp[0][r + 1][c] [r + 1] [0] dp 0 r + 1 r 1 c tmp dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c]) dp[1][r + 1][c] [r + 1] [1] dp 1 r + 1 r 1 c max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c]) max dp[1][r + 1][c] [r + 1] [1] dp 1 r + 1 r 1 c tmp + items[r + 1][c] tmp items[r + 1][c] [r + 1] items r + 1 r 1 c ans = 0 ans 0 for i in range(4):
        ans = max(ans, dp[i][-1][-1])
     i range(4) range 4 ans = max(ans, dp[i][-1][-1]) ans max(ans, dp[i][-1][-1]) max ans dp[i][-1][-1] [-1] [i] dp i -1 -1 print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main input = stdin.readline stdin.readline input def main():
    R, C, K = map(int, input().split())
    items = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(4)]
    dp[1][0][0] = items[0][0]
    for r in range(R):
        for c in range(C):
            for i in range(4):
                tmp = dp[i][r][c]
                # right
                if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
    ans = 0
    for i in range(4):
        ans = max(ans, dp[i][-1][-1])
    print(ans) def main():
    R, C, K = map(int, input().split())
    items = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(4)]
    dp[1][0][0] = items[0][0]
    for r in range(R):
        for c in range(C):
            for i in range(4):
                tmp = dp[i][r][c]
                # right
                if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
    ans = 0
    for i in range(4):
        ans = max(ans, dp[i][-1][-1])
    print(ans) main
from sys import stdin
input = stdin.readline
def main():
    R, C, K = map(int, input().split())
    items = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(4)]
    dp[1][0][0] = items[0][0]
    for r in range(R):
        for c in range(C):
            for i in range(4):
                tmp = dp[i][r][c]
                # right
                if c != C - 1:
                    # unpick
                    dp[i][r][c + 1] = max(dp[i][r][c+1], tmp)
                    # pick
                    if i < 3:
                        dp[i+1][r][c + 1] = max(dp[i+1][r]
                                                [c + 1], tmp + items[r][c + 1])
                # down
                if r != R - 1:
                    # unpick
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], tmp)
                    # pick
                    dp[1][r + 1][c] = max(dp[1][r + 1][c],
                                          tmp + items[r + 1][c])
    ans = 0
    for i in range(4):
        ans = max(ans, dp[i][-1][-1])
    print(ans)


if __name__ == "__main__":
    main()
