h,w,k=map(int,input().split())
dp=[[[0]*(w+2) for _ in range(h+2)] for _ in range(4)]
f=[[0]*(w+1) for _ in range(h+1)]
for _ in range(k):
  r,c,v=map(int,input().split())
  f[r][c]=v
for i in range(1,h+1):
  for j in range(1,w+1):
    for k in range(3,-1,-1):
      if k:dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+f[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
print(max(dp[k][h][w] for k in range(4))) h,w,k=map(int,input().split()) h map(int,input().split()) map int input().split() ().split () input split w k [[0]*(w+2) for _ in range(h+2)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*(w+2) for _ in range(h+2)] dp=[[[0]*(w+2) for _ in range(h+2)] for _ in range(4)] dp [[[0]*(w+2) for _ in range(h+2)] for _ in range(4)] [0]*(w+1) for _ in range(h+1) for _ in range(h+1) _ range(h+1) range h+1 h 1 for _ in range(h+1) [0]*(w+1) [0] 0 w+1 w 1 f=[[0]*(w+1) for _ in range(h+1)] f [[0]*(w+1) for _ in range(h+1)] for _ in range(k):
  r,c,v=map(int,input().split())
  f[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 f[r][c]=v f[r][c] [r] f r c v for i in range(1,h+1):
  for j in range(1,w+1):
    for k in range(3,-1,-1):
      if k:dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+f[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) i range(1,h+1) range 1 h+1 h 1 for j in range(1,w+1):
    for k in range(3,-1,-1):
      if k:dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+f[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) j range(1,w+1) range 1 w+1 w 1 for k in range(3,-1,-1):
      if k:dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+f[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) k range(3,-1,-1) range 3 -1 -1 if k:dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+f[i][j])
       k dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j]) dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j max(dp[0][i+1][j],dp[k][i][j]) max dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j dp[k][i][j] [i] [k] dp k i j dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) dp[k][i][j+1] [i] [k] dp k i j+1 j 1 max(dp[k][i][j+1],dp[k][i][j]) max dp[k][i][j+1] [i] [k] dp k i j+1 j 1 dp[k][i][j] [i] [k] dp k i j print(max(dp[k][h][w] for k in range(4))) print max(dp[k][h][w] for k in range(4)) max dp[k][h][w] [h] [k] dp k h w v=map(int,input().split()) map(int,input().split()) v r,c,v=map(int,input().split()) map(int,input().split()) r c,v=map(int,input().split()) map(int,input().split()) c f=[[0]*(w+1) for _ in range(h+1)] [[0]*(w+1) for _ in range(h+1)] f dp=[[[0]*(w+2) for _ in range(h+2)] for _ in range(4)] [[[0]*(w+2) for _ in range(h+2)] for _ in range(4)] dp k=map(int,input().split()) map(int,input().split()) k h,w,k=map(int,input().split()) map(int,input().split()) h w,k=map(int,input().split()) map(int,input().split()) w
h,w,k=map(int,input().split())
dp=[[[0]*(w+2) for _ in range(h+2)] for _ in range(4)]
f=[[0]*(w+1) for _ in range(h+1)]
for _ in range(k):
  r,c,v=map(int,input().split())
  f[r][c]=v
for i in range(1,h+1):
  for j in range(1,w+1):
    for k in range(3,-1,-1):
      if k:dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j]+f[i][j])
      dp[0][i+1][j]=max(dp[0][i+1][j],dp[k][i][j])
      dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
print(max(dp[k][h][w] for k in range(4)))