import sys
# import time
input = lambda: sys.stdin.readline().rstrip()
r, c, k = map(int, input().split())
# dp = [[[0] * 3 for _ in range(c + 5)] for _ in range(r + 5)]
pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)]

for i in range(k):
    r1, c1, v = map(int, input().split())
    # dp[r1][c1][0] = v
    pt[r1][c1] = v

# start = time.time()
a = 0


def solve():
    memo = [[0] * 4 for _ in range(c + 1)]
    prev = [[0] * 4 for _ in range(c + 1)]
    for i in range(1, r + 1):
        memo, prev = prev, memo
        for j in range(1, c + 1):
            V = pt[i][j]
            memo[j][0] = max(prev[j][3], memo[j - 1][0])
            memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
            memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
            memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])

            # dp[i][j][0] = max(dp[i - 1][j][2] + V, dp[i][j - 1][0])
            # dp[i][j][1] = max(dp[i][j - 1][0] + V, dp[i][j - 1][1],
            #                   dp[i][j][0])
            # dp[i][j][2] = max(dp[i][j - 1][1] + V, dp[i][j - 1][2],
            #                   dp[i][j][1])

    # process_time = time.time() - start

    # print(process_time)

    # print(dp[r][c][2])
    return memo[-1][3]





if __name__ == '__main__':
    print(solve()) import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip 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 + 5)] for _ in range(r + 5) for _ in range(r + 5) _ range(r + 5) range r + 5 r 5 for _ in range(r + 5) [0 for _ in range(c + 5)] pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)] pt [[0 for _ in range(c + 5)] for _ in range(r + 5)] for i in range(k):
    r1, c1, v = map(int, input().split())
    # dp[r1][c1][0] = v
    pt[r1][c1] = v

# start = time.time() i range(k) range k r1, c1, v = map(int, input().split()) r1 map(int, input().split()) map int input().split() ().split () input split c1 v pt[r1][c1] = v pt[r1][c1] [r1] pt r1 c1 v a = 0 a 0 def solve():
    memo = [[0] * 4 for _ in range(c + 1)]
    prev = [[0] * 4 for _ in range(c + 1)]
    for i in range(1, r + 1):
        memo, prev = prev, memo
        for j in range(1, c + 1):
            V = pt[i][j]
            memo[j][0] = max(prev[j][3], memo[j - 1][0])
            memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
            memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
            memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])

            # dp[i][j][0] = max(dp[i - 1][j][2] + V, dp[i][j - 1][0])
            # dp[i][j][1] = max(dp[i][j - 1][0] + V, dp[i][j - 1][1],
            #                   dp[i][j][0])
            # dp[i][j][2] = max(dp[i][j - 1][1] + V, dp[i][j - 1][2],
            #                   dp[i][j][1])

    # process_time = time.time() - start

    # print(process_time)

    # print(dp[r][c][2])
    return memo[-1][3] solve [0] * 4 for _ in range(c + 1) for _ in range(c + 1) _ range(c + 1) range c + 1 c 1 for _ in range(c + 1) [0] * 4 [0] 0 4 memo = [[0] * 4 for _ in range(c + 1)] memo [[0] * 4 for _ in range(c + 1)] [0] * 4 for _ in range(c + 1) for _ in range(c + 1) _ range(c + 1) range c + 1 c 1 for _ in range(c + 1) [0] * 4 [0] 0 4 prev = [[0] * 4 for _ in range(c + 1)] prev [[0] * 4 for _ in range(c + 1)] for i in range(1, r + 1):
        memo, prev = prev, memo
        for j in range(1, c + 1):
            V = pt[i][j]
            memo[j][0] = max(prev[j][3], memo[j - 1][0])
            memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
            memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
            memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])

            # dp[i][j][0] = max(dp[i - 1][j][2] + V, dp[i][j - 1][0])
            # dp[i][j][1] = max(dp[i][j - 1][0] + V, dp[i][j - 1][1],
            #                   dp[i][j][0])
            # dp[i][j][2] = max(dp[i][j - 1][1] + V, dp[i][j - 1][2],
            #                   dp[i][j][1])

    # process_time = time.time() - start

    # print(process_time)

    # print(dp[r][c][2])
     i range(1, r + 1) range 1 r + 1 r 1 memo, prev = prev, memo memo prev prev memo for j in range(1, c + 1):
            V = pt[i][j]
            memo[j][0] = max(prev[j][3], memo[j - 1][0])
            memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
            memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
            memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])

            # dp[i][j][0] = max(dp[i - 1][j][2] + V, dp[i][j - 1][0])
            # dp[i][j][1] = max(dp[i][j - 1][0] + V, dp[i][j - 1][1],
            #                   dp[i][j][0])
            # dp[i][j][2] = max(dp[i][j - 1][1] + V, dp[i][j - 1][2],
            #                   dp[i][j][1])

    # process_time = time.time() - start

    # print(process_time)

    # print(dp[r][c][2])
     j range(1, c + 1) range 1 c + 1 c 1 V = pt[i][j] V pt[i][j] [i] pt i j memo[j][0] = max(prev[j][3], memo[j - 1][0]) memo[j][0] [j] memo j 0 max(prev[j][3], memo[j - 1][0]) max prev[j][3] [j] prev j 3 memo[j - 1][0] [j - 1] memo j - 1 j 1 0 memo[j][1] = max(memo[j][0] + V, memo[j - 1][1]) memo[j][1] [j] memo j 1 max(memo[j][0] + V, memo[j - 1][1]) max memo[j][0] + V memo[j][0] [j] memo j 0 V memo[j - 1][1] [j - 1] memo j - 1 j 1 1 memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2]) memo[j][2] [j] memo j 2 max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2]) max memo[j][1] [j] memo j 1 memo[j - 1][1] + V memo[j - 1][1] [j - 1] memo j - 1 j 1 1 V memo[j - 1][2] [j - 1] memo j - 1 j 1 2 memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3]) memo[j][3] [j] memo j 3 max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3]) max memo[j][2] [j] memo j 2 memo[j - 1][2] + V memo[j - 1][2] [j - 1] memo j - 1 j 1 2 V memo[j - 1][3] [j - 1] memo j - 1 j 1 3 return memo[-1][3] memo[-1][3] [-1] memo -1 3 if __name__ == '__main__':
    print(solve()) __name__ == '__main__' __name__ '__main__' print(solve()) print solve() solve def solve():
    memo = [[0] * 4 for _ in range(c + 1)]
    prev = [[0] * 4 for _ in range(c + 1)]
    for i in range(1, r + 1):
        memo, prev = prev, memo
        for j in range(1, c + 1):
            V = pt[i][j]
            memo[j][0] = max(prev[j][3], memo[j - 1][0])
            memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
            memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
            memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])

            # dp[i][j][0] = max(dp[i - 1][j][2] + V, dp[i][j - 1][0])
            # dp[i][j][1] = max(dp[i][j - 1][0] + V, dp[i][j - 1][1],
            #                   dp[i][j][0])
            # dp[i][j][2] = max(dp[i][j - 1][1] + V, dp[i][j - 1][2],
            #                   dp[i][j][1])

    # process_time = time.time() - start

    # print(process_time)

    # print(dp[r][c][2])
    return memo[-1][3] def solve():
    memo = [[0] * 4 for _ in range(c + 1)]
    prev = [[0] * 4 for _ in range(c + 1)]
    for i in range(1, r + 1):
        memo, prev = prev, memo
        for j in range(1, c + 1):
            V = pt[i][j]
            memo[j][0] = max(prev[j][3], memo[j - 1][0])
            memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
            memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
            memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])

            # dp[i][j][0] = max(dp[i - 1][j][2] + V, dp[i][j - 1][0])
            # dp[i][j][1] = max(dp[i][j - 1][0] + V, dp[i][j - 1][1],
            #                   dp[i][j][0])
            # dp[i][j][2] = max(dp[i][j - 1][1] + V, dp[i][j - 1][2],
            #                   dp[i][j][1])

    # process_time = time.time() - start

    # print(process_time)

    # print(dp[r][c][2])
    return memo[-1][3] solve k = map(int, input().split()) map(int, input().split()) k input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input c1, v = map(int, input().split()) map(int, input().split()) c1 r1, c1, v = map(int, input().split()) map(int, input().split()) r1 pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)] [[0 for _ in range(c + 5)] for _ in range(r + 5)] pt a = 0 0 a r, c, k = map(int, input().split()) map(int, input().split()) r v = map(int, input().split()) map(int, input().split()) v c, k = map(int, input().split()) map(int, input().split()) c
import sys
# import time
input = lambda: sys.stdin.readline().rstrip()
r, c, k = map(int, input().split())
# dp = [[[0] * 3 for _ in range(c + 5)] for _ in range(r + 5)]
pt = [[0 for _ in range(c + 5)] for _ in range(r + 5)]

for i in range(k):
    r1, c1, v = map(int, input().split())
    # dp[r1][c1][0] = v
    pt[r1][c1] = v

# start = time.time()
a = 0


def solve():
    memo = [[0] * 4 for _ in range(c + 1)]
    prev = [[0] * 4 for _ in range(c + 1)]
    for i in range(1, r + 1):
        memo, prev = prev, memo
        for j in range(1, c + 1):
            V = pt[i][j]
            memo[j][0] = max(prev[j][3], memo[j - 1][0])
            memo[j][1] = max(memo[j][0] + V, memo[j - 1][1])
            memo[j][2] = max(memo[j][1], memo[j - 1][1] + V, memo[j - 1][2])
            memo[j][3] = max(memo[j][2], memo[j - 1][2] + V, memo[j - 1][3])

            # dp[i][j][0] = max(dp[i - 1][j][2] + V, dp[i][j - 1][0])
            # dp[i][j][1] = max(dp[i][j - 1][0] + V, dp[i][j - 1][1],
            #                   dp[i][j][0])
            # dp[i][j][2] = max(dp[i][j - 1][1] + V, dp[i][j - 1][2],
            #                   dp[i][j][1])

    # process_time = time.time() - start

    # print(process_time)

    # print(dp[r][c][2])
    return memo[-1][3]





if __name__ == '__main__':
    print(solve())
