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