import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

if __file__=="test.py":
    f = open("./in_out/input.txt", "r", encoding="utf-8")
    read = f.read
    readline = f.readline

def main():
    R, C, K = map(int, readline().split())
    
    L_INF = int(1e17)
    dp = [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
    cell = [[0 for _ in range(C+1)] for _ in range(R+1)]
    
    for i in range(K):
        x, y, c = map(int, readline().split())
        cell[x-1][y-1] = c
    
    dp[0][0][1] = dp[0][1][0] = 0
    
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
                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] + cell[i-1][j-1])
                if k == 1:
                    dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
 
    print(dp[3][R][C])

if __name__ == "__main__":
    main() import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline if __file__=="test.py":
    f = open("./in_out/input.txt", "r", encoding="utf-8")
    read = f.read
    readline = f.readline __file__=="test.py" __file__ "test.py" f = open("./in_out/input.txt", "r", encoding="utf-8") f open("./in_out/input.txt", "r", encoding="utf-8") open "./in_out/input.txt" "r" encoding="utf-8" encoding "utf-8" read = f.read read f.read f read readline = f.readline readline f.readline f readline def main():
    R, C, K = map(int, readline().split())
    
    L_INF = int(1e17)
    dp = [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
    cell = [[0 for _ in range(C+1)] for _ in range(R+1)]
    
    for i in range(K):
        x, y, c = map(int, readline().split())
        cell[x-1][y-1] = c
    
    dp[0][0][1] = dp[0][1][0] = 0
    
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
                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] + cell[i-1][j-1])
                if k == 1:
                    dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
 
    print(dp[3][R][C]) main R, C, K = map(int, readline().split()) R map(int, readline().split()) map int readline().split() ().split () readline split C K L_INF = int(1e17) L_INF int(1e17) int 1e17 [[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[-L_INF for _ in range(C+1)] for _ in range(R+1)] dp = [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] dp [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)] [0 for _ in range(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 for _ in range(C+1)] cell = [[0 for _ in range(C+1)] for _ in range(R+1)] cell [[0 for _ in range(C+1)] for _ in range(R+1)] for i in range(K):
        x, y, c = map(int, readline().split())
        cell[x-1][y-1] = c
    
     i range(K) range K x, y, c = map(int, readline().split()) x map(int, readline().split()) map int readline().split() ().split () readline split y c cell[x-1][y-1] = c cell[x-1][y-1] [x-1] cell x-1 x 1 y-1 y 1 c dp[0][0][1] = dp[0][1][0] = 0 dp[0][0][1] [0] [0] dp 0 0 1 0 = dp[0][1][0] = 0 dp[0][1][0] [1] [0] dp 0 1 0 0 for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
                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] + cell[i-1][j-1])
                if k == 1:
                    dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
 
     i range(1, R + 1) range 1 R + 1 R 1 for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
                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] + cell[i-1][j-1])
                if k == 1:
                    dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
 
     j range(1, C + 1) range 1 C + 1 C 1 for k in range(4):
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
                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] + cell[i-1][j-1])
                if k == 1:
                    dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
 
     k range(4) range 4 if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
                 k > 0 k 0 dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k-1][i][j]) max dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j] [i] [k-1] dp k-1 k 1 i j 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] + cell[i-1][j-1])
                 k > 0 k 0 dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j-1] + cell[i-1][j-1]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k-1][i][j-1] + cell[i-1][j-1]) max dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j-1] + cell[i-1][j-1] dp[k-1][i][j-1] [i] [k-1] dp k-1 k 1 i j-1 j 1 cell[i-1][j-1] [i-1] cell i-1 i 1 j-1 j 1 if k == 1:
                    dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
 
     k == 1 k 1 dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1]) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1]) max dp[1][i][j] [i] [1] dp 1 i j dp[3][i-1][j] + cell[i-1][j-1] dp[3][i-1][j] [i-1] [3] dp 3 i-1 i 1 j cell[i-1][j-1] [i-1] cell i-1 i 1 j-1 j 1 print(dp[3][R][C]) print dp[3][R][C] [R] [3] dp 3 R C if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    R, C, K = map(int, readline().split())
    
    L_INF = int(1e17)
    dp = [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
    cell = [[0 for _ in range(C+1)] for _ in range(R+1)]
    
    for i in range(K):
        x, y, c = map(int, readline().split())
        cell[x-1][y-1] = c
    
    dp[0][0][1] = dp[0][1][0] = 0
    
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
                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] + cell[i-1][j-1])
                if k == 1:
                    dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
 
    print(dp[3][R][C]) def main():
    R, C, K = map(int, readline().split())
    
    L_INF = int(1e17)
    dp = [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
    cell = [[0 for _ in range(C+1)] for _ in range(R+1)]
    
    for i in range(K):
        x, y, c = map(int, readline().split())
        cell[x-1][y-1] = c
    
    dp[0][0][1] = dp[0][1][0] = 0
    
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
                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] + cell[i-1][j-1])
                if k == 1:
                    dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
 
    print(dp[3][R][C]) main readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline read = f.read f.read read readline = f.readline f.readline readline read = sys.stdin.buffer.read sys.stdin.buffer.read read f = open("./in_out/input.txt", "r", encoding="utf-8") open("./in_out/input.txt", "r", encoding="utf-8") f
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

if __file__=="test.py":
    f = open("./in_out/input.txt", "r", encoding="utf-8")
    read = f.read
    readline = f.readline

def main():
    R, C, K = map(int, readline().split())
    
    L_INF = int(1e17)
    dp = [[[-L_INF for _ in range(C+1)] for _ in range(R+1)] for _ in range(4)]
    cell = [[0 for _ in range(C+1)] for _ in range(R+1)]
    
    for i in range(K):
        x, y, c = map(int, readline().split())
        cell[x-1][y-1] = c
    
    dp[0][0][1] = dp[0][1][0] = 0
    
    for i in range(1, R + 1):
        for j in range(1, C + 1):
            for k in range(4):
                if k > 0:
                    dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j])
                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] + cell[i-1][j-1])
                if k == 1:
                    dp[1][i][j] = max(dp[1][i][j], dp[3][i-1][j] + cell[i-1][j-1])
 
    print(dp[3][R][C])

if __name__ == "__main__":
    main()
