R, C, K = map(int, input().split())
# = int(input())
p = []
for k in range(K):
  p.append(list(map(int, input().split())))

maps = [[0 for _ in range(C)] for _ in range(R)]
for k in range(K):
  maps[p[k][0]-1][p[k][1]-1] += p[k][2]

point1 = [[0 for _ in range(C)] for _ in range(R)]
point2 = [[0 for _ in range(C)] for _ in range(R)]
point3 = [[0 for _ in range(C)] for _ in range(R)]

point1[0][0] = maps[0][0]

for r in range(R):
  for c in range(C):
    a, b, d = point1[r][c], point2[r][c], point3[r][c]  
    if c < C - 1:
      x = maps[r][c+1]
      point1[r][c+1] = max(point1[r][c+1], x, a)
      point2[r][c+1] = max(point2[r][c+1], a + x, b)
      point3[r][c+1] = max(point3[r][c+1], b + x, d)
    if r < R - 1:
      point1[r+1][c] = maps[r+1][c] + max(a, b, d)


print(max(point1[-1][-1], point2[-1][-1], point3[-1][-1])) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K p = [] p [] for k in range(K):
  p.append(list(map(int, input().split()))) k range(K) range K p.append(list(map(int, input().split()))) p.append p append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split [0 for _ in range(C)] for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] maps = [[0 for _ in range(C)] for _ in range(R)] maps [[0 for _ in range(C)] for _ in range(R)] for k in range(K):
  maps[p[k][0]-1][p[k][1]-1] += p[k][2] k range(K) range K maps[p[k][0]-1][p[k][1]-1] += p[k][2] maps[p[k][0]-1][p[k][1]-1] [p[k][0]-1] maps p[k][0]-1 p[k][0] [k] p k 0 1 p[k][1]-1 p[k][1] [k] p k 1 1 p[k][2] [k] p k 2 [0 for _ in range(C)] for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] point1 = [[0 for _ in range(C)] for _ in range(R)] point1 [[0 for _ in range(C)] for _ in range(R)] [0 for _ in range(C)] for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] point2 = [[0 for _ in range(C)] for _ in range(R)] point2 [[0 for _ in range(C)] for _ in range(R)] [0 for _ in range(C)] for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] point3 = [[0 for _ in range(C)] for _ in range(R)] point3 [[0 for _ in range(C)] for _ in range(R)] point1[0][0] = maps[0][0] point1[0][0] [0] point1 0 0 maps[0][0] [0] maps 0 0 for r in range(R):
  for c in range(C):
    a, b, d = point1[r][c], point2[r][c], point3[r][c]  
    if c < C - 1:
      x = maps[r][c+1]
      point1[r][c+1] = max(point1[r][c+1], x, a)
      point2[r][c+1] = max(point2[r][c+1], a + x, b)
      point3[r][c+1] = max(point3[r][c+1], b + x, d)
    if r < R - 1:
      point1[r+1][c] = maps[r+1][c] + max(a, b, d) r range(R) range R for c in range(C):
    a, b, d = point1[r][c], point2[r][c], point3[r][c]  
    if c < C - 1:
      x = maps[r][c+1]
      point1[r][c+1] = max(point1[r][c+1], x, a)
      point2[r][c+1] = max(point2[r][c+1], a + x, b)
      point3[r][c+1] = max(point3[r][c+1], b + x, d)
    if r < R - 1:
      point1[r+1][c] = maps[r+1][c] + max(a, b, d) c range(C) range C a, b, d = point1[r][c], point2[r][c], point3[r][c] a point1[r][c] [r] point1 r c b point2[r][c] [r] point2 r c d point3[r][c] [r] point3 r c if c < C - 1:
      x = maps[r][c+1]
      point1[r][c+1] = max(point1[r][c+1], x, a)
      point2[r][c+1] = max(point2[r][c+1], a + x, b)
      point3[r][c+1] = max(point3[r][c+1], b + x, d)
     c < C - 1 c C - 1 C 1 x = maps[r][c+1] x maps[r][c+1] [r] maps r c+1 c 1 point1[r][c+1] = max(point1[r][c+1], x, a) point1[r][c+1] [r] point1 r c+1 c 1 max(point1[r][c+1], x, a) max point1[r][c+1] [r] point1 r c+1 c 1 x a point2[r][c+1] = max(point2[r][c+1], a + x, b) point2[r][c+1] [r] point2 r c+1 c 1 max(point2[r][c+1], a + x, b) max point2[r][c+1] [r] point2 r c+1 c 1 a + x a x b point3[r][c+1] = max(point3[r][c+1], b + x, d) point3[r][c+1] [r] point3 r c+1 c 1 max(point3[r][c+1], b + x, d) max point3[r][c+1] [r] point3 r c+1 c 1 b + x b x d if r < R - 1:
      point1[r+1][c] = maps[r+1][c] + max(a, b, d) r < R - 1 r R - 1 R 1 point1[r+1][c] = maps[r+1][c] + max(a, b, d) point1[r+1][c] [r+1] point1 r+1 r 1 c maps[r+1][c] + max(a, b, d) maps[r+1][c] [r+1] maps r+1 r 1 c max(a, b, d) max a b d print(max(point1[-1][-1], point2[-1][-1], point3[-1][-1])) print max(point1[-1][-1], point2[-1][-1], point3[-1][-1]) max point1[-1][-1] [-1] point1 -1 -1 point2[-1][-1] [-1] point2 -1 -1 point3[-1][-1] [-1] point3 -1 -1 C, K = map(int, input().split()) map(int, input().split()) C b, d = point1[r][c], point2[r][c], point3[r][c] point2[r][c] b p = [] [] p a, b, d = point1[r][c], point2[r][c], point3[r][c] point1[r][c] a x = maps[r][c+1] maps[r][c+1] x maps = [[0 for _ in range(C)] for _ in range(R)] [[0 for _ in range(C)] for _ in range(R)] maps R, C, K = map(int, input().split()) map(int, input().split()) R point3 = [[0 for _ in range(C)] for _ in range(R)] [[0 for _ in range(C)] for _ in range(R)] point3 K = map(int, input().split()) map(int, input().split()) K point2 = [[0 for _ in range(C)] for _ in range(R)] [[0 for _ in range(C)] for _ in range(R)] point2 point1 = [[0 for _ in range(C)] for _ in range(R)] [[0 for _ in range(C)] for _ in range(R)] point1 d = point1[r][c], point2[r][c], point3[r][c] point3[r][c] d
R, C, K = map(int, input().split())
# = int(input())
p = []
for k in range(K):
  p.append(list(map(int, input().split())))

maps = [[0 for _ in range(C)] for _ in range(R)]
for k in range(K):
  maps[p[k][0]-1][p[k][1]-1] += p[k][2]

point1 = [[0 for _ in range(C)] for _ in range(R)]
point2 = [[0 for _ in range(C)] for _ in range(R)]
point3 = [[0 for _ in range(C)] for _ in range(R)]

point1[0][0] = maps[0][0]

for r in range(R):
  for c in range(C):
    a, b, d = point1[r][c], point2[r][c], point3[r][c]  
    if c < C - 1:
      x = maps[r][c+1]
      point1[r][c+1] = max(point1[r][c+1], x, a)
      point2[r][c+1] = max(point2[r][c+1], a + x, b)
      point3[r][c+1] = max(point3[r][c+1], b + x, d)
    if r < R - 1:
      point1[r+1][c] = maps[r+1][c] + max(a, b, d)


print(max(point1[-1][-1], point2[-1][-1], point3[-1][-1]))