output_description: Print the maximum possible sum of the integers written on the picked cards.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N H W
      R_1 C_1 A_1
      R_2 C_2 A_2
      \vdots
      R_N C_N A_N
attempt: N, H, W = map(int, input().split())
  r = []
  c = []
  w = []
  tmp = []
  for num in range(N):
      a1, a2, a3 = map(int, input().split())
      r.append(a1)
      c.append(a2)
      w.append(a3)
  
  count = 0
  for num in range(N):
      tmp_list = [u for s, t, u in zip(r, c, w) if s == num]
      if tmp_list == []:
          continue
      max_r = max(tmp_list)
      if tmp_list.count(max_r) > 1:
          indexes = [i for i, u in enumerate(tmp_list) if u == max_r]
  
          cs = [t for i, t in enumerate(c) if i in indexes]
          ws = [u for s, t, u in zip(r, c, w) if t in cs and s == num]
          index_1 = ws.index(max(ws))
      else:
          index_1 = tmp_list.index(max_r)
      w[index_1] = 0
      count += max_r
  
  tmp_r = r
  r = c
  c = tmp_r
  for num in range(N):
      tmp_list = [u for s, t, u in zip(r, c, w) if s == num]
      if tmp_list == []:
          continue
      max_r = max(tmp_list)
      if tmp_list.count(max_r) > 1:
          indexes = [i for i, u in enumerate(tmp_list) if u == max_r]
  
          cs = [t for i, t in enumerate(c) if i in indexes]
          ws = [u for s, t, u in zip(r, c, w) if t in cs and s == num]
          index_1 = ws.index(max(ws))
      else:
          index_1 = tmp_list.index(max_r)
      w[index_1] = 0
      count += max_r
  
  print(count)
  
problem_description: Statement
  
  There are N cards placed on a grid with H rows and W columns of squares.
  
  The i-th card has an integer A_i written on it, and it is placed on the square
  at the R_i-th row from the top and the C_i-th column from the left.
  
  Multiple cards may be placed on the same square.
  
  You will first pick up at most one card from each row.
  
  Then, you will pick up at most one card from each column.
  
  Find the maximum possible sum of the integers written on the picked cards.
samples: [{"input": "6 2 2\n    2 2 2\n    1 1 8\n    1 1 5\n    1 2 9\n    1 2 7\n    2 1 4", "output": "28\n    \n\nThe sum of the integers written on the picked cards will be 28, the maximum\nvalue possible, if you pick up cards as follows:\n\n  * Pick up the fourth card from the first row.\n  * Pick up the sixth card from the second row.\n  * Pick up the second card from the first column.\n  * Pick up the fifth card from the second column.\n\n* * *"}, {"input": "13 5 6\n    1 3 35902\n    4 6 19698\n    4 6 73389\n    3 6 3031\n    3 1 4771\n    1 4 4784\n    2 1 36357\n    2 1 24830\n    5 6 50219\n    4 6 22645\n    1 2 30739\n    1 4 68417\n    1 5 78537", "output": "430590\n    \n\n* * *"}, {"input": "1 100000 100000\n    1 1 1", "output": "1"}]