import sys

readline = sys.stdin.readline

def solve():
    R, C, K = map(int, readline().split())
    items = [[0] * C for i in range(R)]
    for i in range(K):
        r,c,k = map(int, readline().split())
        items[r - 1][c - 1] = k
    
    dp = [[[0] * C for i in range(R)] for j in range(4)]

    for i in range(R):
        for j in range(C):
            for k in range(4):
                if i == 0 and j == 0:
                    if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                else:
                    if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

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

solve() import sys sys readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline def solve():
    R, C, K = map(int, readline().split())
    items = [[0] * C for i in range(R)]
    for i in range(K):
        r,c,k = map(int, readline().split())
        items[r - 1][c - 1] = k
    
    dp = [[[0] * C for i in range(R)] for j in range(4)]

    for i in range(R):
        for j in range(C):
            for k in range(4):
                if i == 0 and j == 0:
                    if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                else:
                    if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

    print(dp[-1][-1][-1]) solve R, C, K = map(int, readline().split()) R map(int, readline().split()) map int readline().split() ().split () readline split C K [0] * C for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0] * C [0] 0 C items = [[0] * C for i in range(R)] items [[0] * C for i in range(R)] for i in range(K):
        r,c,k = map(int, readline().split())
        items[r - 1][c - 1] = k
    
     i range(K) range K r,c,k = map(int, readline().split()) r map(int, readline().split()) map int readline().split() ().split () readline split c k items[r - 1][c - 1] = k items[r - 1][c - 1] [r - 1] items r - 1 r 1 c - 1 c 1 k [[0] * C for i in range(R)] for j in range(4) for j in range(4) j range(4) range 4 for j in range(4) [[0] * C for i in range(R)] dp = [[[0] * C for i in range(R)] for j in range(4)] dp [[[0] * C for i in range(R)] for j in range(4)] for i in range(R):
        for j in range(C):
            for k in range(4):
                if i == 0 and j == 0:
                    if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                else:
                    if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

     i range(R) range R for j in range(C):
            for k in range(4):
                if i == 0 and j == 0:
                    if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                else:
                    if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

     j range(C) range C for k in range(4):
                if i == 0 and j == 0:
                    if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                else:
                    if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

     k range(4) range 4 if i == 0 and j == 0:
                    if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                else:
                    if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

     i == 0 and j == 0 i == 0 i 0 j == 0 j 0 if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                 k == 0 k 0 dp[k][i][j] = 0 dp[k][i][j] [i] [k] dp k i j 0 dp[k][i][j] = items[i][j] dp[k][i][j] [i] [k] dp k i j items[i][j] [i] items i j elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                 i == 0 i 0 if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                 k == 0 k 0 dp[k][i][j] = dp[k][i][j - 1] dp[k][i][j] [i] [k] dp k i j dp[k][i][j - 1] [i] [k] dp k i j - 1 j 1 dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1]) dp[k][i][j] [i] [k] dp k i j max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1]) max dp[k - 1][i][j - 1] + items[i][j] dp[k - 1][i][j - 1] [i] [k - 1] dp k - 1 k 1 i j - 1 j 1 items[i][j] [i] items i j dp[k][i][j - 1] [i] [k] dp k i j - 1 j 1 elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                 j == 0 j 0 if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                 k == 0 k 0 dp[k][i][j] = dp[3][i - 1][j] dp[k][i][j] [i] [k] dp k i j dp[3][i - 1][j] [i - 1] [3] dp 3 i - 1 i 1 j dp[k][i][j] = dp[3][i - 1][j] + items[i][j] dp[k][i][j] [i] [k] dp k i j dp[3][i - 1][j] + items[i][j] dp[3][i - 1][j] [i - 1] [3] dp 3 i - 1 i 1 j items[i][j] [i] items i j if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

     k == 0 k 0 dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1]) dp[k][i][j] [i] [k] dp k i j max(dp[3][i - 1][j], dp[k][i][j - 1]) max dp[3][i - 1][j] [i - 1] [3] dp 3 i - 1 i 1 j dp[k][i][j - 1] [i] [k] dp k i j - 1 j 1 dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        ) dp[k][i][j] [i] [k] dp k i j max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        ) max dp[3][i - 1][j] + items[i][j] dp[3][i - 1][j] [i - 1] [3] dp 3 i - 1 i 1 j items[i][j] [i] items i j dp[k - 1][i][j - 1] + items[i][j] dp[k - 1][i][j - 1] [i] [k - 1] dp k - 1 k 1 i j - 1 j 1 items[i][j] [i] items i j dp[k][i][j - 1] [i] [k] dp k i j - 1 j 1 print(dp[-1][-1][-1]) print dp[-1][-1][-1] [-1] [-1] dp -1 -1 -1 solve() solve def solve():
    R, C, K = map(int, readline().split())
    items = [[0] * C for i in range(R)]
    for i in range(K):
        r,c,k = map(int, readline().split())
        items[r - 1][c - 1] = k
    
    dp = [[[0] * C for i in range(R)] for j in range(4)]

    for i in range(R):
        for j in range(C):
            for k in range(4):
                if i == 0 and j == 0:
                    if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                else:
                    if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

    print(dp[-1][-1][-1]) def solve():
    R, C, K = map(int, readline().split())
    items = [[0] * C for i in range(R)]
    for i in range(K):
        r,c,k = map(int, readline().split())
        items[r - 1][c - 1] = k
    
    dp = [[[0] * C for i in range(R)] for j in range(4)]

    for i in range(R):
        for j in range(C):
            for k in range(4):
                if i == 0 and j == 0:
                    if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                else:
                    if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

    print(dp[-1][-1][-1]) solve readline = sys.stdin.readline sys.stdin.readline readline
import sys

readline = sys.stdin.readline

def solve():
    R, C, K = map(int, readline().split())
    items = [[0] * C for i in range(R)]
    for i in range(K):
        r,c,k = map(int, readline().split())
        items[r - 1][c - 1] = k
    
    dp = [[[0] * C for i in range(R)] for j in range(4)]

    for i in range(R):
        for j in range(C):
            for k in range(4):
                if i == 0 and j == 0:
                    if k == 0:
                        dp[k][i][j] = 0
                    else:
                        dp[k][i][j] = items[i][j]
                elif i == 0:
                    if k == 0:
                        dp[k][i][j] = dp[k][i][j - 1]
                    else:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] + items[i][j], dp[k][i][j - 1])
                elif j == 0:
                    if k == 0:
                        dp[k][i][j] = dp[3][i - 1][j]
                    else:
                        dp[k][i][j] = dp[3][i - 1][j] + items[i][j]
                else:
                    if k == 0:
                        dp[k][i][j] = max(dp[3][i - 1][j], dp[k][i][j - 1])
                    else:
                        dp[k][i][j] = max(
                            dp[3][i - 1][j] + items[i][j],
                            dp[k - 1][i][j - 1] + items[i][j],
                            dp[k][i][j - 1]
                        )

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

solve()