#E_Picking Goods
R,C,K = map(int,input().split())
A =     [[0  for j in range(C)] for i in range(R)]
varr = [[[0  for j in range(C)] for i in range(R)] for k in range(4)]

for inputk in range(K):
    r,c,v = map(int,input().split())
    A[r-1][c-1] = v

for i in range(R):  
    for j in range(C):
        for k in range(2,-1,-1):
            if varr[k][i][j] >= 0:
                if  varr[k+1][i][j] < varr[k][i][j] + A[i][j]:
                    varr[k+1][i][j] = varr[k][i][j] + A[i][j]
        for kk in range(0,4):
            if varr[kk][i][j] >= 0:
                if i +1 < R :
                    if  varr[0][i + 1][j] < varr[kk][i][j]:
                        varr[0][i + 1][j] = varr[kk][i][j] 
                if j +1 < C :
                    if  varr[kk][i][j + 1] < varr[kk][i][j]:
                        varr[kk][i][j + 1] = varr[kk][i][j] 
ans = 0
for k in range (4):
    if ans < varr[k][R-1][C-1]:
        ans = varr[k][R-1][C-1]

print(ans) R,C,K = map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [0  for j 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 j in range(C)] A =     [[0  for j in range(C)] for i in range(R)] A [[0  for j in range(C)] for i in range(R)] [[0  for j in range(C)] for i in range(R)] for k in range(4) for k in range(4) k range(4) range 4 for k in range(4) [[0  for j in range(C)] for i in range(R)] varr = [[[0  for j in range(C)] for i in range(R)] for k in range(4)] varr [[[0  for j in range(C)] for i in range(R)] for k in range(4)] for inputk in range(K):
    r,c,v = map(int,input().split())
    A[r-1][c-1] = v inputk 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 A[r-1][c-1] = v A[r-1][c-1] [r-1] A r-1 r 1 c-1 c 1 v for i in range(R):  
    for j in range(C):
        for k in range(2,-1,-1):
            if varr[k][i][j] >= 0:
                if  varr[k+1][i][j] < varr[k][i][j] + A[i][j]:
                    varr[k+1][i][j] = varr[k][i][j] + A[i][j]
        for kk in range(0,4):
            if varr[kk][i][j] >= 0:
                if i +1 < R :
                    if  varr[0][i + 1][j] < varr[kk][i][j]:
                        varr[0][i + 1][j] = varr[kk][i][j] 
                if j +1 < C :
                    if  varr[kk][i][j + 1] < varr[kk][i][j]:
                        varr[kk][i][j + 1] = varr[kk][i][j]  i range(R) range R for j in range(C):
        for k in range(2,-1,-1):
            if varr[k][i][j] >= 0:
                if  varr[k+1][i][j] < varr[k][i][j] + A[i][j]:
                    varr[k+1][i][j] = varr[k][i][j] + A[i][j]
        for kk in range(0,4):
            if varr[kk][i][j] >= 0:
                if i +1 < R :
                    if  varr[0][i + 1][j] < varr[kk][i][j]:
                        varr[0][i + 1][j] = varr[kk][i][j] 
                if j +1 < C :
                    if  varr[kk][i][j + 1] < varr[kk][i][j]:
                        varr[kk][i][j + 1] = varr[kk][i][j]  j range(C) range C for k in range(2,-1,-1):
            if varr[k][i][j] >= 0:
                if  varr[k+1][i][j] < varr[k][i][j] + A[i][j]:
                    varr[k+1][i][j] = varr[k][i][j] + A[i][j]
         k range(2,-1,-1) range 2 -1 -1 if varr[k][i][j] >= 0:
                if  varr[k+1][i][j] < varr[k][i][j] + A[i][j]:
                    varr[k+1][i][j] = varr[k][i][j] + A[i][j]
         varr[k][i][j] >= 0 varr[k][i][j] [i] [k] varr k i j 0 if  varr[k+1][i][j] < varr[k][i][j] + A[i][j]:
                    varr[k+1][i][j] = varr[k][i][j] + A[i][j]
         varr[k+1][i][j] < varr[k][i][j] + A[i][j] varr[k+1][i][j] [i] [k+1] varr k+1 k 1 i j varr[k][i][j] + A[i][j] varr[k][i][j] [i] [k] varr k i j A[i][j] [i] A i j varr[k+1][i][j] = varr[k][i][j] + A[i][j] varr[k+1][i][j] [i] [k+1] varr k+1 k 1 i j varr[k][i][j] + A[i][j] varr[k][i][j] [i] [k] varr k i j A[i][j] [i] A i j for kk in range(0,4):
            if varr[kk][i][j] >= 0:
                if i +1 < R :
                    if  varr[0][i + 1][j] < varr[kk][i][j]:
                        varr[0][i + 1][j] = varr[kk][i][j] 
                if j +1 < C :
                    if  varr[kk][i][j + 1] < varr[kk][i][j]:
                        varr[kk][i][j + 1] = varr[kk][i][j]  kk range(0,4) range 0 4 if varr[kk][i][j] >= 0:
                if i +1 < R :
                    if  varr[0][i + 1][j] < varr[kk][i][j]:
                        varr[0][i + 1][j] = varr[kk][i][j] 
                if j +1 < C :
                    if  varr[kk][i][j + 1] < varr[kk][i][j]:
                        varr[kk][i][j + 1] = varr[kk][i][j]  varr[kk][i][j] >= 0 varr[kk][i][j] [i] [kk] varr kk i j 0 if i +1 < R :
                    if  varr[0][i + 1][j] < varr[kk][i][j]:
                        varr[0][i + 1][j] = varr[kk][i][j] 
                 i +1 < R i +1 i 1 R if  varr[0][i + 1][j] < varr[kk][i][j]:
                        varr[0][i + 1][j] = varr[kk][i][j] 
                 varr[0][i + 1][j] < varr[kk][i][j] varr[0][i + 1][j] [i + 1] [0] varr 0 i + 1 i 1 j varr[kk][i][j] [i] [kk] varr kk i j varr[0][i + 1][j] = varr[kk][i][j] varr[0][i + 1][j] [i + 1] [0] varr 0 i + 1 i 1 j varr[kk][i][j] [i] [kk] varr kk i j if j +1 < C :
                    if  varr[kk][i][j + 1] < varr[kk][i][j]:
                        varr[kk][i][j + 1] = varr[kk][i][j]  j +1 < C j +1 j 1 C if  varr[kk][i][j + 1] < varr[kk][i][j]:
                        varr[kk][i][j + 1] = varr[kk][i][j]  varr[kk][i][j + 1] < varr[kk][i][j] varr[kk][i][j + 1] [i] [kk] varr kk i j + 1 j 1 varr[kk][i][j] [i] [kk] varr kk i j varr[kk][i][j + 1] = varr[kk][i][j] varr[kk][i][j + 1] [i] [kk] varr kk i j + 1 j 1 varr[kk][i][j] [i] [kk] varr kk i j ans = 0 ans 0 for k in range (4):
    if ans < varr[k][R-1][C-1]:
        ans = varr[k][R-1][C-1] k range (4) range 4 if ans < varr[k][R-1][C-1]:
        ans = varr[k][R-1][C-1] ans < varr[k][R-1][C-1] ans varr[k][R-1][C-1] [R-1] [k] varr k R-1 R 1 C-1 C 1 ans = varr[k][R-1][C-1] ans varr[k][R-1][C-1] [R-1] [k] varr k R-1 R 1 C-1 C 1 print(ans) print ans C,K = map(int,input().split()) map(int,input().split()) C A =     [[0  for j in range(C)] for i in range(R)] [[0  for j in range(C)] for i in range(R)] A r,c,v = map(int,input().split()) map(int,input().split()) r R,C,K = map(int,input().split()) map(int,input().split()) R v = map(int,input().split()) map(int,input().split()) v K = map(int,input().split()) map(int,input().split()) K ans = varr[k][R-1][C-1] varr[k][R-1][C-1] ans c,v = map(int,input().split()) map(int,input().split()) c ans = 0 0 ans varr = [[[0  for j in range(C)] for i in range(R)] for k in range(4)] [[[0  for j in range(C)] for i in range(R)] for k in range(4)] varr
#E_Picking Goods
R,C,K = map(int,input().split())
A =     [[0  for j in range(C)] for i in range(R)]
varr = [[[0  for j in range(C)] for i in range(R)] for k in range(4)]

for inputk in range(K):
    r,c,v = map(int,input().split())
    A[r-1][c-1] = v

for i in range(R):  
    for j in range(C):
        for k in range(2,-1,-1):
            if varr[k][i][j] >= 0:
                if  varr[k+1][i][j] < varr[k][i][j] + A[i][j]:
                    varr[k+1][i][j] = varr[k][i][j] + A[i][j]
        for kk in range(0,4):
            if varr[kk][i][j] >= 0:
                if i +1 < R :
                    if  varr[0][i + 1][j] < varr[kk][i][j]:
                        varr[0][i + 1][j] = varr[kk][i][j] 
                if j +1 < C :
                    if  varr[kk][i][j + 1] < varr[kk][i][j]:
                        varr[kk][i][j + 1] = varr[kk][i][j] 
ans = 0
for k in range (4):
    if ans < varr[k][R-1][C-1]:
        ans = varr[k][R-1][C-1]

print(ans)
