def main():
    R, C, K = list(map(int, input().split()))
    # dp[r][c][n]: r行目でn個のアイテムを拾う場合の(r, c)でのアイテムの価値の合計の最大
    dp_0 = [[0 for _ in range(C)] for _ in range(R)]
    dp_1 = [[0 for _ in range(C)] for _ in range(R)]
    dp_2 = [[0 for _ in range(C)] for _ in range(R)]
    dp_3 = [[0 for _ in range(C)] for _ in range(R)]
    V = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = list(map(int, input().split()))
        V[r - 1][c - 1] = v
    dp_1[0][0] = V[0][0]
    for r in range(R):
        for c in range(C):
            if r == c == 0:
                continue
            v_rc = V[r][c]
            max_dp_before_row = 0 if r == 0 else max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c])
            # dp[r][c][0]
            v1 = 0 if c == 0 else dp_0[r][c - 1]
            dp_0[r][c] = max(v1, max_dp_before_row)
            # dp[r][c][1]
            v1 = 0 if c == 0 else max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc)
            v2 = 0 if r == 0 else (max_dp_before_row + v_rc)
            dp_1[r][c] = max(v1, v2)
            # dp[r][c][2], dp[r][c][3]
            dp_2[r][c] = 0 if c == 0 else max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc)
            dp_3[r][c] = 0 if c == 0 else max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc)
    print(max(dp_0[R-1][C-1], dp_1[R-1][C-1], dp_2[R-1][C-1], dp_3[R-1][C-1]))


if __name__ == '__main__':
    main() def main():
    R, C, K = list(map(int, input().split()))
    # dp[r][c][n]: r行目でn個のアイテムを拾う場合の(r, c)でのアイテムの価値の合計の最大
    dp_0 = [[0 for _ in range(C)] for _ in range(R)]
    dp_1 = [[0 for _ in range(C)] for _ in range(R)]
    dp_2 = [[0 for _ in range(C)] for _ in range(R)]
    dp_3 = [[0 for _ in range(C)] for _ in range(R)]
    V = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = list(map(int, input().split()))
        V[r - 1][c - 1] = v
    dp_1[0][0] = V[0][0]
    for r in range(R):
        for c in range(C):
            if r == c == 0:
                continue
            v_rc = V[r][c]
            max_dp_before_row = 0 if r == 0 else max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c])
            # dp[r][c][0]
            v1 = 0 if c == 0 else dp_0[r][c - 1]
            dp_0[r][c] = max(v1, max_dp_before_row)
            # dp[r][c][1]
            v1 = 0 if c == 0 else max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc)
            v2 = 0 if r == 0 else (max_dp_before_row + v_rc)
            dp_1[r][c] = max(v1, v2)
            # dp[r][c][2], dp[r][c][3]
            dp_2[r][c] = 0 if c == 0 else max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc)
            dp_3[r][c] = 0 if c == 0 else max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc)
    print(max(dp_0[R-1][C-1], dp_1[R-1][C-1], dp_2[R-1][C-1], dp_3[R-1][C-1])) main R, C, K = list(map(int, input().split())) R list(map(int, input().split())) list 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)] dp_0 = [[0 for _ in range(C)] for _ in range(R)] dp_0 [[0 for _ in range(C)] for _ in range(R)] [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)] dp_1 = [[0 for _ in range(C)] for _ in range(R)] dp_1 [[0 for _ in range(C)] for _ in range(R)] [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)] dp_2 = [[0 for _ in range(C)] for _ in range(R)] dp_2 [[0 for _ in range(C)] for _ in range(R)] [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)] dp_3 = [[0 for _ in range(C)] for _ in range(R)] dp_3 [[0 for _ in range(C)] for _ in range(R)] [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)] V = [[0 for _ in range(C)] for _ in range(R)] V [[0 for _ in range(C)] for _ in range(R)] for _ in range(K):
        r, c, v = list(map(int, input().split()))
        V[r - 1][c - 1] = v
     _ range(K) range K r, c, v = list(map(int, input().split())) r list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c v V[r - 1][c - 1] = v V[r - 1][c - 1] [r - 1] V r - 1 r 1 c - 1 c 1 v dp_1[0][0] = V[0][0] dp_1[0][0] [0] dp_1 0 0 V[0][0] [0] V 0 0 for r in range(R):
        for c in range(C):
            if r == c == 0:
                continue
            v_rc = V[r][c]
            max_dp_before_row = 0 if r == 0 else max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c])
            # dp[r][c][0]
            v1 = 0 if c == 0 else dp_0[r][c - 1]
            dp_0[r][c] = max(v1, max_dp_before_row)
            # dp[r][c][1]
            v1 = 0 if c == 0 else max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc)
            v2 = 0 if r == 0 else (max_dp_before_row + v_rc)
            dp_1[r][c] = max(v1, v2)
            # dp[r][c][2], dp[r][c][3]
            dp_2[r][c] = 0 if c == 0 else max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc)
            dp_3[r][c] = 0 if c == 0 else max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc)
     r range(R) range R for c in range(C):
            if r == c == 0:
                continue
            v_rc = V[r][c]
            max_dp_before_row = 0 if r == 0 else max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c])
            # dp[r][c][0]
            v1 = 0 if c == 0 else dp_0[r][c - 1]
            dp_0[r][c] = max(v1, max_dp_before_row)
            # dp[r][c][1]
            v1 = 0 if c == 0 else max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc)
            v2 = 0 if r == 0 else (max_dp_before_row + v_rc)
            dp_1[r][c] = max(v1, v2)
            # dp[r][c][2], dp[r][c][3]
            dp_2[r][c] = 0 if c == 0 else max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc)
            dp_3[r][c] = 0 if c == 0 else max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc)
     c range(C) range C if r == c == 0:
                continue
             r == c == 0 r == c r c 0 continue v_rc = V[r][c] v_rc V[r][c] [r] V r c max_dp_before_row = 0 if r == 0 else max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c]) max_dp_before_row 0 if r == 0 else max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c]) r == 0 r 0 0 max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c]) max dp_0[r - 1][c] [r - 1] dp_0 r - 1 r 1 c dp_1[r - 1][c] [r - 1] dp_1 r - 1 r 1 c dp_2[r - 1][c] [r - 1] dp_2 r - 1 r 1 c dp_3[r - 1][c] [r - 1] dp_3 r - 1 r 1 c v1 = 0 if c == 0 else dp_0[r][c - 1] v1 0 if c == 0 else dp_0[r][c - 1] c == 0 c 0 0 dp_0[r][c - 1] [r] dp_0 r c - 1 c 1 dp_0[r][c] = max(v1, max_dp_before_row) dp_0[r][c] [r] dp_0 r c max(v1, max_dp_before_row) max v1 max_dp_before_row v1 = 0 if c == 0 else max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc) v1 0 if c == 0 else max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc) c == 0 c 0 0 max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc) max dp_1[r][c - 1] [r] dp_1 r c - 1 c 1 dp_0[r][c - 1] + v_rc dp_0[r][c - 1] [r] dp_0 r c - 1 c 1 v_rc v2 = 0 if r == 0 else (max_dp_before_row + v_rc) v2 0 if r == 0 else (max_dp_before_row + v_rc) r == 0 r 0 0 max_dp_before_row + v_rc max_dp_before_row v_rc dp_1[r][c] = max(v1, v2) dp_1[r][c] [r] dp_1 r c max(v1, v2) max v1 v2 dp_2[r][c] = 0 if c == 0 else max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc) dp_2[r][c] [r] dp_2 r c 0 if c == 0 else max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc) c == 0 c 0 0 max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc) max dp_2[r][c - 1] [r] dp_2 r c - 1 c 1 dp_1[r][c - 1] + v_rc dp_1[r][c - 1] [r] dp_1 r c - 1 c 1 v_rc dp_3[r][c] = 0 if c == 0 else max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc) dp_3[r][c] [r] dp_3 r c 0 if c == 0 else max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc) c == 0 c 0 0 max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc) max dp_3[r][c - 1] [r] dp_3 r c - 1 c 1 dp_2[r][c - 1] + v_rc dp_2[r][c - 1] [r] dp_2 r c - 1 c 1 v_rc print(max(dp_0[R-1][C-1], dp_1[R-1][C-1], dp_2[R-1][C-1], dp_3[R-1][C-1])) print max(dp_0[R-1][C-1], dp_1[R-1][C-1], dp_2[R-1][C-1], dp_3[R-1][C-1]) max dp_0[R-1][C-1] [R-1] dp_0 R-1 R 1 C-1 C 1 dp_1[R-1][C-1] [R-1] dp_1 R-1 R 1 C-1 C 1 dp_2[R-1][C-1] [R-1] dp_2 R-1 R 1 C-1 C 1 dp_3[R-1][C-1] [R-1] dp_3 R-1 R 1 C-1 C 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    R, C, K = list(map(int, input().split()))
    # dp[r][c][n]: r行目でn個のアイテムを拾う場合の(r, c)でのアイテムの価値の合計の最大
    dp_0 = [[0 for _ in range(C)] for _ in range(R)]
    dp_1 = [[0 for _ in range(C)] for _ in range(R)]
    dp_2 = [[0 for _ in range(C)] for _ in range(R)]
    dp_3 = [[0 for _ in range(C)] for _ in range(R)]
    V = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = list(map(int, input().split()))
        V[r - 1][c - 1] = v
    dp_1[0][0] = V[0][0]
    for r in range(R):
        for c in range(C):
            if r == c == 0:
                continue
            v_rc = V[r][c]
            max_dp_before_row = 0 if r == 0 else max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c])
            # dp[r][c][0]
            v1 = 0 if c == 0 else dp_0[r][c - 1]
            dp_0[r][c] = max(v1, max_dp_before_row)
            # dp[r][c][1]
            v1 = 0 if c == 0 else max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc)
            v2 = 0 if r == 0 else (max_dp_before_row + v_rc)
            dp_1[r][c] = max(v1, v2)
            # dp[r][c][2], dp[r][c][3]
            dp_2[r][c] = 0 if c == 0 else max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc)
            dp_3[r][c] = 0 if c == 0 else max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc)
    print(max(dp_0[R-1][C-1], dp_1[R-1][C-1], dp_2[R-1][C-1], dp_3[R-1][C-1])) def main():
    R, C, K = list(map(int, input().split()))
    # dp[r][c][n]: r行目でn個のアイテムを拾う場合の(r, c)でのアイテムの価値の合計の最大
    dp_0 = [[0 for _ in range(C)] for _ in range(R)]
    dp_1 = [[0 for _ in range(C)] for _ in range(R)]
    dp_2 = [[0 for _ in range(C)] for _ in range(R)]
    dp_3 = [[0 for _ in range(C)] for _ in range(R)]
    V = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = list(map(int, input().split()))
        V[r - 1][c - 1] = v
    dp_1[0][0] = V[0][0]
    for r in range(R):
        for c in range(C):
            if r == c == 0:
                continue
            v_rc = V[r][c]
            max_dp_before_row = 0 if r == 0 else max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c])
            # dp[r][c][0]
            v1 = 0 if c == 0 else dp_0[r][c - 1]
            dp_0[r][c] = max(v1, max_dp_before_row)
            # dp[r][c][1]
            v1 = 0 if c == 0 else max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc)
            v2 = 0 if r == 0 else (max_dp_before_row + v_rc)
            dp_1[r][c] = max(v1, v2)
            # dp[r][c][2], dp[r][c][3]
            dp_2[r][c] = 0 if c == 0 else max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc)
            dp_3[r][c] = 0 if c == 0 else max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc)
    print(max(dp_0[R-1][C-1], dp_1[R-1][C-1], dp_2[R-1][C-1], dp_3[R-1][C-1])) main
def main():
    R, C, K = list(map(int, input().split()))
    # dp[r][c][n]: r行目でn個のアイテムを拾う場合の(r, c)でのアイテムの価値の合計の最大
    dp_0 = [[0 for _ in range(C)] for _ in range(R)]
    dp_1 = [[0 for _ in range(C)] for _ in range(R)]
    dp_2 = [[0 for _ in range(C)] for _ in range(R)]
    dp_3 = [[0 for _ in range(C)] for _ in range(R)]
    V = [[0 for _ in range(C)] for _ in range(R)]
    for _ in range(K):
        r, c, v = list(map(int, input().split()))
        V[r - 1][c - 1] = v
    dp_1[0][0] = V[0][0]
    for r in range(R):
        for c in range(C):
            if r == c == 0:
                continue
            v_rc = V[r][c]
            max_dp_before_row = 0 if r == 0 else max(dp_0[r - 1][c], dp_1[r - 1][c], dp_2[r - 1][c], dp_3[r - 1][c])
            # dp[r][c][0]
            v1 = 0 if c == 0 else dp_0[r][c - 1]
            dp_0[r][c] = max(v1, max_dp_before_row)
            # dp[r][c][1]
            v1 = 0 if c == 0 else max(dp_1[r][c - 1], dp_0[r][c - 1] + v_rc)
            v2 = 0 if r == 0 else (max_dp_before_row + v_rc)
            dp_1[r][c] = max(v1, v2)
            # dp[r][c][2], dp[r][c][3]
            dp_2[r][c] = 0 if c == 0 else max(dp_2[r][c - 1], dp_1[r][c - 1] + v_rc)
            dp_3[r][c] = 0 if c == 0 else max(dp_3[r][c - 1], dp_2[r][c - 1] + v_rc)
    print(max(dp_0[R-1][C-1], dp_1[R-1][C-1], dp_2[R-1][C-1], dp_3[R-1][C-1]))


if __name__ == '__main__':
    main()
