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
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin>>n;

  vector<int> v = {1};

  stack<pair<int, int>> s;
  s.push({1, 1});

  int sum = 1;

  while(sum <= n){
    int size = v.size();
    for(int i=0 ; i<size ; i++){
      v.push_back(v[i]+1);
    }
    size = v.size();
    for(int i=0 ; i<size ; i++){
      sum+=v[i];
      
      s.push({sum, v[i]});

      if(sum > n) break;
    }
    if(sum > n) break;
  }

  int count = s.size();

  pair<int, int> prev;

  vector<int> wyn;

  while(n != 0){
    while(!s.empty() && s.top().first >= n){
      prev = s.top();
      s.pop();
      count--;
    }

    if(n == prev.first){
      for(int i=count+1 ; i>=1 ; i--){
        wyn.push_back(i);
      }
      break;
    }

    n -= prev.second;
    wyn.push_back(count+1);
  }

  cout<<wyn.size()<<"\n";
  for(auto i : wyn) cout<<i<<" ";

  return 0;
}