import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Comparator;

/**
 * financial_pm to be documented :TODO:.
 *
 * @author Pavel Mavrin
 * @version $Id$
 */
public class financial_pm implements Runnable {

    private BufferedReader in;
    private StringTokenizer st;

    public int nextInt() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return Integer.parseInt(st.nextToken());
    }

    private int[] a;
    private int[] b;
    private int[] p;
    private int[] t;
    private int[] u;
    private int m;

    private void solve() throws IOException {
        in = new BufferedReader(new FileReader("financial.in"));
        PrintWriter out = new PrintWriter("financial.out");
        int n = nextInt();
        int k = nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }

        Integer[] pp = new Integer[n];
        for (int i = 0; i < n; i++) pp[i] = i;
        Arrays.sort(pp, new Comparator<Integer>() {
            public int compare(Integer i, Integer j) {
                return a[i] - a[j];
            }
        });
        p = new int[n];
        for (int i = 0; i < n; i++) p[i] = pp[i];
        int[] pr = new int[n];
        for (int i = 0; i < n; i++) pr[p[i]] = i;

        m = 1;
        while (m < n) m *= 2;
        t = new int[2 * m - 1];

        b = new int[n];
        u = new int[n];

        for (int i = 0; i < n; i++) {
            b[i] = -1;
        }

        for (int i = 0; i < n; i++) {
            set(pr[i], i);
        }

        for (int i = 0; i < n; i++) {
            int max = i;
            int maxv = 1;
            int q = a[i];
            int l;
            int r;

            l = -1;
            r = n;
            while (r > l + 1) {
                int s = (l + r) / 2;
                if (a[p[s]] < (q + k)) l = s;
                else r = s;
            }
            if (r < n) {
                int z = getMax(r, n - 1);
                if (b[z] + 1 > maxv) {
                    maxv = b[z] + 1;
                    max = z;
                }
            }

            l = -1;
            r = n;
            while (r > l + 1) {
                int s = (l + r) / 2;
                if (a[p[s]] <= (q - k)) l = s;
                else r = s;
            }
            if (l >= 0) {
                int z = getMax(0, l);
                if (b[z] + 1 > maxv) {
                    maxv = b[z] + 1;
                    max = z;
                }
            }

            b[i] = maxv;
            u[i] = max;
            set(pr[i], i);
        }

        int z = getMax(0, n - 1);
        out.println(b[z]);
        int[] path = new int[n];
        int l = 0;
        while (u[z] != z) {
            path[l++] = z;
            z = u[z];
        }
        path[l++] = z;
        for (int i = l - 1; i >= 0; i--) {
            out.print(a[path[i]]);
            if (i > 0) {
                out.print(" ");
            } else {
                out.println();
            }
        }
        out.close();
    }

    private void set(int i, int v) {
        set(0, 0, m, i, v);
    }

    private void set(int i, int ll, int rr, int ind, int v) {
        if (rr == ll + 1) {
            t[i] = v;
        } else {
            int mm = (ll + rr) / 2;
            if (ind < mm) {
                set(2 * i + 1, ll, mm, ind, v);
            } else {
                set(2 * i + 2, mm, rr, ind, v);
            }
            if (b[v] >= b[t[i]]) {
                t[i] = v;
            }
        }
    }

    private int getMax(int l, int r) {
        return getMax(0, 0, m, l, r);
    }

    private int getMax(int i, int ll, int rr, int l, int r) {
        if (l <= ll && r >= rr - 1) return t[i];
        int mm = (ll + rr) / 2;
        int max = -1;
        if (l < mm) {
            max = getMax(2 * i + 1, ll, mm, l, r);
        }
        if (r >= mm) {
            int q = getMax(2 * i + 2, mm, rr, l, r);
            if (max == -1 || b[q] > b[max]) max = q;
        }
        return max;
    }


    public static void main(String[] args) {
        new Thread(new financial_pm()).start();
    }

    public void run() {
        try {
            solve();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

}
