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