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
#include <iostream>
#include <algorithm>
#include <string>
#include <deque>
#include <vector>
using namespace std;

int pop(int x) {
    return __builtin_popcount(x);
}

int main() {
    int n;
    cin >> n;
    vector<int> cnt(n+1);
    for (int i = 1; i <= n; i++) {
        cnt[i] = cnt[i-1] + pop(i);
    }
    vector<int> res;
    int lft = n;
    for (int i = n; i >= 1; i--) {
        if (cnt[i-1] < lft) {
            res.push_back(i);
            lft -= pop(i);
        }
    }
    cout << res.size() << endl;
    for (auto i : res) {
        cout << i << ' ';
    }
    cout << endl;
}