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
40
#include <bits/stdc++.h>
#define ll long long
using namespace std;

stack <int> S;
queue<int> S2;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, il;
    cin>>n;
    il=0;
    int j =1;
    while(il<n)
    {
        il+=__builtin_popcount(j);
        S.push(j);
        j++;
    }
    il-=n;
    while(!S.empty())
    {
        if(__builtin_popcount(S.top())<=il)
        {
            il-=__builtin_popcount(S.top());
        }
        else
        S2.push(S.top());
        S.pop();
    }

    cout<<S2.size()<<"\n";
    while(!S2.empty())
    {
        cout<<S2.front()<<" ";
        S2.pop();
    }
}