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


using namespace std;


const int MAXN = 1000010;
int sum[MAXN];


int find_bop(int n) {
  int l = 1;
  int r = n;
  while (l < r) {
    int m = (l + r) / 2;
    if (sum[m] >= n) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  return l;
}


int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + __builtin_popcount(i);
  }

  vector<int> out;
  while (n > 0) {
    int x = find_bop(n);
    out.push_back(x);
    n -= __builtin_popcount(x);
  }
  printf("%d\n", out.size());
  for (auto x : out) printf("%d ", x);
  puts("");
}