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
#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> jedynki (1);
	int x = 0, res = 0, liczba = 0;
	while(res < n)
	{
		liczba++;
		res +=  __builtin_popcount(liczba);
		if(jedynki.size()-1 < __builtin_popcount(liczba))
			jedynki.push_back(liczba);
		jedynki[ __builtin_popcount(liczba)] = liczba;
	}
	x = jedynki[res - n];
	if(res - n == 0)
		cout << liczba << '\n';
	else
		cout << liczba - 1 << '\n';
	for(int i = liczba; i > 0; --i)
		if(i != x)
			cout << i << " ";
	return 0;
}