#!/usr/bin/env python3

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

    dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

    for i in range(1,R+1):
        for j in range(1,C+1):
            V = S[i][j]
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])# アイテムを取らないで下に進む
                dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V)# アイテムを取って下に進む
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])# アイテムを取らないで右に進む
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
    ans = 0
    for k in range(4):
        ans = max(ans, dp[k][R][C])
    print(ans)

if __name__ == "__main__":
    main() def main():
    R, C, K = map(int, input().split())
    S = [[0]*(C+1) for _ in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().split())
        S[r][c] = v

    dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

    for i in range(1,R+1):
        for j in range(1,C+1):
            V = S[i][j]
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])# アイテムを取らないで下に進む
                dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V)# アイテムを取って下に進む
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])# アイテムを取らないで右に進む
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
    ans = 0
    for k in range(4):
        ans = max(ans, dp[k][R][C])
    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]*(C+1) for _ in range(R+1) for _ in range(R+1) _ range(R+1) range R+1 R 1 for _ in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 S = [[0]*(C+1) for _ in range(R+1)] S [[0]*(C+1) for _ in range(R+1)] for i in range(K):
        r, c, v = map(int, input().split())
        S[r][c] = v

     i 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 S[r][c] = v S[r][c] [r] S r c v [[0]*(C+1) for _ in range(R+1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*(C+1) for _ in range(R+1)] dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] dp [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] for i in range(1,R+1):
        for j in range(1,C+1):
            V = S[i][j]
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])# アイテムを取らないで下に進む
                dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V)# アイテムを取って下に進む
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])# アイテムを取らないで右に進む
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
     i range(1,R+1) range 1 R+1 R 1 for j in range(1,C+1):
            V = S[i][j]
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])# アイテムを取らないで下に進む
                dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V)# アイテムを取って下に進む
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])# アイテムを取らないで右に進む
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
     j range(1,C+1) range 1 C+1 C 1 V = S[i][j] V S[i][j] [i] S i j for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])# アイテムを取らないで下に進む
                dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V)# アイテムを取って下に進む
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])# アイテムを取らないで右に進む
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
     k range(4) range 4 dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j]) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j], dp[k][i-1][j]) max dp[0][i][j] [i] [0] dp 0 i j dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j], dp[k][i-1][j] + V) max dp[1][i][j] [i] [1] dp 1 i j dp[k][i-1][j] + V dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j V dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k][i][j-1]) max dp[k][i][j] [i] [k] dp k i j dp[k][i][j-1] [i] [k] dp k i j-1 j 1 if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
     k > 0 k 0 dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k-1][i][j-1] + V) max dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j-1] + V dp[k-1][i][j-1] [i] [k-1] dp k-1 k 1 i j-1 j 1 V ans = 0 ans 0 for k in range(4):
        ans = max(ans, dp[k][R][C])
     k range(4) range 4 ans = max(ans, dp[k][R][C]) ans max(ans, dp[k][R][C]) max ans dp[k][R][C] [R] [k] dp k R C print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    R, C, K = map(int, input().split())
    S = [[0]*(C+1) for _ in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().split())
        S[r][c] = v

    dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

    for i in range(1,R+1):
        for j in range(1,C+1):
            V = S[i][j]
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])# アイテムを取らないで下に進む
                dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V)# アイテムを取って下に進む
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])# アイテムを取らないで右に進む
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
    ans = 0
    for k in range(4):
        ans = max(ans, dp[k][R][C])
    print(ans) def main():
    R, C, K = map(int, input().split())
    S = [[0]*(C+1) for _ in range(R+1)]
    for i in range(K):
        r, c, v = map(int, input().split())
        S[r][c] = v

    dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

    for i in range(1,R+1):
        for j in range(1,C+1):
            V = S[i][j]
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])# アイテムを取らないで下に進む
                dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V)# アイテムを取って下に進む
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])# アイテムを取らないで右に進む
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
    ans = 0
    for k in range(4):
        ans = max(ans, dp[k][R][C])
    print(ans) main
#!/usr/bin/env python3

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

    dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

    for i in range(1,R+1):
        for j in range(1,C+1):
            V = S[i][j]
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])# アイテムを取らないで下に進む
                dp[1][i][j] = max(dp[1][i][j], dp[k][i-1][j] + V)# アイテムを取って下に進む
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])# アイテムを取らないで右に進む
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + V)# アイテムを取って右に進む
    ans = 0
    for k in range(4):
        ans = max(ans, dp[k][R][C])
    print(ans)

if __name__ == "__main__":
    main()