1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;
const int MX=1100100;
int n,le,ri,mid,i,b[MX],c[MX];
vector<int> ans;
int main() {
  scanf("%d",&n);
  for (i=1; i<=n; i++) {
    b[i]=b[i/2]+(i&1);
    c[i]=c[i-1]+b[i];
  }
  while (n>0) {
    le=1; ri=n;
    while (le<ri) {
      mid=(le+ri)/2;
      if (c[mid]>=n) ri=mid; else le=mid+1;
    }
    ans.push_back(ri);
    n-=b[ri];
  }
  printf("%d\n",int(ans.size()));
  for (int x: ans) printf("%d ",x);
  return 0;
}