R , C , K = map(int,input().split())
masu = [[0 for i in range(C)] for j in range(R)]
for i in range(K):
    r , c , v = map(int,input().split())
    masu[r-1][c-1] = v

dp0 = [[0 for i in range(C)] for j in range(R)]
dp1 = [[0 for i in range(C)] for j in range(R)]
dp2 = [[0 for i in range(C)] for j in range(R)] 
dp3 = [[0 for i in range(C)] for j in range(R)]

if masu[0][0] != 0:
    dp1[0][0] = masu[0][0]
for i in range(1,C):
    dp0[0][i] = max(dp0[0][i],dp0[0][i-1])
    dp1[0][i] = max(dp1[0][i],dp1[0][i-1])
    dp2[0][i] = max(dp2[0][i],dp2[0][i-1])
    dp3[0][i] = max(dp3[0][i],dp3[0][i-1])
    if masu[0][i] != 0:
        dp3[0][i] = max(dp3[0][i],dp2[0][i]+masu[0][i])
        dp2[0][i] = max(dp2[0][i],dp1[0][i]+masu[0][i])
        dp1[0][i] = max(dp1[0][i],dp0[0][i]+masu[0][i])




for i in range(1,R):
    for j in range(C):
        dp0[i][j] = max(dp0[i][j],dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j])
        if j != 0:
            dp0[i][j] = max(dp0[i][j],dp0[i][j-1])
            dp1[i][j] = max(dp1[i][j],dp1[i][j-1])
            dp2[i][j] = max(dp2[i][j],dp2[i][j-1])
            dp3[i][j] = max(dp3[i][j],dp3[i][j-1])
        if masu[i][j] != 0:
            dp3[i][j] = max(dp3[i][j],dp2[i][j]+masu[i][j])
            dp2[i][j] = max(dp2[i][j],dp1[i][j]+masu[i][j])
            dp1[i][j] = max(dp1[i][j],dp0[i][j]+masu[i][j])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1])) R , C , K = map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [0 for i in range(C)] for j in range(R) for j in range(R) j range(R) range R for j in range(R) [0 for i in range(C)] masu = [[0 for i in range(C)] for j in range(R)] masu [[0 for i in range(C)] for j in range(R)] for i in range(K):
    r , c , v = map(int,input().split())
    masu[r-1][c-1] = 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 masu[r-1][c-1] = v masu[r-1][c-1] [r-1] masu r-1 r 1 c-1 c 1 v [0 for i in range(C)] for j in range(R) for j in range(R) j range(R) range R for j in range(R) [0 for i in range(C)] dp0 = [[0 for i in range(C)] for j in range(R)] dp0 [[0 for i in range(C)] for j in range(R)] [0 for i in range(C)] for j in range(R) for j in range(R) j range(R) range R for j in range(R) [0 for i in range(C)] dp1 = [[0 for i in range(C)] for j in range(R)] dp1 [[0 for i in range(C)] for j in range(R)] [0 for i in range(C)] for j in range(R) for j in range(R) j range(R) range R for j in range(R) [0 for i in range(C)] dp2 = [[0 for i in range(C)] for j in range(R)] dp2 [[0 for i in range(C)] for j in range(R)] [0 for i in range(C)] for j in range(R) for j in range(R) j range(R) range R for j in range(R) [0 for i in range(C)] dp3 = [[0 for i in range(C)] for j in range(R)] dp3 [[0 for i in range(C)] for j in range(R)] if masu[0][0] != 0:
    dp1[0][0] = masu[0][0] masu[0][0] != 0 masu[0][0] [0] masu 0 0 0 dp1[0][0] = masu[0][0] dp1[0][0] [0] dp1 0 0 masu[0][0] [0] masu 0 0 for i in range(1,C):
    dp0[0][i] = max(dp0[0][i],dp0[0][i-1])
    dp1[0][i] = max(dp1[0][i],dp1[0][i-1])
    dp2[0][i] = max(dp2[0][i],dp2[0][i-1])
    dp3[0][i] = max(dp3[0][i],dp3[0][i-1])
    if masu[0][i] != 0:
        dp3[0][i] = max(dp3[0][i],dp2[0][i]+masu[0][i])
        dp2[0][i] = max(dp2[0][i],dp1[0][i]+masu[0][i])
        dp1[0][i] = max(dp1[0][i],dp0[0][i]+masu[0][i]) i range(1,C) range 1 C dp0[0][i] = max(dp0[0][i],dp0[0][i-1]) dp0[0][i] [0] dp0 0 i max(dp0[0][i],dp0[0][i-1]) max dp0[0][i] [0] dp0 0 i dp0[0][i-1] [0] dp0 0 i-1 i 1 dp1[0][i] = max(dp1[0][i],dp1[0][i-1]) dp1[0][i] [0] dp1 0 i max(dp1[0][i],dp1[0][i-1]) max dp1[0][i] [0] dp1 0 i dp1[0][i-1] [0] dp1 0 i-1 i 1 dp2[0][i] = max(dp2[0][i],dp2[0][i-1]) dp2[0][i] [0] dp2 0 i max(dp2[0][i],dp2[0][i-1]) max dp2[0][i] [0] dp2 0 i dp2[0][i-1] [0] dp2 0 i-1 i 1 dp3[0][i] = max(dp3[0][i],dp3[0][i-1]) dp3[0][i] [0] dp3 0 i max(dp3[0][i],dp3[0][i-1]) max dp3[0][i] [0] dp3 0 i dp3[0][i-1] [0] dp3 0 i-1 i 1 if masu[0][i] != 0:
        dp3[0][i] = max(dp3[0][i],dp2[0][i]+masu[0][i])
        dp2[0][i] = max(dp2[0][i],dp1[0][i]+masu[0][i])
        dp1[0][i] = max(dp1[0][i],dp0[0][i]+masu[0][i]) masu[0][i] != 0 masu[0][i] [0] masu 0 i 0 dp3[0][i] = max(dp3[0][i],dp2[0][i]+masu[0][i]) dp3[0][i] [0] dp3 0 i max(dp3[0][i],dp2[0][i]+masu[0][i]) max dp3[0][i] [0] dp3 0 i dp2[0][i]+masu[0][i] dp2[0][i] [0] dp2 0 i masu[0][i] [0] masu 0 i dp2[0][i] = max(dp2[0][i],dp1[0][i]+masu[0][i]) dp2[0][i] [0] dp2 0 i max(dp2[0][i],dp1[0][i]+masu[0][i]) max dp2[0][i] [0] dp2 0 i dp1[0][i]+masu[0][i] dp1[0][i] [0] dp1 0 i masu[0][i] [0] masu 0 i dp1[0][i] = max(dp1[0][i],dp0[0][i]+masu[0][i]) dp1[0][i] [0] dp1 0 i max(dp1[0][i],dp0[0][i]+masu[0][i]) max dp1[0][i] [0] dp1 0 i dp0[0][i]+masu[0][i] dp0[0][i] [0] dp0 0 i masu[0][i] [0] masu 0 i for i in range(1,R):
    for j in range(C):
        dp0[i][j] = max(dp0[i][j],dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j])
        if j != 0:
            dp0[i][j] = max(dp0[i][j],dp0[i][j-1])
            dp1[i][j] = max(dp1[i][j],dp1[i][j-1])
            dp2[i][j] = max(dp2[i][j],dp2[i][j-1])
            dp3[i][j] = max(dp3[i][j],dp3[i][j-1])
        if masu[i][j] != 0:
            dp3[i][j] = max(dp3[i][j],dp2[i][j]+masu[i][j])
            dp2[i][j] = max(dp2[i][j],dp1[i][j]+masu[i][j])
            dp1[i][j] = max(dp1[i][j],dp0[i][j]+masu[i][j]) i range(1,R) range 1 R for j in range(C):
        dp0[i][j] = max(dp0[i][j],dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j])
        if j != 0:
            dp0[i][j] = max(dp0[i][j],dp0[i][j-1])
            dp1[i][j] = max(dp1[i][j],dp1[i][j-1])
            dp2[i][j] = max(dp2[i][j],dp2[i][j-1])
            dp3[i][j] = max(dp3[i][j],dp3[i][j-1])
        if masu[i][j] != 0:
            dp3[i][j] = max(dp3[i][j],dp2[i][j]+masu[i][j])
            dp2[i][j] = max(dp2[i][j],dp1[i][j]+masu[i][j])
            dp1[i][j] = max(dp1[i][j],dp0[i][j]+masu[i][j]) j range(C) range C dp0[i][j] = max(dp0[i][j],dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j]) dp0[i][j] [i] dp0 i j max(dp0[i][j],dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j]) max dp0[i][j] [i] dp0 i j dp0[i-1][j] [i-1] dp0 i-1 i 1 j dp1[i-1][j] [i-1] dp1 i-1 i 1 j dp2[i-1][j] [i-1] dp2 i-1 i 1 j dp3[i-1][j] [i-1] dp3 i-1 i 1 j if j != 0:
            dp0[i][j] = max(dp0[i][j],dp0[i][j-1])
            dp1[i][j] = max(dp1[i][j],dp1[i][j-1])
            dp2[i][j] = max(dp2[i][j],dp2[i][j-1])
            dp3[i][j] = max(dp3[i][j],dp3[i][j-1])
         j != 0 j 0 dp0[i][j] = max(dp0[i][j],dp0[i][j-1]) dp0[i][j] [i] dp0 i j max(dp0[i][j],dp0[i][j-1]) max dp0[i][j] [i] dp0 i j dp0[i][j-1] [i] dp0 i j-1 j 1 dp1[i][j] = max(dp1[i][j],dp1[i][j-1]) dp1[i][j] [i] dp1 i j max(dp1[i][j],dp1[i][j-1]) max dp1[i][j] [i] dp1 i j dp1[i][j-1] [i] dp1 i j-1 j 1 dp2[i][j] = max(dp2[i][j],dp2[i][j-1]) dp2[i][j] [i] dp2 i j max(dp2[i][j],dp2[i][j-1]) max dp2[i][j] [i] dp2 i j dp2[i][j-1] [i] dp2 i j-1 j 1 dp3[i][j] = max(dp3[i][j],dp3[i][j-1]) dp3[i][j] [i] dp3 i j max(dp3[i][j],dp3[i][j-1]) max dp3[i][j] [i] dp3 i j dp3[i][j-1] [i] dp3 i j-1 j 1 if masu[i][j] != 0:
            dp3[i][j] = max(dp3[i][j],dp2[i][j]+masu[i][j])
            dp2[i][j] = max(dp2[i][j],dp1[i][j]+masu[i][j])
            dp1[i][j] = max(dp1[i][j],dp0[i][j]+masu[i][j]) masu[i][j] != 0 masu[i][j] [i] masu i j 0 dp3[i][j] = max(dp3[i][j],dp2[i][j]+masu[i][j]) dp3[i][j] [i] dp3 i j max(dp3[i][j],dp2[i][j]+masu[i][j]) max dp3[i][j] [i] dp3 i j dp2[i][j]+masu[i][j] dp2[i][j] [i] dp2 i j masu[i][j] [i] masu i j dp2[i][j] = max(dp2[i][j],dp1[i][j]+masu[i][j]) dp2[i][j] [i] dp2 i j max(dp2[i][j],dp1[i][j]+masu[i][j]) max dp2[i][j] [i] dp2 i j dp1[i][j]+masu[i][j] dp1[i][j] [i] dp1 i j masu[i][j] [i] masu i j dp1[i][j] = max(dp1[i][j],dp0[i][j]+masu[i][j]) dp1[i][j] [i] dp1 i j max(dp1[i][j],dp0[i][j]+masu[i][j]) max dp1[i][j] [i] dp1 i j dp0[i][j]+masu[i][j] dp0[i][j] [i] dp0 i j masu[i][j] [i] masu i j print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1])) print max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]) max dp0[-1][-1] [-1] dp0 -1 -1 dp1[-1][-1] [-1] dp1 -1 -1 dp2[-1][-1] [-1] dp2 -1 -1 dp3[-1][-1] [-1] dp3 -1 -1 R , C , K = map(int,input().split()) map(int,input().split()) R masu = [[0 for i in range(C)] for j in range(R)] [[0 for i in range(C)] for j in range(R)] masu K = map(int,input().split()) map(int,input().split()) K dp2 = [[0 for i in range(C)] for j in range(R)] [[0 for i in range(C)] for j in range(R)] dp2 dp1 = [[0 for i in range(C)] for j in range(R)] [[0 for i in range(C)] for j in range(R)] dp1 v = map(int,input().split()) map(int,input().split()) v dp0 = [[0 for i in range(C)] for j in range(R)] [[0 for i in range(C)] for j in range(R)] dp0 C , K = map(int,input().split()) map(int,input().split()) C c , v = map(int,input().split()) map(int,input().split()) c r , c , v = map(int,input().split()) map(int,input().split()) r dp3 = [[0 for i in range(C)] for j in range(R)] [[0 for i in range(C)] for j in range(R)] dp3
R , C , K = map(int,input().split())
masu = [[0 for i in range(C)] for j in range(R)]
for i in range(K):
    r , c , v = map(int,input().split())
    masu[r-1][c-1] = v

dp0 = [[0 for i in range(C)] for j in range(R)]
dp1 = [[0 for i in range(C)] for j in range(R)]
dp2 = [[0 for i in range(C)] for j in range(R)] 
dp3 = [[0 for i in range(C)] for j in range(R)]

if masu[0][0] != 0:
    dp1[0][0] = masu[0][0]
for i in range(1,C):
    dp0[0][i] = max(dp0[0][i],dp0[0][i-1])
    dp1[0][i] = max(dp1[0][i],dp1[0][i-1])
    dp2[0][i] = max(dp2[0][i],dp2[0][i-1])
    dp3[0][i] = max(dp3[0][i],dp3[0][i-1])
    if masu[0][i] != 0:
        dp3[0][i] = max(dp3[0][i],dp2[0][i]+masu[0][i])
        dp2[0][i] = max(dp2[0][i],dp1[0][i]+masu[0][i])
        dp1[0][i] = max(dp1[0][i],dp0[0][i]+masu[0][i])




for i in range(1,R):
    for j in range(C):
        dp0[i][j] = max(dp0[i][j],dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j])
        if j != 0:
            dp0[i][j] = max(dp0[i][j],dp0[i][j-1])
            dp1[i][j] = max(dp1[i][j],dp1[i][j-1])
            dp2[i][j] = max(dp2[i][j],dp2[i][j-1])
            dp3[i][j] = max(dp3[i][j],dp3[i][j-1])
        if masu[i][j] != 0:
            dp3[i][j] = max(dp3[i][j],dp2[i][j]+masu[i][j])
            dp2[i][j] = max(dp2[i][j],dp1[i][j]+masu[i][j])
            dp1[i][j] = max(dp1[i][j],dp0[i][j]+masu[i][j])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))