r,c,k=map(int,input().split())
lst=[[0]*(c+1) for i in range(r+1)]
for i in range(k):
  s,t,u=map(int,input().split())
  lst[s][t]=u


dp1=[[0]*(c+1) for i in range(r+1)]
dp2=[[0]*(c+1) for i in range(r+1)]
dp3=[[0]*(c+1) for i in range(r+1)]

for i in range(1,r+1):
  for j in range(1,c+1):
    dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]+lst[i][j],dp2[i-1][j]+lst[i][j],dp3[i-1][j]+lst[i][j])
    dp2[i][j]=max(dp2[i][j-1],dp1[i][j-1]+lst[i][j])
    dp3[i][j]=max(dp3[i][j-1],dp2[i][j-1]+lst[i][j])

print(max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1],0)) 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 lst=[[0]*(c+1) for i in range(r+1)] lst [[0]*(c+1) for i in range(r+1)] for i in range(k):
  s,t,u=map(int,input().split())
  lst[s][t]=u i range(k) range k s,t,u=map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t u lst[s][t]=u lst[s][t] [s] lst s t u [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 dp1=[[0]*(c+1) for i in range(r+1)] dp1 [[0]*(c+1) for i in range(r+1)] [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 dp2=[[0]*(c+1) for i in range(r+1)] dp2 [[0]*(c+1) for i in range(r+1)] [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 dp3=[[0]*(c+1) for i in range(r+1)] dp3 [[0]*(c+1) for i in range(r+1)] for i in range(1,r+1):
  for j in range(1,c+1):
    dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]+lst[i][j],dp2[i-1][j]+lst[i][j],dp3[i-1][j]+lst[i][j])
    dp2[i][j]=max(dp2[i][j-1],dp1[i][j-1]+lst[i][j])
    dp3[i][j]=max(dp3[i][j-1],dp2[i][j-1]+lst[i][j]) i range(1,r+1) range 1 r+1 r 1 for j in range(1,c+1):
    dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]+lst[i][j],dp2[i-1][j]+lst[i][j],dp3[i-1][j]+lst[i][j])
    dp2[i][j]=max(dp2[i][j-1],dp1[i][j-1]+lst[i][j])
    dp3[i][j]=max(dp3[i][j-1],dp2[i][j-1]+lst[i][j]) j range(1,c+1) range 1 c+1 c 1 dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]+lst[i][j],dp2[i-1][j]+lst[i][j],dp3[i-1][j]+lst[i][j]) dp1[i][j] [i] dp1 i j max(dp1[i][j-1],dp1[i-1][j]+lst[i][j],dp2[i-1][j]+lst[i][j],dp3[i-1][j]+lst[i][j]) max dp1[i][j-1] [i] dp1 i j-1 j 1 dp1[i-1][j]+lst[i][j] dp1[i-1][j] [i-1] dp1 i-1 i 1 j lst[i][j] [i] lst i j dp2[i-1][j]+lst[i][j] dp2[i-1][j] [i-1] dp2 i-1 i 1 j lst[i][j] [i] lst i j dp3[i-1][j]+lst[i][j] dp3[i-1][j] [i-1] dp3 i-1 i 1 j lst[i][j] [i] lst i j dp2[i][j]=max(dp2[i][j-1],dp1[i][j-1]+lst[i][j]) dp2[i][j] [i] dp2 i j max(dp2[i][j-1],dp1[i][j-1]+lst[i][j]) max dp2[i][j-1] [i] dp2 i j-1 j 1 dp1[i][j-1]+lst[i][j] dp1[i][j-1] [i] dp1 i j-1 j 1 lst[i][j] [i] lst i j dp3[i][j]=max(dp3[i][j-1],dp2[i][j-1]+lst[i][j]) dp3[i][j] [i] dp3 i j max(dp3[i][j-1],dp2[i][j-1]+lst[i][j]) max dp3[i][j-1] [i] dp3 i j-1 j 1 dp2[i][j-1]+lst[i][j] dp2[i][j-1] [i] dp2 i j-1 j 1 lst[i][j] [i] lst i j print(max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1],0)) print max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1],0) max dp1[-1][-1] [-1] dp1 -1 -1 dp2[-1][-1] [-1] dp2 -1 -1 dp3[-1][-1] [-1] dp3 -1 -1 0 c,k=map(int,input().split()) map(int,input().split()) c k=map(int,input().split()) map(int,input().split()) k r,c,k=map(int,input().split()) map(int,input().split()) r lst=[[0]*(c+1) for i in range(r+1)] [[0]*(c+1) for i in range(r+1)] lst u=map(int,input().split()) map(int,input().split()) u dp2=[[0]*(c+1) for i in range(r+1)] [[0]*(c+1) for i in range(r+1)] dp2 dp1=[[0]*(c+1) for i in range(r+1)] [[0]*(c+1) for i in range(r+1)] dp1 t,u=map(int,input().split()) map(int,input().split()) t s,t,u=map(int,input().split()) map(int,input().split()) s dp3=[[0]*(c+1) for i in range(r+1)] [[0]*(c+1) for i in range(r+1)] dp3
r,c,k=map(int,input().split())
lst=[[0]*(c+1) for i in range(r+1)]
for i in range(k):
  s,t,u=map(int,input().split())
  lst[s][t]=u


dp1=[[0]*(c+1) for i in range(r+1)]
dp2=[[0]*(c+1) for i in range(r+1)]
dp3=[[0]*(c+1) for i in range(r+1)]

for i in range(1,r+1):
  for j in range(1,c+1):
    dp1[i][j]=max(dp1[i][j-1],dp1[i-1][j]+lst[i][j],dp2[i-1][j]+lst[i][j],dp3[i-1][j]+lst[i][j])
    dp2[i][j]=max(dp2[i][j-1],dp1[i][j-1]+lst[i][j])
    dp3[i][j]=max(dp3[i][j-1],dp2[i][j-1]+lst[i][j])

print(max(dp1[-1][-1],dp2[-1][-1],dp3[-1][-1],0))
