output_description: Print the maximum possible sum of the values of items Takahashi picks up.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      R C K
      r_1 c_1 v_1
      r_2 c_2 v_2
      :
      r_K c_K v_K
attempt: h, w, n = map(int, input().split())
  dp = [[[0] * 4 for _ in range(w + 1)] for _ in range(h + 1)]
  v = [[0] * (w + 1) for _ in range(h + 1)]
  for _ in range(n):
      r, c, f = map(int, input().split())
      v[r][c] = f
  for i in range(1, h + 1):
      for x in 0, 1, 2:
          for j in range(1, w + 1):
              dp[i][j][x + 1] = max(
                  dp[i][j][x],
                  max(dp[i][j + 1][x], (x < 1) * dp[i + 1][j][3]) + v[i][j],
                  dp[i + 1][j][x + 1],
              )
  print(dp[-1][-1][-1])
  
problem_description: Statement
  
  There are K items placed on a grid of squares with R rows and C columns. Let
  (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column
  (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i.
  
  Takahashi will begin at (1, 1), the start, and get to (R, C), the goal. When
  he is at (i, j), he can move to (i + 1, j) or (i, j + 1) (but cannot move to a
  non-existent square).
  
  He can pick up items on the squares he visits, including the start and the
  goal, but at most three for each row. It is allowed to ignore the item on a
  square he visits.
  
  Find the maximum possible sum of the values of items he picks up.
samples: [{"input": "2 2 3\n    1 1 3\n    2 1 4\n    1 2 5", "output": "8\n    \n\nHe has two ways to get to the goal:\n\n  * Visit (1, 1), (1, 2), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 5 = 8.\n  * Visit (1, 1), (2, 1), and (2, 2), in this order. In this case, the total value of the items he can pick up is 3 + 4 = 7.\n\nThus, the maximum possible sum of the values of items he picks up is 8.\n\n* * *"}, {"input": "2 5 5\n    1 1 3\n    2 4 20\n    1 2 1\n    1 3 4\n    1 4 2", "output": "29\n    \n\nWe have four items in the 1-st row. The optimal choices are as follows:\n\n  * Visit (1, 1) (1, 2), (1, 3), (1, 4), (2, 4), and (2, 5), in this order, and pick up all items except the one on (1, 2). Then, the total value of the items he picks up will be 3 + 4 + 2 + 20 = 29.\n\n* * *"}, {"input": "4 5 10\n    2 5 12\n    1 5 12\n    2 3 15\n    1 2 20\n    1 1 28\n    2 4 26\n    3 2 27\n    4 5 21\n    3 5 10\n    1 3 10", "output": "142"}]