import sys
input = sys.stdin.readline
H, W, K = map(int, input().split())
mat = [[0]*W for i in range(H)]

for i in range(K):
    r, c, v = map(int, input().split())
    r, c = r-1, c-1
    mat[r][c] = v

dp0 = [[-1 for i in range(W)] for i in range(H)]
dp1 = [[-1 for i in range(W)] for i in range(H)]
dp2 = [[-1 for i in range(W)] for i in range(H)]
dp3 = [[-1 for i in range(W)] for i in range(H)]

dp0[0][0] = 0
if mat[0][0] != 0:
    dp1[0][0] = mat[0][0]

for i in range(H):
    for j in range(W):
        m = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j])
        if i+1 < H:
            dp1[i+1][j] = max(dp1[i+1][j], m+mat[i+1][j])
            dp0[i+1][j] = max(dp0[i+1][j], m)
        if j+1 < W:
            dp0[i][j+1] = 0
            dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j], dp0[i][j]+mat[i][j+1])
            dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j], dp1[i][j]+mat[i][j+1])
            dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j], dp2[i][j]+mat[i][j+1])

print(max(dp0[H-1][W-1], dp1[H-1][W-1], dp2[H-1][W-1], dp3[H-1][W-1])) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline H, W, K = map(int, input().split()) H map(int, input().split()) map int input().split() ().split () input split W K [0]*W for i in range(H) for i in range(H) i range(H) range H for i in range(H) [0]*W [0] 0 W mat = [[0]*W for i in range(H)] mat [[0]*W for i in range(H)] for i in range(K):
    r, c, v = map(int, input().split())
    r, c = r-1, c-1
    mat[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 r, c = r-1, c-1 r r-1 r 1 c c-1 c 1 mat[r][c] = v mat[r][c] [r] mat r c v [-1 for i in range(W)] for i in range(H) for i in range(H) i range(H) range H for i in range(H) [-1 for i in range(W)] dp0 = [[-1 for i in range(W)] for i in range(H)] dp0 [[-1 for i in range(W)] for i in range(H)] [-1 for i in range(W)] for i in range(H) for i in range(H) i range(H) range H for i in range(H) [-1 for i in range(W)] dp1 = [[-1 for i in range(W)] for i in range(H)] dp1 [[-1 for i in range(W)] for i in range(H)] [-1 for i in range(W)] for i in range(H) for i in range(H) i range(H) range H for i in range(H) [-1 for i in range(W)] dp2 = [[-1 for i in range(W)] for i in range(H)] dp2 [[-1 for i in range(W)] for i in range(H)] [-1 for i in range(W)] for i in range(H) for i in range(H) i range(H) range H for i in range(H) [-1 for i in range(W)] dp3 = [[-1 for i in range(W)] for i in range(H)] dp3 [[-1 for i in range(W)] for i in range(H)] dp0[0][0] = 0 dp0[0][0] [0] dp0 0 0 0 if mat[0][0] != 0:
    dp1[0][0] = mat[0][0] mat[0][0] != 0 mat[0][0] [0] mat 0 0 0 dp1[0][0] = mat[0][0] dp1[0][0] [0] dp1 0 0 mat[0][0] [0] mat 0 0 for i in range(H):
    for j in range(W):
        m = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j])
        if i+1 < H:
            dp1[i+1][j] = max(dp1[i+1][j], m+mat[i+1][j])
            dp0[i+1][j] = max(dp0[i+1][j], m)
        if j+1 < W:
            dp0[i][j+1] = 0
            dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j], dp0[i][j]+mat[i][j+1])
            dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j], dp1[i][j]+mat[i][j+1])
            dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j], dp2[i][j]+mat[i][j+1]) i range(H) range H for j in range(W):
        m = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j])
        if i+1 < H:
            dp1[i+1][j] = max(dp1[i+1][j], m+mat[i+1][j])
            dp0[i+1][j] = max(dp0[i+1][j], m)
        if j+1 < W:
            dp0[i][j+1] = 0
            dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j], dp0[i][j]+mat[i][j+1])
            dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j], dp1[i][j]+mat[i][j+1])
            dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j], dp2[i][j]+mat[i][j+1]) j range(W) range W m = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j]) m max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j]) max dp0[i][j] [i] dp0 i j dp1[i][j] [i] dp1 i j dp2[i][j] [i] dp2 i j dp3[i][j] [i] dp3 i j if i+1 < H:
            dp1[i+1][j] = max(dp1[i+1][j], m+mat[i+1][j])
            dp0[i+1][j] = max(dp0[i+1][j], m)
         i+1 < H i+1 i 1 H dp1[i+1][j] = max(dp1[i+1][j], m+mat[i+1][j]) dp1[i+1][j] [i+1] dp1 i+1 i 1 j max(dp1[i+1][j], m+mat[i+1][j]) max dp1[i+1][j] [i+1] dp1 i+1 i 1 j m+mat[i+1][j] m mat[i+1][j] [i+1] mat i+1 i 1 j dp0[i+1][j] = max(dp0[i+1][j], m) dp0[i+1][j] [i+1] dp0 i+1 i 1 j max(dp0[i+1][j], m) max dp0[i+1][j] [i+1] dp0 i+1 i 1 j m if j+1 < W:
            dp0[i][j+1] = 0
            dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j], dp0[i][j]+mat[i][j+1])
            dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j], dp1[i][j]+mat[i][j+1])
            dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j], dp2[i][j]+mat[i][j+1]) j+1 < W j+1 j 1 W dp0[i][j+1] = 0 dp0[i][j+1] [i] dp0 i j+1 j 1 0 dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j], dp0[i][j]+mat[i][j+1]) dp1[i][j+1] [i] dp1 i j+1 j 1 max(dp1[i][j+1], dp1[i][j], dp0[i][j]+mat[i][j+1]) max dp1[i][j+1] [i] dp1 i j+1 j 1 dp1[i][j] [i] dp1 i j dp0[i][j]+mat[i][j+1] dp0[i][j] [i] dp0 i j mat[i][j+1] [i] mat i j+1 j 1 dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j], dp1[i][j]+mat[i][j+1]) dp2[i][j+1] [i] dp2 i j+1 j 1 max(dp2[i][j+1], dp2[i][j], dp1[i][j]+mat[i][j+1]) max dp2[i][j+1] [i] dp2 i j+1 j 1 dp2[i][j] [i] dp2 i j dp1[i][j]+mat[i][j+1] dp1[i][j] [i] dp1 i j mat[i][j+1] [i] mat i j+1 j 1 dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j], dp2[i][j]+mat[i][j+1]) dp3[i][j+1] [i] dp3 i j+1 j 1 max(dp3[i][j+1], dp3[i][j], dp2[i][j]+mat[i][j+1]) max dp3[i][j+1] [i] dp3 i j+1 j 1 dp3[i][j] [i] dp3 i j dp2[i][j]+mat[i][j+1] dp2[i][j] [i] dp2 i j mat[i][j+1] [i] mat i j+1 j 1 print(max(dp0[H-1][W-1], dp1[H-1][W-1], dp2[H-1][W-1], dp3[H-1][W-1])) print max(dp0[H-1][W-1], dp1[H-1][W-1], dp2[H-1][W-1], dp3[H-1][W-1]) max dp0[H-1][W-1] [H-1] dp0 H-1 H 1 W-1 W 1 dp1[H-1][W-1] [H-1] dp1 H-1 H 1 W-1 W 1 dp2[H-1][W-1] [H-1] dp2 H-1 H 1 W-1 W 1 dp3[H-1][W-1] [H-1] dp3 H-1 H 1 W-1 W 1 H, W, K = map(int, input().split()) map(int, input().split()) H c, v = map(int, input().split()) map(int, input().split()) c input = sys.stdin.readline sys.stdin.readline input dp0 = [[-1 for i in range(W)] for i in range(H)] [[-1 for i in range(W)] for i in range(H)] dp0 dp1 = [[-1 for i in range(W)] for i in range(H)] [[-1 for i in range(W)] for i in range(H)] dp1 W, K = map(int, input().split()) map(int, input().split()) W r, c = r-1, c-1 r-1 r v = map(int, input().split()) map(int, input().split()) v K = map(int, input().split()) map(int, input().split()) K r, c, v = map(int, input().split()) map(int, input().split()) r dp3 = [[-1 for i in range(W)] for i in range(H)] [[-1 for i in range(W)] for i in range(H)] dp3 m = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j]) max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j]) m c = r-1, c-1 c-1 c mat = [[0]*W for i in range(H)] [[0]*W for i in range(H)] mat dp2 = [[-1 for i in range(W)] for i in range(H)] [[-1 for i in range(W)] for i in range(H)] dp2
import sys
input = sys.stdin.readline
H, W, K = map(int, input().split())
mat = [[0]*W for i in range(H)]

for i in range(K):
    r, c, v = map(int, input().split())
    r, c = r-1, c-1
    mat[r][c] = v

dp0 = [[-1 for i in range(W)] for i in range(H)]
dp1 = [[-1 for i in range(W)] for i in range(H)]
dp2 = [[-1 for i in range(W)] for i in range(H)]
dp3 = [[-1 for i in range(W)] for i in range(H)]

dp0[0][0] = 0
if mat[0][0] != 0:
    dp1[0][0] = mat[0][0]

for i in range(H):
    for j in range(W):
        m = max(dp0[i][j], dp1[i][j], dp2[i][j], dp3[i][j])
        if i+1 < H:
            dp1[i+1][j] = max(dp1[i+1][j], m+mat[i+1][j])
            dp0[i+1][j] = max(dp0[i+1][j], m)
        if j+1 < W:
            dp0[i][j+1] = 0
            dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j], dp0[i][j]+mat[i][j+1])
            dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j], dp1[i][j]+mat[i][j+1])
            dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j], dp2[i][j]+mat[i][j+1])

print(max(dp0[H-1][W-1], dp1[H-1][W-1], dp2[H-1][W-1], dp3[H-1][W-1]))
