from copy import deepcopy

def getval():
    r,c,k = map(int,input().split())
    item = [[0 for i in range(c)] for i in range(r)]
    for i in range(k):
        ri,ci,vi = map(int,input().split())
        item[ri-1][ci-1] = vi
    return r,c,k,item

def main(r,c,k,item):
    #DP containing the information of max value given k items picked in i,j
    prev = [[0 for i in range(4)]]
    inititem = item[0][0]
    prev[0] = [0,inititem,inititem,inititem]
    for i in range(1,r):
        initval = prev[i-1][3]
        temp = []
        cur = item[i][0]
        for j in range(4):
            temp.append(initval)
        for j in range(1,4):
            temp[j] += cur
        prev.append(temp)

    for j in range(1,c):
        init = deepcopy(prev[0])
        for i in range(1,4):
            init[i] = max(prev[0][i],prev[0][i-1]+item[0][j])
        curcol = [init]
        for i in range(1,r):
            cur = item[i][j]
            left = curcol[-1]
            down = prev[i]
            temp = [max(left[3],down[0])]
            for k in range(1,4):
                temp.append(max(max(left[3],down[k-1])+cur,down[k]))
            curcol.append(temp)
        prev = curcol
            
    print(max(prev[-1]))
           
if __name__=="__main__":
    r,c,k,item = getval()
    main(r,c,k,item)  from copy import deepcopy def getval():
    r,c,k = map(int,input().split())
    item = [[0 for i in range(c)] for i in range(r)]
    for i in range(k):
        ri,ci,vi = map(int,input().split())
        item[ri-1][ci-1] = vi
    return r,c,k,item getval r,c,k = map(int,input().split()) r map(int,input().split()) map int input().split() ().split () input split c k [0 for i in range(c)] for i in range(r) for i in range(r) i range(r) range r for i in range(r) [0 for i in range(c)] item = [[0 for i in range(c)] for i in range(r)] item [[0 for i in range(c)] for i in range(r)] for i in range(k):
        ri,ci,vi = map(int,input().split())
        item[ri-1][ci-1] = vi
     i range(k) range k ri,ci,vi = map(int,input().split()) ri map(int,input().split()) map int input().split() ().split () input split ci vi item[ri-1][ci-1] = vi item[ri-1][ci-1] [ri-1] item ri-1 ri 1 ci-1 ci 1 vi return r,c,k,item return r,c,k,item r c k item def main(r,c,k,item):
    #DP containing the information of max value given k items picked in i,j
    prev = [[0 for i in range(4)]]
    inititem = item[0][0]
    prev[0] = [0,inititem,inititem,inititem]
    for i in range(1,r):
        initval = prev[i-1][3]
        temp = []
        cur = item[i][0]
        for j in range(4):
            temp.append(initval)
        for j in range(1,4):
            temp[j] += cur
        prev.append(temp)

    for j in range(1,c):
        init = deepcopy(prev[0])
        for i in range(1,4):
            init[i] = max(prev[0][i],prev[0][i-1]+item[0][j])
        curcol = [init]
        for i in range(1,r):
            cur = item[i][j]
            left = curcol[-1]
            down = prev[i]
            temp = [max(left[3],down[0])]
            for k in range(1,4):
                temp.append(max(max(left[3],down[k-1])+cur,down[k]))
            curcol.append(temp)
        prev = curcol
            
    print(max(prev[-1]))
            main 0 for i in range(4) for i in range(4) i range(4) range 4 for i in range(4) 0 prev = [[0 for i in range(4)]] prev [[0 for i in range(4)]] [0 for i in range(4)] inititem = item[0][0] inititem item[0][0] [0] item 0 0 prev[0] = [0,inititem,inititem,inititem] prev[0] prev 0 [0,inititem,inititem,inititem] 0 inititem inititem inititem for i in range(1,r):
        initval = prev[i-1][3]
        temp = []
        cur = item[i][0]
        for j in range(4):
            temp.append(initval)
        for j in range(1,4):
            temp[j] += cur
        prev.append(temp)

     i range(1,r) range 1 r initval = prev[i-1][3] initval prev[i-1][3] [i-1] prev i-1 i 1 3 temp = [] temp [] cur = item[i][0] cur item[i][0] [i] item i 0 for j in range(4):
            temp.append(initval)
         j range(4) range 4 temp.append(initval) temp.append temp append initval for j in range(1,4):
            temp[j] += cur
         j range(1,4) range 1 4 temp[j] += cur temp[j] temp j cur prev.append(temp) prev.append prev append temp for j in range(1,c):
        init = deepcopy(prev[0])
        for i in range(1,4):
            init[i] = max(prev[0][i],prev[0][i-1]+item[0][j])
        curcol = [init]
        for i in range(1,r):
            cur = item[i][j]
            left = curcol[-1]
            down = prev[i]
            temp = [max(left[3],down[0])]
            for k in range(1,4):
                temp.append(max(max(left[3],down[k-1])+cur,down[k]))
            curcol.append(temp)
        prev = curcol
            
     j range(1,c) range 1 c init = deepcopy(prev[0]) init deepcopy(prev[0]) deepcopy prev[0] prev 0 for i in range(1,4):
            init[i] = max(prev[0][i],prev[0][i-1]+item[0][j])
         i range(1,4) range 1 4 init[i] = max(prev[0][i],prev[0][i-1]+item[0][j]) init[i] init i max(prev[0][i],prev[0][i-1]+item[0][j]) max prev[0][i] [0] prev 0 i prev[0][i-1]+item[0][j] prev[0][i-1] [0] prev 0 i-1 i 1 item[0][j] [0] item 0 j curcol = [init] curcol [init] init for i in range(1,r):
            cur = item[i][j]
            left = curcol[-1]
            down = prev[i]
            temp = [max(left[3],down[0])]
            for k in range(1,4):
                temp.append(max(max(left[3],down[k-1])+cur,down[k]))
            curcol.append(temp)
         i range(1,r) range 1 r cur = item[i][j] cur item[i][j] [i] item i j left = curcol[-1] left curcol[-1] curcol -1 down = prev[i] down prev[i] prev i temp = [max(left[3],down[0])] temp [max(left[3],down[0])] max(left[3],down[0]) max left[3] left 3 down[0] down 0 for k in range(1,4):
                temp.append(max(max(left[3],down[k-1])+cur,down[k]))
             k range(1,4) range 1 4 temp.append(max(max(left[3],down[k-1])+cur,down[k])) temp.append temp append max(max(left[3],down[k-1])+cur,down[k]) max max(left[3],down[k-1])+cur max(left[3],down[k-1]) max left[3] left 3 down[k-1] down k-1 k 1 cur down[k] down k curcol.append(temp) curcol.append curcol append temp prev = curcol prev curcol print(max(prev[-1])) print max(prev[-1]) max prev[-1] prev -1 r r c c k k item item if __name__=="__main__":
    r,c,k,item = getval()
    main(r,c,k,item)  __name__=="__main__" __name__ "__main__" r,c,k,item = getval() r getval() getval c k item main(r,c,k,item) main r c k item r,c,k,item = getval() getval() r k,item = getval() getval() k c,k,item = getval() getval() c def main(r,c,k,item):
    #DP containing the information of max value given k items picked in i,j
    prev = [[0 for i in range(4)]]
    inititem = item[0][0]
    prev[0] = [0,inititem,inititem,inititem]
    for i in range(1,r):
        initval = prev[i-1][3]
        temp = []
        cur = item[i][0]
        for j in range(4):
            temp.append(initval)
        for j in range(1,4):
            temp[j] += cur
        prev.append(temp)

    for j in range(1,c):
        init = deepcopy(prev[0])
        for i in range(1,4):
            init[i] = max(prev[0][i],prev[0][i-1]+item[0][j])
        curcol = [init]
        for i in range(1,r):
            cur = item[i][j]
            left = curcol[-1]
            down = prev[i]
            temp = [max(left[3],down[0])]
            for k in range(1,4):
                temp.append(max(max(left[3],down[k-1])+cur,down[k]))
            curcol.append(temp)
        prev = curcol
            
    print(max(prev[-1]))
            def main(r,c,k,item):
    #DP containing the information of max value given k items picked in i,j
    prev = [[0 for i in range(4)]]
    inititem = item[0][0]
    prev[0] = [0,inititem,inititem,inititem]
    for i in range(1,r):
        initval = prev[i-1][3]
        temp = []
        cur = item[i][0]
        for j in range(4):
            temp.append(initval)
        for j in range(1,4):
            temp[j] += cur
        prev.append(temp)

    for j in range(1,c):
        init = deepcopy(prev[0])
        for i in range(1,4):
            init[i] = max(prev[0][i],prev[0][i-1]+item[0][j])
        curcol = [init]
        for i in range(1,r):
            cur = item[i][j]
            left = curcol[-1]
            down = prev[i]
            temp = [max(left[3],down[0])]
            for k in range(1,4):
                temp.append(max(max(left[3],down[k-1])+cur,down[k]))
            curcol.append(temp)
        prev = curcol
            
    print(max(prev[-1]))
            main item = getval() getval() item def getval():
    r,c,k = map(int,input().split())
    item = [[0 for i in range(c)] for i in range(r)]
    for i in range(k):
        ri,ci,vi = map(int,input().split())
        item[ri-1][ci-1] = vi
    return r,c,k,item def getval():
    r,c,k = map(int,input().split())
    item = [[0 for i in range(c)] for i in range(r)]
    for i in range(k):
        ri,ci,vi = map(int,input().split())
        item[ri-1][ci-1] = vi
    return r,c,k,item getval
from copy import deepcopy

def getval():
    r,c,k = map(int,input().split())
    item = [[0 for i in range(c)] for i in range(r)]
    for i in range(k):
        ri,ci,vi = map(int,input().split())
        item[ri-1][ci-1] = vi
    return r,c,k,item

def main(r,c,k,item):
    #DP containing the information of max value given k items picked in i,j
    prev = [[0 for i in range(4)]]
    inititem = item[0][0]
    prev[0] = [0,inititem,inititem,inititem]
    for i in range(1,r):
        initval = prev[i-1][3]
        temp = []
        cur = item[i][0]
        for j in range(4):
            temp.append(initval)
        for j in range(1,4):
            temp[j] += cur
        prev.append(temp)

    for j in range(1,c):
        init = deepcopy(prev[0])
        for i in range(1,4):
            init[i] = max(prev[0][i],prev[0][i-1]+item[0][j])
        curcol = [init]
        for i in range(1,r):
            cur = item[i][j]
            left = curcol[-1]
            down = prev[i]
            temp = [max(left[3],down[0])]
            for k in range(1,4):
                temp.append(max(max(left[3],down[k-1])+cur,down[k]))
            curcol.append(temp)
        prev = curcol
            
    print(max(prev[-1]))
           
if __name__=="__main__":
    r,c,k,item = getval()
    main(r,c,k,item) 