import sys
input = sys.stdin.readline

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)
 import sys sys 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 tuple(map(int,input().split())) for i in range(K) for i in range(K) i range(K) range K for i in range(K) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split J=[tuple(map(int,input().split())) for i in range(K)] J [tuple(map(int,input().split())) for i in range(K)] [0]*(C+2) for i in range(R+2) for i in range(R+2) i range(R+2) range R+2 R 2 for i in range(R+2) [0]*(C+2) [0] 0 C+2 C 2 DP1=[[0]*(C+2) for i in range(R+2)] DP1 [[0]*(C+2) for i in range(R+2)] [0]*(C+2) for i in range(R+2) for i in range(R+2) i range(R+2) range R+2 R 2 for i in range(R+2) [0]*(C+2) [0] 0 C+2 C 2 DP2=[[0]*(C+2) for i in range(R+2)] DP2 [[0]*(C+2) for i in range(R+2)] [0]*(C+2) for i in range(R+2) for i in range(R+2) i range(R+2) range R+2 R 2 for i in range(R+2) [0]*(C+2) [0] 0 C+2 C 2 DP3=[[0]*(C+2) for i in range(R+2)] DP3 [[0]*(C+2) for i in range(R+2)] [0]*C for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0]*C [0] 0 C MAP=[[0]*C for i in range(R)] MAP [[0]*C for i in range(R)] for x,y,v in J:
    MAP[x-1][y-1]=v x y v J MAP[x-1][y-1]=v MAP[x-1][y-1] [x-1] MAP x-1 x 1 y-1 y 1 v for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j]) i range(R) range R for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j]) j range(C) range C DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j]) DP1[i][j] [i] DP1 i j max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j]) max DP1[i][j-1] [i] DP1 i j-1 j 1 DP1[i-1][j]+MAP[i][j] DP1[i-1][j] [i-1] DP1 i-1 i 1 j MAP[i][j] [i] MAP i j DP2[i-1][j]+MAP[i][j] DP2[i-1][j] [i-1] DP2 i-1 i 1 j MAP[i][j] [i] MAP i j DP3[i-1][j]+MAP[i][j] DP3[i-1][j] [i-1] DP3 i-1 i 1 j MAP[i][j] [i] MAP i j DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j]) DP2[i][j] [i] DP2 i j max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j]) max DP2[i][j-1] [i] DP2 i j-1 j 1 DP1[i][j-1]+MAP[i][j] DP1[i][j-1] [i] DP1 i j-1 j 1 MAP[i][j] [i] MAP i j DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j]) DP3[i][j] [i] DP3 i j max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j]) max DP3[i][j-1] [i] DP3 i j-1 j 1 DP2[i][j-1]+MAP[i][j] DP2[i][j-1] [i] DP2 i j-1 j 1 MAP[i][j] [i] MAP i j ANS=0 ANS 0 for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j]) i range(R) range R for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j]) j range(C) range C ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j]) ANS max(ANS,DP1[i][j],DP2[i][j],DP3[i][j]) max ANS DP1[i][j] [i] DP1 i j DP2[i][j] [i] DP2 i j DP3[i][j] [i] DP3 i j print(ANS) print ANS DP2=[[0]*(C+2) for i in range(R+2)] [[0]*(C+2) for i in range(R+2)] DP2 ANS=0 0 ANS input = sys.stdin.readline sys.stdin.readline input C,K=map(int,input().split()) map(int,input().split()) C ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j]) max(ANS,DP1[i][j],DP2[i][j],DP3[i][j]) ANS R,C,K=map(int,input().split()) map(int,input().split()) R DP3=[[0]*(C+2) for i in range(R+2)] [[0]*(C+2) for i in range(R+2)] DP3 J=[tuple(map(int,input().split())) for i in range(K)] [tuple(map(int,input().split())) for i in range(K)] J MAP=[[0]*C for i in range(R)] [[0]*C for i in range(R)] MAP K=map(int,input().split()) map(int,input().split()) K DP1=[[0]*(C+2) for i in range(R+2)] [[0]*(C+2) for i in range(R+2)] DP1
import sys
input = sys.stdin.readline

R,C,K=map(int,input().split())
J=[tuple(map(int,input().split())) for i in range(K)]

#DP0=[[0]*(C+2) for i in range(R+2)]
DP1=[[0]*(C+2) for i in range(R+2)]
DP2=[[0]*(C+2) for i in range(R+2)]
DP3=[[0]*(C+2) for i in range(R+2)]

MAP=[[0]*C for i in range(R)]

for x,y,v in J:
    MAP[x-1][y-1]=v

for i in range(R):
    for j in range(C):
        DP1[i][j]=max(DP1[i][j-1],DP1[i-1][j]+MAP[i][j],DP2[i-1][j]+MAP[i][j],DP3[i-1][j]+MAP[i][j])
        DP2[i][j]=max(DP2[i][j-1],DP1[i][j-1]+MAP[i][j])
        DP3[i][j]=max(DP3[i][j-1],DP2[i][j-1]+MAP[i][j])

ANS=0
for i in range(R):
    for j in range(C):
        ANS=max(ANS,DP1[i][j],DP2[i][j],DP3[i][j])
print(ANS)

