import sys
input = sys.stdin.readline
def main():
    R, C,K = map(int, input().split())
    dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
    # dp[r][c][j] :=r index c columns already j cnt
    dp[0][0][0] = 0
    D = [[0 for i in range(C+1)] for j in range(R+1)]
    import random
    for i in range(K):
        r, c, v = map(int,input().split())
        D[r][c] = v
    
    for i in range(R+1):
        for j in range(C+1):
            if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    
    ans = max(dp[i][-1][-1] for i in range(4))
    print(ans)
main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    R, C,K = map(int, input().split())
    dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
    # dp[r][c][j] :=r index c columns already j cnt
    dp[0][0][0] = 0
    D = [[0 for i in range(C+1)] for j in range(R+1)]
    import random
    for i in range(K):
        r, c, v = map(int,input().split())
        D[r][c] = v
    
    for i in range(R+1):
        for j in range(C+1):
            if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    
    ans = max(dp[i][-1][-1] for i in range(4))
    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 k in range(R+1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*(C+1) for k in range(R+1)] dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)] dp [[[0]*(C+1) for k in range(R+1)] for _ in range(4)] dp[0][0][0] = 0 dp[0][0][0] [0] [0] dp 0 0 0 0 [0 for i in range(C+1)] for j in range(R+1) for j in range(R+1) j range(R+1) range R+1 R 1 for j in range(R+1) [0 for i in range(C+1)] D = [[0 for i in range(C+1)] for j in range(R+1)] D [[0 for i in range(C+1)] for j in range(R+1)] import random random for i in range(K):
        r, c, v = map(int,input().split())
        D[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 D[r][c] = v D[r][c] [r] D r c v for i in range(R+1):
        for j in range(C+1):
            if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    
     i range(R+1) range R+1 R 1 for j in range(C+1):
            if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    
     j range(C+1) range C+1 C 1 if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    
     D[i][j] > 0 D[i][j] [i] D i j 0 v = D[i][j] v D[i][j] [i] D i j M = max(dp[k][i-1][j] for k in range(4)) M max(dp[k][i-1][j] for k in range(4)) max dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j dp[0][i][j] = max(dp[0][i][j-1], M) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j-1], M) max dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 M dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v) dp[1][i][j] [i] [1] dp 1 i j max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v) max dp[0][i][j-1]+v dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 v dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 M+v M v dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1]) dp[2][i][j] [i] [2] dp 2 i j max(dp[1][i][j-1]+v, dp[2][i][j-1]) max dp[1][i][j-1]+v dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 v dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1]) dp[3][i][j] [i] [3] dp 3 i j max(dp[2][i][j-1]+v, dp[3][i][j-1]) max dp[2][i][j-1]+v dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 v dp[3][i][j-1] [i] [3] dp 3 i j-1 j 1 M = max(dp[k][i-1][j] for k in range(4)) M max(dp[k][i-1][j] for k in range(4)) max dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j dp[0][i][j] = max(dp[0][i][j-1], M) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j-1], M) max dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 M dp[1][i][j] = dp[1][i][j-1] dp[1][i][j] [i] [1] dp 1 i j dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 dp[2][i][j] = dp[2][i][j-1] dp[2][i][j] [i] [2] dp 2 i j dp[2][i][j-1] [i] [2] dp 2 i j-1 j 1 dp[3][i][j] = dp[3][i][j-1] dp[3][i][j] [i] [3] dp 3 i j dp[3][i][j-1] [i] [3] dp 3 i j-1 j 1 ans = max(dp[i][-1][-1] for i in range(4)) ans max(dp[i][-1][-1] for i in range(4)) max dp[i][-1][-1] [-1] [i] dp i -1 -1 print(ans) print ans main() main input = sys.stdin.readline sys.stdin.readline input def main():
    R, C,K = map(int, input().split())
    dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
    # dp[r][c][j] :=r index c columns already j cnt
    dp[0][0][0] = 0
    D = [[0 for i in range(C+1)] for j in range(R+1)]
    import random
    for i in range(K):
        r, c, v = map(int,input().split())
        D[r][c] = v
    
    for i in range(R+1):
        for j in range(C+1):
            if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    
    ans = max(dp[i][-1][-1] for i in range(4))
    print(ans) def main():
    R, C,K = map(int, input().split())
    dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
    # dp[r][c][j] :=r index c columns already j cnt
    dp[0][0][0] = 0
    D = [[0 for i in range(C+1)] for j in range(R+1)]
    import random
    for i in range(K):
        r, c, v = map(int,input().split())
        D[r][c] = v
    
    for i in range(R+1):
        for j in range(C+1):
            if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    
    ans = max(dp[i][-1][-1] for i in range(4))
    print(ans) main
import sys
input = sys.stdin.readline
def main():
    R, C,K = map(int, input().split())
    dp = [[[0]*(C+1) for k in range(R+1)] for _ in range(4)]
    # dp[r][c][j] :=r index c columns already j cnt
    dp[0][0][0] = 0
    D = [[0 for i in range(C+1)] for j in range(R+1)]
    import random
    for i in range(K):
        r, c, v = map(int,input().split())
        D[r][c] = v
    
    for i in range(R+1):
        for j in range(C+1):
            if D[i][j] > 0:
                v = D[i][j]
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = max(dp[0][i][j-1]+v, dp[1][i][j-1], M+v)
                dp[2][i][j] = max(dp[1][i][j-1]+v, dp[2][i][j-1])
                dp[3][i][j] = max(dp[2][i][j-1]+v, dp[3][i][j-1])
    
            else:
                M = max(dp[k][i-1][j] for k in range(4))
                dp[0][i][j] = max(dp[0][i][j-1], M)
                dp[1][i][j] = dp[1][i][j-1]
                dp[2][i][j] = dp[2][i][j-1]
                dp[3][i][j] = dp[3][i][j-1]
    
    
    ans = max(dp[i][-1][-1] for i in range(4))
    print(ans)
main()