import sys
from numpy import*
def main(h,w,k,t):
    c=zeros((3001,3001),int_)
    dp=zeros((4,3001,3001),int_)
    for i in range(k):
        y,x,v=t[i]
        c[y,x]=v
    for i in range(1,h+1):
        for j in range(1,w+1):
            x=max(dp[:,i-1,j])
            for k in range(4):
                if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
            dp[1,i,j]=max(dp[1,i,j],x+c[i,j])
    return max(dp[:,h,w])
if sys.argv[-1]=='ONLINE_JUDGE':
  from numba.pycc import CC
  cc=CC('my_module')
  cc.export('main','i8(i8,i8,i8,i8[:,:])')(main)
  cc.compile()
  exit()
from my_module import main
(h,w,k),*t=[int_(t.split())for t in open(0)]
print(main(h,w,k,int_(t))) import sys sys from numpy import* def main(h,w,k,t):
    c=zeros((3001,3001),int_)
    dp=zeros((4,3001,3001),int_)
    for i in range(k):
        y,x,v=t[i]
        c[y,x]=v
    for i in range(1,h+1):
        for j in range(1,w+1):
            x=max(dp[:,i-1,j])
            for k in range(4):
                if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
            dp[1,i,j]=max(dp[1,i,j],x+c[i,j])
    return max(dp[:,h,w]) main c=zeros((3001,3001),int_) c zeros((3001,3001),int_) zeros (3001,3001) 3001 3001 int_ dp=zeros((4,3001,3001),int_) dp zeros((4,3001,3001),int_) zeros (4,3001,3001) 4 3001 3001 int_ for i in range(k):
        y,x,v=t[i]
        c[y,x]=v
     i range(k) range k y,x,v=t[i] y t[i] t i x v c[y,x]=v c[y,x] c y v for i in range(1,h+1):
        for j in range(1,w+1):
            x=max(dp[:,i-1,j])
            for k in range(4):
                if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
            dp[1,i,j]=max(dp[1,i,j],x+c[i,j])
     i range(1,h+1) range 1 h+1 h 1 for j in range(1,w+1):
            x=max(dp[:,i-1,j])
            for k in range(4):
                if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
            dp[1,i,j]=max(dp[1,i,j],x+c[i,j])
     j range(1,w+1) range 1 w+1 w 1 x=max(dp[:,i-1,j]) x max(dp[:,i-1,j]) max dp[:,i-1,j] dp : for k in range(4):
                if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
             k range(4) range 4 if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
             k dp[1,i,j]=max(dp[1,i,j],x+c[i,j]) dp[1,i,j] dp 1 max(dp[1,i,j],x+c[i,j]) max dp[1,i,j] dp 1 x+c[i,j] x c[i,j] c i return max(dp[:,h,w]) max(dp[:,h,w]) max dp[:,h,w] dp : h h w w k k t t if sys.argv[-1]=='ONLINE_JUDGE':
  from numba.pycc import CC
  cc=CC('my_module')
  cc.export('main','i8(i8,i8,i8,i8[:,:])')(main)
  cc.compile()
  exit() sys.argv[-1]=='ONLINE_JUDGE' sys.argv[-1] sys.argv sys argv -1 'ONLINE_JUDGE' from numba.pycc import CC cc=CC('my_module') cc CC('my_module') CC 'my_module' cc.export('main','i8(i8,i8,i8,i8[:,:])')(main) cc.export('main','i8(i8,i8,i8,i8[:,:])') cc.export cc export 'main' 'i8(i8,i8,i8,i8[:,:])' main cc.compile() cc.compile cc compile exit() exit from my_module import main int_(t.split())for t in open(0) for t in open(0) t open(0) open 0 for t in open(0) int_(t.split()) int_ t.split() t.split t split (h,w,k),*t=[int_(t.split())for t in open(0)] (h,w,k) h w k [int_(t.split())for t in open(0)] *t t print(main(h,w,k,int_(t))) print main(h,w,k,int_(t)) main h w k int_(t) int_ t cc=CC('my_module') CC('my_module') cc def main(h,w,k,t):
    c=zeros((3001,3001),int_)
    dp=zeros((4,3001,3001),int_)
    for i in range(k):
        y,x,v=t[i]
        c[y,x]=v
    for i in range(1,h+1):
        for j in range(1,w+1):
            x=max(dp[:,i-1,j])
            for k in range(4):
                if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
            dp[1,i,j]=max(dp[1,i,j],x+c[i,j])
    return max(dp[:,h,w]) def main(h,w,k,t):
    c=zeros((3001,3001),int_)
    dp=zeros((4,3001,3001),int_)
    for i in range(k):
        y,x,v=t[i]
        c[y,x]=v
    for i in range(1,h+1):
        for j in range(1,w+1):
            x=max(dp[:,i-1,j])
            for k in range(4):
                if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
            dp[1,i,j]=max(dp[1,i,j],x+c[i,j])
    return max(dp[:,h,w]) main
import sys
from numpy import*
def main(h,w,k,t):
    c=zeros((3001,3001),int_)
    dp=zeros((4,3001,3001),int_)
    for i in range(k):
        y,x,v=t[i]
        c[y,x]=v
    for i in range(1,h+1):
        for j in range(1,w+1):
            x=max(dp[:,i-1,j])
            for k in range(4):
                if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
            dp[1,i,j]=max(dp[1,i,j],x+c[i,j])
    return max(dp[:,h,w])
if sys.argv[-1]=='ONLINE_JUDGE':
  from numba.pycc import CC
  cc=CC('my_module')
  cc.export('main','i8(i8,i8,i8,i8[:,:])')(main)
  cc.compile()
  exit()
from my_module import main
(h,w,k),*t=[int_(t.split())for t in open(0)]
print(main(h,w,k,int_(t)))