R, C, K = map(int, input().split())
items = [[0]*C for _ in range(R)]

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

dp = [[0]*4 for _ in range(C)]

for x in range(1, 4):
  dp[0][x] = items[0][0]
  for j in range(1, C):
    dp[j][x] = max(dp[j-1][x-1] + items[0][j], dp[j-1][x])

#print(items)
#print(dp)

for i in range(1, R):
  for j in range(C):
    for x in range(4):
      dp[j][x] = dp[j][3]
  for x in range(1, 4):
    dp[0][x] += items[i][0]
    for j in range(1, C):
      dp[j][x] = max(dp[j-1][x-1] + items[i][j], dp[j-1][x], dp[j][3] + items[i][j])
  #print(dp)

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

#print(items)
#print(dp) x range(1, 4) range 1 4 dp[0][x] = items[0][0] dp[0][x] [0] dp 0 x items[0][0] [0] items 0 0 for j in range(1, C):
    dp[j][x] = max(dp[j-1][x-1] + items[0][j], dp[j-1][x])

#print(items)
#print(dp) j range(1, C) range 1 C dp[j][x] = max(dp[j-1][x-1] + items[0][j], dp[j-1][x]) dp[j][x] [j] dp j x max(dp[j-1][x-1] + items[0][j], dp[j-1][x]) max dp[j-1][x-1] + items[0][j] dp[j-1][x-1] [j-1] dp j-1 j 1 x-1 x 1 items[0][j] [0] items 0 j dp[j-1][x] [j-1] dp j-1 j 1 x for i in range(1, R):
  for j in range(C):
    for x in range(4):
      dp[j][x] = dp[j][3]
  for x in range(1, 4):
    dp[0][x] += items[i][0]
    for j in range(1, C):
      dp[j][x] = max(dp[j-1][x-1] + items[i][j], dp[j-1][x], dp[j][3] + items[i][j])
  #print(dp) i range(1, R) range 1 R for j in range(C):
    for x in range(4):
      dp[j][x] = dp[j][3]
   j range(C) range C for x in range(4):
      dp[j][x] = dp[j][3]
   x range(4) range 4 dp[j][x] = dp[j][3] dp[j][x] [j] dp j x dp[j][3] [j] dp j 3 for x in range(1, 4):
    dp[0][x] += items[i][0]
    for j in range(1, C):
      dp[j][x] = max(dp[j-1][x-1] + items[i][j], dp[j-1][x], dp[j][3] + items[i][j])
  #print(dp) x range(1, 4) range 1 4 dp[0][x] += items[i][0] dp[0][x] [0] dp 0 x items[i][0] [i] items i 0 for j in range(1, C):
      dp[j][x] = max(dp[j-1][x-1] + items[i][j], dp[j-1][x], dp[j][3] + items[i][j])
  #print(dp) j range(1, C) range 1 C dp[j][x] = max(dp[j-1][x-1] + items[i][j], dp[j-1][x], dp[j][3] + items[i][j]) dp[j][x] [j] dp j x max(dp[j-1][x-1] + items[i][j], dp[j-1][x], dp[j][3] + items[i][j]) max dp[j-1][x-1] + items[i][j] dp[j-1][x-1] [j-1] dp j-1 j 1 x-1 x 1 items[i][j] [i] items i j dp[j-1][x] [j-1] dp j-1 j 1 x dp[j][3] + items[i][j] dp[j][3] [j] dp j 3 items[i][j] [i] items i j print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 R, C, K = map(int, input().split()) map(int, input().split()) R v = map(int, input().split()) map(int, input().split()) v c, v = map(int, input().split()) map(int, input().split()) c dp = [[0]*4 for _ in range(C)] [[0]*4 for _ in range(C)] dp items = [[0]*C for _ in range(R)] [[0]*C for _ in range(R)] items r, c, v = map(int, input().split()) map(int, input().split()) r C, K = map(int, input().split()) map(int, input().split()) C K = map(int, input().split()) map(int, input().split()) K
R, C, K = map(int, input().split())
items = [[0]*C for _ in range(R)]

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

dp = [[0]*4 for _ in range(C)]

for x in range(1, 4):
  dp[0][x] = items[0][0]
  for j in range(1, C):
    dp[j][x] = max(dp[j-1][x-1] + items[0][j], dp[j-1][x])

#print(items)
#print(dp)

for i in range(1, R):
  for j in range(C):
    for x in range(4):
      dp[j][x] = dp[j][3]
  for x in range(1, 4):
    dp[0][x] += items[i][0]
    for j in range(1, C):
      dp[j][x] = max(dp[j-1][x-1] + items[i][j], dp[j-1][x], dp[j][3] + items[i][j])
  #print(dp)

print(dp[-1][-1])