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
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <bitset>
#include <vector>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    
    int k;
    int sum = 0;
    int num = 0;
    
    std::cin >> k;
    
    while (sum < k) {
        num++;
        std::bitset<32> b(num);
        sum += b.count();
    }
    
    int overflow = sum - k;
    
    std::vector<int> res;
    
    while (num > 0) {
        bool skip = false;
        if (overflow > 0) {
            std::bitset<32> b(num);
            if (b.count() <= overflow) {
                overflow -= b.count();
            } else {
                res.push_back(num);
            }
        } else {
            res.push_back(num);
        }
        num--;
    }
    
    cout << res.size() << "\n";
    bool first = true;
    for (int num : res) {
        if (!first) {
            std::cout << " ";
        }
        first = false;
        std::cout << num ;
    }
}