R, C, K = map(int, input().split())

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

memo = [[0]*4 for _ in range(R+1)]

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

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

memo = [[0]*4 for _ in range(R+1)]

for j in range(1,C+1):
  for i in range(1,R+1):
    if mp[i][j] > 0:
      memo[i][3] = max(memo[i][3], memo[i][2] + mp[i][j])
      memo[i][2] = max(memo[i][2], memo[i][1] + mp[i][j])
      memo[i][1] = max(memo[i][1], memo[i][0] + mp[i][j], max(memo[i-1])+mp[i][j])
      memo[i][0] = max(memo[i][0], max(memo[i-1]))
    else:
      memo[i][0] = max(memo[i][0], max(memo[i-1]))
      
print(max(memo[R]))