import sys
def main():
    input = sys.stdin.readline
    R, C, k = map(int, input().split())
    s = [[0] * (C + 1) for i in range(R + 1)]
    dp = [[[0] * (C + 1) for i in range(R + 1)] for j in range(4)]
    for i in range(k):
        r, c, v = map(int, input().split())
        s[r][c] = v
    for i in range(R):
        for j in range(C):
            m = max(dp[0][i][j + 1], dp[1][i][j + 1], dp[2][i][j + 1], dp[3][i][j + 1])
            for k in range(4):
                if k == 0:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m)
                else:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1])
            dp[1][i + 1][j + 1] = max(dp[1][i + 1][j + 1], s[i + 1][j + 1] + m)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))
if __name__ == "__main__":
    main() import sys sys def main():
    input = sys.stdin.readline
    R, C, k = map(int, input().split())
    s = [[0] * (C + 1) for i in range(R + 1)]
    dp = [[[0] * (C + 1) for i in range(R + 1)] for j in range(4)]
    for i in range(k):
        r, c, v = map(int, input().split())
        s[r][c] = v
    for i in range(R):
        for j in range(C):
            m = max(dp[0][i][j + 1], dp[1][i][j + 1], dp[2][i][j + 1], dp[3][i][j + 1])
            for k in range(4):
                if k == 0:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m)
                else:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1])
            dp[1][i + 1][j + 1] = max(dp[1][i + 1][j + 1], s[i + 1][j + 1] + m)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) main input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 i in range(R + 1) for i in range(R + 1) i range(R + 1) range R + 1 R 1 for i in range(R + 1) [0] * (C + 1) [0] 0 C + 1 C 1 s = [[0] * (C + 1) for i in range(R + 1)] s [[0] * (C + 1) for i in range(R + 1)] [[0] * (C + 1) for i in range(R + 1)] for j in range(4) for j in range(4) j range(4) range 4 for j in range(4) [[0] * (C + 1) for i in range(R + 1)] dp = [[[0] * (C + 1) for i in range(R + 1)] for j in range(4)] dp [[[0] * (C + 1) for i in range(R + 1)] for j in range(4)] 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 for i in range(R):
        for j in range(C):
            m = max(dp[0][i][j + 1], dp[1][i][j + 1], dp[2][i][j + 1], dp[3][i][j + 1])
            for k in range(4):
                if k == 0:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m)
                else:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1])
            dp[1][i + 1][j + 1] = max(dp[1][i + 1][j + 1], s[i + 1][j + 1] + m)
     i range(R) range R for j in range(C):
            m = max(dp[0][i][j + 1], dp[1][i][j + 1], dp[2][i][j + 1], dp[3][i][j + 1])
            for k in range(4):
                if k == 0:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m)
                else:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1])
            dp[1][i + 1][j + 1] = max(dp[1][i + 1][j + 1], s[i + 1][j + 1] + m)
     j range(C) range C m = max(dp[0][i][j + 1], dp[1][i][j + 1], dp[2][i][j + 1], dp[3][i][j + 1]) m max(dp[0][i][j + 1], dp[1][i][j + 1], dp[2][i][j + 1], dp[3][i][j + 1]) max dp[0][i][j + 1] [i] [0] dp 0 i j + 1 j 1 dp[1][i][j + 1] [i] [1] dp 1 i j + 1 j 1 dp[2][i][j + 1] [i] [2] dp 2 i j + 1 j 1 dp[3][i][j + 1] [i] [3] dp 3 i j + 1 j 1 for k in range(4):
                if k == 0:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m)
                else:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1])
             k range(4) range 4 if k == 0:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m)
                else:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1])
             k == 0 k 0 dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m) dp[k][i + 1][j + 1] [i + 1] [k] dp k i + 1 i 1 j + 1 j 1 max(dp[k][i + 1][j], m) max dp[k][i + 1][j] [i + 1] [k] dp k i + 1 i 1 j m dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1]) dp[k][i + 1][j + 1] [i + 1] [k] dp k i + 1 i 1 j + 1 j 1 max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1]) max dp[k][i + 1][j] [i + 1] [k] dp k i + 1 i 1 j dp[k - 1][i + 1][j] + s[i + 1][j + 1] dp[k - 1][i + 1][j] [i + 1] [k - 1] dp k - 1 k 1 i + 1 i 1 j s[i + 1][j + 1] [i + 1] s i + 1 i 1 j + 1 j 1 dp[1][i + 1][j + 1] = max(dp[1][i + 1][j + 1], s[i + 1][j + 1] + m) dp[1][i + 1][j + 1] [i + 1] [1] dp 1 i + 1 i 1 j + 1 j 1 max(dp[1][i + 1][j + 1], s[i + 1][j + 1] + m) max dp[1][i + 1][j + 1] [i + 1] [1] dp 1 i + 1 i 1 j + 1 j 1 s[i + 1][j + 1] + m s[i + 1][j + 1] [i + 1] s i + 1 i 1 j + 1 j 1 m print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) print max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]) max dp[0][R][C] [R] [0] dp 0 R C dp[1][R][C] [R] [1] dp 1 R C dp[2][R][C] [R] [2] dp 2 R C dp[3][R][C] [R] [3] dp 3 R C if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    input = sys.stdin.readline
    R, C, k = map(int, input().split())
    s = [[0] * (C + 1) for i in range(R + 1)]
    dp = [[[0] * (C + 1) for i in range(R + 1)] for j in range(4)]
    for i in range(k):
        r, c, v = map(int, input().split())
        s[r][c] = v
    for i in range(R):
        for j in range(C):
            m = max(dp[0][i][j + 1], dp[1][i][j + 1], dp[2][i][j + 1], dp[3][i][j + 1])
            for k in range(4):
                if k == 0:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m)
                else:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1])
            dp[1][i + 1][j + 1] = max(dp[1][i + 1][j + 1], s[i + 1][j + 1] + m)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) def main():
    input = sys.stdin.readline
    R, C, k = map(int, input().split())
    s = [[0] * (C + 1) for i in range(R + 1)]
    dp = [[[0] * (C + 1) for i in range(R + 1)] for j in range(4)]
    for i in range(k):
        r, c, v = map(int, input().split())
        s[r][c] = v
    for i in range(R):
        for j in range(C):
            m = max(dp[0][i][j + 1], dp[1][i][j + 1], dp[2][i][j + 1], dp[3][i][j + 1])
            for k in range(4):
                if k == 0:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m)
                else:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1])
            dp[1][i + 1][j + 1] = max(dp[1][i + 1][j + 1], s[i + 1][j + 1] + m)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) main
import sys
def main():
    input = sys.stdin.readline
    R, C, k = map(int, input().split())
    s = [[0] * (C + 1) for i in range(R + 1)]
    dp = [[[0] * (C + 1) for i in range(R + 1)] for j in range(4)]
    for i in range(k):
        r, c, v = map(int, input().split())
        s[r][c] = v
    for i in range(R):
        for j in range(C):
            m = max(dp[0][i][j + 1], dp[1][i][j + 1], dp[2][i][j + 1], dp[3][i][j + 1])
            for k in range(4):
                if k == 0:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], m)
                else:
                    dp[k][i + 1][j + 1] = max(dp[k][i + 1][j], dp[k - 1][i + 1][j] + s[i + 1][j + 1])
            dp[1][i + 1][j + 1] = max(dp[1][i + 1][j + 1], s[i + 1][j + 1] + m)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))
if __name__ == "__main__":
    main()
