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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cstdint>
#include <algorithm>

using namespace std;

const int maxn = 1000002;

int n;
uint8_t bits[maxn];
uint8_t res[maxn];

uint8_t n_bits_in_byte(uint8_t x)
{
    x = (x & 0x55) + (x >> 1 & 0x55);
    x = (x & 0x33) + (x >> 2 & 0x33);
    x = (x & 0x0f) + (x >> 4 & 0x0f);
    return x;
}

uint8_t n_bits(unsigned int x)
{
	int result = 0;

	if (bits[x] != 0) {
		return bits[x];
	}

	while(x > 0) {
		result += n_bits_in_byte(x & 255);
		x = x >> 8;
	}

	bits[x] = result;

	return result;
}

int length(int k)
{
	int result = 0;

	for(int i = k; i > 0; --i) {
		result += res[i];
	}
	return result;
}

int main()
{
	int sum, i, maxi;

        scanf("%d\n", &n);

//	for(int i = 1; i < 21; ++i) {
//		printf("%d - %d\n", i, n_bits(i));
//	}

	i = 1;
	sum = 0;
	while(sum < n) {
		sum += n_bits(i);
		++i;
	}

	i -= 1;
	res[i] = 1;
	maxi = i;
	i -= 1;

	while(i > 0) {
		if (sum == n) {
			res[i] = 1;
			--i;
			continue;
		}
		if (sum - n_bits(i) >= n) {
			sum -= n_bits(i);
			--i;
			continue;
		}
		res[i] = 1;
		--i;
	}
	
	printf("%d\n", length(maxi));
	printf("%d", maxi);
	for(i = maxi-1; i > 0; --i) {
		if (res[i] == 1) {
		printf(" %d", i);
		}
	}
	printf("\n");

        return 0;
}