R,C,K=map(int,input().split())
l=[[0] * C for i in range(R)]
for i in range(K):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  l[a][b]=c
dp=[0]*C
for i in range(R):
  ndp=[0]*C
  kdp=[0]*4
  for j in range(0,C):
    kdp[0]=max(kdp[0],dp[j])
    for k in range(2,-1,-1):
      kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
    ndp[j]=max(kdp)
  dp=ndp
print(dp[C-1]) R,C,K=map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [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 l=[[0] * C for i in range(R)] l [[0] * C for i in range(R)] for i in range(K):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  l[a][b]=c i range(K) range K a,b,c=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b c a-=1 a 1 b-=1 b 1 l[a][b]=c l[a][b] [a] l a b c dp=[0]*C dp [0]*C [0] 0 C for i in range(R):
  ndp=[0]*C
  kdp=[0]*4
  for j in range(0,C):
    kdp[0]=max(kdp[0],dp[j])
    for k in range(2,-1,-1):
      kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
    ndp[j]=max(kdp)
  dp=ndp i range(R) range R ndp=[0]*C ndp [0]*C [0] 0 C kdp=[0]*4 kdp [0]*4 [0] 0 4 for j in range(0,C):
    kdp[0]=max(kdp[0],dp[j])
    for k in range(2,-1,-1):
      kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
    ndp[j]=max(kdp)
   j range(0,C) range 0 C kdp[0]=max(kdp[0],dp[j]) kdp[0] kdp 0 max(kdp[0],dp[j]) max kdp[0] kdp 0 dp[j] dp j for k in range(2,-1,-1):
      kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
     k range(2,-1,-1) range 2 -1 -1 kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j]) kdp[k+1] kdp k+1 k 1 max(kdp[k+1],kdp[k]+l[i][j]) max kdp[k+1] kdp k+1 k 1 kdp[k]+l[i][j] kdp[k] kdp k l[i][j] [i] l i j ndp[j]=max(kdp) ndp[j] ndp j max(kdp) max kdp dp=ndp dp ndp print(dp[C-1]) print dp[C-1] dp C-1 C 1 dp=[0]*C [0]*C dp R,C,K=map(int,input().split()) map(int,input().split()) R l=[[0] * C for i in range(R)] [[0] * C for i in range(R)] l C,K=map(int,input().split()) map(int,input().split()) C K=map(int,input().split()) map(int,input().split()) K a,b,c=map(int,input().split()) map(int,input().split()) a b,c=map(int,input().split()) map(int,input().split()) b kdp=[0]*4 [0]*4 kdp a-=1 1 a b-=1 1 b dp=ndp ndp dp ndp=[0]*C [0]*C ndp c=map(int,input().split()) map(int,input().split()) c
R,C,K=map(int,input().split())
l=[[0] * C for i in range(R)]
for i in range(K):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  l[a][b]=c
dp=[0]*C
for i in range(R):
  ndp=[0]*C
  kdp=[0]*4
  for j in range(0,C):
    kdp[0]=max(kdp[0],dp[j])
    for k in range(2,-1,-1):
      kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
    ndp[j]=max(kdp)
  dp=ndp
print(dp[C-1])
