import sys
input=sys.stdin.readline

def main():
    r,c,k=map(int,input().split())
    v=[0] * (c * r)
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[(ri-1)*c + (ci-1)]=a

    dp= [0] * (c * r * 4)

    #print(dp)
    x = c * r
    if v[0]>0: dp[x] = v[0]

    for i in range(r):
        for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1

            if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

            if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
    ans=0
    for i in range(4): ans = max(dp[i*x + (r-1)*c + (c-1)],ans)
    return print(ans)

if __name__=="__main__":
    main() import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    r,c,k=map(int,input().split())
    v=[0] * (c * r)
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[(ri-1)*c + (ci-1)]=a

    dp= [0] * (c * r * 4)

    #print(dp)
    x = c * r
    if v[0]>0: dp[x] = v[0]

    for i in range(r):
        for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1

            if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

            if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
    ans=0
    for i in range(4): ans = max(dp[i*x + (r-1)*c + (c-1)],ans)
    return print(ans) main r,c,k=map(int,input().split()) r map(int,input().split()) map int input().split() ().split () input split c k v=[0] * (c * r) v [0] * (c * r) [0] 0 c * r c r for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[(ri-1)*c + (ci-1)]=a

     _ range(k) range k ri,ci,a=map(int,input().split()) ri map(int,input().split()) map int input().split() ().split () input split ci a v[(ri-1)*c + (ci-1)]=a v[(ri-1)*c + (ci-1)] v (ri-1)*c + (ci-1) (ri-1)*c ri-1 ri 1 c ci-1 ci 1 a dp= [0] * (c * r * 4) dp [0] * (c * r * 4) [0] 0 c * r * 4 c * r c r 4 x = c * r x c * r c r if v[0]>0: dp[x] = v[0]

     v[0]>0 v[0] v 0 0 for i in range(r):
        for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1

            if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

            if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
     i range(r) range r for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1

            if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

            if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
     j range(c) range c idx = i*c+j idx i*c+j i*c i c j idx2 = (i-1)*c + j idx2 (i-1)*c + j (i-1)*c i-1 i 1 c j idx3 = i*c + j-1 idx3 i*c + j-1 i*c + j i*c i c j 1 if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

             i>0 i 0 a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx] a max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx] max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2]) max dp[idx2] dp idx2 dp[x + idx2] dp x + idx2 x idx2 dp[2*x+idx2] dp 2*x+idx2 2*x 2 x idx2 dp[3*x+idx2] dp 3*x+idx2 3*x 3 x idx2 v[idx] v idx dp[x+idx]=max(dp[x+idx], a) dp[x+idx] dp x+idx x idx max(dp[x+idx], a) max dp[x+idx] dp x+idx x idx a dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2]) dp[idx] dp idx max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2]) max dp[idx] dp idx dp[idx2] dp idx2 dp[x+idx2] dp x+idx2 x idx2 dp[2*x+idx2] dp 2*x+idx2 2*x 2 x idx2 dp[3*x+idx2] dp 3*x+idx2 3*x 3 x idx2 if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
     j>0 j 0 dp[idx]=max(dp[idx],dp[idx3]) dp[idx] dp idx max(dp[idx],dp[idx3]) max dp[idx] dp idx dp[idx3] dp idx3 dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3]) dp[x + idx] dp x + idx x idx max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3]) max dp[x + idx] dp x + idx x idx dp[idx3]+v[idx] dp[idx3] dp idx3 v[idx] v idx dp[x + idx3] dp x + idx3 x idx3 dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3]) dp[2*x + idx] dp 2*x + idx 2*x 2 x idx max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3]) max dp[2*x + idx] dp 2*x + idx 2*x 2 x idx dp[x + idx3]+v[idx] dp[x + idx3] dp x + idx3 x idx3 v[idx] v idx dp[2*x + idx3] dp 2*x + idx3 2*x 2 x idx3 dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3]) dp[3*x + idx] dp 3*x + idx 3*x 3 x idx max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3]) max dp[3*x + idx] dp 3*x + idx 3*x 3 x idx dp[2*x + idx3]+v[idx] dp[2*x + idx3] dp 2*x + idx3 2*x 2 x idx3 v[idx] v idx dp[3*x + idx3] dp 3*x + idx3 3*x 3 x idx3 ans=0 ans 0 for i in range(4): ans = max(dp[i*x + (r-1)*c + (c-1)],ans)
     i range(4) range 4 return print(ans) print(ans) print ans if __name__=="__main__":
    main() __name__=="__main__" __name__ "__main__" main() main def main():
    r,c,k=map(int,input().split())
    v=[0] * (c * r)
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[(ri-1)*c + (ci-1)]=a

    dp= [0] * (c * r * 4)

    #print(dp)
    x = c * r
    if v[0]>0: dp[x] = v[0]

    for i in range(r):
        for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1

            if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

            if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
    ans=0
    for i in range(4): ans = max(dp[i*x + (r-1)*c + (c-1)],ans)
    return print(ans) def main():
    r,c,k=map(int,input().split())
    v=[0] * (c * r)
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[(ri-1)*c + (ci-1)]=a

    dp= [0] * (c * r * 4)

    #print(dp)
    x = c * r
    if v[0]>0: dp[x] = v[0]

    for i in range(r):
        for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1

            if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

            if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
    ans=0
    for i in range(4): ans = max(dp[i*x + (r-1)*c + (c-1)],ans)
    return print(ans) main input=sys.stdin.readline sys.stdin.readline input
import sys
input=sys.stdin.readline

def main():
    r,c,k=map(int,input().split())
    v=[0] * (c * r)
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[(ri-1)*c + (ci-1)]=a

    dp= [0] * (c * r * 4)

    #print(dp)
    x = c * r
    if v[0]>0: dp[x] = v[0]

    for i in range(r):
        for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1

            if i>0:
                a = max(dp[idx2],dp[x + idx2],dp[2*x+idx2],dp[3*x+idx2])+v[idx]
                dp[x+idx]=max(dp[x+idx], a)
                dp[idx]=max(dp[idx],dp[idx2],dp[x+idx2],dp[2*x+idx2],dp[3*x+idx2])

            if j>0:
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx],dp[3*x + idx3])

    #print(dp)
    ans=0
    for i in range(4): ans = max(dp[i*x + (r-1)*c + (c-1)],ans)
    return print(ans)

if __name__=="__main__":
    main()
