#include<iostream>
#include<stack>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<cstring>
#include<map>
#include<numeric>
#include<sstream>
#include<cmath>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define f(i,x,y) for(int i = x; i<y; i++ )
#define FORV(it,A) for(vector<int>::iterator it = A.begin(); it!= A.end(); it++)
#define FORS(it,A) for(set<int>::iterator it = A.begin(); it!= A.end(); it++)
#define quad(x) (x) * (x)
#define mp make_pair
#define clr(x, y) memset(x, y, sizeof x)
#define fst first
#define snd second
#define sz(X) (int)(X.size())
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

pii p[100100];
int q[100100], acc[100100], v[100100][32];
vector <pii> s, aux;
int n, m;

bool solve() {
	memset(v, -1, sizeof(v));

	f(j, 0, 31) {
	//f(j, 0, 2) {
		//cout << "====> j=" << j << endl;
		s.clear();
		f(i, 0, m) if ((q[i] & (1<<j)) == 0) s.pb(p[i]);
		sort(s.begin(), s.end());

		//f(i, 0, s.size()) cout << s[i].fst << ' ' << s[i].snd << endl;

		if (s.size() == 0) {
			f(i, 0, n) v[i][j] = 1;
			continue;
		}

		aux.clear();
		int ini=s[0].fst, fim=s[0].snd;
		f(i, 1, s.size()) {
			if (s[i].fst <= fim) fim = max(fim, s[i].snd);
			else {
				aux.pb( make_pair(ini, fim));
				ini=s[i].fst, fim=s[i].snd;
			}
		}
		aux.pb( make_pair(ini, fim));

		//cout << "aux >> " << endl;
		//f(i, 0, aux.size()) cout << aux[i].fst << ' ' << aux[i].snd << endl;

		f(i, 0, n) v[i][j] = 1;
		f(_i, 0, aux.size())
			f(i, aux[_i].fst, aux[_i].snd+1)
				v[i][j] = 0;
		acc[0] = v[0][j];
		f(i, 1, n) acc[i] = acc[i-1] + v[i][j];

		//f(i, 0, n) cout << acc[i] << ' '; cout << endl;
		f(i, 0, m) if ((q[i]&(1<<j))) {
			int val = acc[ p[i].snd ];
			if (p[i].fst != 0) val -= acc[ p[i].fst ];

			if (val == 0) return false;
		}

	}

	return true;
}

int main() {
	cin >> n >> m;

	f(i, 0, n) {
		scanf("%d %d %d", &p[i].fst, &p[i].snd, &q[i]);
		p[i].fst--; p[i].snd--;
	}

	memset(v, -1, sizeof(v));

	if (!solve()) cout << "NO" << endl;
	else {
		cout << "YES" << endl;
		f(i, 0, n) {
			if (i != 0) printf(" ");
			int val=0;
			f(j, 0, 31) val = val|(v[i][j]<<j);
			printf("%d", val);
		}
		cout << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
#define LL long long
using namespace std;

const int N = 11111;
int sum[N<<2];
int lasy[N<<2];
int L[N<<2], R[N<<2], M[N<<2];
int a[N], b[N], c[N];

void build(int l, int r, int k){
    sum[k] = -1;
    lasy[k] = -1;
    L[k] = l;
    R[k] = r;
    int mid = (l + r) >> 1;
    M[k] = mid;
    if(l == r) return;
    build(l, mid, k<<1);
    build(mid+1, r, k<<1|1);
}

void down(int k){
    if(lasy[k] == -1) return;
    if(L[k] != R[k]){
        if(sum[k<<1] == -1) sum[k<<1] = lasy[k];
        else sum[k<<1] |= lasy[k];
        lasy[k<<1] = sum[k<<1];
        if(sum[k<<1|1] == -1) sum[k<<1|1] = lasy[k];
        else sum[k<<1|1] |= lasy[k];
        lasy[k<<1|1] = sum[k<<1|1];
    }
    lasy[k] == -1;
}

void update(int l, int r, int k, int val){
    down(k);
    if(l == L[k] && r == R[k]){
        if(sum[k] == -1){
            sum[k] = val;
            lasy[k] = val;
        } else {
            sum[k] |= val;
            lasy[k] = sum[k];
        }
        return;
    }
    if(r <= M[k]) update(l, r, k<<1, val);
    else if(l > M[k]) update(l, r, k<<1|1, val);
    else{
        update(l, M[k], k<<1, val);
        update(M[k]+1, r, k<<1|1, val);
    }
    if(sum[k<<1] != 1 && sum[k<<1|1] != -1)
        sum[k] = (sum[k<<1] & sum[k<<1|1]);
}

int check(int l, int r, int k){
    down(k);
    if(l == L[k] && r == R[k]) return sum[k];
    if(r <= M[k]) return check(l, r, k<<1);
    else if(l > M[k]) return check(l, r, k<<1|1);
    else{
        int ans1 = check(l, M[k], k<<1);
        int ans2 = check(M[k]+1, r, k<<1|1);
        return (ans1 & ans2);
    }
}

void query(int l, int r, int k){
    down(k);
    if(l == r) {
        if(l > 1) putchar(' ');
        printf("%d", sum[k]);
        return;
    }
    query(l, M[k], k<<1);
    query(M[k]+1, r, k<<1|1);
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    build(1, n, 1);
    for(int i = 0;i < m; ++i){
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        update(a[i], b[i], 1, c[i]);
    }
    bool ans = 1;
    for(int i = 0; i < m; ++i){
        if(check(a[i], b[i], 1) != c[i]){
            ans = 0;
            break;
        }
    }
        //cout<<" ===========";
    if(!ans) puts("NO");
    else query(1, n, 1);
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
#define LL long long
#define lk (k<<1)
#define rk (k<<1|1)
using namespace std;

const int N = 111111;
int sum[N<<2];
int L[N<<2], R[N<<2], M[N<<2];
int a[N], b[N], c[N];

void build(int l, int r, int k){
    sum[k] = 0;
    L[k] = l;
    R[k] = r;
    int mid = (l + r) >> 1;
    M[k] = mid;
    if(l == r) return;
    build(l, mid, lk);
    build(mid+1, r, rk);
}

void update(int l, int r, int k, int val){
    if(l == L[k] && r == R[k]){
        sum[k] |= val;
        return;
    }
    if(r <= M[k]) update(l, r, lk, val);
    else if(l > M[k]) update(l, r, rk, val);
    else{
        update(l, M[k], lk, val);
        update(M[k]+1, r, rk, val);
    }
}

void zhu(int l, int r, int k){
    if(l == r) return;
    sum[lk] |= sum[k];
    sum[rk] |= sum[k];
    zhu(l, M[k], lk);
    zhu(M[k] + 1, r, rk);
    sum[k] = (sum[lk] & sum[rk]);
}

int check(int l, int r, int k){
    if(l == L[k] && r == R[k]) return sum[k];
    if(r <= M[k]) return check(l, r, lk);
    else if(l > M[k]) return check(l, r, rk);
    else{
        int ans1 = check(l, M[k], lk);
        int ans2 = check(M[k]+1, r, rk);
        return (ans1 & ans2);
    }
}

void query(int l, int r, int k){
    if(l == r) {
        if(l > 1) putchar(' ');
        printf("%d", sum[k]);
        return;
    }
    query(l, M[k], lk);
    query(M[k]+1, r, rk);
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    build(1, n, 1);
    for(int i = 0;i < m; ++i){
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        update(a[i], b[i], 1, c[i]);
    }
    zhu(1, n, 1);
    bool ans = 1;
    for(int i = 0; i < m; ++i){
        if(check(a[i], b[i], 1) != c[i]){
            ans = 0;
            break;
        }
    }
        //cout<<" ===========";
    if(!ans) puts("NO");
    else{
        puts("YES");
        query(1, n, 1);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
#define LL long long
using namespace std;

const int N = 11111;
int sum[N<<2];
int lasy[N<<2];
int L[N<<2], R[N<<2], M[N<<2];
int a[N], b[N], c[N];

void build(int l, int r, int k){
    sum[k] = -1;
    lasy[k] = -1;
    L[k] = l;
    R[k] = r;
    int mid = (l + r) >> 1;
    M[k] = mid;
    if(l == r) return;
    build(l, mid, k<<1);
    build(mid+1, r, k<<1|1);
}

void down(int k){
    if(lasy[k] == -1) return;
    if(L[k] != R[k]){
        if(sum[k<<1] == -1) sum[k<<1] = lasy[k];
        else sum[k<<1] |= lasy[k];
        lasy[k<<1] = sum[k<<1];
        if(sum[k<<1|1] == -1) sum[k<<1|1] = lasy[k];
        else sum[k<<1|1] |= lasy[k];
        lasy[k<<1|1] = sum[k<<1|1];
    }
    lasy[k] == -1;
}

void update(int l, int r, int k, int val){
    down(k);
    if(l == L[k] && r == R[k]){
        if(sum[k] == -1){
            sum[k] = val;
            lasy[k] = val;
        } else {
            sum[k] |= val;
            lasy[k] = sum[k];
        }
        return;
    }
    if(r <= M[k]) update(l, r, k<<1, val);
    else if(l > M[k]) update(l, r, k<<1|1, val);
    else{
        update(l, M[k], k<<1, val);
        update(M[k]+1, r, k<<1|1, val);
    }
    if(sum[k<<1] != 1 && sum[k<<1|1] != -1)
        sum[k] = (sum[k<<1] & sum[k<<1|1]);
}

int check(int l, int r, int k){
    down(k);
    if(l == L[k] && r == R[k]) return sum[k];
    if(r <= M[k]) return check(l, r, k<<1);
    else if(l > M[k]) return check(l, r, k<<1|1);
    else{
        int ans1 = check(l, M[k], k<<1);
        int ans2 = check(M[k]+1, r, k<<1|1);
        return (ans1 & ans2);
    }
}

void query(int l, int r, int k){
    down(k);
    if(l == r) {
        if(l > 1) putchar(' ');
        if(sum[k] == -1) sum[k] = 1;
        printf("%d", sum[k]);
        return;
    }
    query(l, M[k], k<<1);
    query(M[k]+1, r, k<<1|1);
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    build(1, n, 1);
    for(int i = 0;i < m; ++i){
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        update(a[i], b[i], 1, c[i]);
    }
    bool ans = 1;
    for(int i = 0; i < m; ++i){
        if(check(a[i], b[i], 1) != c[i]){
            ans = 0;
            break;
        }
    }
        //cout<<" ===========";
    if(!ans) puts("NO");
    else{
        puts("YES");
        query(1, n, 1);
    }
    return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
#define LL long long
#define lk (k<<1)
#define rk (k<<1|1)
using namespace std;

const int N = 11111;
int sum[N<<2];
int L[N<<2], R[N<<2], M[N<<2];
int a[N], b[N], c[N];

void build(int l, int r, int k){
    sum[k] = 0;
    L[k] = l;
    R[k] = r;
    int mid = (l + r) >> 1;
    M[k] = mid;
    if(l == r) return;
    build(l, mid, lk);
    build(mid+1, r, rk);
}

void update(int l, int r, int k, int val){
    if(l == L[k] && r == R[k]){
        sum[k] |= val;
        return;
    }
    if(r <= M[k]) update(l, r, lk, val);
    else if(l > M[k]) update(l, r, rk, val);
    else{
        update(l, M[k], lk, val);
        update(M[k]+1, r, rk, val);
    }
}

void zhu(int l, int r, int k){
    if(l == r) return;
    sum[lk] |= sum[k];
    sum[rk] |= sum[k];
    zhu(l, M[k], lk);
    zhu(M[k] + 1, r, rk);
    sum[k] = (sum[lk] & sum[rk]);
}

int check(int l, int r, int k){
    if(l == L[k] && r == R[k]) return sum[k];
    if(r <= M[k]) return check(l, r, lk);
    else if(l > M[k]) return check(l, r, rk);
    else{
        int ans1 = check(l, M[k], lk);
        int ans2 = check(M[k]+1, r, rk);
        return (ans1 & ans2);
    }
}

void query(int l, int r, int k){
    if(l == r) {
        if(l > 1) putchar(' ');
        printf("%d", sum[k]);
        return;
    }
    query(l, M[k], lk);
    query(M[k]+1, r, rk);
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    build(1, n, 1);
    for(int i = 0;i < m; ++i){
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        update(a[i], b[i], 1, c[i]);
    }
    zhu(1, n, 1);
    bool ans = 1;
    for(int i = 0; i < m; ++i){
        if(check(a[i], b[i], 1) != c[i]){
            ans = 0;
            break;
        }
    }
        //cout<<" ===========";
    if(!ans) puts("NO");
    else{
        puts("YES");
        query(1, n, 1);
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for( int i = (a); i < (b); i++ )
#define ALL(A) A.begin(), A.end()
#define Set(a, s) memset(a, s, sizeof (a))
#define pb push_back
#define mp make_pair
typedef long long LL;

using namespace std;
const int N = 1000005;
LL T[N<<2];
LL L[N<<2];

void refresh(int x)
{
    T[x] |= L[x];
    L[2*x] |= L[x];
    L[2*x+1] |= L[x];
    L[x]=0;
}

void update(int l , int r , int x , int a , int b , LL v)
{
    if(l>b || r<a || l>r) return;
    refresh(x);
    if(l>=a && r<=b)
    {
        L[x] |= v;
        refresh(x);
        return ;
    }

    int mid=(l+r)/2;
    update(l,mid,x*2,a,b,v);
    update(mid+1,r,x*2+1,a,b,v);
    T[x] = T[x*2]&T[x*2+1];
}

LL query(int l , int r , int x,  int a , int b)
{
    if(l>b || r<a || l>r) return (1LL<<50)-1;;
    refresh(x);
    if(l>=a && r<=b)
        return T[x];

    int mid=(l+r)/2;
    LL q1 = query(l,mid,x*2, a,b);
    LL q2 = query(mid+1,r,x*2+1,a,b);
    return q1 & q2;
}

LL Q[100009][3];
int main()
{
    ios_base::sync_with_stdio(0);
   // freopen("input.txt", "r" , stdin);

    int n,m;
    while(cin>>n>>m)
    {
     Set(T,0);
     Set(L,0);

    FOR(i,0,m)
        FOR(j,0,3)cin>>Q[i][j];

    FOR(i,0,m)
        update(0,n-1,1,Q[i][0]-1,Q[i][1]-1,Q[i][2]);

    bool ok=1;
    FOR(i,0,m)
        if(ok)
            ok &= query(0,n-1,1,Q[i][0]-1,Q[i][1]-1)==Q[i][2];
        else break;
        if(!ok)
        {
            cout << "NO" <<endl;
        }
        else
            {
            cout << "YES" <<endl;
    FOR(i,0,n)
        cout << query(0,n-1,1,i,i) << " ";
    cout << endl;
    }
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for( int i = (a); i < (b); i++ )
#define ALL(A) A.begin(), A.end()
#define Set(a, s) memset(a, s, sizeof (a))
#define pb push_back
#define mp make_pair
typedef long long LL;

using namespace std;
const int N = 1000005;
LL T[N<<2];
LL L[N<<2];

void refresh(int x)
{
    T[x] |= L[x];
    L[2*x] |= L[x];
    L[2*x+1] |= L[x];
    L[x]=0;
}

void update(int l , int r , int x , int a , int b , LL v)
{
    refresh(x);
    if(l>b || r<a || l>r) return;
    if(l>=a && r<=b)
    {
      //  T[x] |= v;
        L[x] |= v;
        //refresh(x);
        return ;
    }

    int mid=(l+r)/2;
    update(l,mid,x*2,a,b,v);
    update(mid+1,r,x*2+1,a,b,v);
    T[x] = T[x*2]&T[x*2+1];
}

LL query(int l , int r , int x,  int a , int b)
{
    refresh(x);
    if(l>b || r<a || l>r) return (1LL<<50)-1;;
    if(l>=a && r<=b)
        return T[x];

    int mid=(l+r)/2;
    LL q1 = query(l,mid,x*2, a,b);
    LL q2 = query(mid+1,r,x*2+1,a,b);
    return q1 & q2;
}

LL Q[100009][3];
int main()
{
    ios_base::sync_with_stdio(0);
 //   freopen("input.txt", "r" , stdin);

    int n,m;
    while(cin>>n>>m)
    {
     Set(T,0);
     Set(L,0);

    FOR(i,0,m)
        FOR(j,0,3)cin>>Q[i][j];

    FOR(i,0,m)
        update(0,n-1,1,Q[i][0]-1,Q[i][1]-1,Q[i][2]);

    bool ok=1;
    FOR(i,0,m)
            ok &= query(0,n-1,1,Q[i][0]-1,Q[i][1]-1)==Q[i][2];

        if(!ok)
            cout << "NO" <<endl;

        else
            {
            cout << "YES" <<endl;
    FOR(i,0,n)
        cout << query(0,n-1,1,i,i) << " ";
    cout << endl;
    }
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for( int i = (a); i < (b); i++ )
#define ALL(A) A.begin(), A.end()
#define Set(a, s) memset(a, s, sizeof (a))
#define pb push_back
#define mp make_pair
typedef long long LL;

using namespace std;
const int N = 1000005;
LL T[N<<2];
LL L[N<<2];

void refresh(int x)
{
    T[x] |= L[x];
    L[2*x] |= L[x];
    L[2*x+1] |= L[x];
    L[x]=0;
}

void update(int l , int r , int x , int a , int b , LL v)
{
    refresh(x);
    if(l>b || r<a || l>r) return;
    if(l>=a && r<=b)
    {
      //  T[x] |= v;
        L[x] |= v;
        refresh(x);
        return ;
    }

    int mid=(l+r)/2;
    update(l,mid,x*2,a,b,v);
    update(mid+1,r,x*2+1,a,b,v);
    T[x] = T[x*2]&T[x*2+1];
}

LL query(int l , int r , int x,  int a , int b)
{
    refresh(x);
    if(l>b || r<a || l>r) return (1LL<<50)-1;;
    if(l>=a && r<=b)
        return T[x];

    int mid=(l+r)/2;
    LL q1 = query(l,mid,x*2, a,b);
    LL q2 = query(mid+1,r,x*2+1,a,b);
    return q1 & q2;
}

LL Q[100009][3];
int main()
{
    ios_base::sync_with_stdio(0);
  //  freopen("input.txt", "r" , stdin);

    int n,m;
    while(cin>>n>>m)
    {
     Set(T,0);
     Set(L,0);

    FOR(i,0,m)
        FOR(j,0,3)cin>>Q[i][j];

    FOR(i,0,m)
        update(0,n-1,1,Q[i][0]-1,Q[i][1]-1,Q[i][2]);

    bool ok=1;
    FOR(i,0,m)
            ok &= query(0,n-1,1,Q[i][0]-1,Q[i][1]-1)==Q[i][2];

        if(!ok)
            cout << "NO" <<endl;

        else
            {
            cout << "YES" <<endl;
    FOR(i,0,n)
        cout << query(0,n-1,1,i,i) << " ";
    cout << endl;
    }
    }
    return 0;
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for( int i = (a); i < (b); i++ )
#define ALL(A) A.begin(), A.end()
#define Set(a, s) memset(a, s, sizeof (a))
#define pb push_back
#define mp make_pair
typedef long long LL;

using namespace std;
const int N = 100005;
int T[N<<2];
int L[N<<2];
int arr[N];

void refresh(int x)
{
    T[x] |= L[x];
    L[2*x] |= L[x];
    L[2*x+1] |= L[x];
    L[x]=0;
}

void update(int l , int r , int x , int a , int b , int v)
{
    if(l>b || r<a || l>r) return;

    if(l>=a && r<=b)
    {
        L[x] |= v;
        refresh(x);
        return ;
    }
    refresh(x);
    int mid=(l+r)/2;
    update(l,mid,x*2,a,b,v);
    update(mid+1,r,x*2+1,a,b,v);
    T[x] = T[x*2]&T[x*2+1];
}

LL query(int l , int r , int x,  int a , int b)
{
    if(l>b || r<a || l>r) return (1LL<<50)-1;;
    if(l>=a && r<=b)
    {
        refresh(x);
        return T[x];
    }
    refresh(x);
    int mid=(l+r)/2;
    LL q1 = query(l,mid,x*2, a,b);
    LL q2 = query(mid+1,r,x*2+1,a,b);
    return q1 & q2;
}

int Q[100009][3];
int main()
{
    ios_base::sync_with_stdio(0);
   // freopen("input.txt", "r" , stdin);

    int n,m;
    cin>>n>>m;

    FOR(i,0,m)
        FOR(j,0,3)cin>>Q[i][j];

    FOR(i,0,m)
        update(0,n-1,1,Q[i][0]-1,Q[i][1]-1,Q[i][2]);

    bool ok=1;
    FOR(i,0,m)
        if(ok)
            ok &= query(0,n-1,1,Q[i][0]-1,Q[i][1]-1)==Q[i][2];
        else break;
        if(!ok)
        {
            cout << "NO" <<endl;
        }
        else
            {
            cout << "YES" <<endl;
    FOR(i,0,n)
        cout << query(0,n-1,1,i,i) << " ";
    cout << endl;
    }
    return 0;
}


#include <set>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn = 100005;
typedef unsigned long long ll;

struct Cons {
    Cons(){}
    Cons(pair<int, int> lr_, ll q_): lr(lr_), q(q_) {}
    pair<int, int> lr;
    ll q;

    bool operator< (const Cons &c) const {
        if (lr == c.lr)  return q < c.q;
        return lr < c.lr;
    }
};

ll a[maxn];
ll cou[maxn];
set<Cons> s;

int main () {
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int l, r;
        ll q;
        cin >> l >> r >> q;
        s.insert(Cons(make_pair(l, r), q));
    }

    ll curp = 1;
    curp <<= 32;

    bool isok = true;

    while (isok && curp > 0) {

        for (int i = 1; i <= n; ++i) {
            a[i] <<= 1;
        }

        set<pair<int, int> > s1, s0;
        for (auto i : s) {
            if ((i.q & curp) > 0) {
                s1.insert(i.lr);
            } else {
                s0.insert(i.lr);
            }
        }

        int lastp = 1;
        for (auto i : s1) {
            if (i.first > lastp) {
                lastp = i.first;
            }
            while (lastp <= i.second) {
                a[lastp] |= 1;
                ++lastp;
            }
        }

        memset(cou, 0, sizeof(cou));

        for (int i = 1; i <= n; ++i) {
            cou[i] = cou[i-1] + (a[i] & 1);
        }

        for (auto i : s0) {
            if (cou[i.second] - cou[i.first - 1] == i.second - i.first + 1) {
                isok = false;
                break;
            }
        }

        curp >>= 1;
    }

    if (!isok) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
        for (int i = 1; i <= n; ++i) {
            cout << a[i] << " ";
        }
        cout << endl;
    }

    return 0;
}


#include <set>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

const int maxn = 100005;
typedef unsigned long long ll;

struct Cons {
    Cons(){}
    Cons(pair<int, int> lr_, ll q_): lr(lr_), q(q_) {}
    pair<int, int> lr;
    ll q;

    bool operator< (const Cons &c) const {
        if (lr == c.lr)  return q < c.q;
        return lr < c.lr;
    }
};

ll a[maxn];
ll cou[maxn];

int main () {
    int n, m;
    cin >> n >> m;

    vector<Cons> s(m);

    for (int i = 0; i < m; ++i) {
        int l, r;
        ll q;
        cin >> l >> r >> q;
        s[i] = Cons(make_pair(l, r), q);
    }

    ll curp = 1;
    curp <<= 31;

    bool isok = true;

    while (isok && curp > 0) {

        for (int i = 1; i <= n; ++i) {
            a[i] <<= 1;
        }

        set<pair<int, int> > s1, s0;
        for (auto i : s) {
            if ((i.q & curp) > 0) {
                s1.insert(i.lr);
            } else {
                s0.insert(i.lr);
            }
        }

        int lastp = 1;
        for (auto i : s1) {
            if (i.first > lastp) {
                lastp = i.first;
            }
            while (lastp <= i.second) {
                a[lastp] |= 1;
                ++lastp;
            }
        }

        memset(cou, 0, sizeof(cou));

        for (int i = 1; i <= n; ++i) {
            cou[i] = cou[i-1] + (a[i] & 1);
        }

        for (auto i : s0) {
            if (cou[i.second] - cou[i.first - 1] == i.second - i.first + 1) {
                isok = false;
                break;
            }
        }

        curp >>= 1;
    }

    if (!isok) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
        for (int i = 1; i <= n; ++i) {
            cout << a[i] << " ";
        }
        cout << endl;
    }

    return 0;
}


#include <set>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

const int maxn = 100005;
typedef unsigned long long ll;

struct Cons {
    Cons(){}
    Cons(pair<int, int> lr_, ll q_): lr(lr_), q(q_) {}
    pair<int, int> lr;
    ll q;

    bool operator< (const Cons &c) const {
        if (lr == c.lr)  return q < c.q;
        return lr < c.lr;
    }
};

ll a[maxn];
ll cou[maxn];

int main () {
    int n, m;
    cin >> n >> m;

    vector<Cons> s(m);

    for (int i = 0; i < m; ++i) {
        int l, r;
        ll q;
        cin >> l >> r >> q;
        s[i] = Cons(make_pair(l, r), q);
    }

    ll curp = 1;
    curp <<= 31;

    bool isok = true;

    while (isok && curp > 0) {

        for (int i = 1; i <= n; ++i) {
            a[i] <<= 1;
        }

        vector<pair<int, int> > s1(m), s0(m);
        int t1(0), t0(0);
        for (auto i : s) {
            if ((i.q & curp) > 0) {
                s1[t1++] = i.lr;
            } else {
                s0[t0++] = i.lr;
            }
        }
        s1.resize(t1);  s0.resize(t0);
        sort(s1.begin(), s1.end());  sort(s0.begin(), s0.end());

        int lastp = 1;
        for (auto i : s1) {
            if (i.first > lastp) {
                lastp = i.first;
            }
            while (lastp <= i.second) {
                a[lastp] |= 1;
                ++lastp;
            }
        }

        memset(cou, 0, sizeof(cou));

        for (int i = 1; i <= n; ++i) {
            cou[i] = cou[i-1] + (a[i] & 1);
        }

        for (auto i : s0) {
            if (cou[i.second] - cou[i.first - 1] == i.second - i.first + 1) {
                isok = false;
                break;
            }
        }

        curp >>= 1;
    }

    if (!isok) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
        for (int i = 1; i <= n; ++i) {
            cout << a[i] << " ";
        }
        cout << endl;
    }

    return 0;
}


#include <set>
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 100005;
typedef unsigned long long ll;

struct Cons {
    Cons(){}
    Cons(pair<int, int> lr_, ll q_): lr(lr_), q(q_) {}
    pair<int, int> lr;
    ll q;

    bool operator< (const Cons &c) const {
        if (lr == c.lr)  return q < c.q;
        return lr < c.lr;
    }
};

ll a[maxn];
set<Cons> s;

int main () {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int l, r;
        ll q;
        cin >> l >> r >> q;
        s.insert(Cons(make_pair(l, r), q));
    }

    int lastpos = 1;
    ll lastv = 0;
    bool isok = true;
    for (set<Cons>::iterator iter = s.begin(); isok && iter != s.end(); ++iter) {
        while (lastpos < iter->lr.first) {
            a[lastpos] = lastv;
            ++lastpos;
        }

        pair<int, int> lr1 = iter->lr;
        ll q1 = iter->q;

        set<Cons>::iterator jj = iter;  ++jj;
        while (jj != s.end() && jj->lr.first <= lr1.second) {
            pair<int, int> lr2 = jj->lr;
            ll q2 = jj->q;
            if (q1 == q2) {
                lr1.second = max(lr1.second, jj->lr.second);
                set<Cons>::iterator t = jj;
                ++jj;
                s.erase(t);
            } else if ((q1 | q2) == q1) {
                set<Cons>::iterator t = jj;
                ++jj;
                s.erase(t);
                lr2.first = lr1.second + 1;
                if (lr2.first > lr2.second) {
                    isok = false;
                    break;
                }
                s.insert(Cons(lr2, q2));
            } else if ((q1 | q2) == q2) {
                if (lr1.second > lr2.second) {
                    s.insert(Cons(make_pair(lr2.second+1, lr1.second), q1));
                }
                lr1.second = lr2.first - 1;
                if (lr1.first > lr1.second) {
                    isok = false;
                    break;
                }
                ++jj;
            } else {
                pair<int, int> lrm(lr2.first, lr1.second);
                ll qm(q1 | q2);
                lr1.second = lr2.first - 1;  lr2.first = lr1.second + 1;
                if (lr1.first > lr1.second || lr2.first > lr2.second) {
                    isok = false;
                    break;
                }
                s.insert(Cons(lrm, qm));
                set<Cons>::iterator t = jj;
                ++jj;
                s.erase(t);
                s.insert(Cons(lr2, q2));
            }
        }
        lastv = q1;
    }

    while (isok && lastpos <= n) {
        a[lastpos] = lastv;
        ++lastpos;
    }

    if (!isok) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
        for (int i = 1; i <= n; ++i) {
            cout << a[i] << " ";
        }
        cout << endl;
    }

    return 0;
}


#include <set>
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 100005;
typedef unsigned long long ll;

struct Cons {
    Cons(){}
    Cons(pair<int, int> lr_, ll q_): lr(lr_), q(q_) {}
    pair<int, int> lr;
    ll q;

    bool operator< (const Cons &c) const {
        if (lr == c.lr)  return q < c.q;
        return lr < c.lr;
    }
};

ll a[maxn];
set<Cons> s;

int main () {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int l, r;
        ll q;
        cin >> l >> r >> q;
        s.insert(Cons(make_pair(l, r), q));
    }

    int lastpos = 1;
    ll lastv = 0;
    bool isok = true;
    for (set<Cons>::iterator iter = s.begin(); isok && iter != s.end(); ++iter) {
        while (lastpos < iter->lr.first) {
            a[lastpos] = lastv;
            ++lastpos;
        }

        pair<int, int> lr1 = iter->lr;
        ll q1 = iter->q;

        set<Cons>::iterator jj = iter;  ++jj;
        while (jj != s.end() && jj->lr.first <= lr1.second) {
            pair<int, int> lr2 = jj->lr;
            ll q2 = jj->q;
            if (q1 == q2) {
                lr1.second = max(lr1.second, jj->lr.second);
                set<Cons>::iterator t = jj;
                ++jj;
                s.erase(t);
            } else if ((q1 | q2) == q1) {
                set<Cons>::iterator t = jj;
                ++jj;
                s.erase(t);
                lr2.first = lr1.second + 1;
                if (lr2.first > lr2.second) {
                    isok = false;
                    break;
                }
                s.insert(Cons(lr2, q2));
            } else if ((q1 | q2) == q2) {
                if (lr1.second > lr2.second) {
                    s.insert(Cons(make_pair(lr2.second+1, lr1.second), q1));
                }
                lr1.second = lr2.first - 1;
                if (lr1.first > lr1.second) {
                    isok = false;
                    break;
                }
                ++jj;
            } else {
                pair<int, int> lrm(lr2.first, lr1.second);
                ll qm(q1 | q2);
                lr1.second = lr2.first - 1;  lr2.first = lr1.second + 1;
                if (lr1.first > lr1.second || lr2.first > lr2.second) {
                    isok = false;
                    break;
                }
                s.insert(Cons(lrm, qm));
                set<Cons>::iterator t = jj;
                ++jj;
                s.erase(t);
                s.insert(Cons(lr2, q2));
            }
        }
        lastv = q1;
    }

    while (isok && lastpos <= n) {
        a[lastpos] = lastv;
        ++lastpos;
    }

    if (!isok) {
        cout << "NO" << endl;
    } else {
        for (int i = 1; i <= n; ++i) {
            cout << a[i] << " ";
        }
        cout << endl;
    }

    return 0;
}


//ITNOG
#include<bits/stdc++.h>

using namespace std;
#define int long long
const int maxN = 100*1000 + 5;
const int inf = 1000*1000*1000;
int seg[30][4 * maxN];
int ans[4 * maxN];
int a[maxN];
void add(int p, int l, int r, int s, int e, int ind)
{
    if(e <= l || r <= s) return;
    if(l <= s && e <= r) { seg[p][ind] = 1; return; }

    int mid = (s + e) >> 1;

    add(p, l, r, s, mid, 2 * ind + 0);
    add(p, l, r, mid, e, 2 * ind + 1);
}
int get(int pos, int p, int s, int e, int ind)
{
    if(e - s == 1) { return seg[pos][ind]; }

    int mid = (s + e) >> 1;
    int an = seg[pos][ind];
    if(p < mid) an |= get(pos, p, s, mid, 2 * ind);
    else an |= get(pos, p, mid, e, 2 * ind + 1);

    return an;
}

void addA(int p, int val, int s, int e, int ind)
{
    if(e - s == 1) { ans[ind] = val; return; }
    int mid = ( s + e ) >> 1;

    if(p < mid) addA(p, val, s, mid, 2 * ind);
    else addA(p, val, mid, e, 2 * ind + 1);

    ans[ind] = ans[2 * ind] & ans[2 * ind + 1];
}

int getA(int l, int r, int s, int e, int ind)
{
    if(e <= l || r <= s) return (1LL << 31) - 1;
    if(l <= s && e <= r) return ans[ind];

    int mid = (s + e) >> 1;

    int ans1 = getA(l, r, s, mid, 2 * ind + 0);
    int ans2 = getA(l, r, mid, e, 2 * ind + 1);

    return (ans1 & ans2);
}
main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n, q; cin >> n >> q;
    vector< pair< pair<int, int> , int> > v;
    for(int i = 0; i < q; i ++)
    {
	  int l, r, p; cin >> l >> r >> p; l --;
	  for(int j = 0; j < 30; j ++)
		if(p & (1 << j))
		    add(j, l, r, 0, n, 1);
	  v.push_back(make_pair(make_pair(l, r), p));
    }

    for(int i = 0; i < n; i ++)
    {
	  for(int j = 0; j < 30; j ++)
		if(get(j, i, 0, n, 1))
		    a[i] += (1 << j);

	  addA(i, a[i], 0, n, 1);
    }
    for(int i = 0; i < q; i ++)
    {
	  int tmp = getA(v[i].first.first, v[i].first.second, 0, n, 1);
	  if(tmp != v[i].second) { cout << "NO" << endl; return 0; }
    }
    cout << "YES" << endl;
    for(int i = 0; i < n; i ++)
	  cout << a[i] << ' ';
    cout << endl;
    return 0;
}


//ITNOG
#include<bits/stdc++.h>

using namespace std;
//#define int long long
const int maxN = 100*1000 + 5;
const int inf = 1000*1000*1000;
int seg[30][4 * maxN];
int ans[4 * maxN];
int a[maxN];
void add(int p, int l, int r, int s, int e, int ind)
{
    if(e <= l || r <= s) return;
    if(l <= s && e <= r) { seg[p][ind] = 1; return; }

    int mid = (s + e) >> 1;

    add(p, l, r, s, mid, 2 * ind + 0);
    add(p, l, r, mid, e, 2 * ind + 1);
}
int get(int pos, int p, int s, int e, int ind)
{
    if(e - s == 1) { return seg[pos][ind]; }

    int mid = (s + e) >> 1;
    int an = seg[pos][ind];
    if(p < mid) an |= get(pos, p, s, mid, 2 * ind);
    else an |= get(pos, p, mid, e, 2 * ind + 1);

    return an;
}

void addA(int p, int val, int s, int e, int ind)
{
    if(e - s == 1) { ans[ind] = val; return; }
    int mid = ( s + e ) >> 1;

    if(p < mid) addA(p, val, s, mid, 2 * ind);
    else addA(p, val, mid, e, 2 * ind + 1);

    ans[ind] = ans[2 * ind] & ans[2 * ind + 1];
}

int getA(int l, int r, int s, int e, int ind)
{
    if(e <= l || r <= s) return (1 << 30) - 1;
    if(l <= s && e <= r) return ans[ind];

    int mid = (s + e) >> 1;

    int ans1 = getA(l, r, s, mid, 2 * ind + 0);
    int ans2 = getA(l, r, mid, e, 2 * ind + 1);

    return (ans1 & ans2);
}
main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n, q; cin >> n >> q;
    vector< pair< pair<int, int> , int> > v;
    for(int i = 0; i < q; i ++)
    {
	  int l, r, p; cin >> l >> r >> p; l --;
	  for(int j = 0; j < 30; j ++)
		if(p & (1 << j))
		    add(j, l, r, 0, n, 1);
	  v.push_back(make_pair(make_pair(l, r), p));
    }

    for(int i = 0; i < n; i ++)
    {
	  for(int j = 0; j < 30; j ++)
		if(get(j, i, 0, n, 1))
		    a[i] += (1 << j);

	  addA(i, a[i], 0, n, 1);
    }
    for(int i = 0; i < q; i ++)
    {
	  int tmp = getA(v[i].first.first, v[i].first.second, 0, n, 1);
	  if(tmp != v[i].second) { cout << "NO" << endl; return 0; }
    }
    cout << "YES" << endl;
    for(int i = 0; i < n; i ++)
	  cout << a[i] << ' ';
    cout << endl;
    return 0;
}


//ITNOG
#include<bits/stdc++.h>

using namespace std;
//#define int long long
const int maxN = 100*1000 + 5;
const int inf = 1000*1000*1000;
bool seg[30][4 * maxN];
int ans[4 * maxN];
int a[maxN];

inline void add(int p, int l, int r, int s, int e, int ind)
{
    if(e <= l || r <= s) return;
    if(l <= s && e <= r) { seg[p][ind] = 1; return; }

    int mid = (s + e) >> 1;

    add(p, l, r, s, mid, 2 * ind + 0);
    add(p, l, r, mid, e, 2 * ind + 1);
}
inline int get(int pos, int p, int s, int e, int ind)
{
    if(e - s == 1) { return seg[pos][ind]; }

    int mid = (s + e) >> 1;
    int an = seg[pos][ind];
    if(p < mid) an |= get(pos, p, s, mid, 2 * ind);
    else an |= get(pos, p, mid, e, 2 * ind + 1);

    return an;
}

inline void addA(int p, int val, int s, int e, int ind)
{
    if(e - s == 1) { ans[ind] = val; return; }
    int mid = ( s + e ) >> 1;

    if(p < mid) addA(p, val, s, mid, 2 * ind);
    else addA(p, val, mid, e, 2 * ind + 1);

    ans[ind] = ans[2 * ind] & ans[2 * ind + 1];
}

inline int getA(int l, int r, int s, int e, int ind)
{
    if(e <= l || r <= s) return (1 << 30) - 1;
    if(l <= s && e <= r) return ans[ind];

    int mid = (s + e) >> 1;

    int ans1 = getA(l, r, s, mid, 2 * ind + 0);
    int ans2 = getA(l, r, mid, e, 2 * ind + 1);

    return (ans1 & ans2);
}
main()
{
    //ios::sync_with_stdio(0); cin.tie(0);
    int n, q; scanf("%d%d", &n, &q);

    vector< pair< pair<int, int> , int> > v;
    for(int i = 0; i < q; i ++)
    {
	  int l, r, p; scanf("%d%d%d", &l, &r, &p); l --;
	  for(int j = 0; j < 30; j ++)
		if(p & (1 << j))
		    add(j, l, r, 0, n, 1);
	  v.push_back(make_pair(make_pair(l, r), p));
    }

    for(int i = 0; i < n; i ++)
    {
	  for(int j = 0; j < 30; j ++)
		if(get(j, i, 0, n, 1))
		    a[i] += (1 << j);

	  addA(i, a[i], 0, n, 1);
    }
    for(int i = 0; i < q; i ++)
    {
	  int tmp = getA(v[i].first.first, v[i].first.second, 0, n, 1);
	  if(tmp != v[i].second) { printf("NO\n"); return 0; }
    }

    printf("YES\n");
    for(int i = 0; i < n; i ++)
	  printf("%d ", a[i]);
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
#define LLI long long int
using namespace std;
const int MX = 1e5+10;
LLI a[MX] , power[31] , n, m , valu[4*MX] , l[MX] , r[MX] , c[MX];
bool val[4*MX][31];

void pre(){
	power[0] = 1;
	for(int i=1;i<=30;++i)
		power[i] = power[i-1] * 2;
}

void seg(int L , int R , int l , int r , int up , int id){
	if(L == l && R == r)
		return (val[id][up] = true , void());

	int mid = (R+L)/2;
	if(l < mid)
		seg(L , mid , l , min(mid , r) , up , 2*id+1);
	if(r > mid)
		seg(mid , R , max(mid , l) , r , up , 2*id+2);
}

bool ans(int L , int R , int now , int bit , int id){
	if(R - L == 1){
		if(val[id][bit])
			return true;
		else
			return false;
	}
	int mid = (R+L)/2;
	if(val[id][bit])
		return true;
	if(now < mid)
		return ans(L , mid , now , bit , 2*id+1);
	else
		return ans(mid , R , now , bit , 2*id+2);
}

void pre_procces(int L , int R , int id){
	if(R - L == 1)
		return (valu[id] = a[L] , void());

	int mid = (R+L)/2;
	pre_procces(L , mid , 2*id+1);
	pre_procces(mid , R , 2*id+2);
	valu[id] = valu[2*id+1] & valu[2*id+2];
}

LLI check(int L , int R , int l , int r , int id){
	if(L == l && R == r)
		return (valu[id]);

	int mid = (R+L)/2 , ret1 , ret2 , ret;
	bool q1 = false , q2 = false;
	if(l < mid){
		q1 = true;
		ret1 = check(L , mid , l , min(r , mid) , 2*id+1);
	}
	if(r > mid){
		q2 = true;
		ret2 = check(mid , r , min(l , mid) , r , 2*id+2);
	}
	if(q1 & q2)
		ret = ret1 & ret2;
	return ret;

}

main(){
	pre();
	cin >>n >>m;
	for(int i=0;i<m;++i){
		cin >>l[i] >>r[i] >>c[i];
		l[i]--;
		for(int j=0;j<30;++j)
			if(c[i] & power[j])
				seg(0 , n , l[i] , r[i] , j , 0);
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<30;++j){
			if(ans(0 , n , i , j , 0) )
				a[i] += power[j];
		}
	}
	pre_procces(0 , n , 0);
	for(int i=0;i<m;++i){
		if(c[i] != check(0 , n , l[i] , r[i] , 0) ){
			cout <<"NO"<<endl;
			return 0;
		}
	}
	cout <<"YES"<<endl;
	for(int i=0;i<n;++i)
		cout << a[i]<<" ";
}


#include<bits/stdc++.h>
#define MP make_pair
#define R second
#define L first
using namespace std;
const long long maxn=100000+100;
pair<long long, pair<long long, long long> > q[maxn];
long long a[maxn][32];
long long ans[maxn];
int main(){
	long long n, m;
	cin >> n >> m;
	for(long long i=0;i<m;i++){
		long long l, r, val;
		cin >> l >> r >> val;
		q[i]=MP(val, MP(--l, r));
		for(int mask=0;mask<=30;mask++)
			if(val&(1<<mask))
				a[l][mask]++, a[r][mask]--;
	}
	for(int i=1;i<n;i++)
		for(int mask=0;mask<=30;mask++)
			a[i][mask]+=a[i-1][mask];
	for(int i=0;i<n;i++){
		for(int mask=0;mask<=30;mask++)
			if(a[i][mask]>0)
				ans[i]+=(1<<mask);
	}
	for(long long i=0;i<m;i++)
		if((ans[q[i].R.L]&ans[q[i].R.R-1])!=q[i].L){
			cout << "NO" << endl;
			return 0;
		}
	cout << "YES" << endl;
	for(long long i=0;i<n;i++)
		cout << ans[i] << " ";
	cout << endl;
}


#include<bits/stdc++.h>
#define LLI long long int
using namespace std;
const int MX = 1e5+10;
int a[MX] , power[31] , n, m , valu[2*MX] , l[MX] , r[MX] , c[MX];
bool val[2*MX][31];

void pre(){
    power[0] = 1;
    for(int i=1;i<=30;++i)
        power[i] = power[i-1] * 2;
}

void seg(int L , int R , int l , int r , int up , int id){
    if(L == l && R == r)
        return (val[id][up] = true , void());

    int mid = (R+L)/2;
    if(l < mid)
        seg(L , mid , l , min(mid , r) , up , 2*id+1);
    if(r > mid)
        seg(mid , R , max(mid , l) , r , up , 2*id+2);
}

bool ans(int L , int R , int now , int bit , int id){
    if(R - L == 1){
        if(val[id][bit])
            return true;
        else
            return false;
    }
    int mid = (R+L)/2;
    if(val[id][bit])
        return true;
    if(now < mid)
        return ans(L , mid , now , bit , 2*id+1);
    else
        return ans(mid , R , now , bit , 2*id+2);
}

void pre_procces(int L , int R , int id){
    if(R - L == 1)
        return (valu[id] = a[L] , void());

    int mid = (R+L)/2;
    pre_procces(L , mid , 2*id+1);
    pre_procces(mid , R , 2*id+2);
    valu[id] = valu[2*id+1] & valu[2*id+2];
}

LLI check(int L , int R , int l , int r , int id){
    if(L == l && R == r)
        return (valu[id]);

    int mid = (R+L)/2 , ret1 , ret2 , ret;
    bool q1 = false , q2 = false;
    if(l < mid){
        q1 = true;
        ret1 = check(L , mid , l , min(r , mid) , 2*id+1);
    }
    if(r > mid){
        q2 = true;
        ret2 = check(mid , r , max(l , mid) , r , 2*id+2);
    }
    if(q1 & q2)
        ret = ret1 & ret2;
    return ret;

}

main(){
    pre();
    cin >>n >>m;
    for(int i=0;i<m;++i){
        cin >>l[i] >>r[i] >>c[i];
        l[i]--;
        for(int j=0;j<30;++j)
            if(c[i] & power[j])
                seg(0 , n , l[i] , r[i] , j , 0);
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<30;++j){
            if(ans(0 , n , i , j , 0) )
                a[i] += power[j];
        }
    }
    pre_procces(0 , n , 0);
    for(int i=0;i<m;++i){
        if(c[i] != check(0 , n , l[i] , r[i] , 0) ){
            cout <<"NO"<<endl;
            return 0;
        }
    }
    cout <<"YES"<<endl;
    for(int i=0;i<n;++i)
        cout << a[i]<<" ";
}


#include<bits/stdc++.h>
#define MP make_pair
#define R second
#define L first
using namespace std;
const int maxn=100000+100;
pair<pair<int, int>, int> q[maxn];
int seg[maxn*4];
int a[maxn][32];
int val[maxn];

void pre_process(int id, int L, int R){
	if(R-L==1)
		return (seg[id]=val[L], void());
	int mid=(L+R)/2;
	pre_process(id*2+0, L, mid);
	pre_process(id*2+1, mid, R);
	seg[id]=seg[id*2+0]&seg[id*2+1];
	return ;
}

int get(int id, int L, int R, int l, int r){
	if(L==l && R==r)
		return seg[id];
	int mid=(L+R)/2, ret=(1<<30)-1;
	if(l<mid)
		ret&=get(id*2+0, L, mid, l, min(mid, r));
	if(r>mid)
		ret&=get(id*2+1, mid, R, max(l, mid), r);
	return ret;
}

int main(){
	int n, m;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int l, r, v;
		cin >> l >> r >> v;
		l--, r--;
		q[i]=MP(MP(l, r), v);
		for(int j=0;j<30;j++)
			if(v&(1<<j))
				a[l][j]++, a[r+1][j]--;
	}
	for(int i=1;i<n;i++)
		for(int j=0;j<30;j++)
			a[i][j]+=a[i-1][j];
	for(int i=0;i<n;i++)
		for(int j=0;j<30;j++)
			if(a[i][j]>0)
				val[i]+=(1<<j);
	pre_process(1, 0, n);
	for(int i=0;i<m;i++){
		if(get(1, 0, n, q[i].L.L, q[i].L.R+1)!=q[i].R){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	for(int i=0;i<n;i++)
		cout << val[i] << " ";
	cout << endl;
}


#include<bits/stdc++.h>
#define LLI long long int
using namespace std;
const int MX = 1e5+10;
int a[MX] , power[31] , n, m , valu[4*MX] , l[MX] , r[MX] , c[MX];
bool val[4*MX][31];

void pre(){
	power[0] = 1;
	for(int i=1;i<=30;++i)
		power[i] = power[i-1] * 2;
}

void seg(int L , int R , int l , int r , int up , int id){
	if(L == l && R == r)
		return (val[id][up] = true , void());

	int mid = (R+L)/2;
	if(l < mid)
		seg(L , mid , l , min(mid , r) , up , 2*id+1);
	if(r > mid)
		seg(mid , R , max(mid , l) , r , up , 2*id+2);
}

bool ans(int L , int R , int now , int bit , int id){
	if(R - L == 1){
		if(val[id][bit])
			return true;
		else
			return false;
	}
	int mid = (R+L)/2;
	if(val[id][bit])
		return true;
	if(now < mid)
		return ans(L , mid , now , bit , 2*id+1);
	else
		return ans(mid , R , now , bit , 2*id+2);
}

void pre_procces(int L , int R , int id){
	if(R - L == 1)
		return (valu[id] = a[L] , void());

	int mid = (R+L)/2;
	pre_procces(L , mid , 2*id+1);
	pre_procces(mid , R , 2*id+2);
	valu[id] = valu[2*id+1] & valu[2*id+2];
}

int check(int L , int R , int l , int r , int id){
	if(L == l && R == r)
		return (valu[id]);

	int mid = (R+L)/2 , ret1 , ret2 , ret;
	bool q1 = false , q2 = false;
	if(l < mid){
		q1 = true;
		ret1 = check(L , mid , l , min(r , mid) , 2*id+1);
	}
	if(r > mid){
		q2 = true;
		ret2 = check(mid , r , min(l , mid) , r , 2*id+2);
	}
	if(q1 & q2)
		ret = ret1 & ret2;
	return ret;

}

main(){
	pre();
	cin >>n >>m;
	for(int i=0;i<m;++i){
		cin >>l[i] >>r[i] >>c[i];
		l[i]--;
		for(int j=0;j<30;++j)
			if(c[i] & power[j])
				seg(0 , n , l[i] , r[i] , j , 0);
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<30;++j){
			if(ans(0 , n , i , j , 0) )
				a[i] += power[j];
		}
	}
	pre_procces(0 , n , 0);
	for(int i=0;i<m;++i){
		if(c[i] != check(0 , n , l[i] , r[i] , 0) ){
			cout <<"NO"<<endl;
			return 0;
		}
	}
	cout <<"YES"<<endl;
	for(int i=0;i<n;++i)
		cout << a[i]<<" ";
}


#include<bits/stdc++.h>
#define LLI long long int
using namespace std;
const int MX = 1e5+10;
LLI a[MX] , power[31] , n, m , valu[2*MX] , l[MX] , r[MX] , c[MX];
bool val[2*MX][31];

void pre(){
	power[0] = 1;
	for(int i=1;i<=30;++i)
		power[i] = power[i-1] * 2;
}

void seg(int L , int R , int l , int r , int up , int id){
	if(L == l && R == r)
		return (val[id][up] = true , void());

	int mid = (R+L)/2;
	if(l < mid)
		seg(L , mid , l , min(mid , r) , up , 2*id+1);
	if(r > mid)
		seg(mid , R , max(mid , l) , r , up , 2*id+2);
}

bool ans(int L , int R , int now , int bit , int id){
	if(R - L == 1){
		if(val[id][bit])
			return true;
		else
			return false;
	}
	int mid = (R+L)/2;
	if(val[id][bit])
		return true;
	if(now < mid)
		return ans(L , mid , now , bit , 2*id+1);
	else
		return ans(mid , R , now , bit , 2*id+2);
}

void pre_procces(int L , int R , int id){
	if(R - L == 1)
		return (valu[id] = a[L] , void());

	int mid = (R+L)/2;
	pre_procces(L , mid , 2*id+1);
	pre_procces(mid , R , 2*id+2);
	valu[id] = valu[2*id+1] & valu[2*id+2];
}

LLI check(int L , int R , int l , int r , int id){
	if(L == l && R == r)
		return (valu[id]);

	int mid = (R+L)/2 , ret1 , ret2 , ret;
	bool q1 = false , q2 = false;
	if(l < mid){
		q1 = true;
		ret1 = check(L , mid , l , min(r , mid) , 2*id+1);
	}
	if(r > mid){
		q2 = true;
		ret2 = check(mid , r , min(l , mid) , r , 2*id+2);
	}
	if(q1 & q2)
		ret = ret1 & ret2;
	return ret;

}

main(){
	pre();
	cin >>n >>m;
	for(int i=0;i<m;++i){
		cin >>l[i] >>r[i] >>c[i];
		l[i]--;
		for(int j=0;j<30;++j)
			if(c[i] & power[j])
				seg(0 , n , l[i] , r[i] , j , 0);
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<30;++j){
			if(ans(0 , n , i , j , 0) )
				a[i] += power[j];
		}
	}
	pre_procces(0 , n , 0);
	for(int i=0;i<m;++i){
		if(c[i] != check(0 , n , l[i] , r[i] , 0) ){
			cout <<"NO"<<endl;
			return 0;
		}
	}
	cout <<"YES"<<endl;
	for(int i=0;i<n;++i)
		cout << a[i]<<" ";
}


#include<bits/stdc++.h>
#define MP make_pair
#define R second
#define L first
using namespace std;
const long long maxn=100000+100;
pair<long long, pair<long long, long long> > q[maxn];
long long a[maxn][32];
long long ans[maxn];
int main(){
	long long n, m;
	cin >> n >> m;
	for(long long i=0;i<m;i++){
		long long l, r, val;
		cin >> l >> r >> val;
		q[i]=MP(val, MP(--l, r));
		for(int mask=0;mask<=30;mask++)
			if(val&(1<<mask))
				a[l][mask]++, a[r][mask]--;
	}
	for(int i=1;i<n;i++)
		for(int mask=0;mask<=30;mask++)
			a[i][mask]+=a[i-1][mask];
	for(int i=0;i<n;i++){
		for(int mask=0;mask<=30;mask++)
			if(a[i][mask]>0)
				ans[i]+=(1<<mask);
		if(ans[i]==0)
			ans[i]++;
	}
	for(long long i=0;i<m;i++)
		if((ans[q[i].R.L]&ans[q[i].R.R-1])!=q[i].L){
			cout << "NO" << endl;
			return 0;
		}
	cout << "YES" << endl;
	for(long long i=0;i<n;i++)
		cout << ans[i] << " ";
	cout << endl;
}


#include<bits/stdc++.h>
#define LLI long long int
using namespace std;
const int MX = 1e5+10;
LLI a[MX] , power[MX] , n, m , valu[4*MX] , l[MX] , r[MX] , c[MX];
bool val[4*MX][31];

void pre(){
	power[0] = 1;
	for(int i=1;i<=30;++i)
		power[i] = power[i-1] * 2;
}

void seg(int L , int R , int l , int r , int up , int id){
	if(L == l && R == r)
		return (val[id][up] = true , void());

	int mid = (R+L)/2;
	if(l < mid)
		seg(L , mid , l , min(mid , r) , up , 2*id+1);
	if(r > mid)
		seg(mid , R , max(mid , l) , r , up , 2*id+2);
}

bool ans(int L , int R , int now , int bit , int id){
	if(R - L == 1){
		if(val[id][bit])
			return true;
		else
			return false;
	}
	int mid = (R+L)/2;
	if(val[id][bit])
		return true;
	if(now < mid)
		return ans(L , mid , now , bit , 2*id+1);
	else
		return ans(mid , R , now , bit , 2*id+2);
}

void pre_procces(int L , int R , int id){
	if(R - L == 1)
		return (valu[id] = a[L] , void());

	int mid = (R+L)/2;
	pre_procces(L , mid , 2*id+1);
	pre_procces(mid , R , 2*id+2);
	valu[id] = valu[2*id+1] & valu[2*id+2];
}

LLI check(int L , int R , int l , int r , int id){
	if(L == l && R == r)
		return (valu[id]);

	int mid = (R+L)/2 , ret1 , ret2 , ret;
	bool q1 = false , q2 = false;
	if(l < mid){
		q1 = true;
		ret1 = check(L , mid , l , min(r , mid) , 2*id+1);
	}
	if(r > mid){
		q2 = true;
		ret2 = check(mid , r , min(l , mid) , r , 2*id+2);
	}
	if(q1 & q2)
		ret = ret1 & ret2;
	return ret;

}

main(){
	pre();
	cin >>n >>m;
	for(int i=0;i<m;++i){
		cin >>l[i] >>r[i] >>c[i];
		l[i]--;
		for(int j=0;j<30;++j)
			if(c[i] & power[j])
				seg(0 , n , l[i] , r[i] , j , 0);
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<30;++j){
			if(ans(0 , n , i , j , 0) )
				a[i] += power[j];
		}
	}
	pre_procces(0 , n , 0);
	for(int i=0;i<m;++i){
		if(c[i] != check(0 , n , l[i] , r[i] , 0) ){
			cout <<"NO"<<endl;
			return 0;
		}
	}
	cout <<"YES"<<endl;
	for(int i=0;i<n;++i)
		cout << a[i]<<" ";
}


#include <bits/stdc++.h>
using namespace std;
#define TR(i,v)         for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x)        cout << #x << " = " << (x) << endl;
#define SIZE(p)         (int)(p).size()
#define MP(a, b)        make_pair((a), (b))
#define ALL(p)          (p).begin(), (p).end()
#define rep(i, n)       for(int (i)=0; (i)<(int)(n); ++(i))
#define REP(i, a, n)    for(int (i)=(a); (i)<(int)(n); ++(i))
#define FOR(i, a, b)    for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
#define FORD(i, b, a)   for(int (i)=(int)(b); (i)>=(int)(a); --(i))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;
int R[100005],fa[100005];
vector<pii> qq[2][32];
int find(int x) {
    if(x==-1)   return -1;
    return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif
    // ios::sync_with_stdio(false);     cin.tie(0);
    int n,m;    scanf("%d%d",&n,&m);
    rep(ss,m) {
        int l,r,x;  scanf("%d%d%d",&l,&r,&x);   --l,--r;
        rep(i,30)
            qq[x>>i&1][i].push_back(MP(l,r));
    }
    rep(k,30) {
        vector<pii> &q0=qq[0][k],&q1=qq[1][k];
        if(q0.empty()&&q1.empty())  continue;
        static int fix[100005]; CLR(fix,0);
        sort(ALL(q1));
        int cr=-1,cl=-1;
        // DEBUG(k);
        for(auto p:q1) {
            if(p.first>cr) {
                FOR(i,max(cl,0),cr) fix[i]=1,R[i]|=1<<k;
                cl=p.first,cr=p.second;
                // printf("[%d %d]\n",cl,cr);
            }else
                cr=max(cr,p.second);
        }
        FOR(i,max(cl,0),cr) fix[i]=1,R[i]|=1<<k;
        sort(ALL(q0));
        rep(i,n) {
            if(!fix[i]) fa[i]=i;
            else        fa[i]=i?fa[i-1]:-1;
        }
        for(auto p:q0) {
            int t=find(p.second);
            if(t==-1 || t<p.first)   return puts("NO"),0;
        }
    }
    puts("YES");
    rep(i,n)    printf("%d%c",R[i]," \n"[i+1==n]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define TR(i,v)         for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x)        cout << #x << " = " << (x) << endl;
#define SIZE(p)         (int)(p).size()
#define MP(a, b)        make_pair((a), (b))
#define ALL(p)          (p).begin(), (p).end()
#define rep(i, n)       for(int (i)=0; (i)<(int)(n); ++(i))
#define REP(i, a, n)    for(int (i)=(a); (i)<(int)(n); ++(i))
#define FOR(i, a, b)    for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
#define FORD(i, b, a)   for(int (i)=(int)(b); (i)>=(int)(a); --(i))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;
int R[100005],fa[100005];
vector<pii> qq[2][32];
int find(int x) {
    if(x==-1)   return -1;
    return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif
    // ios::sync_with_stdio(false);     cin.tie(0);
    int n,m;    scanf("%d%d",&n,&m);
    rep(ss,m) {
        int l,r,x;  scanf("%d%d%d",&l,&r,&x);   --l,--r;
        rep(i,30)
            qq[x>>i&1][i].push_back(MP(l,r));
    }
    rep(k,30) {
        vector<pii> &q0=qq[0][k],&q1=qq[1][k];
        if(q0.empty()&&q1.empty())  continue;
        static int fix[100005]; CLR(fix,0);
        sort(ALL(q1));
        int cr=-1,cl=-1;
        // DEBUG(k);
        for(auto p:q1) {
            if(p.first>cr) {
                cl=p.first,cr=p.second;
                FOR(i,max(cl,0),cr) fix[i]=1,R[i]|=1<<k;
                // printf("[%d %d]\n",cl,cr);
            }else
                cr=max(cr,p.second);
        }
        sort(ALL(q0));
        rep(i,n) {
            if(!fix[i]) fa[i]=i;
            else        fa[i]=i?fa[i-1]:-1;
        }
        for(auto p:q0) {
            int t=find(p.second);
            if(t==-1 || t<p.first)   return puts("NO"),0;
        }
    }
    puts("YES");
    rep(i,n)    printf("%d%c",R[i]," \n"[i+1==n]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define TR(i,v)         for(__typeof((v).begin())i=(v).begin();i!=(v).end();++i)
#define DEBUG(x)        cout << #x << " = " << (x) << endl;
#define SIZE(p)         (int)(p).size()
#define MP(a, b)        make_pair((a), (b))
#define ALL(p)          (p).begin(), (p).end()
#define rep(i, n)       for(int (i)=0; (i)<(int)(n); ++(i))
#define REP(i, a, n)    for(int (i)=(a); (i)<(int)(n); ++(i))
#define FOR(i, a, b)    for(int (i)=(int)(a); (i)<=(int)(b); ++(i))
#define FORD(i, b, a)   for(int (i)=(int)(b); (i)>=(int)(a); --(i))
#define CLR(x, y)       memset((x), (y), sizeof((x)))
typedef long long LL;
typedef pair<int, int> pii;
int R[100005],fa[100005];
vector<pii> qq[2][32];
int find(int x) {
    if(x==-1)   return -1;
    return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif
    // ios::sync_with_stdio(false);     cin.tie(0);
    int n,m;    scanf("%d%d",&n,&m);
    rep(ss,m) {
        int l,r,x;  scanf("%d%d%d",&l,&r,&x);   --l,--r;
        rep(i,30)
            qq[x>>i&1][i].push_back(MP(l,r));
    }
    rep(k,30) {
        vector<pii> &q0=qq[0][k],&q1=qq[1][k];
        if(q0.empty()&&q1.empty())  continue;
        static int fix[100005]; CLR(fix,0);
        sort(ALL(q1));
        int cr=-1,cl=-1;
        // DEBUG(k);
        for(auto p:q1) {
            if(p.first>cr) {
                FOR(i,max(cl,0),cr) fix[i]=1,R[i]|=1<<k;
                cl=p.first,cr=p.second;
                // printf("[%d %d]\n",cl,cr);
            }else
                cr=max(cr,p.second);
        }
        sort(ALL(q0));
        rep(i,n) {
            if(!fix[i]) fa[i]=i;
            else        fa[i]=i?fa[i-1]:-1;
        }
        for(auto p:q0) {
            int t=find(p.second);
            if(t==-1 || t<p.first)   return puts("NO"),0;
        }
    }
    puts("YES");
    rep(i,n)    printf("%d%c",R[i]," \n"[i+1==n]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100010, M = 35;
long long prefix[M][N], bit[M][N];

int get_sum(int p, int left, int right) {
    int res = prefix[p][right];
    if (left > 0)
        res -= prefix[p][left-1];
    return res;
}

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n, m;
    scanf("%d %d", &n, &m);

    vector<vector<int>> arr;
    arr.reserve(m);
    for (int i = 0; i < m; i++) {
        int left, right, q;
        scanf("%d %d %d", &left, &right, &q);

        for (long long j = 0; (1LL<<j) <= q; j++) {
            if (q & (1<<j)) {
                bit[j][left-1] += 1;
                bit[j][right] += -1;
            }
        }

        arr.push_back({left, right, q});
    }

    for (int j = 0; j < M; j++) {
        int balance = 0;
        for (int i = 0; i < n; i++) {
            balance += bit[j][i];
            prefix[j][i] = (balance > 0);
            if (i > 0)
                prefix[j][i] += prefix[j][i-1];
        }
    }

    for (auto it : arr) {
        for (int j = 0; j < M; j++) {
            if (((1LL<<j) & it[2]) == 0 && get_sum(j, it[0]-1, it[1]-1) == it[1]-it[0]+1) {
                printf("NO\n");
                return 0;
            }
        }
    }

    printf("YES\n");
    for (int i = 0; i < n; i++) {
        long long elem = 0;
        for (int j = 0; j < M; j++) {
            if (get_sum(j, i, i))
                elem |= (1LL<<j);
        }
        printf("%lld ", elem);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100010, M = 32;
int prefix[M][N], bit[M][N];

int get_sum(int p, int left, int right) {
    int res = prefix[p][right];
    if (left > 0)
        res -= prefix[p][left-1];
    return res;
}

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n, m;
    scanf("%d %d", &n, &m);

    vector<vector<int>> arr;
    for (int i = 0; i < m; i++) {
        int left, right, q;
        scanf("%d %d %d", &left, &right, &q);

        for (int j = 0; (1<<j) < q; j++) {
            if (q & (1<<j)) {
                bit[j][left-1] += 1;
                bit[j][right] += -1;
            }
        }

        arr.push_back({left, right, q});
    }

    for (int j = 0; j < M; j++) {
        int balance = 0;
        for (int i = 0; i < n; i++) {
            balance += bit[j][i];
            prefix[j][i] = (balance > 0);
            if (i > 0)
                prefix[j][i] += prefix[j][i-1];
            cerr << j << " " << prefix[j][i] << "\n";
        }
    }

    for (auto it : arr) {
        for (int j = 0; (1<<j) <= it[2]; j++) {
            if (((1<<j) & it[2]) == 0 && get_sum(j, it[0]-1, it[1]-1) == it[1]-it[0]+1) {
                printf("NO\n");
                return 0;
            }
        }
    }

    printf("YES\n");
    for (int i = 0; i < n; i++) {
        int elem = 0;
        for (int j = 0; j < M; j++) {
            if (get_sum(j, i, i))
                elem |= (1<<j);
        }
        printf("%d ", elem);
    }

    return 0;
}


#include<stdio.h>
int main()
{
    int a[40];
    int n,d,k=0;
    scanf("%d %d",&n,&d);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        for(int j=0;j<i;j++)
        {
           if ((a[j]-a[i])<=d)
            k=+2;
        }
    }
    printf("%d\n",k);

    return 0;

}


#include<stdio.h>
int main()
{
    int a[40];
    int n,d,k=0;
    scanf("%d %d",&n,&d);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        for(int j=0;j<i;j++)
        {
           if ((a[j]-a[i])<=d)
            k=+2;
        }
    }
    printf("6",k);

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int a[1001];
int main()
{

    int n,d,k=0,s=0;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        for(int j=0;j<i;j++)
        {
            if((a[i]==a[j])||(abs(a[i]-a[j])<=d))
                {k++;
                s=k*2;
                }

        }
    }
        cout<<s<<endl;
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[40];
    int n,d,k=0,s=0;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        for(int j=0;j<i;j++)
        {
            if((a[i]-a[j])==d||(((a[i]-a[j])<d) && ((a[i]-a[j])>0)))
                {k++;
                s=k*2;
                }

        }
    }
        cout<<s<<endl;
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[40];
    int n,d,k=0,s=0;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        for(int j=0;j<i;j++)
        {
            if((a[i]==a[j])||(abs(a[i]-a[j])<=d))
                {k++;
                s=k*2;
                }

        }
    }
        cout<<s<<endl;
        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[40];
    int n,d,k=0,s=0;
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        for(int j=0;j<i;j++)
        {
            if((a[i]-a[j])==d||(abs(a[i]-a[j])<d))
                {k++;
                s=k*2;
                }

        }
    }
        cout<<s<<endl;
        return 0;
    }


#include <iostream>
using namespace std;
int main(){
	int n,k = 0;
	cin>>n;
	string s;
	cin>>s;

	for(int i = 0;i < n;i ++){
		if((s[i]-'0')%2 == 0) k+=(i+1);
	}
	cout<<k;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n, d,s=0;
	cin>>n>>d;
	int x[n];
	for(int i=0;i<n;i++){
		cin>>x[i];
	}
	sort(x,x+n);
	for(int i = 0;i < n; i ++){
		for(int j = i+1; j < n; j ++){
				if(x[j]-x[i]<=d) s+=2;
		}
	}
	cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--){
        int n,d;cin>>n>>d;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);int cnt=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(abs(a[i]-a[j])<=d)cnt++;
            }
        }

        cout<<cnt<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--){
        int n,d;cin>>n>>d;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        sort(a,a+n);
        int cnt=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(abs(a[i]-a[j])<=d)cnt++;
            }
        }

        cout<<cnt<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n,d;cin>>n>>d;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);int cnt=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(abs(a[i]-a[j])<=d)cnt++;
            }
        }

        cout<<cnt<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

        int n,d;cin>>n>>d;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);int cnt=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                if(abs(a[i]-a[j])<=d)cnt++;
            }
        }

        cout<<cnt*2<<endl;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
   int n,d;
   cin>>n>>d;
   int a[n];
   int i,j,k;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
   }
   sort(a,a+n);
   int ans=0;
   for(i=0;i<n;i++)
   {
      for(j=0;j<n;j++)
      {
          if(i==j)
             continue;
          if((abs(a[j]-a[i]))<=d)
          {
             ans++;
          }
      }
   }
   cout<<ans<<endl;
   return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
   int n,d;
   cin>>n>>d;
   int a[n];
   int i,j,k;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
   }
   sort(a,a+n);
   int ans=0;
   for(i=0;i<n;i++)
   {
      for(j=i+1;j<n;j++)
      {
          if((a[j]-a[i])<=d)
          {
             ans++;
          }
      }
   }
   cout<<ans<<endl;
   return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
   int n,d;
   cin>>n>>d;
   int a[n];
   int i,j,k;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
   }
   sort(a,a+n);
   int ans=0;
   for(i=0;i<n;i++)
   {
      for(j=0;j<n;j++)
      {
          if(i==j)
             continue;
          if((a[j]-a[i])<=d)
          {
             ans++;
          }
      }
   }
   cout<<ans<<endl;
   return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
   int n,d;
   cin>>n<<d;
   int a[n];
   int i,j,k;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
   }
   sort(a,a+n);
   int ans=0;
   for(i=0;i<n;i++)
   {
      for(j=i+1;j<n;j++)
      {
          if((a[j]-a[i])<=d)
          {
             ans++;
          }
      }
   }
   cout<<ans<<endl;
   return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
ll fast_exp(ll base, ll exp) {
  ll res = 1;
  while (exp > 0) {
    if (exp % 2 == 1)
      res = (res * base) % MOD;
    base = (base * base) % MOD;
    exp /= 2;
  }
  return res;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, d, res = 0;
  cin >> n >> d;
  ll arr[n];
  REP(i, 0, n) cin >> arr[i];
  sort(arr, arr + n);
  ll prev = arr[0];
  REP(i, 1, n) {
    if (arr[i] - prev <= d) {
      if (arr[i] != prev)
        res += 1;
      else
        res += 2;
    }
    prev = arr[i];
  }
  cout << res << "\n";
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
ll fast_exp(ll base, ll exp) {
  ll res = 1;
  while (exp > 0) {
    if (exp % 2 == 1)
      res = (res * base) % MOD;
    base = (base * base) % MOD;
    exp /= 2;
  }
  return res;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, d, res = 0;
  cin >> n >> d;
  ll arr[n];
  REP(i, 0, n) cin >> arr[i];
  sort(arr, arr + n);
  ll prev = arr[0];
  REP(i, 1, n) {
    if (arr[i] - prev <= d) {
      if (arr[i] == prev)
        res += 1;
      else
        res += 2;
    }
    prev = arr[i];
  }
  cout << res << "\n";
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
ll fast_exp(ll base, ll exp) {
  ll res = 1;
  while (exp > 0) {
    if (exp % 2 == 1)
      res = (res * base) % MOD;
    base = (base * base) % MOD;
    exp /= 2;
  }
  return res;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, d, res = 0;
  cin >> n >> d;
  ll arr[n];
  REP(i, 0, n) cin >> arr[i];
  sort(arr, arr + n);
  ll prev = arr[0];
  REP(i, 1, n) {
    if (arr[i] - prev <= d)
      res += 2;
    prev = arr[i];
  }
  cout << res << "\n";
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
ll fast_exp(ll base, ll exp) {
  ll res = 1;
  while (exp > 0) {
    if (exp % 2 == 1)
      res = (res * base) % MOD;
    base = (base * base) % MOD;
    exp /= 2;
  }
  return res;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, d, res = 0;
  cin >> n >> d;
  ll arr[n];
  REP(i, 0, n) cin >> arr[i];
  sort(arr, arr + n);
  // ll prev = arr[0];
  REP(i, 0, n) {
    int j = i + 1;
    while (abs(arr[j] - arr[i]) <= d) {
      // cout << arr[j] << " " << arr[i] << endl;
      res = res + 2;
      j++;
    }
  }
  cout << res << "\n";
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
ll fast_exp(ll base, ll exp) {
  ll res = 1;
  while (exp > 0) {
    if (exp % 2 == 1)
      res = (res * base) % MOD;
    base = (base * base) % MOD;
    exp /= 2;
  }
  return res;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, d, res = 0;
  cin >> n >> d;
  ll arr[n];
  REP(i, 0, n) cin >> arr[i];
  sort(arr, arr + n);
  ll prev = arr[0];
  REP(i, 1, n) {
    if (arr[i] - prev <= d)
      res += 2;
    prev = arr[i];
  }
  cout << res;
  return 0;
}


#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
using namespace std;

const long long N = 3e6;
const long long INF = 1e9 + 1;
const long long mod = 1e9 + 7;

ll n, m, a[N], cnt = 1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for ( int i=0; i<n; i++ )
        cin >> a[i];
    for ( int i=0; i<n; i++ )
        if ( a[i] >= m )
            cnt ++;
    cout << ( cnt );
}


#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
using namespace std;

const long long N = 3e6;
const long long INF = 1e9 + 1;
const long long mod = 1e9 + 7;

ll n, m, a[N], cnt = 1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for ( int i=0; i<n; i++ )
        cin >> a[i];
    for ( int i=0; i<n; i++ )
        for ( int j=0; j<n; j++ )
            if ( abs( a[i] - a[j] ) <= m )
                cnt ++;
    cout << cnt / 2 ;
}


#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
using namespace std;

const long long N = 3e6;
const long long INF = 1e9 + 1;
const long long mod = 1e9 + 7;

ll n, m, a[N], cnt;
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for ( int i=0; i<n; i++ )
        cin >> a[i];
    for ( int i=0; i<n; i++ )
        for ( int j=0; j<n; j++ )
            if ( abs( a[i] - a[j] ) <= m and i != j )
                cnt ++;
    cout << cnt ;
}


#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
using namespace std;

const long long N = 3e6;
const long long INF = 1e9 + 1;
const long long mod = 1e9 + 7;

ll n, m, a[N], cnt = 1;
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    for ( int i=0; i<n; cin >> a[i++] )
    for ( int i=0; i<n; i++ )
        if ( a[i] >= m )
            cnt ++;
    cout << ( cnt + 1 ) / 2  ;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define A first
#define B second
#define lb long double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,n) for(i=0;i<n;i++)
#define mpp map<ll,ll>m;
#define vec vector<ll>v;
#define mod (ll)(1e9+7)
#define nl cout<<"\n";

void solve()
{
	ll n,d,i,j;
	cin>>n>>d;
	ll a[n],c=0,k=0;

	fo(i,n) cin>>a[i];
	sort(a,a+n);
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++)
		if(a[j]-a[i]<=d)
		{c++;
		if(a[i]!=a[j])
		k++;
			cout<<i<<" "<<j<<"\n";
			}
	}
	cout<<(2*c);
	nl

}
int main()
{
   fast
   int t=1;
   //cin>>t;
   while(t--)
   {
      solve();
   }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define A first
#define B second
#define lb long double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,n) for(i=0;i<n;i++)
#define mpp map<ll,ll>m;
#define vec vector<ll>v;
#define mod (ll)(1e9+7)
#define nl cout<<"\n";

void solve()
{
	ll n,d,i,j;
	cin>>n>>d;
	ll a[n],c=0,k=0;

	fo(i,n) cin>>a[i];
	sort(a,a+n);
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++)
		if(a[j]-a[i]<=d)
		{c++;
		if(a[i]!=a[j])
		k++;
			//cout<<i<<" "<<j<<"\n";
			}
	}
	cout<<(2*c);
	nl

}
int main()
{
   fast
   int t=1;
   //cin>>t;
   while(t--)
   {
      solve();
   }
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ldb long double

void solve()
{
    int n, d;
    cin >> n >> d;

    vector<int> a(n);

    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int ans = 0;

    for(int i = 0; i < n - 1; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            if(abs(a[i] - a[j]) <= d)
            {
                ans += 2;
            }
        }
    }

    cout << ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    //int t;
    // cin >> t;

    // while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ldb long double

void solve()
{
    int n, d;
    cin >> n >> d;

    vector<int> a(n);

    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    int ans = 0;

    for(int i = 0; i < n - 1; i++)
    {
        if(a[i + 1] - a[i] <= d)
        {
            ans += 2;
        }
    }

    cout << ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    // int t;
    // cin >> t;

    // while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ldb long double

void solve()
{
    int n, d;
    cin >> n >> d;

    vector<int> a(n);

    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int ans = 0;

    for(int i = 0; i < n - 1; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            if(abs(a[i] - a[j]) <= d)
            {
                ans += 2;
            }
        }
    }

    cout << ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    // int t;
    // cin >> t;

    // while(t--)
        solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int n,d,a[100],count=0;
cin>>n>>d;
for(int i=0 ;i<n;i++){
  cin>>a[i];
}
for (int i=0;i<n;i++){
  for (int j=0;j<n;j++){
    if(abs(a[i]-a[j])<=d && i!=j){
      count+=1;
    }
  }
}
cout<<count;
  }


#include <bits/stdc++.h>
using namespace std;
int main(){
int n,d,a[1000],c=0;
cin>>n>>d;
for(int i=0 ;i<n;i++){
  cin>>a[i];
}
for (int i=0;i<n;i++){
  for (int j=0;j<n;j++){
    if(abs(a[i]-a[j])<=d && i!=j){
      c+=1;
    }
  }
}
cout<<c;
  }


#include <bits/stdc++.h>
using namespace std;
int main(){
int n,d,a[50],c=0;
cin>>n>>d;
for(int i=0 ;i<n;i++){
  cin>>a[i];
}
for (int i=0;i<n;i++){
  for (int j=0;j<n;j++){
    if(abs(a[i]-a[j])<=d && i!=j){
      c+=1;
    }
  }
}
cout<<c;
  }


#include <iostream>
#include<algorithm>
using namespace std;

int main()
{int count=0,n,d,i,a[1001],b[1000],add=0,j;
   cin>>n;
   cin>>d;
   for(i=0;i<n;i++)
    cin>>a[i];
sort(a,a+n);
   for(i=0;i<n;i++)
{
    for(j=i+1;j<n;j++)
    {
        if((a[j]-a[i])<=d)
            add++;
    }
}
cout<<2*add;
    return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;

int main()
{int count=0,n,d,i,a[1001],b[1000],add=0,j;
   cin>>n;
   cin>>d;
   for(i=0;i<n;i++)
    cin>>a[i];

   for(i=0;i<n;i++)
{
    for(j=i+1;j<n;j++)
    {
        if(a[j]-a[i]<=d||a[i]-a[j]<=d)
            add++;
    }
}
cout<<2*add;
    return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;

int main()
{int count=0,n,d,i,a[1001],b[1000];
   cin>>n;
   cin>>d;
   for(i=0;i<n;i++)
    cin>>a[i];
   sort(a,a+n);
   for(i=0;i<n-1;i++)
   {
       b[i]=a[i+1]-a[i];
   if(b[i]<=d)
    count++;
   }
   cout<<2*count;
    return 0;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define gottagofast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#define DEBUG
using namespace std;
int main()
{
	gottagofast;
	int n, d;
	int s = 0;
	cin >> n >> d;
	vector <int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	for (int i = 1; i < n; i++)
	{
		if (a[i] - a[i - 1] <= d) s += 2;
	}
	cout << s;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define gottagofast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#define DEBUG
using namespace std;
int main()
{
	gottagofast;
	int n, d;
	int s = 0;
	cin >> n >> d;
	vector <int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i != j && a[i] - a[j] <= d) s++;
		}
	}
	cout << s;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#define gottagofast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#define DEBUG
using namespace std;
int main()
{
	gottagofast;
	int n, d;
	int s = 0;
	cin >> n >> d;
	vector <int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < i; j++)
		{
			if (a[i] - a[j] <= d) s+=2;
		}
	}
	cout << s;
}


#include <bits/stdc++.h>
#define ll long long
#define MN INT_MIN
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    int ar[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    sort(ar,ar+n);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(ar[i]+ar[j]>d)
                break;
            if(ar[i]!=ar[j])
                ans+=2;
            else
                ans+=1;
        }
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define MN INT_MIN
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    int ar[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    sort(ar,ar+n);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(abs(ar[i]-ar[j])>d)
                break;
            if(ar[i]!=ar[j])
                ans+=2;
            else
                ans+=1;
        }
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define MN INT_MIN
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    int ar[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    sort(ar,ar+n);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(abs(ar[i]-ar[j])>d)
                break;
            if(ar[i]!=ar[j])
                ans+=2;
            else
                ans+=2;
         }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int i,j=0;
    for(i=0;i<n-1;i++)
    {
        if(a[i+1]-a[i]<=10)
            j++;
    }
    cout<<2*j;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int i,k=0,j;
    for(i=0;i<n-1;i++)
    {
        for(j=1;j<n-i;j++)
        {
            if(a[i+j]-a[i]<=d)
                k++;
        }
    }
    cout<<2*k;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
    int n,d,a[n];
    cin>>n>>d;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int k=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i!=j)
            {
                if(abs(a[i]-a[j])<=d)
                    k++;
            }
        }
    }
    cout<<k<<endl;
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   int n,d;
   cin>>n>>d;
  int a[n];
  int cnt=0;
  for(int i=0;i<n;i++)
  {
      for(int j=1;j<n;j++)
      {
          if(abs(a[i]-a[j])<=d)
          cnt++;

      }
  }
  cout<<cnt<<endl;
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   int n,d;
   cin>>n>>d;
  int a[n];
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  int cnt=0;
  for(int i=0;i<n;i++)
  {
      for(int j=i+1;j<n;j++)
      {
          if(abs(a[i]-a[j])<=d)
          cnt++;

      }
  }
  cout<<2*cnt<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,d,cnt=0;
cin>>n>>d;
int a[n];
for(int i=0;i<n;i++)
{
    cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++)
{ for(int j=0;j<n;j++)
   { if(abs(a[i]-a[j])<=d)
     {
        cnt+=2;
     }
   }
}
cout<<cnt;
return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,d,cnt=0;
cin>>n>>d;
int a[n];
for(int i=0;i<n;i++)
{
    cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n-1;i++)
{
    if(0<a[i+1]-a[i] && a[i+1]-a[i]<=d)
    {
        cnt+=2;
    }
}
cout<<cnt;
return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{ int n,d,cnt=0;
cin>>n>>d;
int a[n];
for(int i=0;i<n;i++)
{
    cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n-1;i++)
{
    for(int j=i+1;j<n;j++)
    {if(abs(a[i]-a[j])<=d && a[i]-a[j]!=0)
    {
        cnt+=2;
    }
    }
}
cout<<cnt;
return 0;

}


#include<bits/stdc++.h>
using namespace std;

int main(){

    int n,d,V[ 5000 ],res=0;

    cin>>n>>d;
    for(int i=1; i<=n; i++) cin>>V[i];

    for(int i = 1; i <= n; i++ ){
        for(int j=1; j <= n; j++ ){
            if(i != j && ( max( V[ i ], V[ j ] ) - min( V[ i ], V[ j ] ) <= d ) )
                res++;
        }
    }
    cout<< res ;

    return 0;
}


/*
||-----------------------------------||
||        Rahat Khan Pathan          ||
||      BGC Trust University         ||
||       Department of CSE           ||
||-----------------------------------||
*/
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pub push_back
#define pi 3.14159265359
#define pob pop_back
#define puf push_front
#define pof pop_front
#define vi vector<int>
#define vll vector<ll>
#define All(X) (X).begin(),(X).end()
#define Reverse(X) reverse(All(X))
#define Unique(X) (X).erase(unique((X).begin(),(X).end()),(X).end())
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define vpair vector<pair<ll,ll>>
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define print(A,B) cout<<A<<" "<<B<<endl;
using namespace std;
void solve()
{
    ll n,i,j,d,ans=0;
    cin>>n>>d;
    ll a[n+1];
    for(i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[j]-a[i]<=d)
                ans++;
        }
    }
    cout<<ans*2<<endl;
}
int main()
{
    fast;
    ll t;
//    cin>>t;
//    while(t--)
        solve();
    return 0;
}


/*
||-----------------------------------||
||        Rahat Khan Pathan          ||
||      BGC Trust University         ||
||       Department of CSE           ||
||-----------------------------------||
*/
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pub push_back
#define pi 3.14159265359
#define pob pop_back
#define puf push_front
#define pof pop_front
#define vi vector<int>
#define vll vector<ll>
#define All(X) (X).begin(),(X).end()
#define Reverse(X) reverse(All(X))
#define Unique(X) (X).erase(unique((X).begin(),(X).end()),(X).end())
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define vpair vector<pair<ll,ll>>
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define print(A,B) cout<<A<<" "<<B<<endl;
using namespace std;
void solve()
{
    ll n,i,d,ans=0;
    cin>>n>>d;
    ll a[n+1];
    for(i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(i=1;i<n;i++)
    {
        if(a[i]-a[i-1]<=d)
            ans++;
    }
    cout<<ans*2<<endl;
}
int main()
{
    fast;
    ll t;
//    cin>>t;
//    while(t--)
        solve();
    return 0;
}


/**
 * File              : main.cpp
 * Author            : Bao To Hoai
 * Date              : 23.09.2020 14:53:53
 * Last Modified Date: 23.09.2020 14:55:39
 * Last Modified By  : Bao To Hoai
 */
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    vector<int> A(n);
    for (int &a : A) {
        cin >> a;
    }

    sort(A.begin(), A.end());
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        if (A[i + 1] - A[i] <= d) {
            cnt++;
        }
    }

    cout << cnt*2 << "\n";

    return 0;
}


/**
 * File              : main.cpp
 * Author            : Bao To Hoai
 * Date              : 23.09.2020 14:53:53
 * Last Modified Date: 23.09.2020 14:58:12
 * Last Modified By  : Bao To Hoai
 */
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    vector<int> A(n);
    for (int &a : A) {
        cin >> a;
    }

    sort(A.begin(), A.end());
    int cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (A[j] - A[i] <= d) {
                cnt++;
            }
        }
    }

    cout << cnt*2 << "\n";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n,d;
  cin>>n>>d;
  vector<int> a(n);
  for(int &x: a)  cin>>x;
  int cnt =0;
  for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++)
      if(abs(a[i]-a[j]) <=d)
        cnt++;
  cout<<(cnt<<1)<<"\n";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n,d;
  cin>>n>>d;
  vector<int> a;
  for(int &x: a)  cin>>x;
  int cnt =0;
  for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++)
      if(abs(a[i]-a[j]) <=d)
        cnt++;
  cout<<(cnt<<1)<<"\n";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
  int n,d;
  cin>>n>>d;
  vector<int> v;
  for(int &x: v)  cin>>x;
  int cnt =0;
  for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++)
      if(abs(a[i]-a[j]) <=d)
        cnt++;
  cout<<(cnt<<1)<<"\n";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
main(){
    int n,d,res=0;
    cin>>n>>d;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin>>a[i];
    }
    for(int i = 0;i < n;i++){
        for(int j = i + 1;j < n;j++){
            if (abs(a[j] - a[i] <= d)){
                res += 2;
            }
        }
    }
    cout<<res;
}


#include <bits/stdc++.h>
using namespace std;
main(){
    int n,d,res=0;
    cin>>n>>d;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin>>a[i];
    }
    for(int i = 0;i < n;i++){
        for(int j = i + 1;j < n;j++){
            if (abs(a[j] - a[i]) <= d){
                res += 2;
            }
        }
    }
    cout<<res;
}


//cnt0 += s[i] == '0';
#include <bits/stdc++.h>
#include <set>
# define ll long long
# define str string
# define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
vector < pair < string , int > > A,B;
set<int> st,st1;
ll a,b,c,d,e,f,g,h,cnt,bnt,l;
str s,lk;
int main(){
	speed;
	cin>>a>>b;
	for (int i = 0; i < a; ++i)
	{
		cin>>c;
	}
	cout<<a+1<<"\n";

	time;
	return 0;
}


//cnt0 += s[i] == '0';
#include <bits/stdc++.h>
#include <set>
# define ll long long
# define str string
# define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
vector < pair < string , int > > A,B;
set<int> st,st1;
ll a,b,c,d,e,f,g,h,cnt,bnt,l,x,y,z,t1=1,t2=2,t3;
str s,sg,stg;
int main(){
	speed;
	cin>>a>>b;
	ll arr[a+5];
	for(int i=0;i<a;i++){
		cin>>arr[i];
	}
	sort(arr,arr+a);
	reverse(arr,arr+a);
	for (int i = 0; i < a; i++){
		for (int j = 0; j < a; j++){
			if(i!=j){
				if(abs(arr[i]-arr[j])<=b){
				 	cnt++;
				 }
			}
		}
	}
	cout<<cnt<<' ';

	time;
	return 0;
}


//cnt0 += s[i] == '0';
#include <bits/stdc++.h>
#include <set>
# define ll long long
# define str string
# define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
vector < pair < string , int > > A,B;
set<int> st,st1;
ll a,b,c,d,e,f,g,h,cnt,bnt,l,x,y,z,t1=1,t2=2,t3;
str s,sg,stg;
int main(){
	speed;
	cin>>a>>b;
	ll arr[a+5];
	for(int i=0;i<a;i++){
		cin>>arr[i];
	}
	sort(arr,arr+a);
	reverse(arr,arr+a);
	for (int i = 0; i < a; ++i)
	{
		cout<<arr[i]<<' ';
	}
	cout<<"\n";
	for (int i = 0; i < a; i++){
		for (int j = 0; j < a; j++){
			if(i!=j){
				if(abs(arr[i]-arr[j])<=b){
				 	cnt++;
				 }
			}
		}
	}
	cout<<cnt<<' ';

	time;
	return 0;
}


#include <iostream>
#include <sstream>
#include <ctype.h>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <vector>
#include <iterator>
#define ll long long int
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, d, ans = 0;
    cin >> n >> d;
    vector<ll> v(n);
    for(ll i=0; i<n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    for(ll i=0; i<n-1; i++){
        if(abs(v[i]-v[i+1])<=d){
            ans += 2;
        }
    }
    cout << ans << "\n";
}


#include <iostream>
#include <sstream>
#include <ctype.h>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <vector>
#include <iterator>
#define ll long long int
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, d, ans = 0;
    cin >> n >> d;
    vector<ll> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i!=j && abs(v[i]-v[j])<=d) ans++;
        }
    }
    cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v;

int n,s,d,ans=0,j;

int main()
{ scanf("%d %d",&n,&d);
for(int i=0;i<n;i++){
    scanf("%d",&s);
    v.push_back(s);
}
sort(v.begin(),v.end());

for(int i=0;i<n;i++){
    j=i+1;
    while(v[j]-v[i]<=d&&j<n){

    ans+=2;j++;}

}
    printf("%d",ans);

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main () {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  int n, d;
  cin >> n >> d;

  vector <int> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }

  sort(v.begin(), v.end());

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (v[j] - v[i] > d) break;
      ans += 2;
    }
  }

  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> v;

int n,s,d,ans=0;

int main()
{ scanf("%d %d",&n,&d);
for(int i=0;i<n;i++){
    scanf("%d",&s);
    v.push_back(s);
}
sort(v.begin(),v.end());

for(int i=1;i<n;i++){
    if(v[i]-v[i-1]<=d)
    ans+=2;}
    printf("%d",ans);

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n,d,ans=0,j;

int main()
{ scanf("%d %d",&n,&d);
vector<int> v(n);
for(int i=0;i<n;i++){
    scanf("%d",&v[i]);

}
sort(v.begin(),v.end());

for(int i=0;i<n;i++){
    j=i+1;
    while(v[j]-v[i]<=d&&j<n){

    ans+=2;j++;}

}
    printf("%d",ans);

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{int n,d,ans=0,j;
    scanf("%d %d",&n,&d);
vector<int> v(n);
for(int i=0;i<n;i++){
    scanf("%d",&v[i]);

}
sort(v.begin(),v.end());

for(int i=0;i<n;i++){
    j=i+1;
    while(v[j]-v[i]<=d&&j<n){

    ans+=2;j++;}

}
    printf("%d",ans);
    return 0;

}


#include <vector>
#include <algorithm>
using namespace std;

int n,d,ans=0,j;

int main()
{ scanf("%d %d",&n,&d);
vector<int> v(n);
for(int i=0;i<n;i++){
    scanf("%d",&v[i]);

}
sort(v.begin(),v.end());

for(int i=0;i<n;i++){
    j=i+1;
    while(v[j]-v[i]<=d&&j<n){

    ans+=2;j++;}

}
    printf("%d",ans);

}


#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;
#define INF INT_MAX
#define mINF INT_MIN

#define sz(a) (int)(a).size()

int ans;
void solve()
{
	int cnt = 0,d;
	int n;	cin>>n>>d;
	int arr[10000];
	for(int i = 0; i < n; ++i)	cin>>arr[i];
	for(int i = 0; i < n; ++i){
		for(int j = i+1; j < n; ++j){
			if(abs(arr[i]-arr[j]) <= d)
				cnt++;
		}
	}
	cout<<cnt*2;
}

int main()
{
	int testc;	testc = 1;
	for(int t = 0; t < testc; ++t){
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long int ll;
typedef unsigned long long int ull;
#define inf INT_MAX
#define minf INT_MIN
#define watch(x)	cout<<(#x)<<"=>"<<x<<'\n';
#define sz(a) (int)(a).size()
#define all(x) (x.begin(),x.end())

ll ans;
int arr[300009];
vi vr;
void solve()
{
    int d;
    int n;  cin>>n>>d;

    for(int i = 0; i < n; ++i)  cin>>arr[i];

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if(i != j && abs(arr[i] - arr[j]) <= d)
                ans++;
        }
    }
    cout<<ans;
    cout<<'\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testc;  testc = 1;
    for(int t = 0; t < testc; ++t){
        solve();
    }
    return 0;
}

	//Mon 07 Sep 2020 04:17:05 PM IST

		/***astrainL3gi0N***/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n, d; cin >> n >> d;
    vector<int> v;
    for(int i = 0, a; i < n; i++) {
        cin >> a; v.push_back(a);
    }
    sort(v.begin(), v.end());
    ll cnt = 0;
    vector<int> v2[1010];
    for(int i = 1; i < v.size(); i++){
        if(v[i] == v[i-1]){
            if(v2[v[i]].size()>=2){
                v2[v[i]].push_back(v[i]);
            }
            else{
                v2[v[i]].push_back(v[i]);
                v2[v[i]].push_back(v[i]);
            }

        }
        else if(v[i]-v[i-1] <= d){
            cnt+=2;
        }
    }
    for(int i = 0; i < 1010; i++){
        if(v2[i].size()>0) cnt+= v2[i].size()*(v2[i].size()-1);
    }
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n, d; cin >> n >> d;
    vector<int> v;
    ll cnt = 0;
    for(int i = 0, a; i < n; i++) {
        cin >> a; v.push_back(a);
    }
    for(int i = 0; i < v.size(); i++){
        for(int j = 0; j < v.size(); j++){
            if(i!=j && abs(v[i]-v[j])<=d) cnt++;
        }
    }
    cout << cnt << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n, d; cin >> n >> d;
    vector<int> v;
    for(int i = 0, a; i < n; i++) {
        cin >> a; v.push_back(a);
    }
    sort(v.begin(), v.end());
    ll cnt = 0;
    vector<int> v2[1010];
    for(int i = 1; i < v.size(); i++){
        if(v[i] == v[i-1]){
            if(v2[v[i]].size()>=2){
                v2[v[i]].push_back(v[i]);
            }
            else{
                v2[v[i]].push_back(v[i]);
                v2[v[i]].push_back(v[i]);
            }

        }
        else if(v[i]-v[i-1] <= d){
            cnt+=2;
        }
    }
    for(int i = 0; i < 1010; i++){
        if(v2[i].size()>0) cnt+= 1ll*v2[i].size()*(v2[i].size()-1);
    }
    cout << cnt << endl;
}


#include <iostream>
#include <vector>     // vector
#include <algorithm>  // sort
#include <iterator>
#include <math.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int k=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int p;
            p=abs(a[j]-a[i]);
            if(p<=d){
                if(i!=j){
                    k++;
                }
            }
        }
    }
    cout<<k;
    return 0;
}


#include <iostream>
#include <vector>     // vector
#include <algorithm>  // sort
#include <iterator>
#include <math.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int k=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int p;
            p=abs(a[j]-a[i]);
            if(p<=d){
                k++;
            }
        }
    }
    cout<<k;
}


#include <iostream>
#include <vector>     // vector
#include <algorithm>  // sort
#include <iterator>
#include <math.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int k=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int p;
            p=abs(a[j]-a[i]);
            if(p<=d){
                if(i!=j){
                    k++;
                }
            }
        }
    }
    cout<<k;
}


#include <iostream>
#include <vector>     // vector
#include <algorithm>  // sort
#include <iterator>
#include <math.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int k=0;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            int p;
            p=abs(a[j]-a[i]);
            if(p<=d){
                if(i!=j){
                    k++;
                }
            }
        }
    }
    cout<<k*2;
    return 0;
}


#include <iostream>
#include <vector>     // vector
#include <algorithm>  // sort
#include <iterator>
#include <math.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int k=0;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            int p;
            p=abs(a[j]-a[i]);
            if(p<=d){
                if(i!=j){
                    k++;
                }
            }
        }
    }
    cout<<k*2;
}


#include <iostream>
using namespace std;
int main(){
    int n, d, i, j, cnt=0;
    cin >> n >> d ;
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
    }
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            if(abs(a[i]-a[j]) <= d){
                cnt+=2;
            }
        }
    }
    cout << cnt ;
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    int n, d, i, j, cnt=0;
    cin >> n >> d ;
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
    }
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            if(abs(a[i]-a[j]) == d){
                cnt=2;
            }
        }
    }
    cout << cnt ;
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    int n, d, i, j, cnt=0;
    cin >> n >> d ;
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
    }
    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            if(abs(a[i]-a[j]) == d){
                cnt=2;
            }
        }

    cout << cnt ;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, d, a[1005], wynik = 0;
    cin >> n >> d;
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    sort(a, a+n);
    for(int i=0; i<n-1; i++) {
        if(abs(a[i]-a[i+1]) <= d) {
            wynik++;
        }
    }
    cout << wynik*2;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, d, a[1005], wynik = 0;
    cin >> n >> d;
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            if(abs(a[i]-a[j]) <= d && i != j) {
                wynik++;
            }
        }
    }
    cout << wynik;
    return 0;
}