import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    auto N = readln.chomp.to!long;
    long[] X;
    long x = 1;
    for (;;) {
        X ~= x;
        x = x * 2 + 1;
        if (x > 1e12) break;
    }

    int[] ans;
    int K = X.size;
    for (int k = K - 1; k >= 0; k--) {
        foreach (q; 0 .. 2) {
            long y = X[k];
            if (N >= y) {
                //log([N, k, y]);
                N -= y;
                ans ~= k + 2;
            }
        }
    }
    int[] r;
    int c = 1;
    foreach (a; ans) {
        foreach (k; 0 .. a) {
            r ~= c;
        }
        c++;
    }
    writeln(r.length);
    writefln("%(%s %)", r);
}
