import numpy as np
def main(R,C,K,RCV):
    V=np.zeros((R+1,C+1),dtype=np.int64)
    for i in range(K):
        V[RCV[i][0]][RCV[i][1]]=RCV[i][2]
    d=np.zeros((R+1,C+1,4),dtype=np.int64)
    for i in range(R):
        for j in range(C):
            m=max(d[i][j+1])
            d[i+1][j+1][0]=m
            for k in range(3):
                d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
    return max(d[-1][-1])
import sys
readline=sys.stdin.buffer.readline
read=sys.stdin.buffer.read
if sys.argv[-1]=='ONLINE_JUDGE':
    from numba import*
    from numba.pycc import CC
    cc=CC('my_module')
    def cc_export(f,s):
        cc.export(f.__name__,s)(f)
        return njit(f)
    main=cc_export(main,(i8,i8,i8,i8[:,:],))
    cc.compile()
    exit()
R,C,K=np.array(readline().split(),dtype=np.int64)
RCV=np.array(read().split(),dtype=np.int64).reshape(K,3)
from my_module import main
print(main(R,C,K,RCV)) import numpy as np numpy def main(R,C,K,RCV):
    V=np.zeros((R+1,C+1),dtype=np.int64)
    for i in range(K):
        V[RCV[i][0]][RCV[i][1]]=RCV[i][2]
    d=np.zeros((R+1,C+1,4),dtype=np.int64)
    for i in range(R):
        for j in range(C):
            m=max(d[i][j+1])
            d[i+1][j+1][0]=m
            for k in range(3):
                d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
    return max(d[-1][-1]) main V=np.zeros((R+1,C+1),dtype=np.int64) V np.zeros((R+1,C+1),dtype=np.int64) np.zeros np zeros (R+1,C+1) R+1 R 1 C+1 C 1 dtype=np.int64 dtype np.int64 np int64 for i in range(K):
        V[RCV[i][0]][RCV[i][1]]=RCV[i][2]
     i range(K) range K V[RCV[i][0]][RCV[i][1]]=RCV[i][2] V[RCV[i][0]][RCV[i][1]] [RCV[i][0]] V RCV[i][0] [i] RCV i 0 RCV[i][1] [i] RCV i 1 RCV[i][2] [i] RCV i 2 d=np.zeros((R+1,C+1,4),dtype=np.int64) d np.zeros((R+1,C+1,4),dtype=np.int64) np.zeros np zeros (R+1,C+1,4) R+1 R 1 C+1 C 1 4 dtype=np.int64 dtype np.int64 np int64 for i in range(R):
        for j in range(C):
            m=max(d[i][j+1])
            d[i+1][j+1][0]=m
            for k in range(3):
                d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
     i range(R) range R for j in range(C):
            m=max(d[i][j+1])
            d[i+1][j+1][0]=m
            for k in range(3):
                d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
     j range(C) range C m=max(d[i][j+1]) m max(d[i][j+1]) max d[i][j+1] [i] d i j+1 j 1 d[i+1][j+1][0]=m d[i+1][j+1][0] [j+1] [i+1] d i+1 i 1 j+1 j 1 0 m for k in range(3):
                d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
     k range(3) range 3 d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1]) d[i+1][j+1][k+1] [j+1] [i+1] d i+1 i 1 j+1 j 1 k+1 k 1 max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1]) max d[i+1][j][k+1] [j] [i+1] d i+1 i 1 j k+1 k 1 m+V[i+1][j+1] m V[i+1][j+1] [i+1] V i+1 i 1 j+1 j 1 d[i+1][j][k]+V[i+1][j+1] d[i+1][j][k] [j] [i+1] d i+1 i 1 j k V[i+1][j+1] [i+1] V i+1 i 1 j+1 j 1 return max(d[-1][-1]) max(d[-1][-1]) max d[-1][-1] [-1] d -1 -1 R R C C K K RCV RCV import sys sys readline=sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline read=sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read if sys.argv[-1]=='ONLINE_JUDGE':
    from numba import*
    from numba.pycc import CC
    cc=CC('my_module')
    def cc_export(f,s):
        cc.export(f.__name__,s)(f)
        return njit(f)
    main=cc_export(main,(i8,i8,i8,i8[:,:],))
    cc.compile()
    exit() sys.argv[-1]=='ONLINE_JUDGE' sys.argv[-1] sys.argv sys argv -1 'ONLINE_JUDGE' from numba import* from numba.pycc import CC cc=CC('my_module') cc CC('my_module') CC 'my_module' def cc_export(f,s):
        cc.export(f.__name__,s)(f)
        return njit(f)
     cc_export cc.export(f.__name__,s)(f) cc.export(f.__name__,s) cc.export cc export f.__name__ f __name__ s f return njit(f) njit(f) njit f f f s s main=cc_export(main,(i8,i8,i8,i8[:,:],)) main cc_export(main,(i8,i8,i8,i8[:,:],)) cc_export main (i8,i8,i8,i8[:,:],) i8 i8 i8 i8[:,:] i8 : cc.compile() cc.compile cc compile exit() exit R,C,K=np.array(readline().split(),dtype=np.int64) R np.array(readline().split(),dtype=np.int64) np.array np array readline().split() ().split () readline split dtype=np.int64 dtype np.int64 np int64 C K RCV=np.array(read().split(),dtype=np.int64).reshape(K,3) RCV np.array(read().split(),dtype=np.int64).reshape(K,3) np.array(read().split(),dtype=np.int64).reshape np.array(read().split(),dtype=np.int64) np.array np array read().split() ().split () read split dtype=np.int64 dtype np.int64 np int64 reshape K 3 from my_module import main print(main(R,C,K,RCV)) print main(R,C,K,RCV) main R C K RCV def main(R,C,K,RCV):
    V=np.zeros((R+1,C+1),dtype=np.int64)
    for i in range(K):
        V[RCV[i][0]][RCV[i][1]]=RCV[i][2]
    d=np.zeros((R+1,C+1,4),dtype=np.int64)
    for i in range(R):
        for j in range(C):
            m=max(d[i][j+1])
            d[i+1][j+1][0]=m
            for k in range(3):
                d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
    return max(d[-1][-1]) def main(R,C,K,RCV):
    V=np.zeros((R+1,C+1),dtype=np.int64)
    for i in range(K):
        V[RCV[i][0]][RCV[i][1]]=RCV[i][2]
    d=np.zeros((R+1,C+1,4),dtype=np.int64)
    for i in range(R):
        for j in range(C):
            m=max(d[i][j+1])
            d[i+1][j+1][0]=m
            for k in range(3):
                d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
    return max(d[-1][-1]) main C,K=np.array(readline().split(),dtype=np.int64) np.array(readline().split(),dtype=np.int64) C def cc_export(f,s):
        cc.export(f.__name__,s)(f)
        return njit(f)
     def cc_export(f,s):
        cc.export(f.__name__,s)(f)
        return njit(f)
     cc_export K=np.array(readline().split(),dtype=np.int64) np.array(readline().split(),dtype=np.int64) K main=cc_export(main,(i8,i8,i8,i8[:,:],)) cc_export(main,(i8,i8,i8,i8[:,:],)) main RCV=np.array(read().split(),dtype=np.int64).reshape(K,3) np.array(read().split(),dtype=np.int64).reshape(K,3) RCV R,C,K=np.array(readline().split(),dtype=np.int64) np.array(readline().split(),dtype=np.int64) R readline=sys.stdin.buffer.readline sys.stdin.buffer.readline readline cc=CC('my_module') CC('my_module') cc read=sys.stdin.buffer.read sys.stdin.buffer.read read
import numpy as np
def main(R,C,K,RCV):
    V=np.zeros((R+1,C+1),dtype=np.int64)
    for i in range(K):
        V[RCV[i][0]][RCV[i][1]]=RCV[i][2]
    d=np.zeros((R+1,C+1,4),dtype=np.int64)
    for i in range(R):
        for j in range(C):
            m=max(d[i][j+1])
            d[i+1][j+1][0]=m
            for k in range(3):
                d[i+1][j+1][k+1]=max(d[i+1][j][k+1],m+V[i+1][j+1],d[i+1][j][k]+V[i+1][j+1])
    return max(d[-1][-1])
import sys
readline=sys.stdin.buffer.readline
read=sys.stdin.buffer.read
if sys.argv[-1]=='ONLINE_JUDGE':
    from numba import*
    from numba.pycc import CC
    cc=CC('my_module')
    def cc_export(f,s):
        cc.export(f.__name__,s)(f)
        return njit(f)
    main=cc_export(main,(i8,i8,i8,i8[:,:],))
    cc.compile()
    exit()
R,C,K=np.array(readline().split(),dtype=np.int64)
RCV=np.array(read().split(),dtype=np.int64).reshape(K,3)
from my_module import main
print(main(R,C,K,RCV))
