Problem:
Score : 100 points

Problem 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.

Constraints

1 \leq N \leq 1000

0 \leq D \leq 10^9

0 \leq X_i < Y_i \leq 10^9

All values in Input are integer.

Input

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

Output

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.

Sample Input 1

3 2
1 4
2 5
0 6

Sample Output 1

Yes
4
2
0

Sample Input 2

3 3
1 4
2 5
0 6

Sample Output 2

No

Solution in C++ (GCC 9.2.1 with AC Library v1.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,d;
  cin >> n >> d;
  
  vec x(n),y(n);
  for(ll i=0;i<n;i++)cin >> x[i] >> y[i];

  two_sat ts(n);

  for(ll i=0;i<n;i++){
    for(ll j=i+1;j<n;j++){
      if (abs(x[i] - x[j]) < d) {
        // cannot use both of x[i] and x[j]
        ts.add_clause(i, false, j, false);
      }
      if (abs(x[i] - y[j]) < d) {
        ts.add_clause(i, false, j, true);
      }
      if (abs(y[i] - x[j]) < d) {
        ts.add_clause(i, true, j, false);
      }
      if (abs(y[i] - y[j]) < d) {
        ts.add_clause(i, true, j, true); 
      }     
    }
  }

  if (!ts.satisfiable()) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  auto answer = ts.answer();
  for (int i = 0; i < n; i++) {
    if (answer[i])
      cout << x[i] << endl;
    else
      cout << y[i] << endl;
  }



}