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

int main(){
  //int a; cin >> a;
  //cout << __builtin_popcount(a) << endl;
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n; cin >> n;
  vector <int> ziomale;
  vector <bool> biore;
  int temp = 0;
  int obec = 0;
  while(temp < n){
    obec ++;
    temp += __builtin_popcount(obec);
    ziomale.push_back(obec);
    biore.push_back(true);
  }
  //teraz pora wyrównac szanse
  /*for(int a : ziomale){
    cout << a << " ";
  }
  cout << endl << endl;*/
  int j = 0;
  int ziomalskirozmiar = ziomale.size();
  reverse(ziomale.begin(), ziomale.end());
  reverse(biore.begin(), biore.end());
  while(temp != n){
    if(temp - __builtin_popcount(ziomale[j]) >= n){
      ziomalskirozmiar --;
      temp -= __builtin_popcount(ziomale[j]);
      biore[j] = false;
    }
    j++;
  }
  cout << ziomalskirozmiar << endl;
  for(int i=0; i<ziomale.size(); i++){
    if(biore[i] == true)
      cout << ziomale[i] << " ";
  }

}