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
36
37
38
39
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int n, nn;
int a;
map<int, int> m;
vector<int> v;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    nn = n;
    a = 1;
    while(nn > 0)
    {
        nn -= __builtin_popcount(a);
        m[__builtin_popcount(a)] = a;
        a++;
    }
    nn = m[-nn];
    for(int i = 1; i < a; i++)
    {
        if(i != nn)
        {
            v.push_back(i);
        }
    }
    cout << v.size() << '\n';
    for(int i = (int)v.size() - 1; i >= 0; i--)
        cout << v[i] << ' ';
    return 0;
}