R,C,K=map(int,input().split())
value=[[0]*(C+1) for i in range(R+1)]
for i in range(K):
  r,c,v=map(int,input().split())
  value[r][c]=v
DP0=[[0]*(C+1) for i in range(R+1)]
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):
    v=value[i][j]
    a=DP0[i][j-1]
    b=DP1[i][j-1]
    c=DP1[i-1][j]
    d=DP2[i-1][j]
    e=DP3[i-1][j]
    f=DP2[i][j-1]
    DP0[i][j]=max(a,c,d,e)
    DP1[i][j]=max(DP0[i-1][j]+v,c+v,d+v,e+v,b,a+v)
    DP2[i][j]=max(b+v,f)
    DP3[i][j]=max(f+v,DP3[i][j-1])

print(max(DP0[R][C],DP1[R][C],DP2[R][C],DP3[R][C])) 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 value=[[0]*(C+1) for i in range(R+1)] value [[0]*(C+1) for i in range(R+1)] for i in range(K):
  r,c,v=map(int,input().split())
  value[r][c]=v i 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 value[r][c]=v value[r][c] [r] value r c v [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 DP0=[[0]*(C+1) for i in range(R+1)] DP0 [[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 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):
    v=value[i][j]
    a=DP0[i][j-1]
    b=DP1[i][j-1]
    c=DP1[i-1][j]
    d=DP2[i-1][j]
    e=DP3[i-1][j]
    f=DP2[i][j-1]
    DP0[i][j]=max(a,c,d,e)
    DP1[i][j]=max(DP0[i-1][j]+v,c+v,d+v,e+v,b,a+v)
    DP2[i][j]=max(b+v,f)
    DP3[i][j]=max(f+v,DP3[i][j-1]) i range(1,R+1) range 1 R+1 R 1 for j in range(1,C+1):
    v=value[i][j]
    a=DP0[i][j-1]
    b=DP1[i][j-1]
    c=DP1[i-1][j]
    d=DP2[i-1][j]
    e=DP3[i-1][j]
    f=DP2[i][j-1]
    DP0[i][j]=max(a,c,d,e)
    DP1[i][j]=max(DP0[i-1][j]+v,c+v,d+v,e+v,b,a+v)
    DP2[i][j]=max(b+v,f)
    DP3[i][j]=max(f+v,DP3[i][j-1]) j range(1,C+1) range 1 C+1 C 1 v=value[i][j] v value[i][j] [i] value i j a=DP0[i][j-1] a DP0[i][j-1] [i] DP0 i j-1 j 1 b=DP1[i][j-1] b DP1[i][j-1] [i] DP1 i j-1 j 1 c=DP1[i-1][j] c DP1[i-1][j] [i-1] DP1 i-1 i 1 j d=DP2[i-1][j] d DP2[i-1][j] [i-1] DP2 i-1 i 1 j e=DP3[i-1][j] e DP3[i-1][j] [i-1] DP3 i-1 i 1 j f=DP2[i][j-1] f DP2[i][j-1] [i] DP2 i j-1 j 1 DP0[i][j]=max(a,c,d,e) DP0[i][j] [i] DP0 i j max(a,c,d,e) max a c d e DP1[i][j]=max(DP0[i-1][j]+v,c+v,d+v,e+v,b,a+v) DP1[i][j] [i] DP1 i j max(DP0[i-1][j]+v,c+v,d+v,e+v,b,a+v) max DP0[i-1][j]+v DP0[i-1][j] [i-1] DP0 i-1 i 1 j v c+v c v d+v d v e+v e v b a+v a v DP2[i][j]=max(b+v,f) DP2[i][j] [i] DP2 i j max(b+v,f) max b+v b v f DP3[i][j]=max(f+v,DP3[i][j-1]) DP3[i][j] [i] DP3 i j max(f+v,DP3[i][j-1]) max f+v f v DP3[i][j-1] [i] DP3 i j-1 j 1 print(max(DP0[R][C],DP1[R][C],DP2[R][C],DP3[R][C])) print max(DP0[R][C],DP1[R][C],DP2[R][C],DP3[R][C]) max DP0[R][C] [R] DP0 R C DP1[R][C] [R] DP1 R C DP2[R][C] [R] DP2 R C DP3[R][C] [R] DP3 R C DP0=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] DP0 DP3=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] DP3 b=DP1[i][j-1] DP1[i][j-1] b f=DP2[i][j-1] DP2[i][j-1] f e=DP3[i-1][j] DP3[i-1][j] e R,C,K=map(int,input().split()) map(int,input().split()) R value=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] value a=DP0[i][j-1] DP0[i][j-1] a v=map(int,input().split()) map(int,input().split()) v DP1=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] DP1 d=DP2[i-1][j] DP2[i-1][j] d K=map(int,input().split()) map(int,input().split()) K v=value[i][j] value[i][j] v C,K=map(int,input().split()) map(int,input().split()) C r,c,v=map(int,input().split()) map(int,input().split()) r c,v=map(int,input().split()) map(int,input().split()) c DP2=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] DP2 c=DP1[i-1][j] DP1[i-1][j] c
R,C,K=map(int,input().split())
value=[[0]*(C+1) for i in range(R+1)]
for i in range(K):
  r,c,v=map(int,input().split())
  value[r][c]=v
DP0=[[0]*(C+1) for i in range(R+1)]
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):
    v=value[i][j]
    a=DP0[i][j-1]
    b=DP1[i][j-1]
    c=DP1[i-1][j]
    d=DP2[i-1][j]
    e=DP3[i-1][j]
    f=DP2[i][j-1]
    DP0[i][j]=max(a,c,d,e)
    DP1[i][j]=max(DP0[i-1][j]+v,c+v,d+v,e+v,b,a+v)
    DP2[i][j]=max(b+v,f)
    DP3[i][j]=max(f+v,DP3[i][j-1])

print(max(DP0[R][C],DP1[R][C],DP2[R][C],DP3[R][C]))