R,C,K = map(int,input().split())
mat = {}
for _ in range(K):
  r,c,v = map(int,input().split())
  mat[(r,c)] = v

# dp[i][j][k] = i,jまでで、i列のものをk個取ったときのスコア
dp0 = [[0] * (C+1) for _ in range(R+1) ]
dp1 = [[0] * (C+1) for _ in range(R+1) ]
dp2 = [[0] * (C+1) for _ in range(R+1) ]
dp3 = [[0] * (C+1) for _ in range(R+1) ]

for i in range(1,R+1):
  for j in range(1,C+1):
    if (i,j) in mat:
      m = mat[(i,j)]
      # 左からの遷移
      dp1[i][j] = max(dp1[i][j-1], dp0[i][j-1]+m)
      dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1]+m)
      dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1]+m)
    else:
      dp1[i][j] = dp1[i][j-1]
      dp2[i][j] = dp2[i][j-1]
      dp3[i][j] = dp3[i][j-1]

    # 上からの遷移
    x = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
    dp0[i][j] = max(dp0[i][j-1], x)
    if (i,j) in mat:
      m = mat[(i,j)]
      dp1[i][j] = max(dp1[i][j], x+m)
    else:
      dp1[i][j] = max(dp1[i][j], x)

print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])) R,C,K = map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K mat = {} mat {} for _ in range(K):
  r,c,v = map(int,input().split())
  mat[(r,c)] = v

# dp[i][j][k] = i,jまでで、i列のものをk個取ったときのスコア _ 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 mat[(r,c)] = v mat[(r,c)] mat (r,c) r c v [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 dp0 = [[0] * (C+1) for _ in range(R+1) ] dp0 [[0] * (C+1) for _ in range(R+1) ] [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 dp1 = [[0] * (C+1) for _ in range(R+1) ] dp1 [[0] * (C+1) for _ in range(R+1) ] [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 dp2 = [[0] * (C+1) for _ in range(R+1) ] dp2 [[0] * (C+1) for _ in range(R+1) ] [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 dp3 = [[0] * (C+1) for _ in range(R+1) ] dp3 [[0] * (C+1) for _ in range(R+1) ] for i in range(1,R+1):
  for j in range(1,C+1):
    if (i,j) in mat:
      m = mat[(i,j)]
      # 左からの遷移
      dp1[i][j] = max(dp1[i][j-1], dp0[i][j-1]+m)
      dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1]+m)
      dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1]+m)
    else:
      dp1[i][j] = dp1[i][j-1]
      dp2[i][j] = dp2[i][j-1]
      dp3[i][j] = dp3[i][j-1]

    # 上からの遷移
    x = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
    dp0[i][j] = max(dp0[i][j-1], x)
    if (i,j) in mat:
      m = mat[(i,j)]
      dp1[i][j] = max(dp1[i][j], x+m)
    else:
      dp1[i][j] = max(dp1[i][j], x) i range(1,R+1) range 1 R+1 R 1 for j in range(1,C+1):
    if (i,j) in mat:
      m = mat[(i,j)]
      # 左からの遷移
      dp1[i][j] = max(dp1[i][j-1], dp0[i][j-1]+m)
      dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1]+m)
      dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1]+m)
    else:
      dp1[i][j] = dp1[i][j-1]
      dp2[i][j] = dp2[i][j-1]
      dp3[i][j] = dp3[i][j-1]

    # 上からの遷移
    x = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
    dp0[i][j] = max(dp0[i][j-1], x)
    if (i,j) in mat:
      m = mat[(i,j)]
      dp1[i][j] = max(dp1[i][j], x+m)
    else:
      dp1[i][j] = max(dp1[i][j], x) j range(1,C+1) range 1 C+1 C 1 if (i,j) in mat:
      m = mat[(i,j)]
      # 左からの遷移
      dp1[i][j] = max(dp1[i][j-1], dp0[i][j-1]+m)
      dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1]+m)
      dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1]+m)
    else:
      dp1[i][j] = dp1[i][j-1]
      dp2[i][j] = dp2[i][j-1]
      dp3[i][j] = dp3[i][j-1]

    # 上からの遷移
     (i,j) in mat (i,j) i j mat m = mat[(i,j)] m mat[(i,j)] mat (i,j) i j dp1[i][j] = max(dp1[i][j-1], dp0[i][j-1]+m) dp1[i][j] [i] dp1 i j max(dp1[i][j-1], dp0[i][j-1]+m) max dp1[i][j-1] [i] dp1 i j-1 j 1 dp0[i][j-1]+m dp0[i][j-1] [i] dp0 i j-1 j 1 m dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1]+m) dp2[i][j] [i] dp2 i j max(dp2[i][j-1], dp1[i][j-1]+m) max dp2[i][j-1] [i] dp2 i j-1 j 1 dp1[i][j-1]+m dp1[i][j-1] [i] dp1 i j-1 j 1 m dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1]+m) dp3[i][j] [i] dp3 i j max(dp3[i][j-1], dp2[i][j-1]+m) max dp3[i][j-1] [i] dp3 i j-1 j 1 dp2[i][j-1]+m dp2[i][j-1] [i] dp2 i j-1 j 1 m dp1[i][j] = dp1[i][j-1] dp1[i][j] [i] dp1 i j dp1[i][j-1] [i] dp1 i j-1 j 1 dp2[i][j] = dp2[i][j-1] dp2[i][j] [i] dp2 i j dp2[i][j-1] [i] dp2 i j-1 j 1 dp3[i][j] = dp3[i][j-1] dp3[i][j] [i] dp3 i j dp3[i][j-1] [i] dp3 i j-1 j 1 x = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j]) x max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j]) max dp0[i-1][j] [i-1] dp0 i-1 i 1 j dp1[i-1][j] [i-1] dp1 i-1 i 1 j dp2[i-1][j] [i-1] dp2 i-1 i 1 j dp3[i-1][j] [i-1] dp3 i-1 i 1 j dp0[i][j] = max(dp0[i][j-1], x) dp0[i][j] [i] dp0 i j max(dp0[i][j-1], x) max dp0[i][j-1] [i] dp0 i j-1 j 1 x if (i,j) in mat:
      m = mat[(i,j)]
      dp1[i][j] = max(dp1[i][j], x+m)
    else:
      dp1[i][j] = max(dp1[i][j], x) (i,j) in mat (i,j) i j mat m = mat[(i,j)] m mat[(i,j)] mat (i,j) i j dp1[i][j] = max(dp1[i][j], x+m) dp1[i][j] [i] dp1 i j max(dp1[i][j], x+m) max dp1[i][j] [i] dp1 i j x+m x m dp1[i][j] = max(dp1[i][j], x) dp1[i][j] [i] dp1 i j max(dp1[i][j], x) max dp1[i][j] [i] dp1 i j x print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C])) print max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]) max dp0[R][C] [R] dp0 R C dp1[R][C] [R] dp1 R C dp2[R][C] [R] dp2 R C dp3[R][C] [R] dp3 R C m = mat[(i,j)] mat[(i,j)] m x = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j]) max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j]) x dp3 = [[0] * (C+1) for _ in range(R+1) ] [[0] * (C+1) for _ in range(R+1) ] dp3 R,C,K = map(int,input().split()) map(int,input().split()) R dp0 = [[0] * (C+1) for _ in range(R+1) ] [[0] * (C+1) for _ in range(R+1) ] dp0 r,c,v = map(int,input().split()) map(int,input().split()) r m = mat[(i,j)] mat[(i,j)] m v = map(int,input().split()) map(int,input().split()) v mat = {} {} mat K = map(int,input().split()) map(int,input().split()) K dp2 = [[0] * (C+1) for _ in range(R+1) ] [[0] * (C+1) for _ in range(R+1) ] dp2 c,v = map(int,input().split()) map(int,input().split()) c C,K = map(int,input().split()) map(int,input().split()) C dp1 = [[0] * (C+1) for _ in range(R+1) ] [[0] * (C+1) for _ in range(R+1) ] dp1
R,C,K = map(int,input().split())
mat = {}
for _ in range(K):
  r,c,v = map(int,input().split())
  mat[(r,c)] = v

# dp[i][j][k] = i,jまでで、i列のものをk個取ったときのスコア
dp0 = [[0] * (C+1) for _ in range(R+1) ]
dp1 = [[0] * (C+1) for _ in range(R+1) ]
dp2 = [[0] * (C+1) for _ in range(R+1) ]
dp3 = [[0] * (C+1) for _ in range(R+1) ]

for i in range(1,R+1):
  for j in range(1,C+1):
    if (i,j) in mat:
      m = mat[(i,j)]
      # 左からの遷移
      dp1[i][j] = max(dp1[i][j-1], dp0[i][j-1]+m)
      dp2[i][j] = max(dp2[i][j-1], dp1[i][j-1]+m)
      dp3[i][j] = max(dp3[i][j-1], dp2[i][j-1]+m)
    else:
      dp1[i][j] = dp1[i][j-1]
      dp2[i][j] = dp2[i][j-1]
      dp3[i][j] = dp3[i][j-1]

    # 上からの遷移
    x = max(dp0[i-1][j], dp1[i-1][j], dp2[i-1][j], dp3[i-1][j])
    dp0[i][j] = max(dp0[i][j-1], x)
    if (i,j) in mat:
      m = mat[(i,j)]
      dp1[i][j] = max(dp1[i][j], x+m)
    else:
      dp1[i][j] = max(dp1[i][j], x)

print(max(dp0[R][C], dp1[R][C], dp2[R][C], dp3[R][C]))