R,C,K=map(int,input().split())
m=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
  r,c,v=map(int,input().split())
  m[r][c]=v
d=[[0]*4 for _ in range(R+1)]
for j in range(1,C+1):
  for i in range(1,R+1):
    t=m[i][j]
    if t>0:
      d[i][3]=max(d[i][3],d[i][2]+t)
      d[i][2]=max(d[i][2],d[i][1]+t)
      d[i][1]=max(d[i][1],d[i][0]+t,max(d[i-1])+t)
      d[i][0]=max(d[i][0],max(d[i-1]))
    else:
      d[i][0]=max(d[i][0],max(d[i-1]))
print(max(d[R])) R,C,K=map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [0]*(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]*(C+1) [0] 0 C+1 C 1 m=[[0]*(C+1) for _ in range(R+1)] m [[0]*(C+1) for _ in range(R+1)] for _ in range(K):
  r,c,v=map(int,input().split())
  m[r][c]=v _ 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 m[r][c]=v m[r][c] [r] m r c v [0]*4 for _ in range(R+1) for _ in range(R+1) _ range(R+1) range R+1 R 1 for _ in range(R+1) [0]*4 [0] 0 4 d=[[0]*4 for _ in range(R+1)] d [[0]*4 for _ in range(R+1)] for j in range(1,C+1):
  for i in range(1,R+1):
    t=m[i][j]
    if t>0:
      d[i][3]=max(d[i][3],d[i][2]+t)
      d[i][2]=max(d[i][2],d[i][1]+t)
      d[i][1]=max(d[i][1],d[i][0]+t,max(d[i-1])+t)
      d[i][0]=max(d[i][0],max(d[i-1]))
    else:
      d[i][0]=max(d[i][0],max(d[i-1])) j range(1,C+1) range 1 C+1 C 1 for i in range(1,R+1):
    t=m[i][j]
    if t>0:
      d[i][3]=max(d[i][3],d[i][2]+t)
      d[i][2]=max(d[i][2],d[i][1]+t)
      d[i][1]=max(d[i][1],d[i][0]+t,max(d[i-1])+t)
      d[i][0]=max(d[i][0],max(d[i-1]))
    else:
      d[i][0]=max(d[i][0],max(d[i-1])) i range(1,R+1) range 1 R+1 R 1 t=m[i][j] t m[i][j] [i] m i j if t>0:
      d[i][3]=max(d[i][3],d[i][2]+t)
      d[i][2]=max(d[i][2],d[i][1]+t)
      d[i][1]=max(d[i][1],d[i][0]+t,max(d[i-1])+t)
      d[i][0]=max(d[i][0],max(d[i-1]))
    else:
      d[i][0]=max(d[i][0],max(d[i-1])) t>0 t 0 d[i][3]=max(d[i][3],d[i][2]+t) d[i][3] [i] d i 3 max(d[i][3],d[i][2]+t) max d[i][3] [i] d i 3 d[i][2]+t d[i][2] [i] d i 2 t d[i][2]=max(d[i][2],d[i][1]+t) d[i][2] [i] d i 2 max(d[i][2],d[i][1]+t) max d[i][2] [i] d i 2 d[i][1]+t d[i][1] [i] d i 1 t d[i][1]=max(d[i][1],d[i][0]+t,max(d[i-1])+t) d[i][1] [i] d i 1 max(d[i][1],d[i][0]+t,max(d[i-1])+t) max d[i][1] [i] d i 1 d[i][0]+t d[i][0] [i] d i 0 t max(d[i-1])+t max(d[i-1]) max d[i-1] d i-1 i 1 t d[i][0]=max(d[i][0],max(d[i-1])) d[i][0] [i] d i 0 max(d[i][0],max(d[i-1])) max d[i][0] [i] d i 0 max(d[i-1]) max d[i-1] d i-1 i 1 d[i][0]=max(d[i][0],max(d[i-1])) d[i][0] [i] d i 0 max(d[i][0],max(d[i-1])) max d[i][0] [i] d i 0 max(d[i-1]) max d[i-1] d i-1 i 1 print(max(d[R])) print max(d[R]) max d[R] d R v=map(int,input().split()) map(int,input().split()) v r,c,v=map(int,input().split()) map(int,input().split()) r d=[[0]*4 for _ in range(R+1)] [[0]*4 for _ in range(R+1)] d m=[[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] m t=m[i][j] m[i][j] t R,C,K=map(int,input().split()) map(int,input().split()) R C,K=map(int,input().split()) map(int,input().split()) C c,v=map(int,input().split()) map(int,input().split()) c K=map(int,input().split()) map(int,input().split()) K
R,C,K=map(int,input().split())
m=[[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
  r,c,v=map(int,input().split())
  m[r][c]=v
d=[[0]*4 for _ in range(R+1)]
for j in range(1,C+1):
  for i in range(1,R+1):
    t=m[i][j]
    if t>0:
      d[i][3]=max(d[i][3],d[i][2]+t)
      d[i][2]=max(d[i][2],d[i][1]+t)
      d[i][1]=max(d[i][1],d[i][0]+t,max(d[i-1])+t)
      d[i][0]=max(d[i][0],max(d[i-1]))
    else:
      d[i][0]=max(d[i][0],max(d[i-1]))
print(max(d[R]))