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
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long n;
	cin>>n;
	long long wyn=0;
	vector <long long> val;
	val.push_back(0);
	long long x=1;
	while(wyn<n){
		if(x%2==1){
			val.push_back(val[x/2]+1);
			wyn+=val[x];
		}
		else{
			val.push_back(val[x/2]);
			wyn+=val[x];
		}
		x++;
	}
	x--;
	long long ile=0;
	long long max=x;
	vector <bool> vis (x+1);
	while(wyn>n){
		if(wyn-val[x]>=n){
			wyn-=val[x];
			vis[x]=0;
		}
		else{
			ile++;
			vis[x]=1;
		}
		x--;
	}
	cout<<ile+x<<endl;
	for(long long i=max; i>x; i--){
		if(vis[i]){
			cout<<i<<" ";
		}
	}
	for(long long i=x; i>=1; i--){
		cout<<i<<" ";
	}
}