R,C,K=map(int,input().split())
rcv=[list(map(int,input().split())) for _ in range(K)]
mat=[[0]*C for _ in range(R)]
for r,c,v in rcv:
  mat[r-1][c-1]=v
dp=[0]*C
for i in range(R):
  ndp=[0]*C
  wdp=[0]*4
  for j in range(C):
    wdp[0]=max(wdp[0],dp[j])
    if mat[i][j]>0:
      v=mat[i][j]
      wdp[3]=max(wdp[3],wdp[2]+v)
      wdp[2]=max(wdp[2],wdp[1]+v)
      wdp[1]=max(wdp[1],wdp[0]+v)
    ndp[j]=max(wdp)
  dp=ndp.copy()
print(max(wdp)) R,C,K=map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K list(map(int,input().split())) for _ in range(K) for _ in range(K) _ range(K) range K for _ in range(K) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split rcv=[list(map(int,input().split())) for _ in range(K)] rcv [list(map(int,input().split())) for _ in range(K)] [0]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C mat=[[0]*C for _ in range(R)] mat [[0]*C for _ in range(R)] for r,c,v in rcv:
  mat[r-1][c-1]=v r c v rcv mat[r-1][c-1]=v mat[r-1][c-1] [r-1] mat r-1 r 1 c-1 c 1 v dp=[0]*C dp [0]*C [0] 0 C for i in range(R):
  ndp=[0]*C
  wdp=[0]*4
  for j in range(C):
    wdp[0]=max(wdp[0],dp[j])
    if mat[i][j]>0:
      v=mat[i][j]
      wdp[3]=max(wdp[3],wdp[2]+v)
      wdp[2]=max(wdp[2],wdp[1]+v)
      wdp[1]=max(wdp[1],wdp[0]+v)
    ndp[j]=max(wdp)
  dp=ndp.copy() i range(R) range R ndp=[0]*C ndp [0]*C [0] 0 C wdp=[0]*4 wdp [0]*4 [0] 0 4 for j in range(C):
    wdp[0]=max(wdp[0],dp[j])
    if mat[i][j]>0:
      v=mat[i][j]
      wdp[3]=max(wdp[3],wdp[2]+v)
      wdp[2]=max(wdp[2],wdp[1]+v)
      wdp[1]=max(wdp[1],wdp[0]+v)
    ndp[j]=max(wdp)
   j range(C) range C wdp[0]=max(wdp[0],dp[j]) wdp[0] wdp 0 max(wdp[0],dp[j]) max wdp[0] wdp 0 dp[j] dp j if mat[i][j]>0:
      v=mat[i][j]
      wdp[3]=max(wdp[3],wdp[2]+v)
      wdp[2]=max(wdp[2],wdp[1]+v)
      wdp[1]=max(wdp[1],wdp[0]+v)
     mat[i][j]>0 mat[i][j] [i] mat i j 0 v=mat[i][j] v mat[i][j] [i] mat i j wdp[3]=max(wdp[3],wdp[2]+v) wdp[3] wdp 3 max(wdp[3],wdp[2]+v) max wdp[3] wdp 3 wdp[2]+v wdp[2] wdp 2 v wdp[2]=max(wdp[2],wdp[1]+v) wdp[2] wdp 2 max(wdp[2],wdp[1]+v) max wdp[2] wdp 2 wdp[1]+v wdp[1] wdp 1 v wdp[1]=max(wdp[1],wdp[0]+v) wdp[1] wdp 1 max(wdp[1],wdp[0]+v) max wdp[1] wdp 1 wdp[0]+v wdp[0] wdp 0 v ndp[j]=max(wdp) ndp[j] ndp j max(wdp) max wdp dp=ndp.copy() dp ndp.copy() ndp.copy ndp copy print(max(wdp)) print max(wdp) max wdp R,C,K=map(int,input().split()) map(int,input().split()) R mat=[[0]*C for _ in range(R)] [[0]*C for _ in range(R)] mat K=map(int,input().split()) map(int,input().split()) K wdp=[0]*4 [0]*4 wdp rcv=[list(map(int,input().split())) for _ in range(K)] [list(map(int,input().split())) for _ in range(K)] rcv dp=ndp.copy() ndp.copy() dp v=mat[i][j] mat[i][j] v ndp=[0]*C [0]*C ndp dp=[0]*C [0]*C dp C,K=map(int,input().split()) map(int,input().split()) C
R,C,K=map(int,input().split())
rcv=[list(map(int,input().split())) for _ in range(K)]
mat=[[0]*C for _ in range(R)]
for r,c,v in rcv:
  mat[r-1][c-1]=v
dp=[0]*C
for i in range(R):
  ndp=[0]*C
  wdp=[0]*4
  for j in range(C):
    wdp[0]=max(wdp[0],dp[j])
    if mat[i][j]>0:
      v=mat[i][j]
      wdp[3]=max(wdp[3],wdp[2]+v)
      wdp[2]=max(wdp[2],wdp[1]+v)
      wdp[1]=max(wdp[1],wdp[0]+v)
    ndp[j]=max(wdp)
  dp=ndp.copy()
print(max(wdp))