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_slowest 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++) {
            for (int j = m; j >= 0; j--) {
                if (a[i] >= min[j] + k || a[i] <= max[j] - k) {
                    if (j == m) {
                        m++;
                        min[m] = a[i];
                        max[m] = a[i];
                        mina[m] = i;
                        maxa[m] = i;
                    } else {
                        if (a[i] < min[j + 1]) {
                            min[j + 1] = a[i];
                            mina[j + 1] = i;
                        }
                        if (a[i] > max[j + 1]) {
                            max[j + 1] = a[i];
                            maxa[j + 1] = i;
                        }
                    }
                    if (a[i] >= min[j] + k) {
                        u[i] = mina[j];    
                    } else {
                        u[i] = maxa[j];
                    }                    
                    break;
                }
            }
        }

        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_slowest()).start();
    }

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

}
