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
#include <cstdio>

const int NN = 1000001;
char buf[NN * 8];
int t[NN];

int bits(int v) {
  int ret = 0;
  while (v) {
    ret += v & 1;
    v >>= 1;
  }
  return ret;
}

int main() {
  int k;
  scanf("%d", &k);
  int v = 1;
  for (int i = 1; i <= k; ++v) {
    for (int j = 0, b = bits(v); j < b; ++j, ++i) {
      t[i] = v;
    }
  }

  int steps = 0;
  int offset = 0;
  while (k) {
    offset += sprintf(buf + offset, "%d ", t[k]);
    k -= bits(t[k]);
    ++ steps;
  }
  printf("%d\n%s\n", steps, buf);
  return 0;
}