import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	private static final int bits = 40;
	private static int nodeCnt = 1;
	public static void insert(TrieNode[] trie, long num){
        int k = 0;
		for (int i = bits; i >= 0; i--){
    		int pos = ((num & (1L << i)) != 0) ? 1 : 0;
            if (trie[k].children[pos] == -1) {
                trie[nodeCnt] = new TrieNode();
                trie[k].children[pos] = nodeCnt++;
            }
            k = trie[k].children[pos];
        }
	}

	public static long findMaxXor(TrieNode[] trie, long num){
        int k = 0;
        long result = 0;
		for (int i = bits; i >= 0; i--){
    		int pos = ((num & (1L << i)) != 0) ? 0 : 1;
            if (trie[k].children[pos] != -1) {
                result += (1L << i);
                k = trie[k].children[pos];
            } else {
            	k = trie[k].children[pos ^ 1];
            }
        }
		return result;
	}

	public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
//        int n = in.nextInt();
//        long[] numsArr = new long[n];
//        for(int i = 0; i < n; i++){
//            numsArr[i] = in.nextLong();
//        }
//        in.close();
		InputReader in = new InputReader(System.in);
		int n = in.nextInt();
		long[] numsArr = new long[n];
		for(int i = 0; i < n; i++){
			numsArr[i] = in.nextLong();
		}
//        System.out.println((int) Math.pow(2, 51));
        TrieNode[] trie = new TrieNode[41 * 100000];
        trie[0] = new TrieNode();

        long[] suffixXor = new long[n];
        for (int i = n - 1; i >= 0; i--){
        	if (i == n - 1){
        		suffixXor[i] = numsArr[i];
        		continue;
        	}
        	suffixXor[i] = suffixXor[i + 1] ^ numsArr[i];
//        	System.out.println(i+":\t"+suffixXor[i]);
        }

        long[] prefixXor = new long[n];
        for (int i = 0; i < n; i++){
        	if (i == 0){
        		prefixXor[i] = numsArr[i];
        		continue;
        	}
        	prefixXor[i] = prefixXor[i - 1] ^ numsArr[i];
        }

        long maxXor = suffixXor[0];
//        System.out.println("\t"+maxXor);
        long suffixValue = 0;
        insert(trie, 0);
        for (int i = 0; i < n; i++){
        	insert(trie, prefixXor[i]);
//        	System.out.println("insert:\t"+prefixXor[i]);
        	suffixValue = (i + 1 < n) ? suffixXor[i+1] : 0;

//        	System.out.println(suffixValue+"\t"+trie.findMaxXor(suffixValue));
        	maxXor = Math.max(findMaxXor(trie, suffixValue), maxXor);
        }

        System.out.println(maxXor);
	}

//	  public static void main(String[] args) {
//		    // TODO Auto-generated method stub
//
//		    InputReader cin = new InputReader(System.in);
//		    PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out));
//
//
//
//		    cout.flush();
//		  }

		  private static class InputReader {

		      public BufferedReader rea;
		      public StringTokenizer tok;

		      public InputReader(InputStream stream) {
		          rea = new BufferedReader(new InputStreamReader(stream), 32768);
		          tok = null;
		      }

		      public String next() {
		          while (tok == null || !tok.hasMoreTokens()) {
		              try {
		                  tok = new StringTokenizer(rea.readLine());
		              } catch (IOException e) {
		                  throw new RuntimeException(e);
		              }
		          }
		          return tok.nextToken();
		      }

		      public int nextInt() {
		          return Integer.parseInt(next());
		      }

		      public long nextLong() {
		          return Long.parseLong(next());
		      }
		  }
}

class TrieNode {
	public int[] children;
    public TrieNode() {
        children = new int[2];
        children[0] = children[1] = -1;
    }
}


import java.util.Scanner;

public class Main {
	static Trie_Node root = new Trie_Node();
	private static final int bit_len = 40;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
	    long prefix = 0, suffix = 0, ans = 0;
	    Scanner sc = new Scanner(System.in);
		int len = sc.nextInt();
		long[] arr = new long [len];

	    for(int i = 0; i < len; i++) {
	        arr[i] = sc.nextLong();
	        suffix^=arr[i];
	    }
	    sc.close();

	    add(prefix);
        ans = Math.max(ans, query(suffix));
	    for(int i = 0; i < len+1; i++) {
	        add(prefix);
	        ans = Math.max(ans, query(suffix));
	        if(i < len) {
	        	prefix^=arr[i];
	        	suffix^=arr[i];
	        }

	    }
	    System.out.println(ans);

	}

	public static void add(long val) {

		Trie_Node tmp = root;
	    for(int i = bit_len; i>=0; i--) {
	        byte bit_val = (byte) ((byte)(val>>i)&1);
	        if(tmp.next[bit_val]==null){
	        	tmp.next[bit_val] = new Trie_Node();
	        }
	        tmp = tmp.next[bit_val];
	    }
	}
	public static long query(long val) {
		Trie_Node tmp = root;
	    long ret = 0;
	    for(int i = bit_len; i>=0; i--) {
	    	byte bit_val = (byte) ((byte)(val>>i)&1);
	        if(tmp.next[1^bit_val] !=null) {
	            ret |= 1L<<i;
	            bit_val ^=1;
	        }
	        tmp = tmp.next[bit_val];
	    }
	    return ret;
	}
}

class Trie_Node{
	Trie_Node[] next = new Trie_Node[2];
	public Trie_Node(){
		next[0] = null;
		next[1] = null;
	}

}


import java.io.*;
import java.util.*;

public class E {
    public static void main(String[] args) {
        try {
            new E().solve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        // Scanner sc = new Scanner(System.in);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] sp;
        int n = Integer.parseInt(in.readLine());
        long[] a = new long[n];
        sp = in.readLine().split(" ");
        long amax = 0;
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(sp[i]);
            amax = Math.max(amax, a[i]);
        }

        // K,root
        K = 1;
        while (amax >> K != 0) {
            K++;
        }
        root = new BitTree();
        add(0);

        // xor
        long xor1 = 0;
        long xor2 = 0;
        for (int i = 0; i < n; i++) {
            xor1 ^= a[i];
        }

        // max
        long max = 0;
        for (int i = n - 1; i >= 0; i--) {
            max = Math.max(max, xor1 ^ find(~xor1));
            xor1 ^= a[i];
            xor2 ^= a[i];
            add(xor2);
        }
        max = Math.max(max, xor1 ^ find(~xor1));

        System.out.println(max);
    }

    int K;
    BitTree root;
    void add(long v) {
        BitTree bt = root;
        for (int k = K - 1; k >= 0; k--) {
            int i = (int) (v >> k & 1);
            if (bt.child[i] == null) {
                bt.child[i] = new BitTree();
            }
            bt = bt.child[i];
        }
    }

    long find(long v) {
        BitTree bt = root;
        long ret = 0;
        for (int k = K - 1; k >= 0; k--) {
            int i = (int) (v >> k & 1);
            if (bt.child[i] == null) {
                i = 1 - i;
            }
            bt = bt.child[i];
            ret |= ((long) i) << k;
        }
        return ret;
    }
    class BitTree {
        BitTree[] child = new BitTree[] { null, null };
    }
}

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


import java.io.*;
import java.util.*;

public class E {
    public static void main(String[] args) {
        try {
            new E().solve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        // Scanner sc = new Scanner(System.in);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] sp;
        int n = Integer.parseInt(in.readLine());
        long[] a = new long[n];
        sp = in.readLine().split(" ");
        long amax = 0;
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sp[i]);
            amax = Math.max(amax, a[i]);
        }

        // K,root
        K = 1;
        while (amax >> K != 0) {
            K++;
        }
        root = new BitTree();
        add(0);

        // xor
        long xor1 = 0;
        long xor2 = 0;
        for (int i = 0; i < n; i++) {
            xor1 ^= a[i];
        }

        // max
        long max = 0;
        for (int i = n - 1; i >= 0; i--) {
            max = Math.max(max, xor1 ^ find(~xor1));
            xor1 ^= a[i];
            xor2 ^= a[i];
            add(xor2);
        }
        max = Math.max(max, xor1 ^ find(~xor1));

        System.out.println(max);
    }

    int K;
    BitTree root;
    void add(long v) {
        BitTree bt = root;
        for (int k = K - 1; k >= 0; k--) {
            int i = (int) (v >> k & 1);
            if (bt.child[i] == null) {
                bt.child[i] = new BitTree();
            }
            bt = bt.child[i];
        }
    }

    long find(long v) {
        BitTree bt = root;
        long ret = 0;
        for (int k = K - 1; k >= 0; k--) {
            int i = (int) (v >> k & 1);
            if (bt.child[i] == null) {
                i = 1 - i;
            }
            bt = bt.child[i];
            ret |= ((long) i) << k;
        }
        return ret;
    }
    class BitTree {
        BitTree[] child = new BitTree[] { null, null };
    }
}

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


import java.io.*;
import java.util.*;

public class E {
    public static void main(String[] args) {
        try {
            new E().solve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        // Scanner sc = new Scanner(System.in);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] sp;
        int n = Integer.parseInt(in.readLine());
        long[] a = new long[n];
        sp = in.readLine().split(" ");
        long amax = 0;
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(sp[i]);
            amax = Math.max(amax, a[i]);
        }

        // K,root
        K = 1;
        while (amax >> K != 0) {
            K++;
        }
        root = new BitTree();
        add(0);

        // xor
        long xor1 = 0;
        long xor2 = 0;
        for (int i = 0; i < n; i++) {
            xor1 ^= a[i];
        }

        // max
        long max = 0;
        for (int i = n - 1; i >= 0; i--) {
            max = Math.max(max, xor1 ^ find(~xor1));
            xor1 ^= a[i];
            xor2 ^= a[i];
            add(xor2);
        }

        System.out.println(max);
    }

    int K;
    BitTree root;
    void add(long v) {
        BitTree bt = root;
        for (int k = K - 1; k >= 0; k--) {
            int i = (int) (v >> k & 1);
            if (bt.child[i] == null) {
                bt.child[i] = new BitTree();
            }
            bt = bt.child[i];
        }
    }

    long find(long v) {
        BitTree bt = root;
        long ret = 0;
        for (int k = K - 1; k >= 0; k--) {
            int i = (int) (v >> k & 1);
            if (bt.child[i] == null) {
                i = 1 - i;
            }
            bt = bt.child[i];
            ret |= ((long) i) << k;
        }
        return ret;
    }
    class BitTree {
        BitTree[] child = new BitTree[] { null, null };
    }
}

//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


import java.util.Scanner;

public class Main {
	private TrieNode root;
	public static final int INT_SIZE=64;
	public Main(){
		root = new TrieNode();
	}
	public  void insert(long pre_xor){
		TrieNode node =root;
		for(int i=INT_SIZE-1;i>=0;i--){
			long val = pre_xor & (1<<i);
			int sign=0;
			if(val!=0){
				sign=1;
			}
			if(node.children[sign]==null){
				node.children[sign]=new TrieNode();
			}
			node = node.children[sign];
		}
		node.value=pre_xor;
	}
	public long query(long pre_xor){
		TrieNode node = root;
		for(int i=INT_SIZE-1;i>=0;i--){
			long val = pre_xor & (1<<i);
			int sign=0;
			if(val!=0){
				sign=1;
			}
			if(node.children[1-sign]!=null){
				node = node.children[1-sign];
			}
			else if(node.children[sign]!=null){
				node = node.children[sign];
			}
		}
		return pre_xor^(node.value);
	}
	public long maxXor(long[] nums){
		if(nums==null||nums.length==0){
			return 0;
		}
		long pre_xor =0;
		for(int i=0;i<nums.length;i++){
			pre_xor=pre_xor^nums[i];
		}
		insert(0);
		long result=pre_xor;
		long pre=0;
		for(int i=0;i<nums.length;i++){
			pre=pre^nums[i];
			insert(pre);
			result = Math.max(result, query(pre_xor^pre));
		}
		return result;
	}
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int N=sc.nextInt();
			long[] nums = new long[N];
			for(int i=0;i<N;i++){
				nums[i] = sc.nextLong();
			}
			Main t =new Main();
			System.out.println(t.maxXor(nums));
		}
	}
}
class TrieNode{
	public  TrieNode[] children = new TrieNode[2];
	public long value;

}


import java.util.Scanner;

public class Main {
	private TrieNode root;
	public static final int INT_SIZE=40;
	public Main(){
		root = new TrieNode();
	}
	public  void insert(long pre_xor){
		TrieNode node =root;
		for(int i=INT_SIZE-1;i>=0;i--){
			long val = pre_xor & (1<<i);
			int sign=0;
			if(val!=0){
				sign=1;
			}
			if(node.children[sign]==null){
				node.children[sign]=new TrieNode();
			}
			node = node.children[sign];
		}
		node.value=pre_xor;
	}
	public long query(long pre_xor){
		TrieNode node = root;
		for(int i=INT_SIZE-1;i>=0;i--){
			long val = pre_xor & (1<<i);
			int sign=0;
			if(val!=0){
				sign=1;
			}
			if(node.children[1-sign]!=null){
				node = node.children[1-sign];
			}
			else if(node.children[sign]!=null){
				node = node.children[sign];
			}
		}
		return pre_xor^(node.value);
	}
	public long maxXor(long[] nums){
		if(nums==null||nums.length==0){
			return 0;
		}
		long pre_xor =0;
		for(int i=0;i<nums.length;i++){
			pre_xor=pre_xor^nums[i];
		}
		insert(0);
		long result=pre_xor;
		long pre=0;
		for(int i=0;i<nums.length;i++){
			pre=pre^nums[i];
			insert(pre);
			result = Math.max(result, query(pre_xor^pre));
		}
		return result;
	}
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int N=sc.nextInt();
			long[] nums = new long[N];
			for(int i=0;i<N;i++){
				nums[i] = sc.nextLong();
			}
			Main t =new Main();
			System.out.println(t.maxXor(nums));
		}
	}
}
class TrieNode{
	public  TrieNode[] children = new TrieNode[2];
	public long value;

}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
#include<queue>
using namespace std;
#pragma GCC optimize(2)
int n, z;
int a[200010];
int dp[200010];
int main()
{
	cin >> n >> z;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	for (int i = 2; i <= n; i++)
	{
		int k = lower_bound(a + 1, a + n + 1, a[i] - z) - a + 1;
		if (a[k] != a[i] - z)
			k--;
		if (k == 0)
		{
			dp[i] = dp[i - 1];
			continue;
		}
		//cout << dp[k - 1] + 1 << ' ' << dp[i - 1] << endl;
		//cout << i << endl;
		//cout <<i<<' '<<k<<' '<< dp[k - 1] << ' ' << dp[i - 1] << ' ' << dp[k] << endl;
		dp[i] = max(dp[k] + 1 + dp[i - 1] - dp[k+1], dp[i - 1]);
		//cout << dp[i] << ' ' << dp[i - 1] << endl;
	}
	cout << dp[n];
	return 0;
}
/*
int n, z;
int a[200010];
int b[200010];
int vis[200010];
int ans1, ans2;
int main()
{
	cin >> n >> z;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = -a[i];
	}

	sort(a, a + n);
	sort(b, b + n);
	//cout << "****" << endl;
	//int j = 0;
	for (int i = 0; i < n; i++)
	{
		//cout << i << ' ' << j << endl;
		if (vis[i])
			continue;
		int p = lower_bound(a, a + n, a[i] + z) - a;
		while (vis[p])
		{
			p++;
		}
		if (p == n)
			break;
		vis[i] = 1;
		vis[p] = 1;
		ans1++;
	}
	//int k = n - 1;
	memset(vis, 0, sizeof(vis));
	for (int i = 0; i < n; i++)
	{
		if (vis[i])
			continue;
		int p = lower_bound(b, b + n, b[i] + z) - b;
		while (vis[p])
		{
			p++;
		}
		if (p == n)break;
		vis[i] = 1;
		vis[p] = 1;
		ans2++;
	}
	cout << max(ans1, ans2);
	return 0;
}
*/


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
#include<queue>
using namespace std;
//#pragma GCC optimize(2)
int n;
int a[1000];
int ans;
int main()
{
	cin >> n;
	cin >> a[0];
	for (int i = 1; i < n; i++)
	{
		cin >> a[i];
		if ( (a[i] == 3 && a[i - 1] == 2))
		{
			cout << "Infinite";
			return 0;
		}
		if (a[i - 1] == 1)
		{
			if (a[i] == 2)
				ans += 3;
			if (a[i] == 3)
				ans += 4;
		}
		if (a[i - 1] == 2)
		{
			if (a[i] == 1)
				ans += 3;
		}
		if (a[i - 1] == 3)
		{
			if (a[i] == 1)
				ans += 4;
			if (i >= 2)
			{
				if (a[i] == 2 )
					ans += 2;
			}
			else
			{
				if (a[i] == 2)
					ans += 3;
			}

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


#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 200005;
int x[MAXN], dp[MAXN][2];
int main()
{
    int i, j, n, z;
    cin >> n >> z;
    for(i = 0; i < n; i++)
        cin >> x[i];
    sort(x, x + n);
    for(i = 1; i < n; i++)
    {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        j = upper_bound(x, x + n, x[i] - z) - x;
        for(--j; j >= 0; j--)
            dp[i][1] = max(dp[i][1], dp[j][0] + 1);
    }
    cout << max(dp[n - 1][0], dp[n - 1][1]);
}


#include<cstdio>
#include<cctype>
#include<algorithm>
int n, z;
int a[200010];
bool charvis[128];
inline int fastRead() {
    int X = 0,w = 0; char ch = getchar();
    while(!charvis[ch]) {w |= ch == '-';ch = getchar();}
    while(charvis[ch]) X = (X << 3) + (X << 1) + (ch ^ 48),ch=getchar();
    return w ? -X : X;
}
int main()
{
    for(int i = '0'; i <= '9'; i++)
        charvis[i] = 1;
    n = fastRead();
    z = fastRead();
	for (int i = 0; i < n; i++)
        a[i] = fastRead();
	std::sort(a, a + n);
	int k = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - z >= a[k])
			k++;
	}
	printf("%d\n", std::min(k, n / 2));
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 200005;
int x[MAXN], dp[MAXN][2];
int main()
{
    int i, j, n, z;
    cin >> n >> z;
    for(i = 0; i < n; i++)
        cin >> x[i];
    sort(x, x + n);
    for(i = 1; i < n; i++)
    {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        j = upper_bound(x, x + n, x[i] - z) - x - 1;
        if(j >= 0) dp[i][1] = max(dp[i][1], dp[j][0] + 1);
    }
    cout << max(dp[n - 1][0], dp[n - 1][1]);
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
#include<queue>
using namespace std;
#pragma GCC optimize(2)
int n, z;
int a[200010];
int main()
{
	cin >> n >> z;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int k = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - z >= a[k])
			k++;
	}
	cout << min(k, n / 2);
	return 0;
}
/*
int n, z;
int a[200010];
int dp[200010];
int main()
{
	cin >> n >> z;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	for (int i = 2; i <= n; i++)
	{
		int k = lower_bound(a + 1, a + n + 1, a[i] - z) - a + 1;
		if (a[k] != a[i] - z)
			k--;
		if (k == 0)
		{
			dp[i] = dp[i - 1];
			continue;
		}
		//cout << dp[k - 1] + 1 << ' ' << dp[i - 1] << endl;
		//cout << i << endl;
		//cout <<i<<' '<<k<<' '<< dp[k - 1] << ' ' << dp[i - 1] << ' ' << dp[k] << endl;
		dp[i] = max(dp[k - 1] + 1, dp[i - 1]);
		//cout << dp[i] << ' ' << dp[i - 1] << endl;
	}
	cout << dp[n];
	return 0;
}
/*
int n, z;
int a[200010];
int b[200010];
int vis[200010];
int ans1, ans2;
int main()
{
	cin >> n >> z;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = -a[i];
	}

	sort(a, a + n);
	sort(b, b + n);
	//cout << "****" << endl;
	//int j = 0;
	for (int i = 0; i < n; i++)
	{
		//cout << i << ' ' << j << endl;
		if (vis[i])
			continue;
		int p = lower_bound(a, a + n, a[i] + z) - a;
		while (vis[p])
		{
			p++;
		}
		if (p == n)
			break;
		vis[i] = 1;
		vis[p] = 1;
		ans1++;
	}
	//int k = n - 1;
	memset(vis, 0, sizeof(vis));
	for (int i = 0; i < n; i++)
	{
		if (vis[i])
			continue;
		int p = lower_bound(b, b + n, b[i] + z) - b;
		while (vis[p])
		{
			p++;
		}
		if (p == n)break;
		vis[i] = 1;
		vis[p] = 1;
		ans2++;
	}
	cout << max(ans1, ans2);
	return 0;
}
*/


#include<cstdio>
#include<algorithm>
int n, z;
int a[200010];
inline int fastRead()
{
    int x = 0;
    char ch = '-';
    while(ch < '0' || ch > '9') ch = getchar();
    while('0' <= ch && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}
int main()
{
    n = fastRead();
    z = fastRead();
	for (int i = 0; i < n; i++)
        a[i] = fastRead();
	std::sort(a, a + n);
	int k = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - z >= a[k])
			k++;
	}
	printf("%d\n", std::min(k, n / 2));
	return 0;
}


#include<cstdio>
#include<algorithm>
int n, z;
int a[200010];
void fastRead(int &x)
{
    x = 0;
    char ch = '-';
    while(ch < '0' || ch > '9') ch = getchar();
    while('0' <= ch && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
}
int main()
{
    fastRead(n);
    fastRead(z);
	for (int i = 0; i < n; i++)
        fastRead(a[i]);
	std::sort(a, a + n);
	int k = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - z >= a[k])
			k++;
	}
	printf("%d\n", std::min(k, n / 2));
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
#include<queue>
using namespace std;
#pragma GCC optimize(2)
int n, z;
int a[200010];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
	cin >> n >> z;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	int k = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - z >= a[k])
			k++;
	}
	cout << min(k, n / 2);
	return 0;
}


#include<cstdio>
#include<algorithm>
int n, z;
int a[200010];
inline void fastRead(int &x)
{
    x = 0;
    char ch = '-';
    while(ch < '0' || ch > '9') ch = getchar();
    while('0' <= ch && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
}
int main()
{
    fastRead(n);
    fastRead(z);
	for (int i = 0; i < n; i++)
        fastRead(a[i]);
	std::sort(a, a + n);
	int k = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - z >= a[k])
			k++;
	}
	printf("%d\n", std::min(k, n / 2));
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
#include<queue>
using namespace std;
#pragma GCC optimize(2)
int n, z;
int a[200010];
int b[200010];
int vis[200010];
int ans1, ans2;
int main()
{
	cin >> n >> z;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = -a[i];
	}

	sort(a, a + n);
	sort(b, b + n);
	//cout << "****" << endl;
	//int j = 0;
	for (int i = 0; i < n; i++)
	{
		//cout << i << ' ' << j << endl;
		if (vis[i])
			continue;
		int p = lower_bound(a, a + n, a[i] + z) - a;
		while (vis[p])
		{
			p++;
		}
		if (p == n)
			break;
		vis[i] = 1;
		vis[p] = 1;
		ans1++;
	}
	//int k = n - 1;
	memset(vis, 0, sizeof(vis));
	for (int i = 0; i < n; i++)
	{
		if (vis[i])
			continue;
		int p = lower_bound(b, b + n, b[i] + z) - b;
		while (vis[p])
		{
			p++;
		}
		if (p == n)break;
		vis[i] = 1;
		vis[p] = 1;
		ans2++;
	}
	cout << max(ans1, ans2);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<set>
#include<queue>
using namespace std;
#pragma GCC optimize(2)
int n, z;
int a[200010];
int ans1, ans2;
int main()
{
	cin >> n >> z;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	//cout << "****" << endl;
	int j = 0;
	for (int i = 1; i < n; i++)
	{
		//cout << i << ' ' << j << endl;
		if (a[i] - a[j] >= z)
		{
			ans1++;
			j = i + 1;
			i++;

		}
	}
	int k = n - 1;
	for (int i = n - 1; i >= 0; i--)
	{
		if (a[k] - a[i] >= z)
		{
			ans2++;
			k = i - 1;
			i--;

		}
	}
	cout << max(ans1, ans2);
	return 0;
}


#include<cstdio>
#include<cctype>
#include<algorithm>
int n, z;
int a[200010];
inline int fastRead() {
    int X = 0,w = 0; char ch = getchar();
    while(ch < '0' || ch > '9') {w |= ch == '-';ch = getchar();}
    while('0' <= ch && ch <= '9') X = (X << 3) + (X << 1) + (ch ^ 48),ch=getchar();
    return w ? -X : X;
}
int main()
{
    n = fastRead();
    z = fastRead();
	for (int i = 0; i < n; i++)
        a[i] = fastRead();
	std::sort(a, a + n);
	int k = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - z >= a[k])
			k++;
	}
	printf("%d\n", std::min(k, n / 2));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int ans = 0;
    for(int i = 1, j = n/2+1; i <= n/2+1; i++){
        if(vis[i]) continue;
        while(j <= n && a[j]-a[i] < m) j++;
        if(j > n) break;
        ans++; j++;
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int l = 1, r = 2, ans = 0;
    while(r <= n){
        if(a[r]-a[l] >= m){
            ans++; vis[l] = vis[r] = 1;
            l++;
            while(vis[l]) l++;
        }
        r++;
        while(vis[r] || r <= l) r++;
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int l, r, ans = 0, mid, res;
    for(int i = 1; i <= n; i++){
        if(vis[i]) continue;
        l = i; r = n; res = i;
        while(l <= r){
            mid = (l+r)/2;
            if(vis[mid]){ l = mid+1; continue; }
            if(a[mid]-a[i] >= m) res = mid, r = mid-1;
            else l = mid+1;
        }
        if(a[res]-a[i] >= m) ans++, vis[res] = 1, vis[i] = 1;
        else break;
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int l, r, ans = 0, mid, res;
    for(int i = 1; i <= n; i++){
        if(vis[i]) continue;
        l = i; r = n; res = i;
        while(l <= r){
            mid = (l+r)/2;
            if(vis[mid]) l = mid+1;
            if(a[mid]-a[i] >= m) res = mid, r = mid-1;
            else l = mid+1;
        }
        if(a[res]-a[i] >= m) ans++, vis[res] = 1, vis[i] = 1;
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main()
{
    int n, m, ans = 0;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i = 1; i <= n; i++){
        if(vis[i]) continue;
        int p = lower_bound(a+1,a+n+1,a[i]+m)-a;
        while(vis[p] || p == i) p++;
        if(p <= n){
            ans++;
            vis[i] = 1; vis[p] = 1;
        }
        if(p == n) break;
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int l, r, ans = 0, mid, res;
    for(int i = 1; i <= n; i++){
        if(vis[i]) continue;
        l = i+1; r = n; res = i;
        while(l <= r){
            mid = (l+r)/2;
            if(vis[mid]){ l = mid+1; continue; }
            if(a[mid]-a[i] >= m) res = mid, r = mid-1;
            else l = mid+1;
        }
        if(a[res]-a[i] >= m && res^i) ans++, vis[res] = 1, vis[i] = 1;
        else break;
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main()
{
    int n, m;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int ans = 0;
    for(int i = 1, j = n/2+1; i <= n/2+1; i++){
        if(vis[i]) continue;
        while(j <= n && a[j]-a[i] < m) j++;
        if(j > n) break;
        vis[j]++; ans++; j++;
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
int main()
{
    int n, m, ans = 0;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    int l = 1, r = lower_bound(a+1,a+n+1,a[1]+m)-a;
    while(r <= n){
        ans++;
        l++; r++;
        while(a[r]-a[l] < m) r++;
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main()
{
    int n, m, ans = 0;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i = 1; i <= n; i++){
        if(vis[i]) continue;
        int p = lower_bound(a+1,a+n+1,a[i]+m)-a;
        while(vis[p]) p++;
        if(p <= n){
            ans++;
            vis[i] = 1; vis[p] = 1;
        }
        if(p == n) break;
    }
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main()
{
    int n, m, ans = 0;
    scanf("%d%d",&n,&m);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i = 1; i <= n; i++){
        int p = lower_bound(a+1,a+n+1,a[i]+m)-a;
        while(vis[p]) p++;
        if(p <= n){
            ans++;
            vis[i] = 1; vis[p] = 1;
        }
        if(p == n) break;
    }
    printf("%d\n",ans);
    return 0;
}


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

typedef long long ll ;

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

    ll n, z ; cin>>n>>z ;
    vector<ll> a(n, -1LL) ;

    for(ll i=0;i<n; i++) cin>>a[i] ;
    sort(a.begin(), a.end()) ;

    ll pcnt=0LL ;
    for(ll i=0, j=0 ; j < n ; )
    {
        if( a[i] == -1LL) { i++ ; continue ; }
        else if( a[j] == -1LL || i == j) { j++ ; continue ; }

        if( a[j] - a[i] >= z) { a[i] = ( a[j] = -1LL) ; pcnt++ ; }
        j++ ;
    }

    cout << pcnt << '\n' ;

    return 0 ;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 200043;

int n, z;
int a[N];
// editorial solution optimization check !!
int main()
{
	scanf("%d", &n);
	scanf("%d", &z);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n);
	int l = 0;
	int r = n / 2 + 1;
	while(r - l > 1)
	{
		int m = (l + r) / 2;
		bool good = true;
		for(int i = l/2 ; i < m; i++)
			good &= (a[n - m + i] - a[i] >= z);
		if(good)
			l = m;
		else
			r = m;
	}
	cout << l << endl;
}


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

typedef long long ll ;

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

    ll n, z ; cin>>n>>z ;
    vector<ll> a(n, -1LL) ;

    for(ll i=0;i<n; i++) cin>>a[i] ;
    sort(a.begin(), a.end()) ;

    ll pcnt=0LL ;
    for(ll i=0, j=0 ; j < n ; )
    {
        if( a[i] == -1LL) { i++ ; continue ; }
        else if(  i >=  j) { j = i + 1 ; continue ; }

        assert( j > i && a[j] > a[i]) ;
        if( a[j] - a[i] >= z) { a[i] = ( a[j] = -1LL) ; pcnt++ ; }
        j++ ;
    }

    cout << pcnt << '\n' ;

    return 0 ;
}


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

typedef long long ll ;

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

    ll n, z ; cin>>n>>z ;
    vector<ll> a(n, -1LL) ;

    for(ll i=0;i<n; i++) cin>>a[i] ;
    sort(a.begin(), a.end()) ;

    ll pcnt=0LL ;
    for(ll i=0, j=0 ; j < n ; )
    {
        if( a[i] == -1LL) { i++ ; continue ; }
        else if(  i >=  j) { j = i + 1 ; continue ; }

        if( a[j] - a[i] >= z) { a[i] = ( a[j] = -1LL) ; pcnt++ ; }
        j++ ;
    }

    cout << pcnt << '\n' ;

    return 0 ;
}


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

typedef long long ll ;

/*
 upsolving after understanding the editorial thoroughly!!

  my thoughts / effort before reading editorial :
     ->  sorting is obvious as it gives
         _________________________________
           small values  |  big values
         ________________________________
                 fig. (1)

     -> is a[0] ( and a[n-1]  ) always present in maximum pairs ?
     -> two pointers i,j starting from front (or end)
         if( a[j] - a[i] >= z)
             j++, i++ and mark a[j], a[i] -> -1 so they are not reconsidered
     -> if a[i] can be paired with a[0...p] and a[q... n-1]
        then how to decide which is the best pair
     -> if a[i] + z > max || a[i] - z < mn then a[i] does
        not belong to any pair
     -> some how I need to find p bigger points and p smaller points
         and pair them such that big_i - small_i >= z
     -> there could be some partition like in fig. 1
         which I should binary search on but how to pair them becomes
         the challenge

   concept learnt:
    what helped in this problem is imagining how a general
    solution (pairing) exists which can be modeled as follows:
| a0 | a1 | a2 | L1 | a4 | R1 | a5 | L2 | a7 |L3| a8 | a9 | R3 | a10 | R2| a11 |
 in this case max pairs formed is 3 -> (L1, R1) (L2, R2) (L3, R3)

 now form a bijection, for every such answer there exists
 a pairing in which small points are left most and
 large points are right most !!! phew !!
 (now binary search on
 that number)
 |L1|L2|L3| Li| | | | | |Ri |R1|R2|R3|

*/

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

    ll n, z ; cin>>n>>z ;
    vector<ll> a(n, -1LL) ;

    for(ll i=0;i<n; i++) cin>>a[i] ;
    sort(a.begin(), a.end()) ;

    ll l=0 ; // always l points some feasible number of pairs
    ll r = (n>>1) + 1  ; // always r points infeasible high number of pairs

    while( r > l + 1 )
    {
        ll m = (l + r) >> 1;
        bool good = true;
        for(ll i=0 ; i < m ; i++)
            good = good & ( a[n-m+i] - a[i] >= z ) ;

        if(good)
          l = m ;
        else
          r = m ;
    }

    cout << l << '\n' ;

    return 0 ;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 200043;

int n, z;
int a[N];
// editorial solution check
int main()
{
	scanf("%d", &n);
	scanf("%d", &z);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n);
	int l = 0;
	int r = n / 2 + 1;
	while(r - l > 1)
	{
		int m = (l + r) / 2;
		bool good = true;
		for(int i = 0; i < m; i++)
			good &= (a[n - m + i] - a[i] >= z);
		if(good)
			l = m;
		else
			r = m;
	}
	cout << l << endl;
}


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

typedef long long ll ;

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

    ll n, z ; cin>>n>>z ;
    vector<ll> a(n, -1LL) ;

    for(ll i=0;i<n; i++) cin>>a[i] ;
    sort(a.begin(), a.end()) ;

    ll pcnt=0LL ;
    for(ll i=0, j=0 ; j < n ; )
    {
        if( a[i] == -1) { i++ ; continue ; }
        else if( i == j) { j++ ; continue ; }

        if( a[j] - a[i] >= z) { a[i] = a[j] = -1LL ; pcnt++ ; }
        j++ ;
    }

    cout << pcnt << '\n' ;

    return 0 ;
}


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

typedef long long ll ;

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

    ll n, z ; cin>>n>>z ;
    vector<ll> a(n, -1LL) ;

    for(ll i=0;i<n; i++) cin>>a[i] ;
    sort(a.begin(), a.end()) ;

    ll pcnt=0LL ;
    for(ll i=0, j=0 ; j < n ; )
    {
        if( a[i] == -1LL) { i++ ; continue ; }
        if( a[j] == -1LL) { j++ ; continue ; }

        if( i >=  j)
        {
            j = i + 1 ;
            continue ;
        }

        if( ( a[j] - a[i] ) >= z)
        {
            a[i] = -1LL ;
            a[j] = -1LL ;
            pcnt++ ;
        }

        else
             j++ ;
    }

    cout << pcnt << '\n' ;

    return 0 ;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 200043;

int n, z;
int a[N];
// editorial solution optimization check !!
int main()
{
	scanf("%d", &n);
	scanf("%d", &z);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n);
	int l = 0;
	int r = n / 2 + 1;
	while(r - l > 1)
	{
		int m = (l + r) / 2;
		bool good = true;
		for(int i = l; i < m; i++)
			good &= (a[n - m + i] - a[i] >= z);
		if(good)
			l = m;
		else
			r = m;
	}
	cout << l << endl;
}


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

typedef long long ll ;

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

    ll n, z ; cin>>n>>z ;
    vector<ll> a(n, -1LL) ;

    for(ll i=0;i<n; i++) cin>>a[i] ;
    sort(a.begin(), a.end()) ;
    reverse(a.begin(), a.end());

    ll pcnt=0LL ;
    for(ll i=0, j=0 ; j < n ; )
    {
        if( a[i] == -1LL) { i++ ; continue ; }
        if( a[j] == -1LL) { j++ ; continue ; }

        if( i >=  j)
        {
            j = i + 1 ;
            continue ;
        }

        if( ( a[i] - a[j] ) >= z)
        {
            a[i] = -1LL ;
            a[j] = -1LL ;
            pcnt++ ;
        }

        else
             j++ ;
    }

    cout << pcnt << '\n' ;

    return 0 ;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	vector<int> x(n), y;
	rep(i, n)scanf("%d", &x[i]);
	y = x;
	rep(i, n)y[i] *= -1;
	sort(all(y));
	int ans = 0;
	rep(i, n) {
 		ans += max<int>(distance(lower_bound(all(y), -(x[i] - z)), y.end()) - ans * 2, 0);
	}
	printf("%d\n", ans);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	multiset<int> st;
	int x;
	rep(i, n) {
		scanf("%d", &x);
		st.insert(x);
	}
	int ans = 0;
	while (st.size() > 1) {
		int first = *st.begin();
		auto ite = st.lower_bound(z + first);
		if (ite == st.end())break;
		else {
			++ans;
			st.erase(st.begin());
			st.erase(ite);
		}
	}
	printf("%d\n", ans);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	sort(all(a));
	int ushi = 0, tapu = n;
	while (abs(ushi - tapu) > 1) {
		int nichia = (ushi + tapu) / 2;
		bool kun = true;
		rep(i, nichia) if (abs(a[i] - a[n - nichia + i]) < z)kun = false;
		if (kun)ushi = nichia;
		else tapu = nichia;
	}
	printf("%d\n", ushi);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	sort(all(a));
	int ushi = -1, tapu = n;
	while (abs(ushi - tapu) > 1) {
		int nichia = (ushi + tapu) / 2;
		bool kun = true;
		rep(i, nichia) if (abs(a[i] - a[n - nichia + i]) < z)kun = false;
		if (kun)ushi = nichia;
		else tapu = nichia;
	}
	printf("%d\n", ushi);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	multiset<int> st;
	int x;
	rep(i, n) {
		scanf("%d", &x);
		st.insert(x);
	}
	int ans = 0;
	while (st.size() > 1) {
		int first = *st.begin();
		auto ite = st.lower_bound(z + first);
		if (ite == st.end())break;
		else {
			++ans;
			st.erase(ite);
			st.erase(st.begin());
		}
	}
	printf("%d\n", ans);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	multiset<int> st;
	int x;
	rep(i, n) {
		scanf("%d", &x);
		st.insert(x);
	}
	int ans = 0;
	while (st.size() > 1) {
		int first = *st.begin();
		st.erase(st.begin());
		auto ite = st.lower_bound(z + first);
		if (ite == st.end())break;
		else {
			++ans;
			st.erase(ite);
		}
	}
	printf("%d\n", ans);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	sort(all(a));
	int ushi = 0, tapu = n / 2 + 1;
	while (abs(ushi - tapu) > 1) {
		int nichia = (ushi + tapu) / 2;
		bool kun = true;
		rep(i, nichia) if (abs(a[i] - a[n - nichia + i]) < z)kun = false;
		if (kun)ushi = nichia;
		else tapu = nichia;
	}
	printf("%d\n", ushi);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	vector<int> x(n), y;
	rep(i, n)scanf("%d", &x[i]);
	y = x;
	rep(i, n)y[i] *= -1;
	sort(all(y));
	ll ans = 0;
	rep(i, n) {
 		ans += max(distance(lower_bound(all(y), -(x[i] - z)), y.end()) - ans * 2ll, 0ll);
	}
	printf("%lld\n", ans);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	ll n, z;
	scanf("%lld%lld", &n, &z);
	multiset<ll> st;
	ll x;
	rep(i, n) {
		scanf("%lld", &x);
		st.insert(x);
	}
	ll ans = 0;
	while (st.size() > 1) {
		ll first = *st.begin();
		auto ite = st.lower_bound(z + first);
		if (ite == st.end())break;
		else {
			++ans;
			st.erase(ite);
			st.erase(st.begin());
		}
	}
	printf("%lld\n", ans);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	sort(all(a));
	int ushi = 0, tapu = n;
	while (abs(ushi - tapu) > 1) {
		int nichia = (ushi + tapu) / 2;
		bool kun = true;
		rep(i, nichia) if (abs(a[i] - a[n - nichia + i]) < z)kun = false;
		if (kun)tapu = nichia;
		else ushi = nichia;
	}
	printf("%d\n", ushi);

	Please AC;
}


/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, z;
	scanf("%d%d", &n, &z);
	multiset<int> st;
	int x;
	rep(i, n) {
		scanf("%d", &x);
		st.insert(x);
	}
	int ans = 0;
	while (st.size() > 1) {
		int first = *st.begin();
		auto ite = st.lower_bound(z + first);
		if (ite == st.end())break;
		else {
			++ans;
			st.erase(ite);
			st.erase(st.lower_bound(first));
		}
	}
	printf("%d\n", ans);

	Please AC;
}


/*#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int a[30];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		string str;
		cin >> str;
		for (int i = 0; i < str.size(); i++)
			a[str[i] - 'a']++;

	}
	return  0;
}*/

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
long long int num[200005];
bool compare(long long int a, long long int b)
{
	return a < b;
}
int main()
{
	long long int n, t, we = 0;
	cin >> n >> t;
	for (long long int i = 0; i < n; i++)
		cin >> num[i];
	long long int l = 0, r = 1;
	while (r < n)
	{
		while (num[l] == 0)
			l++;
		if (num[r] - num[l] >= t || num[r] - num[l] <= -t)
		{
			num[r] = 0;
			we++;
			l++;
			r++;
		}
		else
		{
			if(r <= n)
				r++;
		}
	}
	cout << we << endl;
	return 0;
}


/*#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int a[30];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		string str;
		cin >> str;
		for (int i = 0; i < str.size(); i++)
			a[str[i] - 'a']++;

	}
	return  0;
}*/

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int num[200005];
bool compare(int a, int b)
{
	return a < b;
}
int main()
{
	int n, t, we = 0;
	cin >> n >> t;
	for (int i = 0; i < n; i++)
		cin >> num[i];
	sort(num, num + n, compare);
	int l = 0, r = 1;
	while (r < n)
	{
		if (num[r] - num[l] >= t)
		{
			we++;
			l++;
			r++;
		}
		else
		{
			if(r <= n)
				r++;
		}
	}
	cout << we << endl;
	return 0;
}


/*#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int a[30];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		string str;
		cin >> str;
		for (int i = 0; i < str.size(); i++)
			a[str[i] - 'a']++;

	}
	return  0;
}*/

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int num[200005];
int a[200005];
bool compare(int a, int b)
{
	return a < b;
}
int main()
{
	int n, t;
	cin >> n >> t;
	for (int i = 0; i < n; i++)
		cin >> num[i];
	sort(num, num + n, compare);
	for (int i = 1; i < n; i++)
		a[i] = a[i - 1] + num[i] - num[i - 1];
	int we = 1;
	for (int i = 1; i < n; i++)
	{
		if (a[i] >= t)
			t += a[we++];
	}

	cout << we - 1 << endl;
	return 0;
}


/*#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int a[30];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		string str;
		cin >> str;
		for (int i = 0; i < str.size(); i++)
			a[str[i] - 'a']++;

	}
	return  0;
}*/

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int num[200005];
bool compare(int a, int b)
{
	return a < b;
}
int main()
{
	int n, t, we = 0;
	cin >> n >> t;
	for (int i = 0; i < n; i++)
		cin >> num[i];
	sort(num, num + n, compare);
	int l = 0, r = 1;
	while (r < n)
	{
		while (num[l] == 0)
			l++;
		if (num[r] - num[l] >= t)
		{
			num[r] = 0;
			we++;
			l++;
			r++;
		}
		else
		{
			if(r <= n)
				r++;
		}
	}
	cout << we << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int num[200005];
bool compare(int a, int b)
{
	return a < b;
}
int main()
{
	int n, m, ans = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> num[i];
	sort(num, num + n, compare);
	int l = (n - 1) / 2, r = n - 1;
	while (l >= 0)
	{
		if (num[r] - num[l] >= m)
		{
			num[l] = 0;
			l--;
			r--;
			ans++;
		}
		else
			l--;
	}
	cout << ans << endl;
	return 0;
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.329
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CONTEST", "CONTEST\CONTEST.vcxproj", "{D95C81CB-57CF-4B29-85B0-33144B7BF70C}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|x64 = Debug|x64
		Debug|x86 = Debug|x86
		Release|x64 = Release|x64
		Release|x86 = Release|x86
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{D95C81CB-57CF-4B29-85B0-33144B7BF70C}.Debug|x64.ActiveCfg = Debug|x64
		{D95C81CB-57CF-4B29-85B0-33144B7BF70C}.Debug|x64.Build.0 = Debug|x64
		{D95C81CB-57CF-4B29-85B0-33144B7BF70C}.Debug|x86.ActiveCfg = Debug|Win32
		{D95C81CB-57CF-4B29-85B0-33144B7BF70C}.Debug|x86.Build.0 = Debug|Win32
		{D95C81CB-57CF-4B29-85B0-33144B7BF70C}.Release|x64.ActiveCfg = Release|x64
		{D95C81CB-57CF-4B29-85B0-33144B7BF70C}.Release|x64.Build.0 = Release|x64
		{D95C81CB-57CF-4B29-85B0-33144B7BF70C}.Release|x86.ActiveCfg = Release|Win32
		{D95C81CB-57CF-4B29-85B0-33144B7BF70C}.Release|x86.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {318DD523-2E7F-49BD-AC80-1B1037D18346}
	EndGlobalSection
EndGlobal


#include <iostream>
#include <algorithm>
using namespace std;
int num[200005];
bool compare(int a, int b)
{
	return a < b;
}
int main()
{
	int n, m, ans = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> num[i];
	sort(num, num + n, compare);
	int l = n / 2, r = n - 1;
	while (l >= 0)
	{
		if (num[r] - num[l] >= m)
		{
			l--;
			r--;
			ans++;
		}
		else
			l--;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int num[200005];
bool compare(int a, int b)
{
	return a < b;
}
int main()
{
	int n, m, ans = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> num[i];
	sort(num, num + n, compare);
	int l = (n - 1) / 2, r = n - 1;
	while (l >= 0)
	{
		if (num[r] - num[l] >= m)
		{
			l--;
			r--;
			ans++;
		}
		else
			l--;
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],z,ans,b;
queue<int> q;
vector<int> please;

int main(){
    scanf("%d%d",&n,&z);
    multiset<int> s;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        s.insert(a[i]);
    }
    sort(a+1,a+1+n);
    for(int i=n;i>=1;i--){
        if(s.empty())
        break;
        auto ff=s.rbegin();
        b=*ff;
        if(a[i]>z){
        auto it=s.lower_bound(b-z);
        if(*it+z>b&&it==s.begin()){
            break;
        }
        else if(*it+z>b) --it;
        //cout<<"? "<<b<<" "<<*it<<endl;
            if(b-z>=*it){
            ans++;
            auto ss=s.find(*it);
            s.erase(ss);
            ss=s.find(b);
            s.erase(ss);
        }
        }
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],z,dp[maxn],l,r,mid,ans;
deque<int> q;

int main(){
    scanf("%d%d",&n,&z);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        if(q.empty()){
            q.push_front(a[i]);
            continue;
        }
        q.push_back(a[i]);
        if(q.size()>=2){
            if(q.back()-q.front()>=z){
                q.pop_back();q.pop_front();
                ans++;
            }
        }
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],z,ans,b,l,r,mid,d[maxn],ct;
queue<int> q;
vector<int> please;

int main(){
    scanf("%d%d",&n,&z);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    l=1,r=n/2;ans=0;
    while(l<=r){
        mid=(l+r)>>1;
        bool ch=true;
        for(int i=1;i<=mid;i++){
            if(a[n-mid+i]-a[i]<z){
                ch=false;
            }
        }
        if(ch){
            ans=mid;
            l=mid+1;
        }
        else{
            r=mid-1;
        }
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],z,ans;
queue<int> q;
vector<int> please;

int main(){
    scanf("%d%d",&n,&z);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        while(!q.empty()&&a[i]-q.front()>=z){
            please.push_back(q.front());
            q.pop();
        }
        if(!please.empty()){
            if(a[i]-please.back()>=z){
                please.pop_back();
                ans++;
            }
            else{
                q.push(a[i]);
            }
        }
        else{
            q.push(a[i]);
        }
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],z,dp[maxn],l,r,mid,ans;

int main(){
    scanf("%d%d",&n,&z);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        if(a[1]+z<=a[i]){
            l=1,r=i-1,ans=-1;
            while(l<=r){
                mid=(l+r)>>1;
                if(a[mid]+z<=a[i]){
                    ans=mid;
                    l=mid+1;
                }
                else{
                    r=mid-1;
                }
            }
            if(ans>0)
            dp[i]=max(dp[i-1],1+dp[ans-1]);
        }
    }
    printf("%d\n",dp[n]);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],z,ans,b,l,r,mid,d[maxn],ct;
queue<int> q;
vector<int> please;

int main(){
    scanf("%d%d",&n,&z);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        l=i+1,r=n,ans=-1;
        while(l<=r){
            mid=(l+r)>>1;
            if(a[mid]-a[i]>=z){
                ans=mid;
                r=mid-1;
            }
            else{
                l=mid+1;
            }
        }
        if(ans==-1){
            break;
        }
        d[i]=ans;
    }
    int pt=n;
    ans=0;
    for(int i=n;i>=1;i--){
        while(a[pt]==-1){
            pt--;
        }
        if(d[i]>0&&pt>=d[i]){
            if(a[i]+z<=a[pt]){
                ans++;
                pt--;
            }
            a[i]=-1;
        }
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],z,ans;
queue<int> q;
stack<int> please;

int main(){
    scanf("%d%d",&n,&z);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        if(q.empty()){
            q.push(a[i]);
            continue;
        }
        while(!q.empty()&&a[i]-q.front()>=z){
            please.push(q.front());
            q.pop();
        }
        if(!please.empty()){
            if(a[i]-please.top()>=z){
                please.pop();
                ans++;
            }
            else{
                q.push(a[i]);
            }
        }
        else{
            q.push(a[i]);
        }
    }
    printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],z,ans,b,l,r;

int main(){
    scanf("%d%d",&n,&z);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    l=1,r=n/2+1;ans=0;
    while(l<=n/2&&r<=n){
        if(a[l]+z<=a[r]){
            ans++,l++,r++;
        }
        else
            r++;
    }
    printf("%d\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,z,ans=0,x[200000],cur=-1;
    cin>>n>>z;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    sort(x,x+n);
    long long int t=x[0]+z;
    for(int i=1;i<n;i++){

            if(x[i]>=t&&i!=cur){ ans++; t=x[i+1]+z; cur=i+1;   }

    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,z,ans=0,x[200000];
    map<int,int>s;
    cin>>n>>z;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
        if(abs(x[i]-x[j])>=z&&i!=j&&s[i]==0&&s[j]==0){ans++; s[i]=1; s[j]=1;    }
    } }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,z,ans=0,x[200000];
    map<int,int>s;
    cin>>n>>z;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
        if(abs(x[i]-x[j])>=z&&i!=j&&s[i]==0&&s[j]==0){ans++; s[i]=1; s[j]=1;   break; }
    } }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,z,ans=0,x[200000],cur=-1;
    cin>>n>>z;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    sort(x,x+n);
    int t=x[0]+z;
    for(int i=1;i<n;i++){

            if(x[i]>=t&&i!=cur){ ans++; t=x[i+1]+z; cur=i+1;   }

    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,z,x[200000],cur=-1;
    cin>>n>>z;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    sort(x,x+n);
    long long int l=0,r=1,ans=0;
    while(r<n){
        if(x[r]-x[l]>=z){   r++; l++; ans++; }
        else{
        r++;
    }
    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,z,ans=0,x[200000];
    cin>>n>>z;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    sort(x,x+n);

    for(int i=0;i<n;i++){
        if(abs(x[i]-x[i+1])>=z){ans++; i+=2; }
    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+9;

int n,k,a[N];

bool ok(int mid){
    int r=n-mid+1;
    for(int i=1;i<=mid;i++){
       if(abs(a[i]-a[r])<k)return false;
       r++;
    }
    return true;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    int l=0,r=n/2,ans;
    while(l<=r){
        int mid=(l+r)/2;
        if(ok(mid)){
            ans=mid;
            l=mid+1;
        }
        else {
            r=mid-1;
        }
    }
    cout<<ans<<'\n';
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,z,x[200000];
    map<int,int>s;
    cin>>n>>z;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    sort(x,x+n);
    long long int l=0,r=1,ans=0;
    while(r<n){
        if(x[r]-x[l]>=z&&s[l]==0&&s[r]==0){ s[l]++; s[r]++;  r++; l++; ans++;    }
        else{
        r++;
    }
    }
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,z;

int main(){
  cin>>n>>z;
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
  }
  sort(all(v));
  bool b[300000]={};

  int ans=0;
  int i=0;
  int j=0;
  while(i<n){
    while(b[i]) i++;
    if(i>=n) break;
    b[i]=true;
    while(j<v.size()&&v[i]+z>v[j]) j++;
    while(j<v.size()&&b[j]) j++;
    if(n==200000)
      cout<<i<<' '<<j<<endl;
    if(j==v.size()){
      break;
    }
    b[j]=true;
    ans++;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,z;

int main(){
  cin>>n>>z;
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
  }
  sort(all(v));
  bool b[300000]={};

  int ans=0;
  int i=0;
  int j=0;
  while(i<n){
    while(b[i]) i++;
    if(i>=n) break;
    b[i]=true;
    while(j<v.size()&&v[i]+z>v[j]) j++;
//    cout<<i<<' '<<j<<endl;
    if(j==v.size()){
      break;
    }
    b[j]=true;
    ans++;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,z;

int main(){
  cin>>n>>z;
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
  }
  sort(all(v));
  bool b[300000]={};

  int ans=0;
  int i=0;
  int j=0;
  while(i<n){
    while(b[i]) i++;
    if(i>=n) break;
    b[i]=true;
    while(j<v.size()&&b[j]&&v[i]+z>v[j]) j++;
//    cout<<i<<' '<<j<<endl;
    if(j==v.size()){
      break;
    }
    b[j]=true;
    ans++;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,z;
multiset<int> s;

int main(){
  cin>>n>>z;
  rep(i,n){
    int a;
    cin>>a;
    s.insert(a);
  }

  int ans=0;
  while(!s.empty()){
    int v=*s.begin();
    s.erase(s.begin());
    auto itr = lower_bound(all(s),v+z);
    if(itr==s.end()){
      break;
    }
    ans++;
    s.erase(itr);
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,z;

main(){
  cin>>n>>z;
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
  }

  sort(all(v));
  int l=0,r=n/2+1;

  while(r-l>1){
    int m=(l+r)/2;
    bool flag=true;
    rep(i,m){
      flag &= (v[n-m+i]-v[i]>=z);
    }
    if(flag)
      l=m;
    else
      r=m;
  }

  cout<<l<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,z;

int main(){
  cin>>n>>z;
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
  }
  sort(all(v));
  bool b[300000]={};

  int ans=0;
  int i=0;
  int j=0;
  while(i<n){
    while(b[i]) i++;
    if(i>=n) break;
    b[i]=true;
    while(j<v.size()&&v[i]+z>v[j]) j++;
    while(j<v.size()&&b[j]) j++;
//    cout<<i<<' '<<j<<endl;
    if(j==v.size()){
      break;
    }
    b[j]=true;
    ans++;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,z;
multiset<int> s;

int main(){
  cin>>n>>z;
  rep(i,n){
    int a;
    cin>>a;
    s.insert(a);
  }

  int ans=0;
  while(!s.empty()){
    int v=*s.begin();
    s.erase(s.begin());
    auto itr = lower_bound(all(s),v+z);
    if(itr!=s.end()){
      ans++;
      s.erase(itr);
    }
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,z;

main(){
  cin>>n>>z;
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
  }
  sort(all(v));
  bool b[300000]={};

  int ans=0;
  int i=0;
  int j=0;
  while(i<n){
    while(b[i]) i++;
    if(i>=n) break;
    b[i]=true;
    while(j<v.size()&&v[i]-v[j]+z>0) j++;
    while(j<v.size()&&b[j]) j++;

    if(j==v.size()){
      break;
    }
    b[j]=true;
    ans++;
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3e5+10;
int a[maxn];
int n, m, z;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a + n);
    int r = n-1, l = 0;
    while (l < r - 1)
    {
        int m = l + r >> 1;
        int f = 1;
        for (int i = 0; i < m;i++)
            f &= (a[n - m + i] - a[i] >= z);
        if (f)
            l = m;
        else
            r = m;
    }
    cout << l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=2e5+10;
int a[maxn],vis[maxn];
int n,m,z;
multiset<ll> s;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin>>a[i],s.insert(a[i]);
    int ans=0;
    for (auto x:s)
    {
        auto f=s.equal_range(x).first;
//        s.erase(f);
        ll q=x+z;
        f=s.lower_bound(q);
        if (f!=s.end())
        {
            ++ans;
            s.erase(f);
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3e5+10;
int a[maxn];
int n, m, z;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a + n);
    int l = 0, r = n;
    while(l<r-1){
        int m = l + r >> 1;
        int f = 1;
        for (int i = 0; i < m;i++)
            f &= (a[n - m + i] - a[i] >= z);
        if (f)
            l = m;
        else
            r = m;
    }
    cout << l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3e5+10;
int a[maxn];
int n, m, z;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a + n);
    int l = 0, r = n>>1|1;
    while(l<r-1){
        int m = l + r >> 1;
        int f = 1;
        for (int i = 0; i < m;i++)
            f &= (a[n - m + i] - a[i] >= z);
        if (f)
            l = m;
        else
            r = m;
    }
    cout << l;
    return 0;
}


/*
    二分求上界
*/
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3e5+10;
int a[maxn];
int n, m, z;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a + n);
    int l = 0, r = n/2+1;
    while(l<r-1){
        int m = l + r >> 1;
        int f = 1;
        for (int i = 0; i < m;i++)
            f &= (a[n - m + i] - a[i] >= z);
        if (f)
            l = m+1;
        else
            r = m-1;
    }
    cout << l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3e5+10;
int a[maxn];
int n, m, z;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a + n);
    int l = 0, r = n/2+1;
    while(l<r-1){
        int m = l + r >> 1;
        int f = 1;
        for (int i = 0; i < m;i++)
            f &= (a[n - m + i] - a[i] >= z);
        if (f)
            l = m;
        else
            r = m;
    }
    cout << l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3e5+10;
int a[maxn];
int n, m, z;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a + n);
    int r = n, l = 0;
    while (l < r - 1)
    {
        int m = l + r >> 1;
        int f = 1;
        for (int i = 0; i < m;i++)
            f &= (a[n - m + i] - a[i] >= z);
        if (f)
            l = m;
        else
            r = m;
    }
    cout << l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3e5+10;
int a[maxn],vis[maxn];
int n,m,z;
multiset<ll> s;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin>>a[i],s.insert(a[i]);
    int ans=0;
    for (auto x:s)
    {
        ll q=x+z;
        auto f=s.lower_bound(q);
        if (f!=s.end()){
            ++ans;
            s.erase(f);
        }
    }
    cout<<ans;
    return 0;
}


/*
    二分求上界
*/
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3e5+10;
int a[maxn];
int n, m, z;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a + n);
    int l = 0, r = n/2+1;
    while(l<=r-1){
        int m = l + r >> 1;
        int f = 1;
        for (int i = 0; i < m;i++)
            f &= (a[n - m + i] - a[i] >= z);
        if (f)
            l = m+1;
        else
            r = m-1;
    }
    cout << l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=3e5+10;
int a[maxn];
int n, m, z;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>z;
    for (int i=0; i<n; i++)
        cin >> a[i];
    sort(a, a + n);
    int l = 0, r = n;
    while(l<r-1){
        int m = l + r >> 1;
        int f = 1;
        for (int i = 0; i < m;i++)
            f &= (a[n - m + i] - a[i] >= z);
        if (f)
            l = m + 1;
        else
            r = m;
    }
    cout << l-1;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<=r){
        if(l>n/2) break;
        int mid = (l+r)/2;
        bool fa = 1;
        for(int j=1;j<=mid&&;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid-1;
        }
        //cout<<l<<" "<<r<<endl;
    }
    cout<<l-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<=r){
        if(l>n/2) break;
        int mid = (l+r)/2;
        bool fa = 1;
        for(int j=1;j<=mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid-1;
        }
        //cout<<l<<" "<<r<<endl;
    }
    cout<<l-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<r){
        int mid = (l+r-1)/2;
        bool fa = 0;
        for(int j=1;j<=mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }else{
                fa|=1;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid;
        }
        //if(l>n/2) break;

    }
    cout<<l-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<r){
        int mid = (l+r-1)/2;
        bool fa = 0;
        for(int j=1;j<=mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }else{
                fa|=1;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid;
        }
       // cout<<l<<" "<<r<<" "<<fa<<" "<<mid<<endl;
        if(l>n/2) break;

    }
    cout<<l-1<<endl;
}