import sys,heapq
input = sys.stdin.buffer.readline
 
R,C,k = map(int,input().split())
 
 
val = dict()
for _ in range(k):
    rr,cc,vv = map(int,input().split())
    rr -= 1
    cc -= 1
    val[rr*C + cc] = vv
 
dp = [[0,0,0,0] for i in range(C)]
dp2 = [[0,0,0,0] for i in range(C)]

for i in range(R):
    for j in range(C):
        idx  = j
        if i*C + j in val:
            v = val[i*C + j]
        else:
            v = 0
        if i%2 == 0:
            if i == 0:
                if j == 0:
                    dp[idx][1] = v
                else:
                    dp[idx][1] = max(dp[idx-1][1],v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
            else:
                if j == 0:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3])
                    dp[idx][1] = dp[idx][0] + v
                else:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0])
                    dp[idx][1] = max(dp[idx-1][1],dp[idx][0] + v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
        else:
            if i == 0:
                if j == 0:
                    dp2[idx][1] = v
                else:
                    dp2[idx][1] = max(dp2[idx-1][1],v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
            else:
                if j == 0:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3])
                    dp2[idx][1] = dp2[idx][0] + v
                else:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0])
                    dp2[idx][1] = max(dp2[idx-1][1],dp2[idx][0] + v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
 
print(max(max(dp[-1]),max(dp2[-1]))) import sys,heapq sys heapq input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline R,C,k = map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C k val = dict() val dict() dict for _ in range(k):
    rr,cc,vv = map(int,input().split())
    rr -= 1
    cc -= 1
    val[rr*C + cc] = vv
  _ range(k) range k rr,cc,vv = map(int,input().split()) rr map(int,input().split()) map int input().split() ().split () input split cc vv rr -= 1 rr 1 cc -= 1 cc 1 val[rr*C + cc] = vv val[rr*C + cc] val rr*C + cc rr*C rr C cc vv [0,0,0,0] for i in range(C) for i in range(C) i range(C) range C for i in range(C) [0,0,0,0] 0 0 0 0 dp = [[0,0,0,0] for i in range(C)] dp [[0,0,0,0] for i in range(C)] [0,0,0,0] for i in range(C) for i in range(C) i range(C) range C for i in range(C) [0,0,0,0] 0 0 0 0 dp2 = [[0,0,0,0] for i in range(C)] dp2 [[0,0,0,0] for i in range(C)] for i in range(R):
    for j in range(C):
        idx  = j
        if i*C + j in val:
            v = val[i*C + j]
        else:
            v = 0
        if i%2 == 0:
            if i == 0:
                if j == 0:
                    dp[idx][1] = v
                else:
                    dp[idx][1] = max(dp[idx-1][1],v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
            else:
                if j == 0:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3])
                    dp[idx][1] = dp[idx][0] + v
                else:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0])
                    dp[idx][1] = max(dp[idx-1][1],dp[idx][0] + v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
        else:
            if i == 0:
                if j == 0:
                    dp2[idx][1] = v
                else:
                    dp2[idx][1] = max(dp2[idx-1][1],v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
            else:
                if j == 0:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3])
                    dp2[idx][1] = dp2[idx][0] + v
                else:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0])
                    dp2[idx][1] = max(dp2[idx-1][1],dp2[idx][0] + v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
  i range(R) range R for j in range(C):
        idx  = j
        if i*C + j in val:
            v = val[i*C + j]
        else:
            v = 0
        if i%2 == 0:
            if i == 0:
                if j == 0:
                    dp[idx][1] = v
                else:
                    dp[idx][1] = max(dp[idx-1][1],v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
            else:
                if j == 0:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3])
                    dp[idx][1] = dp[idx][0] + v
                else:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0])
                    dp[idx][1] = max(dp[idx-1][1],dp[idx][0] + v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
        else:
            if i == 0:
                if j == 0:
                    dp2[idx][1] = v
                else:
                    dp2[idx][1] = max(dp2[idx-1][1],v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
            else:
                if j == 0:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3])
                    dp2[idx][1] = dp2[idx][0] + v
                else:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0])
                    dp2[idx][1] = max(dp2[idx-1][1],dp2[idx][0] + v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
  j range(C) range C idx  = j idx j if i*C + j in val:
            v = val[i*C + j]
        else:
            v = 0
         i*C + j in val i*C + j i*C i C j val v = val[i*C + j] v val[i*C + j] val i*C + j i*C i C j v = 0 v 0 if i%2 == 0:
            if i == 0:
                if j == 0:
                    dp[idx][1] = v
                else:
                    dp[idx][1] = max(dp[idx-1][1],v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
            else:
                if j == 0:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3])
                    dp[idx][1] = dp[idx][0] + v
                else:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0])
                    dp[idx][1] = max(dp[idx-1][1],dp[idx][0] + v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
        else:
            if i == 0:
                if j == 0:
                    dp2[idx][1] = v
                else:
                    dp2[idx][1] = max(dp2[idx-1][1],v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
            else:
                if j == 0:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3])
                    dp2[idx][1] = dp2[idx][0] + v
                else:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0])
                    dp2[idx][1] = max(dp2[idx-1][1],dp2[idx][0] + v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
  i%2 == 0 i%2 i 2 0 if i == 0:
                if j == 0:
                    dp[idx][1] = v
                else:
                    dp[idx][1] = max(dp[idx-1][1],v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
            else:
                if j == 0:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3])
                    dp[idx][1] = dp[idx][0] + v
                else:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0])
                    dp[idx][1] = max(dp[idx-1][1],dp[idx][0] + v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
         i == 0 i 0 if j == 0:
                    dp[idx][1] = v
                else:
                    dp[idx][1] = max(dp[idx-1][1],v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
             j == 0 j 0 dp[idx][1] = v dp[idx][1] [idx] dp idx 1 v dp[idx][1] = max(dp[idx-1][1],v) dp[idx][1] [idx] dp idx 1 max(dp[idx-1][1],v) max dp[idx-1][1] [idx-1] dp idx-1 idx 1 1 v dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v) dp[idx][2] [idx] dp idx 2 max(dp[idx-1][2],dp[idx-1][1] + v) max dp[idx-1][2] [idx-1] dp idx-1 idx 1 2 dp[idx-1][1] + v dp[idx-1][1] [idx-1] dp idx-1 idx 1 1 v dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v) dp[idx][3] [idx] dp idx 3 max(dp[idx-1][3],dp[idx-1][2] + v) max dp[idx-1][3] [idx-1] dp idx-1 idx 1 3 dp[idx-1][2] + v dp[idx-1][2] [idx-1] dp idx-1 idx 1 2 v if j == 0:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3])
                    dp[idx][1] = dp[idx][0] + v
                else:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0])
                    dp[idx][1] = max(dp[idx-1][1],dp[idx][0] + v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
         j == 0 j 0 dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3]) dp[idx][0] [idx] dp idx 0 max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3]) max dp2[idx][0] [idx] dp2 idx 0 dp2[idx][1] [idx] dp2 idx 1 dp2[idx][2] [idx] dp2 idx 2 dp2[idx][3] [idx] dp2 idx 3 dp[idx][1] = dp[idx][0] + v dp[idx][1] [idx] dp idx 1 dp[idx][0] + v dp[idx][0] [idx] dp idx 0 v dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0]) dp[idx][0] [idx] dp idx 0 max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0]) max dp2[idx][0] [idx] dp2 idx 0 dp2[idx][1] [idx] dp2 idx 1 dp2[idx][2] [idx] dp2 idx 2 dp2[idx][3] [idx] dp2 idx 3 dp[idx-1][0] [idx-1] dp idx-1 idx 1 0 dp[idx][1] = max(dp[idx-1][1],dp[idx][0] + v) dp[idx][1] [idx] dp idx 1 max(dp[idx-1][1],dp[idx][0] + v) max dp[idx-1][1] [idx-1] dp idx-1 idx 1 1 dp[idx][0] + v dp[idx][0] [idx] dp idx 0 v dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v) dp[idx][2] [idx] dp idx 2 max(dp[idx-1][2],dp[idx-1][1] + v) max dp[idx-1][2] [idx-1] dp idx-1 idx 1 2 dp[idx-1][1] + v dp[idx-1][1] [idx-1] dp idx-1 idx 1 1 v dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v) dp[idx][3] [idx] dp idx 3 max(dp[idx-1][3],dp[idx-1][2] + v) max dp[idx-1][3] [idx-1] dp idx-1 idx 1 3 dp[idx-1][2] + v dp[idx-1][2] [idx-1] dp idx-1 idx 1 2 v if i == 0:
                if j == 0:
                    dp2[idx][1] = v
                else:
                    dp2[idx][1] = max(dp2[idx-1][1],v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
            else:
                if j == 0:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3])
                    dp2[idx][1] = dp2[idx][0] + v
                else:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0])
                    dp2[idx][1] = max(dp2[idx-1][1],dp2[idx][0] + v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
  i == 0 i 0 if j == 0:
                    dp2[idx][1] = v
                else:
                    dp2[idx][1] = max(dp2[idx-1][1],v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
             j == 0 j 0 dp2[idx][1] = v dp2[idx][1] [idx] dp2 idx 1 v dp2[idx][1] = max(dp2[idx-1][1],v) dp2[idx][1] [idx] dp2 idx 1 max(dp2[idx-1][1],v) max dp2[idx-1][1] [idx-1] dp2 idx-1 idx 1 1 v dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v) dp2[idx][2] [idx] dp2 idx 2 max(dp2[idx-1][2],dp2[idx-1][1] + v) max dp2[idx-1][2] [idx-1] dp2 idx-1 idx 1 2 dp2[idx-1][1] + v dp2[idx-1][1] [idx-1] dp2 idx-1 idx 1 1 v dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v) dp2[idx][3] [idx] dp2 idx 3 max(dp2[idx-1][3],dp2[idx-1][2] + v) max dp2[idx-1][3] [idx-1] dp2 idx-1 idx 1 3 dp2[idx-1][2] + v dp2[idx-1][2] [idx-1] dp2 idx-1 idx 1 2 v if j == 0:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3])
                    dp2[idx][1] = dp2[idx][0] + v
                else:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0])
                    dp2[idx][1] = max(dp2[idx-1][1],dp2[idx][0] + v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
  j == 0 j 0 dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3]) dp2[idx][0] [idx] dp2 idx 0 max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3]) max dp[idx][0] [idx] dp idx 0 dp[idx][1] [idx] dp idx 1 dp[idx][2] [idx] dp idx 2 dp[idx][3] [idx] dp idx 3 dp2[idx][1] = dp2[idx][0] + v dp2[idx][1] [idx] dp2 idx 1 dp2[idx][0] + v dp2[idx][0] [idx] dp2 idx 0 v dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0]) dp2[idx][0] [idx] dp2 idx 0 max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0]) max dp[idx][0] [idx] dp idx 0 dp[idx][1] [idx] dp idx 1 dp[idx][2] [idx] dp idx 2 dp[idx][3] [idx] dp idx 3 dp2[idx-1][0] [idx-1] dp2 idx-1 idx 1 0 dp2[idx][1] = max(dp2[idx-1][1],dp2[idx][0] + v) dp2[idx][1] [idx] dp2 idx 1 max(dp2[idx-1][1],dp2[idx][0] + v) max dp2[idx-1][1] [idx-1] dp2 idx-1 idx 1 1 dp2[idx][0] + v dp2[idx][0] [idx] dp2 idx 0 v dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v) dp2[idx][2] [idx] dp2 idx 2 max(dp2[idx-1][2],dp2[idx-1][1] + v) max dp2[idx-1][2] [idx-1] dp2 idx-1 idx 1 2 dp2[idx-1][1] + v dp2[idx-1][1] [idx-1] dp2 idx-1 idx 1 1 v dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v) dp2[idx][3] [idx] dp2 idx 3 max(dp2[idx-1][3],dp2[idx-1][2] + v) max dp2[idx-1][3] [idx-1] dp2 idx-1 idx 1 3 dp2[idx-1][2] + v dp2[idx-1][2] [idx-1] dp2 idx-1 idx 1 2 v print(max(max(dp[-1]),max(dp2[-1]))) print max(max(dp[-1]),max(dp2[-1])) max max(dp[-1]) max dp[-1] dp -1 max(dp2[-1]) max dp2[-1] dp2 -1 rr -= 1 1 rr rr,cc,vv = map(int,input().split()) map(int,input().split()) rr dp = [[0,0,0,0] for i in range(C)] [[0,0,0,0] for i in range(C)] dp v = 0 0 v val = dict() dict() val cc -= 1 1 cc idx  = j j idx cc,vv = map(int,input().split()) map(int,input().split()) cc R,C,k = map(int,input().split()) map(int,input().split()) R vv = map(int,input().split()) map(int,input().split()) vv input = sys.stdin.buffer.readline sys.stdin.buffer.readline input v = val[i*C + j] val[i*C + j] v C,k = map(int,input().split()) map(int,input().split()) C k = map(int,input().split()) map(int,input().split()) k dp2 = [[0,0,0,0] for i in range(C)] [[0,0,0,0] for i in range(C)] dp2
import sys,heapq
input = sys.stdin.buffer.readline
 
R,C,k = map(int,input().split())
 
 
val = dict()
for _ in range(k):
    rr,cc,vv = map(int,input().split())
    rr -= 1
    cc -= 1
    val[rr*C + cc] = vv
 
dp = [[0,0,0,0] for i in range(C)]
dp2 = [[0,0,0,0] for i in range(C)]

for i in range(R):
    for j in range(C):
        idx  = j
        if i*C + j in val:
            v = val[i*C + j]
        else:
            v = 0
        if i%2 == 0:
            if i == 0:
                if j == 0:
                    dp[idx][1] = v
                else:
                    dp[idx][1] = max(dp[idx-1][1],v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
            else:
                if j == 0:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3])
                    dp[idx][1] = dp[idx][0] + v
                else:
                    dp[idx][0] = max(dp2[idx][0],dp2[idx][1],dp2[idx][2],dp2[idx][3],dp[idx-1][0])
                    dp[idx][1] = max(dp[idx-1][1],dp[idx][0] + v)
                    dp[idx][2] = max(dp[idx-1][2],dp[idx-1][1] + v)
                    dp[idx][3] = max(dp[idx-1][3],dp[idx-1][2] + v)
        else:
            if i == 0:
                if j == 0:
                    dp2[idx][1] = v
                else:
                    dp2[idx][1] = max(dp2[idx-1][1],v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
            else:
                if j == 0:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3])
                    dp2[idx][1] = dp2[idx][0] + v
                else:
                    dp2[idx][0] = max(dp[idx][0],dp[idx][1],dp[idx][2],dp[idx][3],dp2[idx-1][0])
                    dp2[idx][1] = max(dp2[idx-1][1],dp2[idx][0] + v)
                    dp2[idx][2] = max(dp2[idx-1][2],dp2[idx-1][1] + v)
                    dp2[idx][3] = max(dp2[idx-1][3],dp2[idx-1][2] + v)
 
print(max(max(dp[-1]),max(dp2[-1])))