1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector> 
using namespace std;
typedef long long ll;
typedef long double ld;
#define st first
#define nd second

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> pref = {0};
    for (int i = 1; pref.back() < n; i++) pref.push_back(pref.back() + __builtin_popcount(i));
    vector<int> ans;
    for (int i = pref.size()-1; i > 0; i--)
    {
        if (pref[i-1] < n)
        {
            ans.push_back(i);
            n -= pref[i] - pref[i-1];
        }
    }
    cout << ans.size() << '\n';
    for (int x: ans) cout << x << ' ';


}