output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N X Y
      c_1 w_1
      :
      c_N w_N
attempt: import sys
  
  readline = sys.stdin.readline
  readlines = sys.stdin.readlines
  
  MOD = 10**9 + 7
  
  N, X, Y = map(int, readline().split())
  CW = (tuple(int(x) for x in line.split()) for line in readlines())
  
  C_to_W = [[] for _ in range(N + 1)]
  for c, w in CW:
      C_to_W[c].append(w)
  
  for c in range(N + 1):
      C_to_W[c].sort()
  
  C_to_W.sort()
  
  C_to_W = [x for x in C_to_W if x]
  
  min_wt = C_to_W[0][0]
  C_to_W = [x for x in C_to_W if x[0] + min_wt <= Y]
  
  if len(C_to_W) <= 1:
      print(1)
      exit()
  
  comp_size = [0] * (len(C_to_W))
  for x in C_to_W[0]:
      if x + C_to_W[0][0] <= X or x + C_to_W[1][0] <= Y:
          comp_size[0] += 1
  
  for i, arr in enumerate(C_to_W[1:], 1):
      for x in arr:
          if x + min_wt <= Y or x + arr[0] <= X:
              comp_size[i] += 1
  
  fact = [1] * (N + 1)
  for i in range(1, N + 1):
      fact[i] = fact[i - 1] * i % MOD
  
  num = fact[sum(comp_size)]
  den = 1
  for x in comp_size:
      den *= fact[x]
      den %= MOD
  answer = num * pow(den, MOD - 2, MOD) % MOD
  print(answer)
  
problem_description: Statement
  
  Snuke arranged N colorful balls in a row. The i-th ball from the left has
  color c_i and weight w_i.
  
  He can rearrange the balls by performing the following two operations any
  number of times, in any order:
  
    * Operation 1: Select two balls with the same color. If the total weight of these balls is at most X, swap the positions of these balls.
    * Operation 2: Select two balls with different colors. If the total weight of these balls is at most Y, swap the positions of these balls.
  
  How many different sequences of colors of balls can be obtained? Find the
  count modulo 10^9 + 7.
samples: [{"input": "4 7 3\n    3 2\n    4 3\n    2 1\n    4 4", "output": "2\n    \n\n  * The sequence of colors (2,4,3,4) can be obtained by swapping the positions of the first and third balls by operation 2.\n  * It is also possible to swap the positions of the second and fourth balls by operation 1, but it does not affect the sequence of colors.\n\n* * *"}, {"input": "1 1 1\n    1 1", "output": "1\n    \n\n* * *"}, {"input": "21 77 68\n    16 73\n    16 99\n    19 66\n    2 87\n    2 16\n    7 17\n    10 36\n    10 68\n    2 38\n    10 74\n    13 55\n    21 21\n    3 7\n    12 41\n    13 88\n    18 6\n    2 12\n    13 87\n    1 9\n    2 27\n    13 15", "output": "129729600"}]