(R,C,K),*t=[map(int,t.split())for t in open(0)]
G,*F=eval("eval('[0]*-~C,'*R),"*5)
for r,c,v in t:G[r-1][c]=v
for r in range(R):
 for x in 1,2,3:
  for c in range(C):F[x][r][c]=max(F[x-1][r][c],max(F[x-1][r][c-1],(x<2)*F[3][r-1][c])+G[r][c+1],F[x][r][c-1])
print(F[3][-1][-2]) map(int,t.split())for t in open(0) for t in open(0) t open(0) open 0 for t in open(0) map(int,t.split()) map int t.split() t.split t split (R,C,K),*t=[map(int,t.split())for t in open(0)] (R,C,K) R C K [map(int,t.split())for t in open(0)] *t t G,*F=eval("eval('[0]*-~C,'*R),"*5) G eval("eval('[0]*-~C,'*R),"*5) eval "eval('[0]*-~C,'*R),"*5 "eval('[0]*-~C,'*R)," 5 *F F for r,c,v in t:G[r-1][c]=v r c v t for r in range(R):
 for x in 1,2,3:
  for c in range(C):F[x][r][c]=max(F[x-1][r][c],max(F[x-1][r][c-1],(x<2)*F[3][r-1][c])+G[r][c+1],F[x][r][c-1]) r range(R) range R for x in 1,2,3:
  for c in range(C):F[x][r][c]=max(F[x-1][r][c],max(F[x-1][r][c-1],(x<2)*F[3][r-1][c])+G[r][c+1],F[x][r][c-1]) x 1 for c in range(C):F[x][r][c]=max(F[x-1][r][c],max(F[x-1][r][c-1],(x<2)*F[3][r-1][c])+G[r][c+1],F[x][r][c-1 c range(C) range C print(F[3][-1][-2]) print F[3][-1][-2] [-1] [3] F 3 -1 -2 G,*F=eval("eval('[0]*-~C,'*R),"*5) eval("eval('[0]*-~C,'*R),"*5) G
(R,C,K),*t=[map(int,t.split())for t in open(0)]
G,*F=eval("eval('[0]*-~C,'*R),"*5)
for r,c,v in t:G[r-1][c]=v
for r in range(R):
 for x in 1,2,3:
  for c in range(C):F[x][r][c]=max(F[x-1][r][c],max(F[x-1][r][c-1],(x<2)*F[3][r-1][c])+G[r][c+1],F[x][r][c-1])
print(F[3][-1][-2])