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
52
53
54
55
56
#include <iostream>  // std::cout
#include <algorithm> // std::sort
#include <vector>    // std::vector
#include <set>
#include <cmath>
#include <bit>
#include <bitset>
#include <cstdint>
#include <string>
#include <map>
#include <cassert>
#include <functional>
#include <tuple>
#include <numeric>
#include <queue>
#include <list>
#include <cassert>

using namespace std;

int n;
vector<int> res, v;

int countBits(int a)
{
  int res = 0;
  while (a)
  {
    res += a & 1;
    a >>= 1;
  }
  return res;
}

int main()
{
  scanf("%d", &n);
  v.push_back(1);
  for (int i = 2; v.back() < n; v.push_back(v.back() + countBits(i++)))
    ;

  while (v.size())
  {
    res.push_back(v.size());
    n -= countBits(v.size());
    for (; v.size() && v.back() - countBits(v.size()) >= n; v.pop_back())
      ;
  }

  printf("%d\n", res.size());
  for (auto r : res)
  {
    printf("%d ", r);
  }
  return 0;
}