R, C, K = map(int, input().split())
xy = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K) :
  r, c, v = map(int, input().split())
  xy[r - 1][c - 1] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for cy in range(R + 1) :
  for cx in range(C + 1) :
    if cx < C :
      dp[0][cy][cx + 1] = max(dp[0][cy][cx + 1], dp[0][cy][cx])
      dp[1][cy][cx + 1] = max(dp[1][cy][cx + 1], dp[0][cy][cx] + xy[cy][cx], dp[1][cy][cx])
      dp[2][cy][cx + 1] = max(dp[2][cy][cx + 1], dp[1][cy][cx] + xy[cy][cx], dp[2][cy][cx])
      dp[3][cy][cx + 1] = max(dp[3][cy][cx + 1], dp[2][cy][cx] + xy[cy][cx], dp[3][cy][cx])
    if cy < R :
      dp[0][cy + 1][cx] = max(dp[i][cy][cx] for i in range(3)) + xy[cy][cx]
      dp[0][cy + 1][cx] = max(dp[0][cy + 1][cx], dp[3][cy][cx])

print(max(dp[i][-1][-1] for i in range(4))) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0] * (C + 1) for _ in range(R + 1) for _ in range(R + 1) _ range(R + 1) range R + 1 R 1 for _ in range(R + 1) [0] * (C + 1) [0] 0 C + 1 C 1 xy = [[0] * (C + 1) for _ in range(R + 1)] xy [[0] * (C + 1) for _ in range(R + 1)] for _ in range(K) :
  r, c, v = map(int, input().split())
  xy[r - 1][c - 1] = v _ 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 xy[r - 1][c - 1] = v xy[r - 1][c - 1] [r - 1] xy r - 1 r 1 c - 1 c 1 v [[0] * (C + 1) for _ in range(R + 1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0] * (C + 1) for _ in range(R + 1)] dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] dp [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] for cy in range(R + 1) :
  for cx in range(C + 1) :
    if cx < C :
      dp[0][cy][cx + 1] = max(dp[0][cy][cx + 1], dp[0][cy][cx])
      dp[1][cy][cx + 1] = max(dp[1][cy][cx + 1], dp[0][cy][cx] + xy[cy][cx], dp[1][cy][cx])
      dp[2][cy][cx + 1] = max(dp[2][cy][cx + 1], dp[1][cy][cx] + xy[cy][cx], dp[2][cy][cx])
      dp[3][cy][cx + 1] = max(dp[3][cy][cx + 1], dp[2][cy][cx] + xy[cy][cx], dp[3][cy][cx])
    if cy < R :
      dp[0][cy + 1][cx] = max(dp[i][cy][cx] for i in range(3)) + xy[cy][cx]
      dp[0][cy + 1][cx] = max(dp[0][cy + 1][cx], dp[3][cy][cx]) cy range(R + 1) range R + 1 R 1 for cx in range(C + 1) :
    if cx < C :
      dp[0][cy][cx + 1] = max(dp[0][cy][cx + 1], dp[0][cy][cx])
      dp[1][cy][cx + 1] = max(dp[1][cy][cx + 1], dp[0][cy][cx] + xy[cy][cx], dp[1][cy][cx])
      dp[2][cy][cx + 1] = max(dp[2][cy][cx + 1], dp[1][cy][cx] + xy[cy][cx], dp[2][cy][cx])
      dp[3][cy][cx + 1] = max(dp[3][cy][cx + 1], dp[2][cy][cx] + xy[cy][cx], dp[3][cy][cx])
    if cy < R :
      dp[0][cy + 1][cx] = max(dp[i][cy][cx] for i in range(3)) + xy[cy][cx]
      dp[0][cy + 1][cx] = max(dp[0][cy + 1][cx], dp[3][cy][cx]) cx range(C + 1) range C + 1 C 1 if cx < C :
      dp[0][cy][cx + 1] = max(dp[0][cy][cx + 1], dp[0][cy][cx])
      dp[1][cy][cx + 1] = max(dp[1][cy][cx + 1], dp[0][cy][cx] + xy[cy][cx], dp[1][cy][cx])
      dp[2][cy][cx + 1] = max(dp[2][cy][cx + 1], dp[1][cy][cx] + xy[cy][cx], dp[2][cy][cx])
      dp[3][cy][cx + 1] = max(dp[3][cy][cx + 1], dp[2][cy][cx] + xy[cy][cx], dp[3][cy][cx])
     cx < C cx C dp[0][cy][cx + 1] = max(dp[0][cy][cx + 1], dp[0][cy][cx]) dp[0][cy][cx + 1] [cy] [0] dp 0 cy cx + 1 cx 1 max(dp[0][cy][cx + 1], dp[0][cy][cx]) max dp[0][cy][cx + 1] [cy] [0] dp 0 cy cx + 1 cx 1 dp[0][cy][cx] [cy] [0] dp 0 cy cx dp[1][cy][cx + 1] = max(dp[1][cy][cx + 1], dp[0][cy][cx] + xy[cy][cx], dp[1][cy][cx]) dp[1][cy][cx + 1] [cy] [1] dp 1 cy cx + 1 cx 1 max(dp[1][cy][cx + 1], dp[0][cy][cx] + xy[cy][cx], dp[1][cy][cx]) max dp[1][cy][cx + 1] [cy] [1] dp 1 cy cx + 1 cx 1 dp[0][cy][cx] + xy[cy][cx] dp[0][cy][cx] [cy] [0] dp 0 cy cx xy[cy][cx] [cy] xy cy cx dp[1][cy][cx] [cy] [1] dp 1 cy cx dp[2][cy][cx + 1] = max(dp[2][cy][cx + 1], dp[1][cy][cx] + xy[cy][cx], dp[2][cy][cx]) dp[2][cy][cx + 1] [cy] [2] dp 2 cy cx + 1 cx 1 max(dp[2][cy][cx + 1], dp[1][cy][cx] + xy[cy][cx], dp[2][cy][cx]) max dp[2][cy][cx + 1] [cy] [2] dp 2 cy cx + 1 cx 1 dp[1][cy][cx] + xy[cy][cx] dp[1][cy][cx] [cy] [1] dp 1 cy cx xy[cy][cx] [cy] xy cy cx dp[2][cy][cx] [cy] [2] dp 2 cy cx dp[3][cy][cx + 1] = max(dp[3][cy][cx + 1], dp[2][cy][cx] + xy[cy][cx], dp[3][cy][cx]) dp[3][cy][cx + 1] [cy] [3] dp 3 cy cx + 1 cx 1 max(dp[3][cy][cx + 1], dp[2][cy][cx] + xy[cy][cx], dp[3][cy][cx]) max dp[3][cy][cx + 1] [cy] [3] dp 3 cy cx + 1 cx 1 dp[2][cy][cx] + xy[cy][cx] dp[2][cy][cx] [cy] [2] dp 2 cy cx xy[cy][cx] [cy] xy cy cx dp[3][cy][cx] [cy] [3] dp 3 cy cx if cy < R :
      dp[0][cy + 1][cx] = max(dp[i][cy][cx] for i in range(3)) + xy[cy][cx]
      dp[0][cy + 1][cx] = max(dp[0][cy + 1][cx], dp[3][cy][cx]) cy < R cy R dp[0][cy + 1][cx] = max(dp[i][cy][cx] for i in range(3)) + xy[cy][cx] dp[0][cy + 1][cx] [cy + 1] [0] dp 0 cy + 1 cy 1 cx max(dp[i][cy][cx] for i in range(3)) + xy[cy][cx] max(dp[i][cy][cx] for i in range(3)) max dp[i][cy][cx] [cy] [i] dp i cy cx xy[cy][cx] [cy] xy cy cx dp[0][cy + 1][cx] = max(dp[0][cy + 1][cx], dp[3][cy][cx]) dp[0][cy + 1][cx] [cy + 1] [0] dp 0 cy + 1 cy 1 cx max(dp[0][cy + 1][cx], dp[3][cy][cx]) max dp[0][cy + 1][cx] [cy + 1] [0] dp 0 cy + 1 cy 1 cx dp[3][cy][cx] [cy] [3] dp 3 cy cx print(max(dp[i][-1][-1] for i in range(4))) print max(dp[i][-1][-1] for i in range(4)) max dp[i][-1][-1] [-1] [i] dp i -1 -1 dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] dp 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 r, c, v = map(int, input().split()) map(int, input().split()) r c, v = map(int, input().split()) map(int, input().split()) c C, K = map(int, input().split()) map(int, input().split()) C xy = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] xy
R, C, K = map(int, input().split())
xy = [[0] * (C + 1) for _ in range(R + 1)]
for _ in range(K) :
  r, c, v = map(int, input().split())
  xy[r - 1][c - 1] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for cy in range(R + 1) :
  for cx in range(C + 1) :
    if cx < C :
      dp[0][cy][cx + 1] = max(dp[0][cy][cx + 1], dp[0][cy][cx])
      dp[1][cy][cx + 1] = max(dp[1][cy][cx + 1], dp[0][cy][cx] + xy[cy][cx], dp[1][cy][cx])
      dp[2][cy][cx + 1] = max(dp[2][cy][cx + 1], dp[1][cy][cx] + xy[cy][cx], dp[2][cy][cx])
      dp[3][cy][cx + 1] = max(dp[3][cy][cx + 1], dp[2][cy][cx] + xy[cy][cx], dp[3][cy][cx])
    if cy < R :
      dp[0][cy + 1][cx] = max(dp[i][cy][cx] for i in range(3)) + xy[cy][cx]
      dp[0][cy + 1][cx] = max(dp[0][cy + 1][cx], dp[3][cy][cx])

print(max(dp[i][-1][-1] for i in range(4)))