output_description: Print `No` if it is impossible to place N flags.
  
  If it is possible, print `Yes` first. After that, print N lines. i-th line of
  them should contain the coodinate of flag i.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N D
      X_1 Y_1
      X_2 Y_2
      \vdots
      X_N Y_N
attempt: from scipy.sparse.csgraph import connected_components
  from scipy.sparse import csr_matrix
  
  N, D, *XY = map(int, open(0).read().split())
  XY = list(zip(*[iter(XY)] * 2))
  
  R, C = [], []
  for i, (x1, y1) in enumerate(XY):
      for j, (x2, y2) in enumerate(XY):
          if i == j:
              continue
  
          if abs(x1 - x2) < D:
              R.append(i)
              C.append(j + N)
          if abs(x1 - y2) < D:
              R.append(i)
              C.append(j)
          if abs(y1 - x2) < D:
              R.append(i + N)
              C.append(j + N)
          if abs(y1 - y2) < D:
              R.append(i + N)
              C.append(j)
  
  G = csr_matrix(([1] * len(R), (R, C)))
  M, label = connected_components(G, connection="strong")
  
  C = [[] for _ in range(M)]
  for i, l in enumerate(label):
      C[l].append(i)
  
  memo = {}
  for c in C:
      for x in c:
          if (x < N and x + N in c) or (N <= x and x - N in c):
              print("No")
              quit()
  
          if x not in memo:
              memo[x] = True
              memo[(x + N) % (2 * N)] = False
  
  print("Yes")
  for i, (x, y) in enumerate(XY):
      print(x if memo[i] else y)
  
problem_description: Statement
  
  Consider placing N flags on a line. Flags are numbered through 1 to N.
  
  Flag i can be placed on the coordinate X_i or Y_i. For any two different
  flags, the distance between them should be at least D.
  
  Decide whether it is possible to place all N flags. If it is possible, print
  such a configulation.
samples: [{"input": "3 2\n    1 4\n    2 5\n    0 6", "output": "Yes\n    4\n    2\n    0\n    \n\n* * *"}, {"input": "3 3\n    1 4\n    2 5\n    0 6", "output": "No"}]