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