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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

/*-------------------------------------------------------------------------------------------*/

int er[40];
int ans[40];

/* ------------------------------------------------------------------------------------------*/

void BinaryRecursion(int n,int step)
{
int a;
a=n%2;
n=n>>1;
if (n==0);
else BinaryRecursion(n,step+1);
er[step] = a;
}

void fan(int n,int m)
{
for(int i = m;i <= n;i++)
{
if(ans[i]) ans[i] = 0;
else ans[i] = 1;
}
}

int f(int n)
{
int i;
for(i = 0;i <= n;i++)
{
if(!ans[i])
{
return i;
}
}
return i;
}

void f1(int n)
{
for(int i = n;i >= 0;i--)
{
if(ans[i] == 1)
{
ans[i] = 0;
}
else
{
ans[i] = 1;
return;
}
}
}

int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/* --------------------------------------------------------------------------------------*/
cin >> N;
fill(er,er+40,-1);
BinaryRecursion(N,0);
int i = 0;
for(;i < 50;i++)
{
if(er[i] == -1) break;
}
i--;
for(int j = 0;j <= i;j++)
{
ans[j] = er[i - j];
//cout << ans[j];
}

int cnt = 0;
int cn = 0;
int a[50];

while(1)
{
int k = f(i);
if(k > i)
{
break;
}
else
{
a[cn++] = i - k + 1;
fan(i,k);
cnt++;
int k = f(i);
if(k > i) break;
f1(i);
cnt++;
}
// for(int j = 0;j <= i;j++)
// {
// cout <<ans[j] << " ";
// }
// cout <<endl;
}

if(cnt == 0) cout << 0 <<endl;
else
{
cout <<cnt <<endl;
for(int j = 0;j < cn;j++)
{
cout << a[j];
if(j!= cnt) cout << " ";
}
}
return 0;
}