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

/**
 * financial_pm_slowest to be documented :TODO:.
 *
 * @author Pavel Mavrin
 * @version $Id$
 */
public class financial_pm_slow 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 void solve() throws IOException {
        in = new BufferedReader(new FileReader("financial.in"));
        PrintWriter out = new PrintWriter("financial.out");
        int n = nextInt();
        int k = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }

        int[] u = new int[n];

        int[] min = new int[n + 1];
        int[] max = new int[n + 1];
        int[] mina = new int[n + 1];
        int[] maxa = new int[n + 1];
        int m = 0;
        min[0] = Integer.MIN_VALUE;
        max[0] = Integer.MAX_VALUE;
        mina[0] = -1;
        maxa[0] = -1;

        for (int i = 0; i < n; i++) {

            int s = 0;

            int l = 0;
            int r = m + 1;
            while (r > l + 1) {
                int t = (l + r) / 2;
                if (a[i] >= min[t] + k)
                    l = t;
                else
                    r = t;
            }
            if (l + 1 > s) {
                s = l + 1;
                u[i] = mina[l];
            }

            l = 0;
            r = m + 1;
            while (r > l + 1) {
                int t = (l + r) / 2;
                if (a[i] <= max[t] - k)
                    l = t;
                else
                    r = t;
            }
            if (l + 1 > s) {
                s = l + 1;
                u[i] = maxa[l];
            }

            if (s > m) {
                m = s;
                min[m] = a[i] + 1; // + 1 is hack
                max[m] = a[i] - 1;
            }

            int j = s;
            while (min[j] > a[i]) {
                min[j] = a[i];
                mina[j] = i;
                j--;
            }

            j = s;
            while (max[j] < a[i]) {
                max[j] = a[i];
                maxa[j] = i;
                j--;
            }
        }

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

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

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

}