import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()

def main():
    R, C, K = map(int, input().split())
    R, C = C, R
    items = [[0] * R for _ in range(C)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v

    dp = [[0] * R for _ in range(4)]
    for i in range(1, 4):
        dp[i][0] = items[0][0]
        for r in range(1, R):
            dp[i][r] = max(dp[i][r - 1], dp[i - 1][r - 1] + items[0][r])

    for c in range(1, C):
        dp2 = [[0] * R for _ in range(4)]
        for i in range(1, 4):
            dp2[i][0] = max(dp[1][0], dp[2][0], dp[3][0]) + items[c][0]
            for r in range(1, R):
                upper = max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r]
                dp2[i][r] = max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r])
        dp = dp2

    print(dp[3][R - 1])



if __name__ == "__main__":
    main() import sys sys from itertools import accumulate def input(): return sys.stdin.readline().strip() input def main():
    R, C, K = map(int, input().split())
    R, C = C, R
    items = [[0] * R for _ in range(C)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v

    dp = [[0] * R for _ in range(4)]
    for i in range(1, 4):
        dp[i][0] = items[0][0]
        for r in range(1, R):
            dp[i][r] = max(dp[i][r - 1], dp[i - 1][r - 1] + items[0][r])

    for c in range(1, C):
        dp2 = [[0] * R for _ in range(4)]
        for i in range(1, 4):
            dp2[i][0] = max(dp[1][0], dp[2][0], dp[3][0]) + items[c][0]
            for r in range(1, R):
                upper = max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r]
                dp2[i][r] = max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r])
        dp = dp2

    print(dp[3][R - 1]) main R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K R, C = C, R R C C R [0] * R for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0] * R [0] 0 R items = [[0] * R for _ in range(C)] items [[0] * R for _ in range(C)] 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] * R for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [0] * R [0] 0 R dp = [[0] * R for _ in range(4)] dp [[0] * R for _ in range(4)] for i in range(1, 4):
        dp[i][0] = items[0][0]
        for r in range(1, R):
            dp[i][r] = max(dp[i][r - 1], dp[i - 1][r - 1] + items[0][r])

     i range(1, 4) range 1 4 dp[i][0] = items[0][0] dp[i][0] [i] dp i 0 items[0][0] [0] items 0 0 for r in range(1, R):
            dp[i][r] = max(dp[i][r - 1], dp[i - 1][r - 1] + items[0][r])

     r range(1, R) range 1 R dp[i][r] = max(dp[i][r - 1], dp[i - 1][r - 1] + items[0][r]) dp[i][r] [i] dp i r max(dp[i][r - 1], dp[i - 1][r - 1] + items[0][r]) max dp[i][r - 1] [i] dp i r - 1 r 1 dp[i - 1][r - 1] + items[0][r] dp[i - 1][r - 1] [i - 1] dp i - 1 i 1 r - 1 r 1 items[0][r] [0] items 0 r for c in range(1, C):
        dp2 = [[0] * R for _ in range(4)]
        for i in range(1, 4):
            dp2[i][0] = max(dp[1][0], dp[2][0], dp[3][0]) + items[c][0]
            for r in range(1, R):
                upper = max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r]
                dp2[i][r] = max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r])
        dp = dp2

     c range(1, C) range 1 C [0] * R for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [0] * R [0] 0 R dp2 = [[0] * R for _ in range(4)] dp2 [[0] * R for _ in range(4)] for i in range(1, 4):
            dp2[i][0] = max(dp[1][0], dp[2][0], dp[3][0]) + items[c][0]
            for r in range(1, R):
                upper = max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r]
                dp2[i][r] = max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r])
         i range(1, 4) range 1 4 dp2[i][0] = max(dp[1][0], dp[2][0], dp[3][0]) + items[c][0] dp2[i][0] [i] dp2 i 0 max(dp[1][0], dp[2][0], dp[3][0]) + items[c][0] max(dp[1][0], dp[2][0], dp[3][0]) max dp[1][0] [1] dp 1 0 dp[2][0] [2] dp 2 0 dp[3][0] [3] dp 3 0 items[c][0] [c] items c 0 for r in range(1, R):
                upper = max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r]
                dp2[i][r] = max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r])
         r range(1, R) range 1 R upper = max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r] upper max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r] max(dp[1][r], dp[2][r], dp[3][r]) max dp[1][r] [1] dp 1 r dp[2][r] [2] dp 2 r dp[3][r] [3] dp 3 r items[c][r] [c] items c r dp2[i][r] = max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r]) dp2[i][r] [i] dp2 i r max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r]) max upper dp2[i][r - 1] [i] dp2 i r - 1 r 1 dp2[i - 1][r - 1] + items[c][r] dp2[i - 1][r - 1] [i - 1] dp2 i - 1 i 1 r - 1 r 1 items[c][r] [c] items c r dp = dp2 dp dp2 print(dp[3][R - 1]) print dp[3][R - 1] [3] dp 3 R - 1 R 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input def main():
    R, C, K = map(int, input().split())
    R, C = C, R
    items = [[0] * R for _ in range(C)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v

    dp = [[0] * R for _ in range(4)]
    for i in range(1, 4):
        dp[i][0] = items[0][0]
        for r in range(1, R):
            dp[i][r] = max(dp[i][r - 1], dp[i - 1][r - 1] + items[0][r])

    for c in range(1, C):
        dp2 = [[0] * R for _ in range(4)]
        for i in range(1, 4):
            dp2[i][0] = max(dp[1][0], dp[2][0], dp[3][0]) + items[c][0]
            for r in range(1, R):
                upper = max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r]
                dp2[i][r] = max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r])
        dp = dp2

    print(dp[3][R - 1]) def main():
    R, C, K = map(int, input().split())
    R, C = C, R
    items = [[0] * R for _ in range(C)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v

    dp = [[0] * R for _ in range(4)]
    for i in range(1, 4):
        dp[i][0] = items[0][0]
        for r in range(1, R):
            dp[i][r] = max(dp[i][r - 1], dp[i - 1][r - 1] + items[0][r])

    for c in range(1, C):
        dp2 = [[0] * R for _ in range(4)]
        for i in range(1, 4):
            dp2[i][0] = max(dp[1][0], dp[2][0], dp[3][0]) + items[c][0]
            for r in range(1, R):
                upper = max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r]
                dp2[i][r] = max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r])
        dp = dp2

    print(dp[3][R - 1]) main
import sys
from itertools import accumulate
def input(): return sys.stdin.readline().strip()

def main():
    R, C, K = map(int, input().split())
    R, C = C, R
    items = [[0] * R for _ in range(C)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r - 1][c - 1] = v

    dp = [[0] * R for _ in range(4)]
    for i in range(1, 4):
        dp[i][0] = items[0][0]
        for r in range(1, R):
            dp[i][r] = max(dp[i][r - 1], dp[i - 1][r - 1] + items[0][r])

    for c in range(1, C):
        dp2 = [[0] * R for _ in range(4)]
        for i in range(1, 4):
            dp2[i][0] = max(dp[1][0], dp[2][0], dp[3][0]) + items[c][0]
            for r in range(1, R):
                upper = max(dp[1][r], dp[2][r], dp[3][r]) + items[c][r]
                dp2[i][r] = max(upper, dp2[i][r - 1], dp2[i - 1][r - 1] + items[c][r])
        dp = dp2

    print(dp[3][R - 1])



if __name__ == "__main__":
    main()
