#include <algorithm>
#include <iostream>
#include <cassert>
#include <map>
#include <utility>
#include <vector>

using namespace std;

constexpr static int MAXN = 42;

int64_t cnt[MAXN];
int64_t split[MAXN][MAXN];
int64_t c[MAXN][MAXN];
map <int64_t, vector <int>> m;

int get_cnt(int64_t n) {
    int t = 0;
    while (n > 0) {
        int k = 2;
        while (cnt[k + 1] <= n)
            k++;
        n -= cnt[k];
        t += k;
    }
    return t;
}

void add_cnt(vector <int>& r, int& z, int64_t n) {
    while (n > 0) {
        int k = 2;
        while (cnt[k + 1] <= n)
            k++;
        n -= cnt[k];
        for (int i = 0; i < k; i++)
            r.push_back(z);
        z++;
    }
}

void add_pair(vector <int>& r, int& z, vector <int> s) {
    for (int i = 0; i < s[1]; i++)
        r.push_back(z);
    for (int i = 0; i < s[3]; i++)
        r.push_back(z + 1);
    for (int i = 0; i < s[0] - s[1]; i++)
        r.push_back(z);
    for (int i = 0; i < s[2] - s[3]; i++)
        r.push_back(z + 1);
    z += 2;
}

vector <int> solve(int64_t n) {
    m[0] = {0, 0, 0, 0};
    for (int i = 1; i < MAXN; i++)
        for (int j = 1; 2 * j <= i; j++)
            for (int i2 = 1; i2 < MAXN; i2++)
                for (int j2 = 1; 2 * j2 <= i2; j2++) {
                    double dval = cnt[i] + cnt[i2];
                    dval += 1.0 * split[i][j] * split[i2][j2];
                    if (dval > n)
                        continue;
                    int64_t ival = cnt[i] + cnt[i2];
                    ival += split[i][j] * split[i2][j2];
                    if (ival > n)
                        continue;
                    if (!m.count(ival)
                            || m[ival][0] + m[ival][2] > i + i2)
                        m[ival] = {i, j, i2, j2};
                }

    int bestcnt = 1e9;
    vector <int> s1, s2;
    int64_t nleft = 0;
    for (auto& kv : m) {
        // use two pairs
        auto it = m.lower_bound(n - kv.first);
        if (it != m.begin()) {
            it--;
            int cnt = (get_cnt(n - kv.first - it->first)
                    + kv.second[0] + kv.second[2]
                    + it->second[0] + it->second[2]);
            if (cnt < bestcnt) {
                bestcnt = cnt;
                s1 = kv.second;
                s2 = it->second;
                nleft = n - kv.first - it->first;;
            }
        }
    }

    /*
    cout << "bestcnt " << bestcnt << endl;
    for (auto s : {s1, s2}) {
        for (int x : s)
            cout << x << " ";
        cout << endl;
    }
    */

    vector <int> r;
    int z = 1;
    add_pair(r, z, s1);
    add_pair(r, z, s2);
    add_cnt(r, z, nleft);
    return r;
}

int main() {
    for (int i = 1; i < MAXN; i++) {
        c[i][0] = c[i][i] = 1;
        for (int j = 1; j < i; j++)
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
    }

    // even subsets: 2^{i-1} - 1
    for (int i = 1; i < MAXN; i++)
        cnt[i] = (1LL << (i - 1)) - 1;

    // i total, split j off
    for (int i = 1; i < MAXN; i++) {
        for (int j = 1; 2 * j <= i; j++) {
            split[i][j] = 0;
            // subset has size k
            for (int k = 1; k <= j; k++)
                split[i][j] += c[j][k] * c[i - j][k];
            //cout << i << " " << j << " " << split[i][j] << endl;
        }
    }

    int64_t n;
    cin >> n;

    auto r = solve(n);
    cout << r.size() << endl;
    for (int i = 0; i < r.size(); i++)
        cout << r[i] << ' ';
    cout << endl;
}


Measured memory_bytes: 5632