Cat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants to utilize this algorithm to create the perfect longcat.

Assume that we have a cat with a number $x$. A perfect longcat is a cat with a number equal $2^m - 1$ for some non-negative integer $m$. For example, the numbers $0$, $1$, $3$, $7$, $15$ and so on are suitable for the perfect longcats.

In the Cat Furrier Transform, the following operations can be performed on $x$:  (Operation A): you select any non-negative integer $n$ and replace $x$ with $x \oplus (2^n - 1)$, with $\oplus$ being a bitwise XOR operator. (Operation B): replace $x$ with $x + 1$. 

The first applied operation must be of type A, the second of type B, the third of type A again, and so on. Formally, if we number operations from one in the order they are executed, then odd-numbered operations must be of type A and the even-numbered operations must be of type B.

Neko wants to produce perfect longcats at industrial scale, thus for each cat Neko only wants to perform at most $40$ operations. Can you help Neko writing a transformation plan?

Note that it is not required to minimize the number of operations. You just need to use no more than $40$ operations.


-----Input-----

The only line contains a single integer $x$ ($1 \le x \le 10^6$).


-----Output-----

The first line should contain a single integer $t$ ($0 \le t \le 40$) — the number of operations to apply.

Then for each odd-numbered operation print the corresponding number $n_i$ in it. That is, print $\lceil \frac{t}{2} \rceil$ integers $n_i$ ($0 \le n_i \le 30$), denoting the replacement $x$ with $x \oplus (2^{n_i} - 1)$ in the corresponding step.

If there are multiple possible answers, you can print any of them. It is possible to show, that there is at least one answer in the constraints of this problem.


-----Examples-----
Input
39

Output
4
5 3 
Input
1

Output
0

Input
7

Output
0



-----Note-----

In the first test, one of the transforms might be as follows: $39 \to 56 \to 57 \to 62 \to 63$. Or more precisely: Pick $n = 5$. $x$ is transformed into $39 \oplus 31$, or $56$.  Increase $x$ by $1$, changing its value to $57$.  Pick $n = 3$. $x$ is transformed into $57 \oplus 7$, or $62$.  Increase $x$ by $1$, changing its value to $63 = 2^6 - 1$. 

In the second and third test, the number already satisfies the goal requirement.

Difficulty: EASY
Tags: Bit manipulation

Graph traversal

Mathematics

Constructive algorithms
Skill types: Bit manipulation

Starter code:

Solutions:
import sys
x = int(input())

def solve(cnt, odds):
	print(cnt)
	print(' '.join(list(map(str, odds))))
	sys.exit(0)
odds = []
cnt = 0
xb = list(bin(x)[2:])
n = len(xb)
if x == 0 or x ^ int(2 ** n - 1) == 0:
	solve(cnt, odds)
while True:
	xb = list(bin(x)[2:])
	n = len(xb)
	for i in range(len(xb)):
		if xb[i] == '0':
			nn = 2 ** (n - i) - 1
			odds.append(n - i)
			x = x ^ nn
			cnt += 1
			if x ^ 2 ** n - 1 == 0:
				solve(cnt, odds)
			x += 1
			cnt += 1
			if x ^ 2 ** n - 1 == 0:
				solve(cnt, odds)
			break


x = int(input())
n = len(str(bin(x))) - 2
curr = (1 << n) - 1
res = 0
resList = []
for i in range(0, n):
	if x ^ curr < x:
		x = x ^ curr
		res = res + 2
		resList.append(n - i)
	curr = curr >> 1
print(res - 1)
print(*resList)


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(x,) = gil()
left = 40
ans = []
if x == 0:
	print(1)
	print(1)
	exit()

def getMsb(x):
	return int(log2(x)) + 1

def end(x):
	m = getMsb(x)
	return x == 2 ** m - 1

def getMask(x):
	m = getMsb(x)
	return 2 ** m - 1
while not end(x) and left > 0:
	if getMask(x) - x + (x & 1) <= left:
		break
	left -= 1
	ans.append(getMsb(x))
	x ^= getMask(x)
	if end(x):
		break
	x += 1
	left -= 1
while not end(x) and left > 0:
	ans.append(~x & 1)
	left -= 1
	x ^= ~x & 1
	if end(x):
		break
	x += 1
	left -= 1
print(40 - left)
print(*ans)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
x = intIn()
ans = 0
li = []
t = 0
while t < 40:
	b = bin(x)[2:]
	l = len(b)
	if b.count('1') == l:
		break
	else:
		for i in range(l):
			if b[i] == '0':
				li.append(l - i)
				break
		x ^= 2 ** (l - i) - 1
		bb = bin(x)[2:]
		if bb.count('1') == len(bb):
			ans += 1
			break
		else:
			ans += 2
		x += 1
	t += 1
if ans == 0:
	print(0)
else:
	print(ans)
	print(*li)


n = int(input())
nBinary = str(bin(n))[2:]
count = 0
lst = []
count1 = 0
while '0' in nBinary and count < 40:
	if count % 2 == 0:
		lst.append(len(nBinary))
		count += 1
		nList = list(nBinary)
		for i in range(len(nList)):
			if nList[i] == '1':
				nList[i] = '0'
			else:
				nList[i] = '1'
		nBinary = ''.join(nList)
		tmp = int(nBinary, 2)
		nBinary = str(bin(tmp))[2:]
	else:
		count += 1
		tmp = int(nBinary, 2) + 1
		nBinary = str(bin(tmp))[2:]
print(count)
print(' '.join(map(str, lst)))


from math import log
x = int(input())
(c, res) = (0, [])
while x & x + 1 != 0:
	mn = x & -x
	res.append(int(log(mn, 2)))
	x ^= mn - 1
	c += 1
	if x & x + 1 == 0:
		break
	c += 1
	x += 1
print(c)
print(*res)


from math import *
x = input()
x = int(x)
s = format(x, 'b')
l = len(s)
output = []
ss = []
counter = 0
for j in range(len(s)):
	ss.append('1')
ss = ''.join(ss)
count = 0
while s != ss:
	count = count + 1
	for i in range(l):
		if s[i] == '0':
			counter = i
			break
	for j in range(counter, l):
		if s[j] == '1':
			s = s[:j] + '0' + s[j + 1:]
		else:
			s = s[:j] + '1' + s[j + 1:]
	output.append(int(l - counter))
	if s == ss:
		break
	count = count + 1
	for j in range(l):
		if s[l - j - 1] == '0':
			s = s[:l - j - 1] + '1' + s[l - j:]
			break
		if s[l - j - 1] == '1':
			s = s[:l - j - 1] + '0' + s[l - j:]
print(count)
for i in range(len(output)):
	print(output[i], sep=' ', end=' ', flush=True)


x = int(input())
n = x.bit_length()
z = 2 ** n - 1
A = []
for i in range(40):
	if x == z:
		print(i)
		break
	if i % 2:
		x += 1
	else:
		n -= 1
		y = x ^ 2 ** n - 1
		A.append(n * (x < y))
		x = max(x, y)
print(*A)


from math import log

def all1(a):
	var = 1
	for x in a:
		if x == '0':
			var = 0
			break
	return var
x = int(input())
s = bin(x)[2:]
count = 0
arr = []
while all1(s) == 0:
	s2 = '1' * len(s)
	arr += [int(log(int(s2, 2) + 1, 2))]
	s = bin(int(s, 2) ^ int(s2, 2))[2:]
	count += 1
	if all1(s):
		break
	s = bin(int(s, 2) + 1)[2:]
	count += 1
print(count)
print(*arr)


x = int(input())
ans = []
cnt = 0
while x & x + 1 != 0:
	bn = str(bin(x)[2:])
	cnt += 1
	ret = -1
	for i in range(len(bn)):
		if bn[i] == '0':
			ret = i
			break
	if ret == -1:
		break
	x ^= 2 ** (len(bn) - ret) - 1
	ans.append(len(bn) - ret)
	if x & x + 1 == 0:
		break
	x += 1
	cnt += 1
print(cnt)
if len(ans) > 0:
	print(' '.join((str(el) for el in ans)))


from math import ceil, log2

def is_one(a):
	return bin(a)[2:].count('1') == len(bin(a)[2:])
a = int(input())
is_one = lambda x: bin(x)[2:].count('1') == len(bin(x)[2:])
l = []
op_a = True
t = 0
while not is_one(a):
	t += 1
	if op_a:
		l.append(ceil(log2(a)))
		a = a ^ 2 ** ceil(log2(a)) - 1
	else:
		a += 1
	op_a = not op_a
print(t)
for i in l:
	print(i, end=' ')


n = int(input())
t = 0
l = []
while n != 2 ** n.bit_length() - 1:
	if t % 2 == 0:
		x = n.bit_length()
		n ^= 2 ** x - 1
		l.append(x)
	else:
		n += 1
	t += 1
print(t)
print(*l)


x = int(input())

def bits(n):
	while n:
		b = n & ~n + 1
		yield b
		n ^= b
already = []
p = []
i = 0
while 2 ** i < 2000001:
	already.append(2 ** i - 1)
	p.append(2 ** i)
	i += 1
if x in already:
	print(0)
	exit()
out = []
steps = True
while x not in already:
	b = [_ for _ in bits(x)]
	i = len(p) - 1
	while p[i] in b or p[i] >= x:
		i -= 1
	i += 1
	out.append(i)
	x ^= already[i]
	if x in already:
		steps = False
		break
	x += 1
if steps:
	print(len(out) * 2)
	print(*out)
else:
	print(len(out) * 2 - 1)
	print(*out)


def main():
	num = int(input())
	answer = solve(num)
	print(answer)

def solve(num):
	import math
	n = []
	iteration = 0
	while math.ceil(math.log2(num + 1)) > math.log2(num + 1):
		if iteration % 2 == 0:
			b = bin(num)[2:]
			deg = len(b) - b.index('0')
			num ^= 2 ** deg - 1
			n.append(deg)
		else:
			num += 1
		iteration += 1
	return str(iteration) + '\n' + ' '.join((str(x) for x in n))
main()


import math
n = int(input())
x = 1
lis = []
while True:
	if x % 2 == 1:
		k = int(math.log2(n)) + 1
		n ^= 2 ** k - 1
		lis.append(k)
	else:
		n += 1
	if math.log2(n + 1) == int(math.log2(n + 1)):
		break
	x += 1
print(x)
for i in lis:
	print(i, end=' ')


n = int(input())
operations = 0
s = bin(n)[2:]
ans = []
while len(s) != s.count('1'):
	if operations % 2 == 0:
		x = s.find('0')
		x = len(s) - x
		n = n ^ 2 ** x - 1
		ans.append(x)
		operations += 1
		s = bin(n)[2:]
	else:
		n = n + 1
		s = bin(n)[2:]
		operations += 1
print(operations)
print(' '.join((str(x) for x in ans)))


n = int(input())
s = bin(n).replace('0b', '')
l = []
for i in range(len(s)):
	l.append(int(s[i]))
c = l.count(1)
(t, ans, k) = (0, [], len(s))
while c != k:
	x = 0
	t += 1
	for i in range(k):
		if l[i] + x == 0:
			x = 1
			ans.append(k - i)
		if x == 1:
			c -= l[i]
			l[i] = (l[i] + 1) % 2
			c += l[i]
	if c == k:
		break
	else:
		t += 1
		if l[-1] == 0:
			l[-1] = 1
			c += 1
		else:
			for i in range(k - 1, -1, -1):
				if l[i] == 1:
					(c, l[i]) = (c - 1, 0)
				else:
					l[i] = 1
					c += 1
					break
print(t)
if t > 0:
	print(*ans)


N = int(input())
tries = 0
ans = []
while True:
	b = '{0:b}'.format(N)
	j = len(b)
	for i in range(len(b)):
		if b[i] == '0':
			break
		j -= 1
	if j == 0:
		break
	elif j != 0:
		tries += 1
		ans.append(j)
		N = N ^ (1 << j) - 1
	b = '{0:b}'.format(N)
	if '0' not in b:
		break
	else:
		tries += 1
		N = N + 1
print(tries)
for i in ans:
	print(i, end=' ')


x = int(input())
o = 0
lo = []
b = list(map(int, bin(x)[2:]))
while 0 in b and 1 in b:
	o += 1
	lo += [len(b) - b.index(0)]
	for i in range(b.index(0), len(b)):
		b[i] = 1 - b[i]
	if 0 in b:
		o += 1
		for i in range(len(b) - 1, 0, -1):
			b[i] = 1 - b[i]
			if b[i] == 1:
				break
print(o)
print(*lo)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x

def chk(x):
	while x % 2 == 0:
		x //= 2
	return True if x == 1 else False

def pw(x):
	cnt = 1
	while x != 1:
		x //= 2
		cnt += 1
	return cnt
N = 10 ** 9 + 7
n = I()
a = []
ex = 0
while n != 1:
	p = pw(n)
	a += (p,)
	n = (n ^ 2 ** p - 1) + 1
	if chk(n):
		ex = 1
		break
print(len(a) * 2 - ex)
print(*a)


from operator import xor
array = []
x = int(input())
x2 = str(bin(int(x)))[2:]
c = 0
k = 0
step = 0
for i in range(20):
	if x + 1 == 2 ** i:
		print(0)
		exit()
for i in range(1, 41):
	c = 0
	k = 0
	step = 0
	x2 = str(bin(int(x)))[2:]
	if i % 2 == 1:
		for num in x2:
			c += 1
		for num in x2:
			k += 1
			if num == '0':
				step = c - k + 1
				break
		x = xor(x, 2 ** step - 1)
		array.append(step)
	for j in range(100):
		if x == 2 ** j - 1:
			print(i)
			print(*array)
			exit()
	if i % 2 == 0:
		x += 1
	for j in range(100):
		if x == 2 ** j - 1:
			print(i)
			print(*array)
			exit()


x = int(input())
flag = 0
ans = []
cnt = 0
while flag == 0:
	s = bin(x)[2:]
	if s.count('0') == 0:
		flag = 1
		break
	i = len(s)
	no = 2 ** i - 1
	x = x ^ no
	ans.append(i)
	cnt += 1
	s = bin(x)[2:]
	if s.count('0') == 0:
		flag = 1
		break
	cnt += 1
	x += 1
print(cnt)
print(*ans)


import math

def bina(n):
	b = []
	while n >= 1:
		b.append(n % 2)
		n = n // 2
	return b

def back(arr):
	val = 0
	ind = 1
	for i in range(len(arr)):
		val = val + ind * arr[i]
		i = i + 1
		ind = 2 * ind
	return val

def flip(n, arr):
	for i in range(n):
		arr[i] = (arr[i] + 1) % 2
	return arr

def find(arr):
	ind = 0
	while ind <= len(arr) - 1 and arr[ind] == 0:
		ind = ind + 1
	return ind

def allones(arr):
	for i in range(len(arr)):
		if arr[i] == 0:
			return False
	return True

def main():
	x = int(input())
	b = bina(x)
	ni = []
	n = find(b)
	ni.append(n)
	t = 0
	while n <= len(b) - 1:
		b = flip(n, b)
		x = back(b)
		t = t + 1
		x = x + 1
		if x - 2 ** int(math.log2(x)) == 0:
			break
		t = t + 1
		b = bina(x)
		n = find(b)
		ni.append(n)
	print(t)
	st = ''
	for i in range(len(ni)):
		st = st + str(ni[i]) + ' '
	print(st)
main()


n = int(input())
zero_positions = []
i = 0
while n > 0:
	if n % 2 == 0:
		zero_positions.append(i)
	n = n // 2
	i += 1
if not zero_positions:
	print(0)
else:
	print(len(zero_positions) * 2 + 1)
	print(0)
	for z in zero_positions:
		print(z)


XOR = 0
ADD = 1

def main():
	buf = input()
	n = int(buf)
	bit_length = n.bit_length()
	op_state = XOR
	op_count = 0
	op_list = []
	while not check_perfection(n):
		if op_state == XOR:
			for i in range(bit_length - 1, -1, -1):
				if n & 1 << i == 0:
					n = xor_operation(n, i + 1)
					op_list.append(i + 1)
					break
			op_count += 1
			op_state = ADD
		elif op_state == ADD:
			n += 1
			op_count += 1
			op_state = XOR
	print(op_count)
	print(' '.join((str(x) for x in op_list)))

def check_perfection(x):
	for i in range(32):
		if x == int(2 ** i) - 1:
			return True
	return False

def xor_operation(x, i):
	return x ^ int(2 ** i) - 1
main()


x = int(input())
ans = []
num = tuple((2 ** i - 1 for i in range(1, 33)))
k = 0
while x not in num:
	k += 1
	t = tuple(bin(x)[2:])
	for i in range(len(t)):
		if t[i] == '0':
			break
	x = int(''.join(t), 2) ^ 2 ** (len(t) - i) - 1
	ans.append(len(t) - i)
	if x in num:
		break
	k += 1
	x += 1
print(k)
print(*ans)


x = int(input())
i = 0
d = []
while i < 100:
	s = str(bin(x))[2:]
	k = s.count('1')
	if k == len(s):
		break
	while s[0] != '0':
		s = s[1:]
	k0 = s.count('0')
	if k0 == len(s):
		i += 2
		d.append(0)
		x = x ^ 2 ** 0 - 1
		x += 1
		d.append(len(s))
		x = x ^ 2 ** len(s) - 1
		x += 1
		break
	else:
		d.append(len(s))
		x = x ^ 2 ** len(s) - 1
		x += 1
	i += 1
print(i * 2)
print(*d)


import math
n = int(input())
add = []
count = 0
while 1:
	nn = bin(n)
	a = nn[2:]
	a = a[::-1]
	text = ''
	c = 0
	s = list(set(a))
	if len(s) == 1 and s[0] == '1':
		break
	power = 0
	for i in range(len(a)):
		if a[i] == '0':
			power = i + 1
	num = 1
	num <<= power
	n ^= num - 1
	add.append(power)
	count += 1
	t = list(bin(n))
	t = t[2:]
	s = list(set(t))
	if len(s) == 1:
		break
	else:
		n += 1
		count += 1
if count:
	print(count)
	print(*add)
else:
	print(0)


x = int(input())
b = bin(x).replace('0b', '')
l = [2 ** i - 1 for i in range(41)]
t = []
count = 0
if x in l:
	print('0')
	exit()
while 1 == 1:
	t.append(len(b))
	x = x ^ 2 ** len(b) - 1
	count += 1
	if x in l:
		break
	x += 1
	count += 1
	if x in l:
		break
	b = bin(x).replace('0b', '')
print(count)
print(*t)


n = int(input())
p = n
b = ''
while p > 0:
	if p % 2 == 1:
		b += '1'
	else:
		b += '0'
	p //= 2
b = b[::-1]
ans = 0
ans1 = list()
while '0' in b:
	i = 0
	while i < len(b) and b[i] == '1':
		i += 1
	if b[i] == '0':
		ans1.append(len(b) - i)
		j = i
		while j < len(b):
			if b[j] == '1':
				b = b[:j] + '0' + b[j + 1:]
			else:
				b = b[:j] + '1' + b[j + 1:]
			j += 1
		i = 0
		x = -1
		while i < len(b):
			if b[i] == '0':
				x = i
			i += 1
		if x == -1:
			ans += 1
			break
		else:
			b = b[:x] + '1' + b[x + 1:]
			j = x + 1
			while j < len(b):
				b = b[:j] + '0' + b[j + 1:]
				j += 1
			ans += 2
print(ans)
for i in ans1:
	print(i, end=' ')


def idealneko(len):
	x = len + 1
	while x != 1:
		if x % 2 == 0:
			x /= 2
		else:
			return 0
	return 1
x = int(input())
answer = []
counter = 0
while idealneko(x) != 1:
	if counter % 2 == 0:
		s = x
		ans = 0
		while idealneko(s) != 1:
			s = s >> 1
			ans += 1
		answer.append(ans)
		s = 1
		for i in range(ans - 1):
			s = (s << 1) + 1
		x = x ^ s
	else:
		x += 1
	counter += 1
print(counter)
print(*answer)


n = int(input())
ans = 0
ansl = []
while bin(n)[2:].find('0') != -1:
	a = bin(n)
	ansl.append(len(a) - 2 - a[2:].find('0'))
	n = n ^ 2 ** (len(a) - 2 - a[2:].find('0')) - 1
	ans += 1
	if bin(n)[2:].find('0') != -1:
		n = n + 1
		ans += 1
print(ans)
print(' '.join(list(map(str, ansl))))


import math
import sys
DEBUG = False

def inp():
	return sys.stdin.readline().rstrip()

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)

def solve(X):
	nops = 0
	ns = []
	while True:
		s = '{:b}'.format(X)
		ls = len(s)
		zerop = s.find('0')
		if X == 0 or zerop == -1:
			break
		n = ls - zerop
		ns.append(n)
		nops += 1
		X ^= (1 << n) - 1
		s = '{:b}'.format(X)
		zerop = s.find('0')
		if X == 0 or zerop == -1:
			break
		X += 1
		nops += 1
	return (nops, ns)

def main():
	X = int(inp())
	(nops, ns) = solve(X)
	print(nops)
	if ns:
		print(*ns)
main()


import math
n = int(input())
ans = []
cnt = 0
b = int(math.log(n) / math.log(2) + 1)
while n != 2 ** b - 1 and cnt < 40:
	if cnt & 1 == 0:
		for j in reversed(range(b)):
			if not n >> j & 1:
				ans.append(j + 1)
				n = n ^ 2 ** (j + 1) - 1
				break
	else:
		n += 1
	cnt += 1
print(cnt)
for i in ans:
	print(i, end=' ')


x = int(input())
x_binary = bin(x)[2:]
l = len(x_binary)
i = 0
result = []
operations = 0
while i < l:
	if x_binary[i] == '0':
		operations += 1
		x = x ^ 2 ** (l - i) - 1
		result.append(l - i)
		if x == 2 ** l - 1:
			break
		else:
			operations += 1
			x = x + 1
	x_binary = bin(x)[2:]
	i += 1
print(operations)
for k in result:
	print(k, end=' ')


import math
n = int(input())
b = bin(n)
b = b[2:]
l = []
s = ''
c = 0
m = 0
if len(set(b)) == 1:
	print(0)
else:
	while len(set(b)) != 1:
		for i in range(len(b)):
			if b[i] == '0':
				c = i
				break
		s = '1' * (len(b) - c)
		k = int(s, 2)
		n = n ^ k
		l.append(int(math.log(k + 1, 2)))
		b = bin(n)
		b = b[2:]
		m = m + 1
		if len(set(b)) == 1:
			break
		else:
			n = n + 1
			b = bin(n)
			b = b[2:]
			m = m + 1
	print(m)
	print(*l)


def main():
	n = int(input())
	s = bin(n)[2:]
	x = len(s) - 1
	st = '1' * (x + 1)
	if st == s:
		print(0)
	else:
		i = 0
		op = 0
		l = []
		while i < x + 1:
			if s == '1' * len(s):
				break
			if s[i] == '0':
				y = len(s) - i
				op += 1
				n = n ^ pow(2, y) - 1
				l.append(y)
				s = bin(n)[2:]
				if s == '1' * len(s):
					break
				n = int(s, 2)
				n = n + 1
				op += 1
				s = bin(n)[2:]
			i += 1
		print(op)
		print(*l)
main()


x = int(input())
y = x
x = list(bin(x)[2:])
l = len(x)
op = []
opc = 0
for i in range(1, l):
	if x[i] != x[i - 1]:
		op.append(l - i)
		opc += 1
opc = max((opc - 1) * 2 + 1, 0)
if y % 2 != 0 and opc > 0:
	opc += 1
print(opc)
if opc:
	print(' '.join(list(map(str, op))))


num = int(input())
ans = []
iters = 0
while num != 0:
	bin = []
	copy = num
	while copy != 0:
		bin.append(copy % 2)
		copy = copy // 2
	bin = bin[::-1]
	counter = 0
	for i in range(len(bin)):
		if bin[i]:
			counter += 1
		else:
			break
	ans.append(len(bin))
	num = 0
	for i in range(counter, len(bin)):
		if not bin[i]:
			num += 2 ** (len(bin) - i - 1)
	if 2 ** (len(bin) - counter) - 1 != num:
		num += 1
		iters += 2
	else:
		iters += 1
		break
print(iters)
print(' '.join((str(s) for s in ans)))


n = int(input())
l = len(bin(n)) - 3
count = 0
a = []
while 1:
	f = False
	for i in range(l, -1, -1):
		if not n >> i & 1:
			n = n ^ (1 << i + 1) - 1
			a.append(i + 1)
			count += 1
			end = True
			for i in range(l + 1):
				if n >> i & 1 == 0:
					n += 1
					count += 1
					end = False
					break
			if end:
				f = True
				break
	if not f:
		break
if not count:
	print(0)
else:
	print(count)
	for i in a:
		print(i)


def power(y):
	res = 0
	while y >= pow(2, res):
		res += 1
	return res
x = int(input())
cat = pow(2, power(x)) - 1
result = list()
count = 0
b = True
while x != cat:
	if b:
		n = power(cat - x)
		x = x ^ pow(2, n) - 1
		result.append(n)
	else:
		x += 1
	b = not b
	count += 1
print(count)
for i in result:
	print(i, end=' ')


x = int(input())

def highestPowerOf2(n):
	k = bin(n)
	return len(k) - k.index('1')
c = []
if x == 1:
	print(0)
	exit()
if x % 2 != 0:
	while x != 1:
		c.append(highestPowerOf2(x))
		x = x ^ pow(2, highestPowerOf2(x)) - 1
		x += 1
else:
	c.append(0)
	x += 1
	while x != 1:
		c.append(highestPowerOf2(x))
		x = x ^ pow(2, highestPowerOf2(x)) - 1
		x += 1
print(len(c) * 2)
print(*c)


x = int(input())
b = bin(x)[2:]
n = len(b)
rep = []
nb = 0
for i in range(n):
	if b[i] == '0':
		nb += 1
		rep.append(n - i)
		x = x ^ 2 ** (n - i) - 1
		b = bin(x)[2:]
		if x == 2 ** n - 1:
			break
		x += 1
		b = bin(x)[2:]
		nb += 1
print(nb)
print(*rep)


def check_num(n):
	s = bin(n)[2:]
	return len(s) == s.count('1')
x = int(input())
if check_num(x):
	print(0)
else:
	ops = 0
	nums = []
	while True:
		ops += 1
		length = len(bin(x)[2:])
		target = 2 ** length - 1
		nums.append(len(bin(target - x)[2:]))
		x = x ^ 2 ** len(bin(target - x)[2:]) - 1
		if check_num(x):
			print(ops)
			print(*nums)
			break
		ops += 1
		x += 1
		if check_num(x):
			print(ops)
			print(*nums)
			break
		if ops > 40:
			break


def check(num):
	if len(set(bin(num)[2:])) == 1 and bin(num)[-1] == '1':
		return 1
	return 0
x = input()
two = [2 ** i - 1 for i in range(21)]
b = bin(int(x))[2:]
ans = []
t = 0
num = int(b, 2)
if num in two:
	print(0)
else:
	for i in range(20, 0, -1):
		if num & 1 << i - 1 >= 1:
			continue
		ans.append(i)
		num = num ^ 2 ** i - 1
		t += 1
		if check(num):
			break
		num += 1
		t += 1
		if check(num):
			break
	print(t)
	print(*ans)


x = int(input())
a = []

def is_power2(num):
	return num != 0 and num & num - 1 == 0
ct = 0
while not is_power2(x + 1):
	if ct > 0:
		x += 1
	for i in range(32):
		if int(2 ** i) & x != 0:
			x ^= int(2 ** i - 1)
			a.append(i)
			break
	ct += 1
print(max(0, len(a) * 2 - 1))
for i in a:
	print(i, end=' ')
print()


import sys
import math
num = int(sys.stdin.readline().rstrip())
nl = math.floor(math.log(num, 2))
a = []
op = 0
while True:
	if num == 2 ** (nl + 1) - 1:
		break
	pw = math.floor(math.log(2 ** (nl + 1) - 1 - num, 2)) + 1
	op += 1
	num = num ^ 2 ** pw - 1
	a.append(pw)
	if num == 2 ** (nl + 1) - 1:
		break
	op += 1
	num += 1
if len(a) == 0:
	print(0)
else:
	print(op)
	print(' '.join([str(i) for i in a]))


n = int(input())
cnt = 0
res = []
while n & n + 1:
	if cnt % 2 == 0:
		b = bin(n)[2:]
		l = len(b)
		z = b.find('0')
		n ^= (1 << l - z) - 1
		res.append(l - z)
	else:
		n += 1
	cnt += 1
print(cnt)
if len(res) != 0:
	print(*res)


n = int(input())
print(39)
j = 19
import math
while j:
	j -= 1
	k = int(math.log(n, 2)) + 1
	n = n ^ int(2 ** k - 1)
	n += 1
	print(k, end=' ')
print(int(math.log(n, 2)) + 1)


from math import *

def main():
	n = int(input())
	i = 0
	l = []
	while n & n + 1 != 0:
		i += 1
		y = int(log2(n))
		l.append(y + 1)
		n ^= (1 << y + 1) - 1
		if n & n + 1 == 0:
			break
		i += 1
		n += 1
	print(i)
	print(*l)
main()


def check(n):
	n += 1
	n1 = n - 1
	if n == 0:
		return 0
	return n & n - 1 == 0
x = int(input())
i = 0
c = t = 0
ans = []
while i < 40:
	temp = 1
	t = 0
	if check(x):
		break
	while temp < x:
		temp *= 2
		t += 1
	temp -= 1
	x = x ^ temp
	c += 1
	ans.append(t)
	if check(x):
		break
	x += 1
	c += 1
	i += 1
print(c)
print(*ans)


x = int(input())

def binary(x):
	s = ''
	while x > 0:
		s = str(x % 2) + s
		x = x // 2
	return s

def decimal(s):
	x = 0
	for i in range(len(s)):
		x += int(s[i]) * 2 ** (len(s) - i - 1)
	return x

def complement(a):
	if a == 0:
		return 1
	else:
		return 0
if x == 0:
	print(0)
else:
	l = []
	c = 0
	s = binary(x)
	while '0' in s:
		if c % 2 == 0:
			l.append(len(s) - s.find('0'))
			a = s.find('1')
			if a == -1:
				d = len(s)
			else:
				d = a
			r = s[:s.find('0')]
			for i in range(s.find('0'), len(s)):
				r += str(complement(int(s[i])))
			s = r
		else:
			x = decimal(s) + 1
			s = binary(x)
		c += 1
	print(c)
	s1 = ''
	for j in range(len(l)):
		s1 += str(l[j]) + ' '
	print(s1)


def main():
	x = int(input())
	n = x.bit_length()
	t = 0
	ans = []
	while True:
		if x + 1 & x == 0:
			break
		if t & 1:
			x += 1
		else:
			for i in range(n - 1, -1, -1):
				if not 1 << i & x:
					ans.append(i + 1)
					x ^= (1 << i + 1) - 1
					break
		t += 1
	print(t)
	print(*ans)
	return 0
main()


n = int(input())
n = bin(n)
n = n[2:len(n)]
bound = len(n)
ans = []
req = ''
for i in range(bound):
	req += '1'
count = 0
while n != req:
	champ = '#'
	count += 1
	for i in range(bound):
		if n[i] != '1':
			champ = req[i:bound]
			break
	if champ != '#':
		temp = int(champ, 2) ^ int(n, 2)
		tempi = bin(temp)
		tempi = tempi[2:len(tempi)]
		ans.append(len(champ))
		if tempi == req:
			break
		temp += 1
		count += 1
		temp = bin(temp)
		n = temp[2:len(temp)]
print(count)
print(*ans)


n = int(input())
if n == 0:
	print(0)
	exit()
t = 0
arpos = []
while str(bin(n))[2:].count('0') != 0:
	pos = str(bin(n))[2:].find('0')
	n = int(n ^ 2 ** (len(str(bin(n))[2:]) - pos) - 1)
	t += 1
	arpos.append(len(str(bin(n))[2:]) - pos)
	if str(bin(n))[2:].count('0') != 0:
		n += 1
		t += 1
	else:
		break
print(t)
print(' '.join((str(i) for i in arpos)))


from sys import *
from math import *
from bisect import *
n = int(stdin.readline())
x = n.bit_length()
ans = []
f = 0
for i in range(x, 0, -1):
	y = bin(1 << i - 1)
	if 1 << i - 1 & n == 0:
		n = n ^ 2 ** i - 1
		k = bin(n)
		ans.append(i)
		if n == 2 ** x - 1:
			f = 1
			break
		n += 1
	if n == 2 ** x - 1:
		break
if f == 0:
	print(len(ans) * 2)
else:
	print(len(ans) * 2 - 1)
if len(ans) != 0:
	print(*ans)


x = int(input())
cnt = 0
lst = []
st = [(1 << i) - 1 for i in range(22)]
while True:
	if x in st:
		break
	cnt += 1
	for i in range(19, -1, -1):
		if x & 1 << i == 0:
			lst.append(i + 1)
			x ^= (1 << i + 1) - 1
			break
	if x in st:
		break
	else:
		x += 1
		cnt += 1
print(cnt)
s = ''
for i in lst:
	s += str(i) + ' '
print(s)


n = int(input())
d = list(map(int, bin(n)[2:]))
counter = 0
nums = []
for i in range(len(d)):
	if d[i] == 1:
		continue
	b = 0
	razr = len(d) - i
	nums.append(razr)
	counter += 1
	for j in range(i, len(d)):
		if d[j] == 1:
			d[j] = 0
			b = 1
		else:
			d[j] = 1
	if not b:
		if d[-1] == 1:
			break
		else:
			counter += 1
			break
	else:
		counter += 1
		for k in range(len(d) - 1, -1, -1):
			if d[k] == 0:
				d[k] = 1
				break
			else:
				d[k] = 0
print(counter)
for i in nums:
	print(i, end=' ')


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque

def data():
	return sys.stdin.readline().strip()

def mdata():
	return map(int, data().split())
x = int(data())
t = 0
l = []
ans = 0
while t <= 20:
	s = bin(x)[2:]
	for i in range(len(s)):
		if s[i] == '0':
			x = x ^ int(pow(2, len(s) - i) - 1)
			l += [len(s) - i]
			ans += 1
			break
	if bin(x)[2:].count('0') == 0:
		break
	elif bin(x + 1)[2:].count('0') == 0:
		ans += 1
		break
	ans += 1
	x += 1
	t += 1
print(ans)
print(*l)


gi = lambda : list(map(int, input().strip().split()))
(n,) = gi()
ans = []
err = 0
while n != 1:
	bit = len(bin(n)) - bin(n).index('1')
	n ^= (1 << bit) - 1
	ans.append(str(bit))
	if '0' not in bin(n)[2:]:
		err = 1
		break
	n += 1
print(len(ans) * 2 - err)
print(' '.join(ans))


x = int(input())
op = 0
ans = []
while '0' in bin(x)[2:]:
	if op % 2 == 0:
		can = int('1' * (len(bin(x)[2:]) - bin(x)[2:].index('0')), 2)
		x ^= can
		ans += [len(bin(can)) - 2]
	else:
		x += 1
	op += 1
print(op)
for a in ans:
	print(a, end=' ')


n = int(input())
ans = []
if n == 0:
	print('0')
else:
	cnt = 0
	for i in range(60):
		if i % 2 == 0:
			b = format(n, 'b')
			if '0' in b:
				pos = b.index('0')
			else:
				print(cnt)
				break
			n = int(b, 2) ^ 2 ** (len(b) - pos) - 1
			cnt += 1
			ans.append(len(b) - pos)
		else:
			b = format(n, 'b')
			if '0' not in b:
				print(cnt)
				break
			n += 1
			cnt += 1
print(' '.join(map(str, ans)))


def getNum(num_ones):
	ans.append(num_ones)
	num = ''
	for i in range(num_ones):
		num += '1'
	return num

def op1(x):
	num = getNum(len(x) - index)
	r = int(x, 2) ^ int(num, 2)
	return bin(r)[2:]

def op2(x):
	x = int(x, 2)
	x += 1
	return bin(x)[2:]
ans = []
x = int(input())
b_x = str(bin(x))[2:]
rounds = 0
flag = 0
while rounds < 41:
	index = b_x.find('0')
	if index == -1:
		print(rounds)
		flag = 1
		break
	b_x = op1(b_x)
	rounds += 1
	index = b_x.find('0')
	if index == -1:
		print(rounds)
		flag = 1
		break
	b_x = op2(b_x)
	rounds += 1
if flag == 1 and rounds != 0:
	for i in ans:
		print(i, end=' ')
	print()
elif flag == 0:
	print('0')


import math
n = int(input().lstrip())
res = 0
poss = []
while bin(n)[2:].find('0') != -1:
	twos = len(bin(n)) - 2
	first_zero = bin(n)[2:].find('0')
	pos = twos - first_zero
	n = n ^ 2 ** pos - 1
	res += 1
	poss.append(pos)
	if bin(n)[2:].find('0') != -1:
		n += 1
		res += 1
print(res)
if poss:
	print(' '.join(map(str, poss)))


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	max_so_far = -sys.maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0
	for i in range(0, size):
		max_ending_here += a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			start = s
			end = i
		if max_ending_here < 0:
			max_ending_here = 0
			s = i + 1
	return (max_so_far, start, end)

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] >= arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def solve():
	n = int(input())
	ans = []
	x = math.ceil(math.log(n, 2))
	num = 2 ** x - 1
	while n != num:
		n = n ^ num
		ans.append(x)
		x = math.ceil(math.log(n, 2))
		num = 2 ** x - 1
		if n == num:
			break
		n += 1
		ans.append(n)
		x = math.ceil(math.log(n, 2))
		num = 2 ** x - 1
	print(len(ans))
	for i in range(0, len(ans), 2):
		print(ans[i], end=' ')
t = 1
for _ in range(t):
	solve()


pots = [1]
for i in range(41):
	pots.append(pots[len(pots) - 1] * 2)
for i in range(41):
	pots[i] -= 1
n = int(input())
x = []
flag = False
op = 0
while n not in pots:
	flag = True
	b = bin(n)[2:]
	k = len(b) - b.index('0')
	x.append(k)
	n = n ^ pots[k]
	op += 1
	if n in pots:
		break
	else:
		n += 1
		op += 1
if flag:
	print(op)
	print(' '.join([str(i) for i in x]))
else:
	print(0)


from bisect import bisect_left
ans = [0] * 21
for i in range(1, 21):
	ans[i] = 2 ** i - 1
x = int(input())
c = 0
a = list()
if x in ans:
	print(0)
else:
	while x not in ans:
		a.append(bisect_left(ans, x))
		x = x ^ ans[bisect_left(ans, x)]
		c += 1
		if x in ans:
			break
		c += 1
		x += 1
	print(c)
	print(' '.join(map(str, a)))


def check(num: int) -> bool:
	if num == 0:
		return True
	num += 1
	t = 1
	while num > t:
		t *= 2
	if num == t:
		return True
	else:
		return False
x = int(input())
count = 0
nlist = []
if check(x):
	print(0)
else:
	while True:
		tcat = 1
		n = 0
		while x > tcat:
			tcat *= 2
			n += 1
		tcat -= 1
		nlist.append(n)
		x = x ^ tcat
		count += 1
		if check(x):
			print(count)
			print(*nlist)
			break
		x += 1
		count += 1
		if check(x):
			print(count)
			print(*nlist)
			break


n = int(input())
a = []
for i in range(31):
	a.append(2 ** i - 1)
t = n
ans = 0
blah = []
c = 0
w = 0
while 1:
	b = list(bin(t))
	b = b[2:]
	for i in range(31):
		if a[i] == t:
			w = 1
			break
	if w == 1:
		break
	if '0' in b:
		z = b.index('0')
		t = t ^ a[len(b) - z]
		blah.append(len(b) - z)
		ans += 1
		for i in range(31):
			if a[i] == t:
				w = 1
				break
		if w == 1:
			break
		ans += 1
		t += 1
	else:
		break
print(ans)
for i in blah:
	print(i, end=' ')


x = int(input())

def get(x):
	n = x
	if not n & n + 1:
		return n
	(pos, temp, count) = (0, n, 0)
	while temp:
		if not temp & 1:
			pos = count
		count += 1
		temp >>= 1
	return pos + 1
out = []
cnt = 0
for i in range(1, 41):
	if x + 1 & x == 0:
		break
	b = get(x)
	if i % 2 == 0:
		x += 1
		cnt += 1
	else:
		x = x ^ (1 << b) - 1
		out.append(str(b))
		cnt += 1
print(cnt)
if len(out) != 0:
	print(' '.join(out))


n = int(input())
cnt = 0
arr = []
while n & n + 1 != 0:
	if cnt % 2 == 0:
		temp = n
		tcnt = 0
		while temp & temp + 1 != 0:
			temp = temp >> 1
			tcnt += 1
		xorWith = 1 << tcnt
		xorWith -= 1
		n = n ^ xorWith
		arr.append(tcnt)
	else:
		n += 1
	cnt += 1
print(cnt)
print(*arr)


x = int(input())
b = bin(x)[2:]
c = 0
r = []
for i in range(1, 41):
	if i % 2 == 1:
		l = len(b)
		d = b.find('0')
		if d == -1:
			break
		c += 1
		r.append(l - d)
		x ^= int('1' * (l - d), 2)
		b = bin(x)[2:]
	else:
		if '0' not in b:
			break
		c += 1
		x += 1
		b = bin(x)[2:]
print(c)
if c > 0:
	print(*r)


n = int(input())
b = f'{n:b}'
a = 0
r = []
while 1:
	if b.count('0'):
		g = b.index('0')
		a += 1
		v = (1 << len(b) - g) - 1
		n ^= v
		r.append(len(b) - g)
		b = f'{n:b}'
	else:
		break
	if b.count('0'):
		a += 1
		n += 1
		b = f'{n:b}'
	else:
		break
print(a)
print(*r)


x = int(input())
answer = 0
ans_array = []
T = 0
while x != 2 ** x.bit_length() - 1:
	if T % 2 == 0:
		ans_array.append(x.bit_length())
		x ^= 2 ** x.bit_length() - 1
	else:
		x += 1
	T += 1
print(T)
print(*ans_array)


n = int(input())
s = bin(n)[2:]
s = list(s)
s = [int(x) for x in s]
ans = []

def plus1(s):
	j = len(s) - 1
	while j >= 0 and s[j] == 1:
		s[j] = 0
		j -= 1
	if j < 0:
		return True
	if j >= 0:
		s[j] = 1
	return False
while len(s) > 0:
	while len(s) > 0 and s[0] == 1:
		s = s[1:]
	if len(s) == 0:
		ans.append(None)
		break
	else:
		s = [1 - x for x in s]
		ans.append(None)
		ans.append(len(s))
	if plus1(s):
		break
print(len(ans) - 1)
print(' '.join([str(x) for x in ans if x]))


n = int(input())
res = []
while not all((i == '1' for i in bin(n)[2:])):
	tmp = bin(n)[2:]
	for j in range(len(tmp)):
		if tmp[j] == '0':
			break
		else:
			continue
	n ^= 2 ** (len(tmp) - j) - 1
	res.append(len(tmp) - j)
	if all((i == '1' for i in bin(n)[2:])):
		break
	else:
		n += 1
		res.append(-1)
		if all((i == '1' for i in bin(n)[2:])):
			break
print(len(res))
if len(res) != 0:
	tmpp = ''
	for i in res:
		if i != -1:
			tmpp += str(i) + ' '
	print(tmpp[:-1])


def xor(i):
	global b, a, c
	c += 1
	b.append(len(a) - i)
	for j in range(i, len(a)):
		if a[j] == '0':
			a[j] = '1'
		else:
			a[j] = '0'

def inr(i):
	global b, a, c
	c += 1
	for j in range(len(a) - 1, i - 1, -1):
		if a[j] == '1':
			a[j] = '0'
		else:
			a[j] = '1'
			break
n = int(input())
c = 0
a = list(bin(n))[2:]
b = []
i = 0
while i != len(a):
	while i < len(a) and a[i] == '1':
		i += 1
	if i == len(a):
		break
	xor(i)
	while i < len(a) and a[i] == '1':
		i += 1
	if i == len(a):
		break
	inr(i)
print(c)
print(*b)


n = int(input())

def p2(n):
	return n != 0 and n - 1 & n == 0
c = 0
cc = 0
nums = []
tt = n
while not p2(n + 1):
	if c == 0:
		n = n ^ 2 ** n.bit_length() - 1
		nums += [n.bit_length()]
	else:
		n += 1
	c = (c + 1) % 2
	cc += 1
print(cc)
print(*nums)


n = int(input())
a = []
i = 30
if not n & 1:
	a.append(0)
	n ^= 1
while 2 ** i > n:
	i -= 1
while i > 1:
	if not n & 2 ** (i - 1):
		a.append(i)
		n ^= 2 ** i - 1
		n += 1
	i -= 1
print(2 * len(a))
for num in a:
	print(str(num), end=' ')


import sys
from sys import setrecursionlimit
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 1000000007
mini = 1000000007
setrecursionlimit(10 ** 5)

def max_subarray(array):
	max_so_far = max_ending_here = array[0]
	start_index = 0
	end_index = 0
	for i in range(1, len(array) - 1):
		temp_start_index = temp_end_index = None
		if array[i] > max_ending_here + array[i]:
			temp_start_index = temp_end_index = i
			max_ending_here = array[i]
		else:
			temp_end_index = i
			max_ending_here = max_ending_here + array[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			if temp_start_index != None:
				start_index = temp_start_index
			end_index = i
	print(max_so_far, start_index, end_index)

def ncr(n, r):
	d = 10 ** 9 + 7
	num = fact(n)
	den = fact(r) * fact(n - r) % d
	den = pow(den, d - 2, d)
	return num * den % d

def sieve(n):
	prime = [True for i in range(n + 1)]
	lst = []
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p = p + 1
	for i in range(2, n + 1):
		if prime[i]:
			lst.append(i)
	return lst

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def calculate_factors(n):
	hh = [1] * (n + 1)
	p = 2
	while p * p < n:
		if hh[p] == 1:
			for i in range(p * 2, n, p):
				hh[i] = 0
		p += 1
	total = 1
	for p in range(2, n + 1):
		if hh[p] == 1:
			count = 0
			if n % p == 0:
				while n % p == 0:
					n = int(n / p)
					count += 1
				total *= count + 1
	return total

def prime_factors(n):
	i = 2
	factors = set()
	while i * i <= n:
		if n % i:
			i += 1
		else:
			factors.add(n // i)
			n = n // i
			factors.add(i)
	if n > 1:
		factors.add(n)
	return factors

def isPrime(n):
	if n == 2 or n == 3:
		return True
	if n % 2 == 0 or n < 2:
		return False
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True

def solve(n):
	if n == 1:
		return 1
	p = 2
	result = []
	while p * p <= n:
		if n % p == 0:
			result.append(p)
			result.append(n // p)
		p = p + 1
	return result

def atMostSum(arr, n, k):
	_sum = 0
	cnt = 0
	maxcnt = 0
	for i in range(n):
		if _sum + arr[i] <= k:
			_sum += arr[i]
			cnt += 1
		elif sum != 0:
			_sum = _sum - arr[i - cnt] + arr[i]
		maxcnt = max(cnt, maxcnt)
	return maxcnt

def leftmost_zero(n):
	length = len(n)
	for i in range(length):
		if n[i] == '0':
			return length - i
	return 0

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
n = bin(n)[2:]
count = 0
result = []
while True:
	z = leftmost_zero(n)
	if z == 0:
		break
	else:
		result.append(z)
		n = bin(int(n, 2) ^ 2 ** z - 1)[2:]
		count += 1
		if leftmost_zero(n) != 0:
			count += 1
			n = bin(int(n, 2) + 1)[2:]
		else:
			break
if count == 0:
	print(0)
else:
	print(count)
	print(*result, sep=' ')


x = int(input())
prop = {2 ** i - 1 for i in range(1, 40)}
ans = 0
Ans = []
while x not in prop:
	j = x.bit_length()
	ans += 1
	Ans.append(j)
	x ^= (1 << j) - 1
	if x in prop:
		break
	x += 1
	ans += 1
print(ans)
if ans:
	print(*Ans)


k = 0
x = int(input())
b = str(bin(x))[2:]
n = len(b)
mas = []
while '0' in b:
	k += 2
	g = n - b.index('0')
	b = str(bin(int(b, 2) ^ int('1' * g, 2)))[2:]
	if '0' in b:
		b = str(bin(int(b, 2) + 1))[2:]
	else:
		k -= 1
	mas.append(g)
print(k)
print(*mas)


def allbits(x):
	cnt = 0
	while x > 0:
		if x & 1 == 0:
			return False
		x = x >> 1
	return True
x = int(input())
t = x
msb = 0
while t > 0:
	msb += 1
	t = int(t / 2)
msb -= 1
ans = []
no = 0
while True:
	first = 0
	go = 0
	while first <= msb and x >> msb - first & 1 == 1:
		first += 1
	if first <= msb:
		ans.append(msb - first)
		x = x ^ pow(2, msb - first + 1) - 1
		no += 1
		if allbits(x) == True:
			break
		else:
			x += 1
			no += 1
			if allbits(x) == True:
				break
	else:
		break
print(no)
for i in ans:
	print(i + 1, end=' ')


x = int(input())

def leftmost_zero(x, n):
	ans = -1
	for i in range(n):
		if x % 2 == 0:
			ans = i
		x = x >> 1
	return ans
ops = []
while True:
	b = leftmost_zero(x, 20)
	if b < 0:
		break
	if x & (1 << b + 1) - 1 == 0:
		ops.append(0)
	else:
		x = x ^ (1 << b + 1) - 1
		ops.append(b + 1)
	x += 1
print(2 * len(ops))
print(' '.join(map(str, ops)))


n = int(input())
b = bin(n)[2:]
lis = []
cnt = 0
while bin(n)[2:].count('0') != 0:
	x = bin(n)[2:]
	y = x.index('0')
	n = n ^ 2 ** (len(x) - y) - 1
	lis.append(len(x) - y)
	cnt += 1
	if bin(n)[2:].count('0') == 0:
		break
	n += 1
	cnt += 1
print(cnt)
if len(lis):
	print(*lis)


x = int(input())
ans = []
t = 0
while x != 2 ** x.bit_length() - 1:
	if t % 2:
		x += 1
	else:
		xb = x.bit_length()
		ans.append(xb)
		x ^= 2 ** xb - 1
	t += 1
print(t)
print(*ans)


n = int(input())
a = '{0:b}'.format(n)
b = []
c = []
bin = True
for i in range(len(a)):
	c += [a[i]]
	if a[i] == '0':
		bin = False
a = c
x = 0
while not bin:
	done = False
	bin = True
	for i in range(len(a)):
		if done:
			if a[i] == '1':
				a[i] = '0'
				bin = False
			else:
				a[i] = '1'
		elif a[i] == '0':
			b += [len(a) - i]
			done = True
			a[i] = '1'
		elif a[i] == '0':
			bin = False
	x += 1
	if bin:
		break
	done = False
	bin = True
	for i in range(len(a) - 1, -1, -1):
		if done:
			if not bin:
				break
			if a[i] == '0':
				bin = False
				break
		elif a[i] == '1':
			a[i] = '0'
			bin = False
		else:
			a[i] = '1'
			done = True
	x += 1
print(x)
for i in range(len(b)):
	print(b[i], end=' ')


x = int(input())
potencias = set()
p2 = []
for i in range(31):
	potencias.add(2 ** i - 1)
	p2.append(2 ** i)
powers = []
ans = 0
if x in potencias:
	print(0)
	exit()
for i in range(1, 41):
	if x in potencias:
		ans = i
		break
	if i % 2 == 1:
		found = False
		xx = x
		index = -1
		for j in range(30, -1, -1):
			if p2[j] > xx and (not found):
				continue
			elif p2[j] > xx and found:
				index = j
				break
			else:
				xx -= p2[j]
				found = True
		x = x ^ 2 ** (index + 1) - 1
		powers.append(index + 1)
	else:
		x += 1
print(ans - 1)
if ans > 0:
	s = ''
	for i in powers:
		s += str(i) + ' '
	print(s)


n = int(input())
moves = []
if n % 2 == 0:
	n += 1
	moves.append(0)
cnt = 0
while cnt <= 40:
	x = bin(n)[2:]
	if x.count('0') == 0:
		break
	ans = 0
	for i in range(len(x)):
		if x[i] == '0':
			ans = len(x) - i
			break
	n = n ^ (1 << ans) - 1
	n += 1
	moves.append(ans)
	cnt += 1
print(len(moves) * 2)
for i in moves:
	print(i, end=' ')
print()


import math

def main():
	x = int(input())
	j = 20
	print(39)
	while j:
		k = int(math.log2(x)) + 1
		x = x ^ 2 ** k - 1
		x = x + 1
		print(k, end=' ')
		j = j - 1
main()


x = int(input())
r = []
i = 0
while True:
	t = '{0:b}'.format(x)
	if '0' not in t:
		break
	if i % 2 == 0:
		p = len(t) - t.find('0')
		r.append(p)
		x = x ^ 2 ** p - 1
	else:
		x += 1
	i += 1
print(i)
print(*r)


x = [2 ** k - 1 for k in range(1, 22)]
n = int(input())
rr = 1 - (n & 1)
r = []
while n not in x:
	(i, k) = (1, 1)
	while n > k:
		if not n & k:
			ii = i
		i += 1
		k <<= 1
	r.append(ii)
	n ^= 2 ** ii - 1
	if n not in x:
		n += 1
print(2 * len(r) - rr)
print(*r)


n = int(input())
s = ''
te = n
while te > 0:
	s += str(te % 2)
	te = te // 2
s = s[::-1]
ans = []
te = n
nn = len(s)
an = 0
te = n
while 1:
	kk = 0
	nn = len(s)
	for i in range(nn):
		if s[i] == '1':
			pass
		else:
			ans.append(nn - i)
			te = te ^ (1 << nn - i) - 1
			an += 1
			break
	s = ''
	tee = te
	while tee > 0:
		s = str(tee % 2) + s
		tee = tee // 2
	nn = len(s)
	for i in range(nn):
		if s[i] == '1':
			kk += 1
	if kk == nn:
		break
	te += 1
	an += 1
	tee = te
	s = ''
	while tee > 0:
		s = str(tee % 2) + s
		tee = tee // 2
print(an)
if len(ans) > 0:
	print(*ans)


X = int(input())
cnt = 0
ans = []
length = len(bin(X)[2:])
bi = bin(X)[2:]
for i in range(length):
	bit = bi[i]
	if bit == '1':
		continue
	else:
		ans.append(length - i)
		cnt += 1
		X = X ^ 2 ** (length - i) - 1
		bi = bin(X)[2:]
		f = True
		for b in bi:
			if b == '0':
				f = False
		if f:
			break
		cnt += 1
		X += 1
		bi = bin(X)[2:]
print(cnt)
for a in ans:
	print(a, end=' ')
print()


x = int(input())
xb = bin(x)
i = 0
a = []
while str(bin(x)).find('0', 1) >= 0:
	if i % 2 == 0:
		p = str(bin(x)).find('0', 1)
		step = len(str(bin(x))) - p
		n = 2 ** step - 1
		x = x ^ n
		a.append(step)
	else:
		x = x + 1
	i += 1
print(i)
for i in a:
	print(i, end=' ')


import math
n = int(input())
if n & n + 1 == 0:
	print(0)
	exit()
ans = 0
ok = []
while n & n + 1 != 0:
	k = n & -n
	ok.append(int(math.log(k, 2)))
	n = n ^ k - 1
	ans += 1
	if n & n + 1 == 0:
		break
	n += 1
	ans += 1
print(ans)
print(' '.join(list(map(str, ok))))


seti = set()
ans = []
for i in range(40):
	seti.add(2 ** i)
n = int(input())
i = 1
while i < 41:
	if n + 1 in seti:
		break
	if i % 2 != 0:
		k = bin(n)[2:]
		count = 0
		for j in k:
			if j == '0':
				break
			else:
				count += 1
		s = '1' * (len(k) - count)
		ans.append(len(s))
		n = int(s, 2) ^ n
	else:
		n += 1
	i += 1
print(i - 1)
print(*ans)


from sys import stdin
from math import *
x = int(stdin.readline())
if pow(2, int(log(x + 1, 2))) == x + 1:
	print(0)
else:
	ch = bin(x)[2:]
	if x % 2 == 0:
		ans = [0]
		x += 1
	else:
		ans = []
	while ('0' in ch) == True:
		for i in range(len(ch)):
			if ch[i] == '1':
				ans.append(len(ch) - i)
				break
		x ^= int(pow(2, len(ch) - i) - 1)
		x += 1
		ch = bin(x)[2:]
	print(len(ans) * 2)
	for i in range(len(ans)):
		print(ans[i], end=' ')


import math
n = int(input())
target = 2 ** math.ceil(math.log2(n + 1)) - 1
ans = []
j = 1
while n != target:
	if j % 2 == 1:
		b = bin(n)[2:]
		i = 0
		while b[i] == '1':
			i += 1
		k = len(b) - i
		ans.append(k)
		n = n ^ 2 ** k - 1
	else:
		n += 1
	j += 1
print(j - 1)
print(*ans)


import math
l = []
for i in range(40):
	l.append(2 ** i - 1)
x = int(input())
if x in l:
	print(0)
else:
	ans = []
	count = 0
	while True:
		bits = len(bin(x)[2:])
		xorval = 2 ** bits - 1
		x = x ^ xorval
		count += 1
		ans.append(bits)
		if x in l:
			break
		x += 1
		count += 1
	print(count)
	print(*ans)


x = int(input())
times = 0
sol = []
preBreak = False
while bin(x)[2:].count('0') != 0:
	b = bin(x)[2:]
	l = len(b)
	current = l - b.index('0')
	sol.append(current)
	x = x ^ 2 ** current - 1
	if bin(x)[2:].count('0') == 0:
		preBreak = True
		break
	x += 1
print(len(sol) * 2 - (1 if preBreak else 0))
if sol:
	print(' '.join((str(x) for x in sol)))


n = int(input())
cnt = 0
res = []
while n & n + 1 and cnt < 40:
	if cnt % 2 == 0:
		b = bin(n)
		l = len(b) - 2
		i = bin(n)[2:].index('0')
		res.append(l - i)
		n ^= (1 << l - i) - 1
	else:
		n += 1
	cnt += 1
print(cnt)
if len(res) != 0:
	print(*res)


x = int(input())
b = bin(x)[2:]
if b.count('0') == 0:
	print(0)
else:
	steps = 0
	flag = 0
	n = []
	while True:
		b = bin(x)[2:]
		l = len(b)
		if b.count('0') == 0:
			print(steps)
			for i in n:
				print(i, end=' ')
			break
		if flag == 0:
			for i in range(l):
				if b[i] == '0':
					x = x ^ 2 ** (l - i) - 1
					n.append(l - i)
					steps += 1
					flag = 1
					break
		elif flag == 1:
			x = x + 1
			steps += 1
			flag = 0


i = int(input())

def getZ(n):
	s = '{0:0b}'.format(n)
	return len(s) - s.find('0')

def check(n):
	return '{0:0b}'.format(n).find('0') == -1
steps = 0
ans = []
while not check(i):
	m = getZ(i)
	i = i ^ 2 ** m - 1
	steps += 1
	ans.append(m)
	if check(i):
		print(steps)
		print(' '.join(map(str, ans)))
		exit(0)
	i += 1
	steps += 1
print(steps)
print(' '.join(map(str, ans)))
exit(0)


n = int(input())

def cbt(n):
	b = bin(n)[2:]
	c = 0
	t = 1
	l = []
	while b.count('1') != len(b):
		t ^= 1
		if not t:
			x = int('1' * len(b), 2)
			y = int('0b' + b, 2)
			l.append(len(b))
			b = x ^ y
			b = bin(b)[2:]
		else:
			x = int('0b' + b, 2)
			x += 1
			b = bin(x)[2:]
		c += 1
	return (c, l)
(c, l) = cbt(n)
print(c)
print(*l) if l else None


from math import log
n = int(input())
ans = []
c = 0
while c < 40:
	if log(n + 1, 2) == int(log(n + 1, 2)):
		break
	binary = bin(n)
	binary = binary[2:]
	l = len(binary)
	for i in range(l):
		if binary[i] == '1':
			break
	n = n ^ pow(2, l - i) - 1
	c = c + 1
	ans.append(l - i)
	if log(n + 1, 2) == int(log(n + 1, 2)):
		break
	else:
		n = n + 1
		c = c + 1
	if log(n + 1, 2) == int(log(n + 1, 2)):
		break
print(c)
print(*ans)


n = int(input())
a = str(bin(n))[2:]
num = a[-1]
an = 0
now = '1'
anp = []
for (idx, i) in enumerate(a):
	if i != now:
		an += 1
		anp.append(len(a) - idx)
		now = i
print(an * 2 - 1 + int(num))
if anp:
	print(' '.join(map(str, anp)))


import sys
x = int(input())
anz = 0
op = []
while True:
	s = bin(x)[2:]
	if not '0' in s:
		break
	anz += 1
	i = len(s) - s.index('0')
	op.append(i)
	x ^= 2 ** i - 1
	if not '0' in bin(x)[2:]:
		break
	anz += 1
	x += 1
print(anz)
if anz:
	print(' '.join((str(o) for o in op)))


import math

def nextPowerOf2(n):
	p = 1
	if n and (not n & n - 1):
		return n
	while p < n:
		p <<= 1
	return p
x = int(input())
n = math.floor(math.log2(x))
t = 0
l = []
if x + 1 and (not x + 1 & x):
	print(0)
	exit()
while True:
	t += 1
	if t % 2 == 1:
		x = x ^ pow(2, n) - 1
	else:
		x += 1
	if t % 2 == 1:
		l.append(n)
	if x + 1 and (not x + 1 & x):
		break
	if t % 2 == 0:
		y = nextPowerOf2(x)
		z = y - x
		n = math.ceil(math.log2(z))
print(t)
print(*l)


def solution2(x):

	def find_zero(num):
		x_s = str(bin(num))[2:]
		for (index, el) in enumerate(x_s):
			if el == '0':
				return index
		return -1
	operations = list()
	num_ops = 0
	for i in range(40):
		zero_in = find_zero(x)
		if zero_in == -1:
			return (num_ops, operations)
		degree = len(str(bin(x))[2:]) - zero_in
		number = pow(2, degree) - 1
		x = x ^ number
		num_ops += 1
		operations.append(degree)
		if find_zero(x) == -1:
			return (num_ops, operations)
		x += 1
		num_ops += 1
x1 = int(input())
(num1, li) = solution2(x1)
print(num1)
if num1 != 0:
	print(' '.join([str(el) for el in li]))


from math import *

def test(x):
	if x == (1 << int(log2(x)) + 1) - 1:
		return False
	return True
x = int(input())
cnt = 0
ch = True
n = []
while test(x):
	cnt += 1
	if ch:
		nn = int(log2(x)) + 1
		x ^= (1 << nn) - 1
		n.append(nn)
		ch = False
	else:
		x += 1
		ch = True
print(cnt)
for k in n:
	print(k, end=' ')
if cnt:
	print()


x = int(input())
x = format(x, 'b')
x = list(x)
ans = 0
anslist = []
for i in range(len(x)):
	if x[i] == '1':
		continue
	else:
		ans += 1
		anslist.append(len(x) - i)
		for j in range(i, len(x)):
			if x[j] == '1':
				x[j] = '0'
			else:
				x[j] = '1'
	if x.count('1') == len(x):
		break
	else:
		ans += 1
		x = ''.join(x)
		x = int(x, 2)
		x += 1
		x = format(x, 'b')
		x = list(x)
print(ans)
if len(anslist) != 0:
	print(' '.join(map(str, anslist)))


def binary(num):
	sr = ''
	while num // 2 > 0:
		if num % 2 == 0:
			sr = '0' + sr
		else:
			sr = '1' + sr
		num = num // 2
	sr = '1' + sr
	return sr

def decimal(sring):
	n = int(input())
	for i in range(len(sring)):
		n += int(sring[len(sring) - 1 - i]) * pow(2, i)
	return n
n = int(input())
s = binary(n)
ar = list(s)
(total, c) = (0, 0)
arr = []
while total < 40:
	if ar.count('0') == 0:
		break
	if total % 2 == 0:
		i = ar.index('0')
		arr.append(len(s) - i)
		for j in range(i, len(s)):
			if ar[j] == '0':
				ar[j] = '1'
			else:
				ar[j] = '0'
		c += 1
	else:
		for j in range(len(s) - 1, -1, -1):
			if ar[j] == '0':
				ar[j] = '1'
				break
			else:
				ar[j] = '0'
		c += 1
	total += 1
print(c)
for el in arr:
	print(el, end=' ')


import math
x = int(input())
steps = 0
n = []
while steps != 20:
	ni = int(math.log2(x) + 1)
	n.append(ni)
	x ^= 2 ** ni - 1
	steps += 1
	x += 1
print(39)
for i in range(20):
	print(n[i], end=' ')


first = int(input())
x = bin(first)[2:]
mul = x.replace('0', '1')
top = int(mul, 2)
nub = 0
sta = []
while first != top:
	a = bin(first)[2:]
	zero = 0
	b = len(a)
	for i in range(len(a)):
		if a[i] == '0' and b != len(a):
			sta.append(b)
			break
		b -= 1
	ans = '1' * b
	x = int(ans, 2)
	ans = int(first ^ x)
	nub += 1
	if ans != top:
		ans += 1
		nub += 1
	first = ans
print(nub)
print(' '.join(map(str, sta)))


def solve(x):
	ret = []
	for i in range(40):
		if bin(x)[2:].count('0') == 0:
			print(i)
			print(*ret)
			return
		if i & 1 == 0:
			binX = bin(x)[2:]
			p = len(binX) - binX.index('0')
			x ^= (1 << p) - 1
			ret.append(p)
		else:
			x += 1
solve(int(input()))


x = int(input())
a = []
c = 0
if x == 1:
	print(0)
	exit()
while True:
	l = len(bin(x)[2:])
	y = 2 ** l - 1
	x ^= y
	a.append(l)
	c += 1
	s = bin(x)[2:]
	if len(s) == s.count('1'):
		break
	c += 1
	x += 1
	s = bin(x)[2:]
	if len(s) == s.count('1'):
		break
print(c)
print(' '.join((str(i) for i in a)))


from sys import stdin, stdout
import math

def solve(n):
	ansarr = []
	x = 0
	while True:
		if n & n - 1 == 0:
			if n == 1:
				break
			else:
				t1 = int(math.log(n, 2))
				ansarr.append(str(t1))
				x = -1
				break
		t1 = int(math.log(n, 2))
		ansarr.append(str(t1 + 1))
		n = n ^ (1 << t1 + 1) - 1
		n = n + 1
	stdout.write(str(len(ansarr) * 2 + x) + '\n')
	stdout.write(' '.join(ansarr) + '\n')
n = int(stdin.readline().strip())
solve(n)


from __future__ import print_function
import math
import collections
x = input()
x = int(x)

def count(num):
	(ans, last, pos) = (0, 0, 0)
	while num:
		pos += 1
		if num % 2 == 0:
			ans += 1
			last = pos
		num //= 2
	return (ans, last)
cnt = 0
table = []
while True:
	(zero_num, pos) = count(x)
	if zero_num:
		cnt += 1
		table.append(pos)
		x ^= 2 ** pos - 1
	else:
		break
	(zero_num, _) = count(x)
	if zero_num:
		cnt += 1
		x += 1
	else:
		break
print(cnt)
for pos in table:
	print(pos)


x = int(input())
toggle = True
ops = 0
odd = []
while '0' in bin(x)[2:]:
	d = bin(x)[2:]
	if toggle:
		i = d.find('0')
		integer = int('1' * (len(d) - i), 2)
		odd.append(len(d) - i)
		x = x ^ integer
	else:
		x += 1
	toggle = not toggle
	ops += 1
print(ops)
print(' '.join(map(str, odd)))


def f(s):
	k = -1
	s = s[::-1]
	for i in range(len(s)):
		if s[i] == '0':
			k = i
	return k
t = True
k = []
n = int(input())
s = bin(n)[2:]
n1 = len(s)
while f(s) != -1:
	r = f(s)
	e = '0b' + '1' * (r + 1)
	h = r + 1
	e = int(e, 2)
	k.append(h)
	n ^= e
	if f(bin(n)[2:]) == -1:
		t = False
		break
	n += 1
	s = bin(n)[2:]
if t:
	a = 2 * len(k)
else:
	a = 2 * len(k) - 1
print(a)
print(*k)


n = int(input())
ans = []
q = 0
if not n % 2:
	n ^= 0
	n += 1
	ans.append(0)
	q += 2
f = str(bin(n))[2:]
l = len(f)
x = f.find('0')
while x != -1:
	pos = l - x
	n ^= 2 ** pos - 1
	n += 1
	f = str(bin(n))[2:]
	q += 2
	ans.append(pos)
	x = f.find('0')
print(q)
if q:
	print(*ans)


x = int(input())
array = []
count = 0
while True:
	f = bin(x)[3:]
	if '0' not in f:
		break
	ind = f.index('0')
	n = pow(2, len(f) - ind) - 1
	x = x ^ n
	array.append(len(f) - ind)
	count += 1
	if '0' not in bin(x)[3:]:
		break
	x += 1
	count += 1
print(count)
print(*array)


x = int(input())
O = []
nop = 0

def opA(x, n):
	nonlocal nop
	nop += 1
	O.append(n)
	r = x ^ (1 << n) - 1
	return r

def opB(x):
	nonlocal nop
	nop += 1
	return x + 1

def islc(x):
	b = '{:b}'.format(x)
	return b.count('0') == 0
for i in range(20):
	b = '{:b}'.format(x)
	n = len(b)
	o = n - b.find('0')
	x = opA(x, o)
	if islc(x):
		break
	x = opB(x)
	if islc(x):
		break
print(nop)
print(*O)


n = int(input())
bits = bin(n)[2:]
enes = []
pasos = 0
while True:
	cero = -1
	for i in range(len(bits)):
		if bits[i] == '0':
			cero = len(bits) - i
			break
	if cero == -1:
		print(pasos)
		break
	num = int(bits, 2)
	num ^= 2 ** cero - 1
	enes.append(cero)
	pasos += 1
	cero = -1
	bits = bin(num)[2:]
	for i in range(len(bits)):
		if bits[i] == '0':
			cero = len(bits) - i
			break
	if cero == -1:
		print(pasos)
		break
	num = int(bits, 2)
	num += 1
	pasos += 1
	bits = bin(num)[2:]
s = ''
for i in enes:
	s += str(i)
	s += ' '
print(s)


x = int(input())
t = 0
sol = []
for i in range(40):
	b = bin(x)[:1:-1]
	if b.count('0') == 0:
		break
	n = b.index('1')
	sol.append(n)
	x = x ^ 2 ** n - 1
	t += 1
	b = bin(x)[:1:-1]
	if b.count('0') == 0:
		break
	x = x + 1
	t += 1
print(t)
print(' '.join(map(str, sol)))


from math import log
x = int(input())
if x < 1 or x == 1 or x & x + 1 == 0:
	print(0)
elif x & x - 1 == 0:
	print(1)
	print(int(log(x, 2)))
else:
	count = 0
	a = []
	while x & x + 1 != 0 and count < 40:
		d = int(log(x, 2))
		p = 2 ** (d + 1) - 1
		a.append(d + 1)
		x = x ^ p
		count += 1
		if x & x + 1 == 0:
			break
		x += 1
		count += 1
	print(count)
	for i in range(len(a)):
		print(a[i], end=' ')


import sys
n = int(input())
binary = []
ans = []
count = 0
steps = 0
while n:
	binary.append(n % 2)
	n = n // 2
binary.reverse()
l = len(binary)
while binary.count(1) != l:
	if count == 0:
		for i in range(len(binary)):
			if binary[i] == 0:
				num = l - i
				ans.append(num)
				j = i
				while j < l:
					binary[j] = (binary[j] + 1) % 2
					j += 1
				break
	else:
		j = l - 1
		while j >= 0:
			if binary[j] == 0:
				binary[j] = 1
				break
			else:
				binary[j] = 0
			j -= 1
	count = (count + 1) % 2
	steps += 1
print(steps)
if steps:
	print(*ans)


import sys
import math
import collections
import heapq
input = sys.stdin.readline
x = int(input())
l = []
c = 0
for i in range(20):
	k = int(math.log(x, 2) + 1)
	l.append(k)
	x ^= pow(2, k) - 1
	x += 1
print(39)
print(*l)


import sys
try:
	import frosch
	frosch.hook()
except ImportError:
	pass
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def is_pow2(x):
	while x & 1 == 0:
		x >>= 1
	return x == 1

def solve():
	x = ini()
	a = []
	while True:
		s = bin(x)[2:]
		i = s.find('0')
		if i < 0:
			return a
		suffix = s[i:]
		if suffix == '0' * len(suffix):
			d = len(s) - i - 1
		else:
			d = len(s) - i
		x ^= 2 ** d - 1
		x += 1
		a.append(d)
a = solve()
print(len(a) * 2)
print(*a)


s = list(bin(int(input())))
turn = 0
ans = []
while '0' in s[2:]:
	if turn % 2 == 0:
		cnt = 0
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '0':
				s[i] = '1'
				cnt += 1
			else:
				break
		ans.append(cnt)
	else:
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '1':
				s[i] = '0'
			else:
				s[i] = '1'
				break
	turn += 1
print(turn)
print(*ans)


import sys
import math
input = sys.stdin.readline

def areAllBitsSet(n):
	if n == 0:
		return False
	if n + 1 & n == 0:
		return True
	return False
n = int(input())
if areAllBitsSet(n):
	print(0)
else:
	cnt = 0
	st = []
	while not areAllBitsSet(n):
		r = math.floor(math.log(n, 2))
		st.append(r + 1)
		n = n ^ pow(2, r + 1) - 1
		cnt += 1
		if not areAllBitsSet(n):
			n += 1
			cnt += 1
	print(cnt)
	print(*st)


n = int(input())
ans = []
step = 0
while n != 2 ** n.bit_length() - 1:
	if step % 2 == 0:
		x = n.bit_length()
		n ^= 2 ** x - 1
		ans.append(x)
	else:
		n += 1
	step += 1
print(step)
print(*ans)


from bisect import bisect_left
should = [0, 2]
while should[-1] < 2000000000.0:
	should.append(2 * should[-1])
should = [max(i - 1, 0) for i in should]
n = int(input())
cnt = 0
ans = []
if n in should:
	print(cnt)
else:
	while n not in should:
		r = bisect_left(should, n)
		n = n ^ should[r]
		cnt += 1
		ans.append(r)
		if n in should:
			break
		cnt += 1
		n += 1
	print(cnt)
	print(*ans)


n = int(input())
b = bin(n)[2:]
l = len(b)
ans = []
k = 0
for i in range(40):
	if i % 2 == 0:
		if '0' in b:
			ans.append(str(l - b.index('0')))
			b = bin(int(b, base=2) ^ 2 ** int(ans[-1]) - 1)[2:]
		else:
			break
	elif '0' in b:
		b = bin(int(b, base=2) + 1)[2:]
	else:
		break
	k += 1
print(k)
print(' '.join(ans))


n = int(input())

def transform():
	global n
	s = bin(n)[2:]
	for i in range(len(s)):
		if s[i] == '0':
			break
	index = i
	res = ''
	for i in range(len(s)):
		if i >= index:
			res += '1'
	n = int(res, 2) ^ n
	return len(res)

def check():
	global n
	s = bin(n)[2:]
	n += 1
	if '0' not in s:
		return True
	else:
		return False
cnt = 0
toprint = []
while True:
	s = bin(n)[2:]
	if '0' not in s:
		print(cnt)
		for i in toprint:
			print(i, end=' ')
		print()
		break
	toprint.append(transform())
	cnt += 1
	if check():
		print(cnt)
		for i in toprint:
			print(i, end=' ')
		print()
		break
	cnt += 1


n = int(input())
l = []
cnt = 0
while True:
	for i in range(21):
		if n == (1 << i) - 1:
			print(cnt)
			if len(l):
				print(' '.join((str(j) for j in l)))
			exit()
	x = 0
	while (1 << x) - 1 < n:
		x += 1
	n = n ^ (1 << x) - 1
	cnt += 1
	l.append(x)
	for i in range(21):
		if n == (1 << i) - 1:
			print(cnt)
			if len(l):
				print(' '.join((str(j) for j in l)))
			exit()
	n += 1
	cnt += 1


n = int(input())
cnt = 0
d = []
while True:
	b = bin(n)[2:]
	if len(b) == b.count('1'):
		break
	k = len(b) - b.index('0')
	n = n ^ 2 ** k - 1
	cnt += 1
	d.append(k)
	b = bin(n)[2:]
	if len(b) == b.count('1'):
		break
	n += 1
	cnt += 1
if len(d) == 0:
	print(0)
else:
	print(cnt)
	print(*d)


t = 0
z = int(input())
ans = []
while True:
	r = bin(z)[2:]
	if r == '1' * len(r):
		break
	if t % 2 == 0:
		k = r.index('0')
		m = int('1' * (len(r) - k), 2)
		z ^= m
		ans.append(len(r) - k)
		t += 1
	else:
		z += 1
		t += 1
print(t)
print(*ans)


def isPowerOfTwo(n):
	if n == 0:
		return False
	while n != 1:
		if n % 2 != 0:
			return False
		n = n // 2
	return True
n = int(input())
c = 0
d = 0
l1 = []
while not isPowerOfTwo(n + 1):
	k = bin(n)
	for i in range(1, len(k)):
		if k[i] == '0':
			c = len(k) - i
			break
	d += 1
	t = 2 ** c - 1
	n ^= t
	l1.append(c)
	if isPowerOfTwo(n + 1):
		break
	d += 1
	n += 1
print(d)
for i in l1:
	print(i, end=' ')


from math import log2 as lg
n = int(input())
l = int(lg(n))
f = bin(n)[2:]
steps = 0
num = []
while n != 2 ** (l + 1) - 1:
	f = bin(n)[2:]
	j = '1' * (len(f) - f.index('0'))
	n = n ^ int(j, 2)
	steps += 1
	num.append(len(j))
	if n == 2 ** (l + 1) - 1:
		break
	n += 1
	steps += 1
print(steps)
print(*num)


x = int(input())
ns = []
for i in range(40):
	b = format(x, 'b')
	n = len(b) - b.find('0')
	if n > len(b):
		print(i)
		if i:
			print(' '.join(ns))
		break
	if i & 1:
		x += 1
	else:
		ns.append(str(n))
		x = x ^ 2 ** n - 1


s = int(input())
cnt = 0
lt = []
while True:
	ch = 1
	k = str(bin(s))
	k = k[2:]
	for i in k:
		if i == '0':
			ch = 0
	if ch == 1:
		break
	ck = 1
	if cnt % 2 == 0:
		k = str(bin(s))
		k = k[2:]
		for j in range(len(k)):
			if ck == 1 and k[j] == '0':
				ch = 2 ** (len(k) - j) - 1
				t = int(k, 2)
				s = t ^ ch
				ck = 0
				cnt += 1
				lt.append(len(k) - j)
		ck = 1
		k = str(bin(t))
	else:
		s += 1
		cnt += 1
print(cnt)
if cnt > 0:
	for i in range(len(lt)):
		print(lt[i], end=' ')
	print()


x = int(input())
c = 0
l = []
ans = 0
from math import log
if int(log(x + 1, 2)) == log(x + 1, 2):
	print(0)
else:
	for i in range(40):
		ans += 1
		if c == 0:
			a = len(bin(x)) - 2
			x = x ^ 2 ** a - 1
			l.append(a)
			c = 1
		else:
			x = x + 1
			c = 0
		if int(log(x + 1, 2)) == log(x + 1, 2):
			break
	print(ans)
	print(*l)


num = int(input())
out = ''

def check_num(val):
	if val == 0:
		return False
	while val != 0:
		if val & 1 == 0:
			return False
		val = val >> 1
	return True

def get_last_zero(val):
	counter = 0
	location = 0
	while val != 0:
		counter += 1
		if val & 1 == 0:
			location = counter
		val = val >> 1
	return location
ops = 0
while not check_num(num):
	n = get_last_zero(num)
	num = num ^ 2 ** n - 1
	ops += 1
	out += str(n) + ' '
	if check_num(num):
		break
	num += 1
	ops += 1
print(ops)
if out:
	print(out.strip())


x = int(input())
(q1, ans) = (0, [])
while set(bin(x)[2:]) != {'1'}:
	if q1 % 2 == 0:
		t = bin(x)[2:]
		y = t.find('0')
		ans.append(len(t) - y)
		x ^= (1 << ans[-1]) - 1
	else:
		x += 1
	q1 += 1
print(q1)
if len(ans) > 0:
	print(*ans)


def solve(x):
	t = 0
	ns = []
	while t <= 40:
		n = 0
		i = 1
		x1 = x
		while x1 > 0:
			if x1 & 1 == 0:
				n = i
			x1 >>= 1
			i += 1
		if n == 0:
			return (t, ns)
		if t % 2 == 0:
			x = x ^ (1 << n) - 1
			ns.append(n)
		else:
			x += 1
		t += 1
	return (t, ns)
x = int(input())
(t, ns) = solve(x)
print(t)
if len(ns) > 0:
	print(' '.join((str(n) for n in ns)))


n = int(input().strip())
x = bin(n)[2:]
length = len(x)
ans = []
cnt = 0
for i in range(length):
	if x[i] == '0':
		pwr = length - i
		ans.append(pwr)
		cnt += 1
		n = n ^ 2 ** pwr - 1
		if n == 2 ** length - 1:
			break
		n += 1
		cnt += 1
		x = bin(n)[2:]
print(cnt)
if cnt != 0:
	for i in ans:
		print(i, end=' ')


x = int(input())
t = list(map(int, list(bin(x).split('b')[1])))
k = 0
ans1 = 0
ans2 = []
while t != [1] * len(t):
	if k % 2 == 0:
		for i in range(len(t)):
			if t[i] == 0:
				break
		s = [1 - j for j in t[i:]]
		t = t[:i] + s
		ans2.append(len(t) - i)
	else:
		t[-1] += 1
		for i in range(1, len(t) - 1):
			if t[-i] != 2:
				break
			t[-i] = 0
			t[-i - 1] += 1
	ans1 += 1
	k += 1
print(ans1)
print(' '.join(list(map(str, ans2))))


def is_perfect(n):
	while n > 0:
		if n % 2 == 0:
			return False
		n //= 2
	return True

def only_left_most_bit(n):
	count = 0
	left_most = 0
	while n > 0:
		if n % 2 == 1:
			left_most = count
		n //= 2
		count += 1
	return 1 << left_most

def left_most_bit(n):
	count = 0
	left_most = 0
	while n > 0:
		if n % 2 == 1:
			left_most = count
		n //= 2
		count += 1
	return (1 << left_most + 1) - 1

def count_ones(n):
	count = 0
	while n > 0:
		if n % 2 == 1:
			count += 1
		n //= 2
	return count

def a(n, moves):
	if n == only_left_most_bit(n):
		xor = left_most_bit(n) >> 1
	else:
		xor = left_most_bit(n)
	ans = n ^ xor
	moves.append(count_ones(xor))
	return ans

def b(n):
	return n + 1
x = int(input())
move = 0
moves = []
while move < 40 and (not is_perfect(x)):
	move += 1
	if move % 2 == 1:
		x = a(x, moves)
	else:
		x = b(x)
print(move)
if len(moves) > 0:
	print(' '.join([str(m) for m in moves]))


from sys import stdin, stdout
x = stdin.readline()
x = int(x)
binary_string = '{0:b}'.format(x)
first = True
cnt = 0
answer = ''
while True:
	if '0' not in binary_string:
		break
	else:
		a = len(binary_string) - binary_string.index('0')
		if first:
			answer += str(a)
			first = False
		else:
			answer += ' ' + str(a)
		x = x ^ 2 ** a - 1
		binary_string = '{0:b}'.format(x)
		cnt += 1
	if '0' not in binary_string:
		break
	else:
		x += 1
		binary_string = '{0:b}'.format(x)
		cnt += 1
if cnt != 0:
	stdout.write(str(cnt) + '\n' + answer + '\n')
else:
	stdout.write('0\n')


import collections
import random
import heapq
import bisect
import math
import time

class Solution2:

	def solve(self, A1, A2):
		pass

class Solution:

	def solve(self, start_num):
		num = list(bin(start_num)[2:])
		out = []
		while not all((n == '1' for n in num)):
			for i in range(len(num)):
				if num[i] == '0':
					out.append(len(num) - i)
					for j in range(i, len(num)):
						num[j] = '1' if num[j] == '0' else '0'
					break
			if all((n == '1' for n in num)):
				return (out, len(out) * 2 - 1)
			num = list(bin(int(''.join(num), 2) + 1)[2:])
		return (out, len(out) * 2)
sol = Solution()
sol2 = Solution2()
for test_case in range(1):
	N = input()
	(out, n) = sol.solve(int(N))
	if n == 0:
		print('0')
		quit()
	print(str(n))
	print(' '.join([str(o) for o in out]))


def to_bin(n):
	s = []
	while n > 0:
		s.append(n % 2)
		n //= 2
	return s[::-1]

def to_kek(a):
	a = a[::-1]
	s = 0
	for i in range(len(a)):
		s += a[i] * (1 << i)
	return s
n = int(input())
ans = []
chislo = to_bin(n)
len_ch = len(chislo)
cur = 0
cur_izm = 0
cur_deystvie = 1
len_ans = 0
while True:
	while cur < len(chislo) and chislo[cur] == 1:
		cur += 1
	if cur == len(chislo):
		break
	n ^= (1 << len_ch - cur) - 1
	ans.append(len_ch - cur)
	len_ans += 1
	chislo = to_bin(n)
	if chislo.count(1) == len(chislo):
		break
	n += 1
	len_ans += 1
	chislo = to_bin(n)
	if chislo.count(1) == len(chislo):
		break
print(len_ans)
if ans:
	print(' '.join(map(str, ans)))


x = int(input())
ind = 0
a = list(bin(x)[2:])
s = []
while True:
	try:
		ind = a.index('0')
	except:
		print(len(s) * 2)
		break
	s.append(str(len(a) - ind))
	x = x ^ 2 ** (len(a) - ind) - 1
	a = list(bin(x)[2:])
	try:
		ind = a.index('0')
	except:
		print(len(s) * 2 - 1)
		break
	x += 1
	a = list(bin(x)[2:])
if len(s) > 0:
	print(' '.join(s))


def first_zero_bit(x):
	length = 0
	while 1 << length < x:
		length += 1
	length -= 1
	while 1 << length & x:
		length -= 1
	return length
n = int(input())
odd = False
A = []
while n & n + 1:
	if odd:
		n += 1
	else:
		fzb = first_zero_bit(n)
		A += [fzb + 1]
		n ^= (1 << fzb + 1) - 1
	odd ^= 1
print(2 * len(A) - int(odd))
print(' '.join(map(str, A)))


import sys
input = sys.stdin.readline
n = int(input())
t = 0
ls = []
while n != 2 ** n.bit_length() - 1:
	if t % 2 == 0:
		x = n.bit_length()
		n ^= 2 ** x - 1
		ls.append(x)
	else:
		n += 1
	t += 1
print(t)
print(*ls, end='')


import math

def comp(n):
	number_of_bits = int(math.floor(math.log(n) / math.log(2))) + 1
	return (1 << number_of_bits) - 1 ^ n
n = int(input())
count = 0
com = comp(n)
a = []
if com == 0:
	print(0)
else:
	while count < 40 and com != 0:
		tmp = int(math.floor(math.log(com) / math.log(2))) + 1
		if tmp != abs(tmp):
			tmp += 1
		if count % 2 == 0:
			a.append(tmp)
			count += 1
			n = n ^ 2 ** tmp - 1
		else:
			count += 1
			n += 1
		com = comp(n)
	print(count)
	for i in range(len(a)):
		print(a[i], end=' ')
	print()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
k1 = n
import math

def xorfind(k):
	c = 0
	while k != 1:
		e = math.log(k + 1, 2)
		if math.ceil(e) == math.floor(e):
			break
		k = k // 2
		c += 1
	return c
d = []
f = 0
while math.ceil(math.log(k1 + 1, 2)) != math.floor(math.log(k1 + 1, 2)):
	z = xorfind(k1)
	d.append(z)
	k1 = k1 ^ 2 ** z - 1
	if math.ceil(math.log(k1 + 1, 2)) == math.floor(math.log(k1 + 1, 2)):
		f = 1
		break
	else:
		k1 += 1
print(len(d) * 2 - f)
print(*d, sep=' ')


x = int(input())
x = list('{0:b}'.format(x))
ans = []
count = 0
len_x = len(x)
while len_x != sum([int(item) for item in x]):
	pos = x.index('0')
	ans.append(len_x - pos)
	count += 1
	for i in range(pos, len_x):
		x[i] = str(1 - int(x[i]))
	if len_x == sum([int(item) for item in x]):
		break
	count += 1
	pos_last = len_x - 1 - x[::-1].index('0')
	x[pos_last] = '1'
	for i in range(pos_last + 1, len_x):
		x[i] = '0'
print(count)
if count > 0:
	print(' '.join([str(item) for item in ans]))


Bin = [1]
op = [0]

def find(x):
	k = 0
	while x != 0:
		x = x // 2
		k = k + 1
	return k
for i in range(1, 31):
	Bin.append(Bin[i - 1] << 1)
x = int(input())
k = find(x)
ans = 0
while x != Bin[k] - 1:
	x = x ^ Bin[k] - 1
	op.append(k)
	ans = ans + 1
	k = find(x)
	if x == Bin[k] - 1:
		break
	x = x + 1
	ans = ans + 1
	k = find(x)
print(ans)
ans = (ans + 1) // 2
ret = ''
for i in range(1, ans + 1):
	ret = ret + str(op[i]) + ' '
if ans > 0:
	print(ret)


import math

def is_good(n):
	if 2 ** int(math.log(n + 1, 2)) == n + 1:
		return True
	return False

def B():
	n = int(input())
	if is_good(n):
		print(0)
		return
	p = []
	i = 1
	while not is_good(n):
		if i % 2:
			aux = bin(n)[2:]
			e = len(aux) - aux.index('0')
			p.append(e)
			n ^= 2 ** e - 1
		else:
			n += 1
		i += 1
	print(i - 1)
	print(*p)
B()


x = int(input())
powers_of_two = [pow(2, i) - 1 for i in range(1, 22)]
num_of_operations = 0
n_i = []
while True:
	if x in powers_of_two:
		if num_of_operations == 0:
			print(num_of_operations)
		else:
			print(num_of_operations)
			print(*n_i)
		break
	else:
		if num_of_operations % 2 == 0:
			if x & 1 == 0:
				n_i.append(0)
			else:
				n_i.append(len(bin(x)) - 2)
				x ^= (1 << len(bin(x)) - 2) - 1
		else:
			x += 1
		num_of_operations += 1


from math import log2, log, ceil

def A(x):
	n = ceil(log2(x))
	n = int(n)
	kk = 2 ** n - 1
	return (x ^ kk, n)

def B(x):
	return x + 1

def check(num):
	num += 1
	mm = log(num) / log(2)
	q = int(mm)
	if mm - q == 0:
		return True
	return False
t = 0
f = True
ans = []
x = int(input())
for i in range(40):
	if check(x):
		print(t)
		if t != 0:
			print(*ans)
		break
	t += 1
	if t % 2 != 0:
		(x, n1) = A(x)
		ans.append(n1)
	else:
		x = B(x)


while True:
	try:
		x = int(input())
		s = '{0:b}'.format(x)
		(t, n, p) = (0, [], 1)
		if s.count('1') != len(s):
			while True:
				i = s.find('0')
				if i < 0:
					break
				t += 1
				if p == 1:
					ni = int((len(s) - i) * '1', base=2)
					x ^= ni
					n.append(len(s) - i)
					p = 0
				else:
					x += 1
					p = 1
				s = '{0:b}'.format(x)
		print(t)
		if len(n) > 0:
			print(' '.join(map(str, n)))
	except:
		break


def solve(num):
	s = bin(num)[2:]
	l = len(s)
	res = []
	target = (1 << l) - 1
	path = 0
	if num == target:
		return (0, res)
	while path < 40:
		s = bin(num)[2:]
		ind = s.index('0')
		n = l - ind
		num ^= (1 << n) - 1
		path += 1
		res.append(str(n))
		if num == target:
			return (path, res)
		num += 1
		path += 1
		if num == target:
			return (path, res)
num = int(input())
(path, res) = solve(num)
print(path)
if res:
	print(' '.join(res))


import sys

def add(b):
	if b[-1] == 0:
		b[-1] = 1
		return b
	elif len(b) == 1:
		return [1, 0]
	else:
		return add(b[:len(b) - 1]) + [0]
n = int(input())
bb = bin(n)[2:]
b = [int(c) for c in bb]
if all((c for c in b)):
	print(0)
	sys.exit()
l = len(b)
num = 0
steps = []
while True:
	n = b.index(0)
	for i in range(n, l):
		if b[i] == 0:
			b[i] = 1
		else:
			b[i] = 0
	steps.append(l - n)
	num += 1
	if all((c for c in b)):
		break
	b = add(b)
	num += 1
	if all((c for c in b)):
		break
print(num)
print(' '.join(map(str, steps)))


__version__ = '0.2'
__date__ = '2019-04-24'
import sys
import math

def rec(x, ns, steps):
	binary = bin(x)[2:]
	for (idx, val) in enumerate(binary):
		if val == '0':
			ns.append(len(binary) - idx)
			n = pow(2, len(binary) - idx) - 1
			steps += 1
			if pow(2, int(math.log((x ^ n) + 1, 2))) ^ (x ^ n) + 1 == 0:
				return steps
			steps += 1
			return rec((x ^ n) + 1, ns, steps)
	return steps

def solve(x):
	ns = []
	steps = rec(x, ns, 0)
	print(steps)
	if steps:
		print(' '.join((str(i) for i in ns)))
	return -1

def main(argv=None):
	x = int(input())
	solve(x)
	return 0
STATUS = main()
sys.exit(STATUS)


import sys
input = sys.stdin.readline
ANSLIST = set([(1 << i) - 1 for i in range(30)])
NOW = int(input())
if NOW in ANSLIST:
	print(0)
	return
ANS = []
while True:
	if NOW in ANSLIST:
		print(len(ANS) * 2)
		print(*ANS)
		return
	for i in range(NOW.bit_length(), 0, -1):
		if NOW & 1 << i - 1 == 0:
			ANS.append(i)
			NOW = NOW ^ (1 << i) - 1
			break
	if NOW in ANSLIST:
		print(len(ANS) * 2 - 1)
		print(*ANS)
		return
	NOW += 1


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
from math import *
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN():
	return list(numIN())

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

def res(ans, t):
	print('Case #{}: {}'.format(t, ans))

def chk(n):
	x = bin(n)[2:]
	if x.count('0') == 0:
		return 1
	return 0
n = int(input())
x = bin(n)[2:]
if chk(n):
	print(0)
else:
	ans = []
	op = 0
	while not chk(n):
		x = bin(n)[2:]
		idx = x.index('0')
		ans.append(len(x) - idx)
		n = n ^ 2 ** ans[-1] - 1
		op += 1
		if chk(n):
			break
		n += 1
		op += 1
	print(op)
	print(' '.join([str(i) for i in ans]))


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())

def findzero(n):
	s = bin(n)[2:]
	for i in range(len(s)):
		if s[i] == '0':
			return len(s) - i
n = int(input())
ans = []
count = 0
while '0' in bin(n)[2:]:
	if count % 2 == 0:
		k = findzero(n)
		num = 2 ** k - 1
		ans.append(k)
		n ^= num
		count += 1
	else:
		n += 1
		count += 1
if count:
	print(count)
	print(*ans)
else:
	print(count)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
t = 0
ls = []
while n != 2 ** n.bit_length() - 1:
	if t % 2 == 0:
		x = n.bit_length()
		n ^= 2 ** x - 1
		ls.append(x)
	else:
		n += 1
	t += 1
print(t)
print(*ls, end='')


from math import log2
n = int(input())
p = 0
l = []
while not log2(n + 1).is_integer():
	p += 2
	k = int(log2(n))
	l.append(k + 1)
	tam = 2 ** k
	kalan = n - 2 ** k
	n -= 2 * kalan
	if log2(n).is_integer():
		p -= 1
		break
print(p)
if l:
	print(*l)


def XOR(a, b):
	return a ^ b

def prod(a):
	return 2 ** a - 1
count = 0
n = int(input())
nums = ''
while count <= 40:
	s = bin(n)[2:]
	i = 0
	while i < len(s):
		if s[i] == '0':
			break
		i += 1
	length = len(s[i:])
	if length == 0:
		break
	if count % 2 == 0:
		count += 1
		nums = nums + str(length) + ' '
		n = XOR(n, prod(length))
	else:
		n = n + 1
		count += 1
print(count)
if nums != '':
	print(nums[:-1])


x = int(input())
a = []
b = list(bin(x)[2:][::-1])
c = 0
t = len(b)
d = t
if x == 0:
	print(0)
else:
	while b != ['1'] * t:
		d -= 1
		if b[d] == '0':
			b = list(bin(x ^ 2 ** (d + 1) - 1)[2:][::-1])
			a.append(str(d + 1))
			x = x ^ 2 ** (d + 1) - 1
			c += 1
			if b != ['1'] * t:
				c += 1
				b = list(bin(x + 1)[2:][::-1])
				x += 1
	if c == 0:
		print(0)
	else:
		print(c)
		print(' '.join(a))


def check(t):
	y = t
	while y:
		if y % 2 == 0:
			return False
		y = y >> 1
	return True
x = int(input())
c = 0
res = []

def cnt(k):
	y = k
	t = 0
	while y:
		t += 1
		y = y >> 1
	return t
while not check(x):
	c += 1
	t = cnt(x)
	res.append(t)
	x = x ^ 2 ** t - 1
	if check(x):
		break
	x += 1
	c += 1
print(c)
print(' '.join([str(x) for x in res]))


n = int(input())
i = 0
diksha = 0
b = []
anmol = list(format(n, 'b'))
while i != len(anmol):
	while i < len(anmol) and anmol[i] == '1':
		i += 1
	if i == len(anmol):
		break
	diksha += 1
	b.append(len(anmol) - i)
	for j in range(i, len(anmol)):
		if anmol[j] == '0':
			anmol[j] = '1'
		else:
			anmol[j] = '0'
	while i < len(anmol) and anmol[i] == '1':
		i += 1
	if i == len(anmol):
		break
	diksha += 1
	for j in range(len(anmol) - 1, i - 1, -1):
		if anmol[j] == '1':
			anmol[j] = '0'
		else:
			anmol[j] = '1'
			break
print(diksha)
print(*b)


x = int(input())
ans = []
z = 0
while True:
	w = bin(x)[2:][::-1]
	cnt = w.count('1')
	if cnt == 0 or cnt == len(w):
		break
	ind = 0
	for i in range(len(w)):
		if w[i] == '1':
			ind = i
	z += 1
	ans.append(ind + 1)
	x = 2 ** (ind + 1) - 1 ^ x
	w = bin(x)[2:][::-1]
	cnt = w.count('1')
	if cnt == 0 or cnt == len(w):
		break
	x += 1
	z += 1
print(z)
print(*ans)


def find_leftmost_one(a):
	cnt = 0
	ret = -1
	while 1 << cnt < a:
		if a & 1 << cnt == 0:
			ret = cnt
		cnt += 1
	return ret

def check_ans(a):
	ret = True
	while a:
		if a & 1 == 0:
			ret = False
			break
		a >>= 1
	return ret
x = int(input())
ans = []
cnt = 0
while cnt <= 40:
	if check_ans(x):
		break
	if cnt % 2 == 0:
		p = find_leftmost_one(x)
		x = (1 << p + 1) - 1 ^ x
		ans += [p + 1]
	else:
		x += 1
	cnt += 1
print(cnt)
if len(ans):
	print(*ans)


n = int(input())
x = 0
a = []
t = 1
while x != 21:
	a.append(t - 1)
	t *= 2
	x += 1
ans = []
c = 0
while True:
	if c % 2 == 0:
		for i in range(len(a)):
			if n == a[i]:
				print(len(ans) + c // 2)
				print(*ans)
				exit()
			if n < a[i]:
				ans.append(i)
				n = n ^ a[i]
				break
	else:
		for i in range(len(a)):
			if n == a[i]:
				print(len(ans) + c // 2)
				print(*ans)
				exit()
		n += 1
	c += 1


t = x = int(input())
s = bin(x).lstrip('0b')
l = len(s)
c = 0
a = []

def check(s):
	for i in range(1, l):
		if s[i] == '0':
			return i
	return l
while True:
	v = check(s)
	if v == l:
		break
	s = bin(int(s, 2) ^ pow(2, l - v) - 1).lstrip('0b')
	a.append(l - v)
	c = c + 1
	v = check(s)
	if v == l:
		break
	s = bin(int(s, 2) + 1).lstrip('0b')
	c = c + 1
print(c)
if c != 0:
	for i in range(0, len(a) - 1):
		print(a[i], end=' ')
	print(a[len(a) - 1])


def s():
	a = int(input())
	o = []
	t = bin(a)[2:]
	while '0' in t:
		at = t.index('0')
		f = len(t) - at
		o.append(f)
		a = a ^ 2 ** f - 1
		for pw in range(0, 31):
			if 2 ** pw - 1 == a:
				print(len(o) * 2 - 1)
				print(' '.join([str(x) for x in o]))
				return
		a += 1
		t = bin(a)[2:]
	print(len(o) * 2)
	print(' '.join([str(x) for x in o]))
s()


n = int(input())
s = bin(n)[2:]
r = 0
l = []
for i in range(40):
	if '0' not in s:
		break
	if i % 2 == 0:
		p = s.index('0')
		t = 2 ** (len(s) - p) - 1
		l.append(len(s) - p)
		n = n ^ t
		r += 1
	else:
		n += 1
		r += 1
	s = bin(n)[2:]
print(r)
if r > 0:
	[print(i, end=' ') for i in l]


def main():
	x = int(input())
	(t, n) = (0, [])
	for i in range(50):
		s = str(bin(x))[2:]
		if '0' not in s:
			t = i
			break
		if i % 2 == 0:
			m = len(s) - s.find('0')
			x ^= 2 ** m - 1
			n.append(m)
		else:
			x += 1
	print(t)
	print(*n)
main()


def invert(s):
	return ''.join([str(1 - int(char)) for char in s])

def plusone(s):
	return str(bin(int(s, 2) + 1))[2:]

def removeones(s):
	while s[0] == '1':
		s = s[1:]
	return s

def f(s):
	count = 0
	nums = []
	while '0' in s and '1' in s:
		s = removeones(s)
		nums.append(len(s))
		s = invert(s)
		count += 1
		if '0' not in s:
			return [count, nums]
		s = plusone(s)
		count += 1
	return [count, nums]
s = bin(int(input()))[2:]
x = f(s)
print(x[0])
if len(x[1]) > 0:
	print(' '.join([str(i) for i in x[1]]))


a = []
x = int(input())
if x + 1 & x == 0:
	print(0)
else:
	add = 0
	v = 0
	n = x
	while True:
		cp = 0
		nb = 0
		x = n
		while n:
			cp += 1
			if n % 2 == 0:
				nb = cp
			n = n >> 1
		if nb == 1:
			a.append(0)
			break
		a.append(nb)
		n = x ^ (1 << nb) - 1
		if n & n + 1 == 0:
			add = 1
			break
		n = n + 1
		if n & n + 1 == 0:
			break
	print(len(a) * 2 - add)
	print(*a)


import io, sys, atexit, os
import math as ma
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mm = 1000000007
yp = 0

def solve():
	t = 1
	for tt in range(t):
		n = nu()
		cc = 0
		s = str(bin(n))[2:]
		xp = []
		pp = 0
		while cc <= 40:
			fl = False
			ind = -1
			for i in range(len(s)):
				if s[i] == '0':
					fl = True
					ind = i
					break
			if fl == False:
				break
			cc += 1
			if pp == 1:
				pp ^= 1
				n += 1
				s = str(bin(n))[2:]
			else:
				pp ^= 1
				gg = pow(2, len(s) - ind) - 1
				xp.append(len(s) - ind)
				n ^= gg
				s = str(bin(n))[2:]
		print(cc)
		print(*xp)

def __starting_point():
	solve()
__starting_point()


x = int(input())
s = bin(x)[2:]
z = 0
a = []
while s != '1' * len(s):
	if z % 2:
		s = bin(int(s, 2) + 1)[2:]
	else:
		i = s.index('0')
		n = len(s) - i
		a.append(n)
		s = bin(int(s, 2) ^ 2 ** n - 1)[2:]
	z += 1
if z:
	print(z)
	print(*a)
else:
	print(0)


def next(x):
	x += 1
	return 2 ** (x - 1).bit_length() - 1

def next_power_of_2(x):
	return 1 if x == 0 else 2 ** (x - 1).bit_length()

def valid(x):
	return next_power_of_2(x) - 1 == x
x = int(input())
state = False
l = []
operations = 0
while not valid(x) and x != 1:
	if not state:
		l.append(next(x).bit_length())
		x ^= next(x)
	else:
		x += 1
	operations += 1
	state = not state
print(operations)
if operations:
	print(' '.join([str(x) for x in l]))


x = int(input())
bin_x = bin(x)[2:]
ans_ls = []

def after_all_zero(s, i):
	all_zero = True
	while i < len(s):
		if s[i] == '1':
			all_zero = False
			break
		i += 1
	return all_zero
if x % 2 == 1:
	for i in range(1, len(bin_x) - 1):
		if bin_x[i] != bin_x[i - 1]:
			ans_ls.append(len(bin_x) - i)
	print(2 * len(ans_ls))
else:
	bin_x = bin(x)[2:]
	ans_ls = []
	for i in range(1, len(bin_x)):
		if bin_x[i] != bin_x[i - 1] and (not (i + 1 < len(bin_x) and bin_x[i] == '1' and after_all_zero(bin_x, i + 1))):
			ans_ls.append(len(bin_x) - i)
	print(max(2 * len(ans_ls) - 1, 0))
if ans_ls:
	print(*ans_ls)


def ok(x):
	while x > 0:
		if x % 2 == 0:
			return 0
		x = x // 2
	return 1
n = int(input())
ans = []
cc = 0
for i in range(20, 0, -1):
	if n & 1 << i - 1:
		continue
	ans.append(i)
	n = n ^ (1 << i) - 1
	cc += 1
	if ok(n):
		break
	n += 1
	cc += 1
print(cc)
for i in ans:
	print(i, end=' ')
print()


import math
x = int(input())
if x + 1 & x == 0:
	print(0)
	exit()
count = 0
ans = []
while x + 1 & x != 0:
	k = x & -x
	ans.append(int(math.log(k, 2)))
	x = x ^ k - 1
	count += 1
	if x + 1 & x == 0:
		break
	count += 1
	x += 1
print(count)
print(' '.join(list(map(str, ans))))


def lastUnset(n):
	if n & n + 1 == 0:
		return 0
	(pos, temp, count) = (0, N, 0)
	while temp:
		if not temp & 1:
			pos = count
		count += 1
		temp >>= 1
	return pos + 1
N = int(input())
count = 0
Ans = []
while N & N + 1 != 0:
	pos = lastUnset(N)
	Mask = (1 << pos) - 1
	N ^= Mask
	Ans.append(pos)
	count += 1
	if N & N + 1 == 0:
		break
	N += 1
	count += 1
print(count)
print(*Ans)


n = int(input())
u = []
b = 1
c = 0

def f(x):
	if x == 1:
		return 0
	return 1
while b <= n:
	c += 1
	b *= 2
b //= 2
n1 = n
for i in range(c):
	u.append(n1 // b)
	n1 %= b
	b //= 2
k = len(u)
ans = []
if u[-1] == 0:
	ans.append(0)
	u[-1] = 1
for i in range(k):
	if u[i] == 0:
		ans.append(k - i)
		for i in range(i, k - 1):
			u[i] = f(u[i])
print(len(ans) * 2)
for i in ans:
	print(i, end=' ')


import collections
x = int(input())
(c, ans) = (0, [])
for i in range(40):
	if x == 2 ** len(format(x, 'b')) - 1:
		break
	if i % 2:
		x += 1
	else:
		ans.append(len(format(x, 'b')))
		x = x ^ 2 ** ans[-1] - 1
	c += 1
print(c)
if c:
	print(' '.join((str(i) for i in ans)))


import collections

def is_satisfied(n):
	while n & 1 != 0:
		n >>= 1
	return n == 0

def msb(n):
	pos = 0
	zero = 0
	while n != 0:
		pos += 1
		if n & 1 == 0:
			zero = pos
		n >>= 1
	return zero

def solve():
	X = int(input())
	t = 0
	t2 = []
	if is_satisfied(X):
		print(t)
		return
	while True:
		t += 1
		n = msb(X)
		t2.append(n)
		X ^= 2 ** n - 1
		if is_satisfied(X):
			print(t)
			print(*t2)
			return
		t += 1
		X += 1
		if is_satisfied(X):
			print(t)
			print(*t2)
			return
solve()


def all_ones(t):
	yes = True
	for i in t:
		if i != '1':
			yes = False
			break
	return yes
x = int(input())
k = 0
n = []
while True:
	s = str(bin(x))[2:]
	if all_ones(s):
		break
	for i in range(len(s)):
		if s[i] == '0':
			k += 1
			n.append(len(s) - i)
			break
	x ^= 2 ** n[len(n) - 1] - 1
	s = str(bin(x))[2:]
	if all_ones(s):
		break
	x += 1
	k += 1
print(k)
for i in n:
	print(i, end=' ')


def add(n):
	nint = 0
	for k in range(len(n)):
		nint += n[k] * pow(2, len(n) - k - 1)
	nint += 1
	return list(map(int, list(bin(nint))[2:]))

def findList(n):
	for k in range(len(n)):
		if n[k] == 0:
			return k
	return -1
n = list(map(int, list(bin(int(input())))[2:]))
cpt = 0
taken = []
while n.count(0) != 0:
	cpt += 1
	p = findList(n)
	taken.append(len(n) - p)
	for k in range(p, len(n)):
		n[k] = not n[k]
	if n.count(0) == 0:
		break
	else:
		cpt += 1
		n = add(n)
print(cpt)
if len(taken) != 0:
	print(' '.join(map(str, taken)))


from math import *

def log2(n):
	return floor(log(n, 2))
n = int(input())
array = []
i = 0

def done(n):
	return 2 ** log2(n + 1) == n + 1
while n > 1:
	if done(n):
		break
	if 2 ** log2(n) == n:
		array.append(log2(n))
		n = n ^ n - 1
		i += 1
		break
	else:
		array.append(log2(n) + 1)
		n = n ^ 2 ** (log2(n) + 1) - 1
	n += 1
	i += 2
print(i)
print(' '.join(map(str, array)))


x = int(input())
ans = []
cnt = 0
while len(set(bin(x)[2:])) != 1:
	s = '1' * (len(bin(x)) - 2)
	ans.append(len(s))
	x ^= int(s, 2)
	if len(set(bin(x)[2:])) == 1:
		cnt = 1
		break
	x += 1
print(len(ans) * 2 - cnt)
print(*ans)


x = int(input())
b = len(bin(x)) - 2
ans = []
n = 0
while x ^ (1 << b) - 1:
	bn = bin(x)[2:]
	for i in range(b):
		if bn[i] == '0':
			x ^= (1 << b - i) - 1
			ans.append(b - i)
			break
	if x ^ (1 << b) - 1 == 0:
		n = len(ans) * 2 - 1
		break
	x += 1
	b = len(bin(x)) - 2
	bn = bin(x)[2:]
print(n if n != 0 else len(ans) * 2)
print(*ans)


x = int(input())
cnt = 0
l = []
while x != 2 ** x.bit_length() - 1:
	if cnt % 2:
		x += 1
	else:
		x ^= 2 ** x.bit_length() - 1
		l.append(x.bit_length())
	cnt += 1
print(cnt)
print(*l)


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n
primes = []

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	else:
		return int(input())
n = f()
res = []
ans = 0
for i in range(40):
	b = bin(n)[2:]
	if b.count('0') == 0:
		ans = i
		break
	if i % 2 == 0:
		pos = b.index('1')
		t = len(b) - pos
		res.append(t)
		n = n ^ 2 ** t - 1
	else:
		n += 1
print(ans)
print(*res)


s = {2 ** i - 1 for i in range(25)}
n = int(input())
tbp = []
c = 0
while n not in s:
	last = -1
	for i in range(20):
		if n & 2 ** i == 0 and 2 ** i < n:
			last = i
	if last == -1:
		break
	n ^= -1 + 2 ** (last + 1)
	c += 1
	tbp.append(str(last + 1))
	if n in s:
		break
	c += 1
	n += 1
print(c)
print(' '.join(tbp))


import math
a = int(input())
k = 0
A = []
while int(math.log(a + 1, 2)) < math.log(a + 1, 2):
	l = int(math.log(a, 2)) + 1
	a = 2 ** l - 1 - a
	if int(math.log(a + 1, 2)) < math.log(a + 1, 2):
		a += 1
		k += 1
	k += 1
	A.append(l)
print(k)
print(*A)


x = int(input())
Bin = list(bin(x)[2:])
Len = len(Bin)
res = []
t = 0
while Bin.count('0') > 0:
	if t % 2 == 0:
		t += 1
		N = 0
		i = Len - 1
		while Bin[i] == '0':
			N += 1
			Bin[i] = '1'
			i -= 1
		res.append(N)
	else:
		t += 1
		i = Len - 1
		while Bin[i] != '0':
			Bin[i] = '0'
			i -= 1
		Bin[i] = '1'
print(t)
print(*res)


x = int(input())
N = [int(2 ** t) - 1 for t in range(32)]
ans = []
if x in N:
	print(0)
else:
	for op in range(1, 21):
		b = bin(x)[2:]
		if b.count('0') == 0:
			print((op - 1) * 2)
			print(' '.join(map(str, ans)))
			break
		i = 0
		while b[i] == '1':
			i += 1
		idx = len(b) - i
		ans.append(idx)
		x = x ^ N[idx]
		b = bin(x)[2:]
		if b.count('0') == 0:
			print(op * 2 - 1)
			print(' '.join(map(str, ans)))
			break
		x += 1


from sys import setcheckinterval, setrecursionlimit, stdout, stdin
setcheckinterval(1000)
setrecursionlimit(10 ** 6)
iin = lambda : int(stdin.readline())
lin = lambda : list(map(int, stdin.readline().split()))
from math import log2
x = iin()
t = 0
ans = []
for i in range(1, 41):
	if x == 1 or x == 0:
		break
	if 2 ** int(log2(x + 1)) - 1 == x:
		break
	t += 1
	if i % 2 == 0:
		x += 1
	else:
		y = bin(x)[2:]
		l = len(y) - y.index('0')
		x = x ^ 2 ** l - 1
		ans.append(l)
print(t)
print(*ans)


x = int(input())
d = x + 1
emon = []
import math
m = math.log(d, 2)
k = m + 1
if m == int(m):
	print('0')
else:
	if 2 ** int(m) - 1 == d:
		print('0')
	else:
		a = 0
		while 1:
			a += 1
			if a % 2 != 0:
				g = 0
				emon1 = []
				while 1:
					f = x ^ 2 ** g - 1
					if f > 2 ** int(k) - 1:
						break
					else:
						emon1.append(f)
						g += 1
				if len(emon1) > 0:
					x = max(emon1)
					j = emon1.index(x)
					emon.append(j)
			else:
				x = x + 1
			if x == 2 ** int(k) - 1:
				break
	print(a)
	for i in range(len(emon)):
		print(emon[i], end=' ')


n = int(input())

def hi(n):
	return len(bin(n)) - 2 - bin(n)[2:].index('0')

def on(n):
	return bin(n).count('1') == len(bin(n)) - 2
a = []
cnt = 0
m = 1
x = n
while on(x) == False and cnt < 40:
	cnt += 1
	if m == 1:
		k = hi(x)
		x = x ^ 2 ** k - 1
		a.append(k)
	else:
		x += 1
	m = 1 - m
print(cnt)
print(*a)


n = int(input())
pl = {2 ** i - 1 for i in range(1, 40)}
ans = 0
l = []
while n not in pl:
	x = n.bit_length()
	ans += 1
	l.append(x)
	n ^= 2 ** x - 1
	if n in pl:
		break
	n += 1
	ans += 1
print(ans)
if ans:
	print(*l)


def check(num):
	if len(set(bin(num)[2:])) == 1 and bin(num)[-1] == '1':
		return 1
	return 0
x = int(input())
two = [2 ** i - 1 for i in range(21)]
b = bin(int(x))[2:]
ans = []
t = 0
num = int(b, 2)
if num in two:
	print(0)
else:
	while x != 2 ** x.bit_length() - 1:
		if t % 2:
			x += 1
		else:
			xb = x.bit_length()
			ans.append(xb)
			x ^= 2 ** xb - 1
		t += 1
	print(t)
	print(*ans)


import math

def test(x):
	if math.log2(x + 1) - math.floor(math.log2(x + 1)) == 0:
		return True
	return False
N = int(input())
if test(N):
	print(0)
	exit()
l = []
cnt = 0
while not test(N):
	b = bin(N)[2:]
	i = b.find('0')
	r = '1' * (len(b) - i)
	r = int(r, 2)
	l.append(math.floor(math.log2(r + 1)))
	cnt += 1
	N = N ^ r
	if test(N):
		break
	N += 1
	cnt += 1
print(cnt)
ans = ''
for a in l:
	ans += str(a) + ' '
print(ans[0:-1])


def solve(x):
	brr = []
	while x > 0:
		brr.append(x % 2)
		x //= 2

	def check(brr):
		return all(brr)
	cnt = 0
	ops = []
	while not check(brr):
		if cnt % 2 == 0:
			n = None
			for i in range(len(brr) - 1, -1, -1):
				if brr[i] == 0:
					n = i
					break
			ops.append(n + 1)
			for i in range(n, -1, -1):
				brr[i] = 1 - brr[i]
		else:
			for i in range(len(brr)):
				if brr[i] == 0:
					brr[i] = 1
					break
				else:
					brr[i] = 0
		cnt += 1
	print(cnt)
	print(' '.join(map(str, ops)))
solve(int(input()))


n = int(input())
ans = []
cnt = 0

def f(x):
	return x & x + 1 == 0
while not f(n):
	s = bin(n)[2:]
	p = s.index('0')
	x = len(s) - p
	ans.append(x)
	n ^= (1 << x) - 1
	cnt += 1
	if f(n):
		break
	n += 1
	cnt += 1
print(cnt)
print(*ans)


def mp():
	return map(int, input().split())

def f(n):
	nonlocal l
	res = []
	l = 0
	while n > 0:
		res.append(n % 2)
		n //= 2
		l += 1
	return res[::-1]
n = int(input())
l = 0
s = f(n)
cnt = 0
ans = []
h = len(s)
while n != 2 ** l - 1:
	if s[-1] == 0:
		ans.append(0)
		n += 1
		s = f(n)
		continue
	idx = ''.join(map(str, s)).find('0')
	ans.append(h - idx)
	n ^= 2 ** (l - idx) - 1
	n += 1
	s = f(n)
print(len(ans) * 2)
for i in ans:
	print(i, end=' ')


def find(n):
	l = 1
	p = 0
	while True:
		if n > l - 1:
			l = l * 2
			p = p + 1
		else:
			break
	return p
n = int(input())
a = []
t = 0
while True:
	s = bin(n)
	s = s[2:]
	if s.count('1') == len(s):
		break
	t += 1
	p = find(n)
	a.append(p)
	k = 2 ** p - 1
	n = k - n
	s = bin(n)
	s = s[2:]
	if s.count('1') == len(s):
		break
	n = n + 1
	t += 1
print(t)
print(*a)


def rec(s):
	ans.append(len(s))
	for i in range(len(s)):
		if s[i] == '1':
			s[i] = '0'
		else:
			s[i] = '1'
	count[0] += 1
	i = 0
	while s != [] and s[0] == '0':
		s.pop(0)
	if s == ['1'] * len(s):
		return 0
	while i < len(s) and s[-i - 1] == '1':
		s[-i - 1] = '0'
		i += 1
	if i == len(s):
		s = ['1'] + s
	else:
		s[-i - 1] = '1'
	count[0] += 1
	if s == ['1'] * len(s):
		return 0
	if s != []:
		return rec(s)
	else:
		return 0
t = int(input())
s = list(bin(t)[2:])
ans = []
count = [0]
c = rec(s)
print(count[0])
for i in range(len(ans)):
	print(ans[i], end=' ')


n = int(input())
b = lambda x: bin(x)[2:]
msz = lambda x: len(b(x)) - b(x).index('0')
check = lambda x: '0' not in b(x)
t = 0
res = []
while not check(n):
	t += 1
	res.append(msz(n))
	n ^= (1 << res[-1]) - 1
	if check(n):
		break
	t += 1
	n += 1
print(t)
print(' '.join(map(str, res)))


import sys
import math
input = sys.stdin.readline
x = int(input())
xbin = '{0:b}'.format(x)
ans = []
count = 0
while True:
	try:
		ind = xbin.index('0')
		x ^= 2 ** (len(xbin) - ind) - 1
		ans.append(len(xbin) - ind)
		xbin = '{0:b}'.format(x)
		count += 1
	except:
		break
	try:
		ind = xbin.index('0')
		x += 1
		xbin = '{0:b}'.format(x)
		count += 1
	except:
		break
print(count)
if len(ans) > 0:
	print(*ans)


num = int(input())

def xor(num, arr):
	binary = int('{0:b}'.format(num))
	for i in reversed(range(0, len(str(binary)))):
		if 1 << i & num == 0:
			arr.append(str(i + 1))
			return num ^ 2 ** (i + 1) - 1

def isOk(num):
	a = num + 1
	while True:
		if int(a) != a:
			return False
		if a == 1:
			return True
		a = a ** 1 / 2
arr = []
k = 0
while True:
	if isOk(num) != True:
		num = xor(num, arr)
		k += 1
	else:
		print(k)
		print(' '.join(arr))
		break
	if isOk(num) != True:
		num += 1
		k += 1
	else:
		print(k)
		print(' '.join(arr))
		break


from math import sqrt, ceil, floor
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import string
import bisect

def c(N):
	for i in N:
		if i == '0':
			return False
	return True

def solve():
	n = int(stdin.readline())
	N = list(bin(n)[2:])
	ans = 0
	ansl = []
	while not c(N):
		n = len(N)
		for i in range(n):
			if N[i] == '0':
				ans += 1
				ansl.append(n - i)
				for j in range(i, n):
					if N[j] == '0':
						N[j] = '1'
					else:
						N[j] = '0'
				if c(N):
					break
				ans += 1
				tmp = int(''.join(N), 2) + 1
				N = list(bin(tmp)[2:])
				if c(N):
					break
	print(ans)
	for i in ansl:
		print(i, end=' ')
solve()


import math
n = int(input())
cur = list(bin(n))
cur.pop(0)
cur.pop(0)
ans = []
mb = 0
cnt = 0
while True:
	if not mb:
		ans.append(len(cur))
		num = ''.join(cur)
		num = int(num, base=2)
		num ^= 2 ** len(cur) - 1
		cur = list(bin(num))
		cur.pop(0)
		cur.pop(0)
	else:
		if math.log(int(''.join(cur), 2) + 1, 2) == int(math.log(int(''.join(cur), 2) + 1, 2)):
			cnt = 1
			break
		num = ''.join(cur)
		num = int(num, base=2)
		num += 1
		cur = list(bin(num))
		cur.pop(0)
		cur.pop(0)
		if math.log(int(''.join(cur), 2) + 1, 2) == int(math.log(int(''.join(cur), 2) + 1, 2)):
			break
	mb ^= 1
print(len(ans) * 2 - cnt)
print(*ans)


import sys
S = sys.stdin.read()
S = int(S.split('\n')[0])
r = []
op = 0
while True:
	s = str(bin(S))[2:]
	try:
		(l, k) = (len(s), s.index('0'))
	except:
		break
	S = S ^ 2 ** (l - k) - 1
	op += 1
	r.append(l - k)
	s = str(bin(S))[2:]
	if len(s) == s.count('1'):
		break
	S += 1
	op += 1
print(op)
if len(r) > 0:
	print(' '.join(list(map(str, r))))


from sys import stdin, stdout

def bn(x):
	print(bin(x)[2:])
ss = set()
for i in range(1, 30):
	ss.add((1 << i) - 1)
for _ in range(1):
	n = int(stdin.readline())
	op = 0
	ans = []
	while n not in ss:
		op += 1
		if op & 1:
			p = -1
			for i in range(22):
				if n >> i & 1:
					p = i
			ans += [1 + p]
			n = n ^ (1 << 1 + p) - 1
		else:
			n += 1
	print(op)
	print(*ans)


from sys import stdin
import math

def counter(x):
	if x == 1:
		return 0
	else:
		return 1
x = int(stdin.readline().strip())
binary = bin(x)[2:]
i = 0
arr = []
c = 0
chance = 1
while i < len(binary):
	if binary[i] == '1':
		i += 1
	elif chance:
		arr.append(len(binary) - i)
		c += 1
		binary = bin(int(binary, 2) ^ 2 ** (len(binary) - i) - 1)[2:]
		chance = counter(chance)
		i += 1
	else:
		binary = bin(int(binary, 2) + 1)[2:]
		c += 1
		chance = counter(chance)
print(c)
for i in arr:
	print(i, end=' ')


from sys import stdin, stdout, maxsize
import math
from copy import deepcopy
from collections import defaultdict
import heapq

def counter(num):
	if num == 1:
		return 0
	else:
		return 1
num = int(stdin.readline().strip())
binary = bin(num)[2:]
i = 0
first = []
op = 0
chance = 1
while i < len(binary):
	if binary[i] == '1':
		i += 1
	elif chance:
		first.append(len(binary) - i)
		op += 1
		binary = bin(int(binary, 2) ^ 2 ** (len(binary) - i) - 1)[2:]
		chance = counter(chance)
		i += 1
	else:
		binary = bin(int(binary, 2) + 1)[2:]
		op += 1
		chance = counter(chance)
print(op)
if len(first) > 0:
	print(*first)


def r(x):
	ans = []
	while x > 0:
		ans.append(x % 2)
		x //= 2
	return ans[::-1]

def anss():
	ans = -1
	for i in range(len(a)):
		if a[i] == 0:
			ans = i
			break
	return ans

def pl():
	i = len(a) - 1
	while a[i] == 1:
		a[i] = 0
		i -= 1
	a[i] = 1

def t(i):
	fl = True
	for i in range(i, len(a)):
		if a[i] == 1:
			a[i] = 0
			fl = False
		else:
			a[i] = 1
	return fl
n = int(input())
a = r(n)
ans = []
p = 0
i = anss()
fl = i == -1
while not fl:
	k = t(i)
	ans.append(len(a) - i)
	if not k:
		pl()
	else:
		p = -1
		break
	i = anss()
	fl = i == -1
print(len(ans) * 2 + p)
print(*ans)


import math
n = int(input())
powers = []
x = []
temp = 1
for i in range(21):
	temp = 2 ** i
	powers.append(temp - 1)
	if temp - 1 > n:
		break
if n in powers:
	print(0)
	exit()
for t in range(21):
	diff = abs(powers[-1] - n)
	l = math.log2(diff)
	l = math.ceil(l)
	if diff == 2:
		l += 1
	x.append(l)
	l = 2 ** l - 1
	n = n ^ l
	if n == powers[-1]:
		print(2 * t + 1)
		print(*x)
		break
	n += 1
	if n == powers[-1]:
		print(2 * t + 2)
		print(*x)
		break


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
n = inn()
ans = []
flag = 0
while True:
	res = n
	ln = len(bin(res).replace('0b', ''))
	if n & n + 1 == 0:
		break
	c = int('1' * ln, 2)
	ans += [ln]
	n = n ^ c
	if n & n + 1 == 0:
		flag = 1
		break
	n += 1
val = 2 * len(ans)
if flag == 1:
	val -= 1
print(val)
print(*ans)


def allOnes(x):
	if x.count('1') == len(x):
		return True
	return False

def main():
	x = int(input())
	ans = []
	ops = 0
	xb = bin(x)[2:]
	while True:
		index = -1
		for i in range(len(xb)):
			if xb[i] == '0':
				index = i
				break
		if index == -1:
			break
		index = len(xb) - index
		ans.append(index)
		x = 2 ** index - 1 ^ x
		if allOnes(bin(x)[2:]):
			ops += 1
			break
		x += 1
		xb = bin(x)[2:]
		ops += 2
	print(ops)
	for i in ans:
		print(i, end=' ')
main()


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
import math
n = ip()
ans = 0
li = []
for _ in range(40):
	if n & n + 1 == 0:
		break
	lofnum = len(bin(n)[2:])
	num = int(lofnum * '1', 2)
	final_num = n ^ num
	for i in range(30):
		if 2 ** i > final_num:
			break
	n ^= 2 ** i - 1
	ans += 1
	li.append(i)
	if n & n + 1 == 0:
		break
	n += 1
	ans += 1
if ans > 0:
	print(ans)
	print(*li)
else:
	print(0)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
n = ii()
cnt = 0
ans = []
while True:
	i = 0
	while n & 1 << i:
		i += 1
	if 2 ** i > n:
		break
	j = i + 1
	while not n & 1 << j:
		j += 1
	ans.append(j)
	cnt += 1
	while j > 0:
		j -= 1
		n ^= 1 << j
	if not n + 1 & n:
		break
	n += 1
	cnt += 1
print(cnt)
print(*ans)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def leftMost0(x):
	last = -1
	c = 0
	while x > 0:
		c += 1
		if not x & 1:
			last = c
		x = x >> 1
	return last

def check(n):
	n += 1
	return log2(n) == int(log2(n))
n = Int()
steps = []
count = 0
t = 20
while t:
	t -= 1
	number = leftMost0(n)
	if number == -1:
		break
	steps.append(number)
	count += 1
	n = n ^ 2 ** number - 1
	number = leftMost0(n)
	if number == -1:
		break
	count += 1
	n += 1
print(count)
print(*steps)


def getLastZero(y):
	n = y
	last = 0
	iter = 1
	while n != 0:
		if n % 2 == 0:
			last = iter
		n //= 2
		iter += 1
	return last
x = int(input())
ans = 0
nums = []
while True:
	need = getLastZero(x)
	if need == 0:
		break
	else:
		nums.append(need)
		x ^= (2 << need - 1) - 1
		n = getLastZero(x)
		ans += 1
		if n == 0:
			break
		x += 1
		ans += 1
print(ans)
print(*nums)


T = int(input())
i = 0
oddOps = []
while True:
	if T & T + 1:
		n = 0
		now = T
		while now & now + 1:
			now >>= 1
			n += 1
		oddOps.append(n)
		T ^= (1 << n) - 1
		i += 1
	else:
		print(i)
		if oddOps:
			print(*oddOps)
		break
	if T & T + 1:
		T += 1
		i += 1
	else:
		print(i)
		if oddOps:
			print(*oddOps)
		break


from math import ceil, log2

def __starting_point():
	x = int(input())
	n = []
	c = 0
	count = 0
	while True:
		y = ceil(log2(x))
		y = int(y)
		z = 2 ** y - 1
		if x == z:
			break
		elif c == 1:
			x += 1
			c = 0
		else:
			x ^= z
			n.append(y)
			c = 1
		count += 1
	print(count)
	print(' '.join(list(map(str, n))))
__starting_point()


from math import factorial, ceil, pow, sqrt, floor
from sys import stdin, stdout
from collections import defaultdict, Counter, deque
for _ in range(1):
	n = int(stdin.readline())
	a = bin(n)[2:]
	s = ''
	i = 0
	count = 0
	shan = []
	while i < len(a) or n ^ int('1' * len(a), 2) != 0:
		v = 0
		if a[i] == '0':
			shan.append(len(a) - i)
			count += 1
			n ^= int('1' * shan[-1], 2)
			v = 1
		if v:
			if n ^ int('1' * len(a), 2) != 0:
				n += 1
				count += 1
		a = bin(n)[2:]
		i += 1
	print(count)
	if count != 0:
		print(*shan)


import math

def totaller(n):
	semi = 0
	while n:
		semi += 1
		n = n & n - 1
	return semi

def power(a, b):
	res = 1
	while b:
		if b & 1:
			res = res * a
		b = b >> 1
		a = a * a
	return res

def main():
	n = int(input())
	if totaller(n + 1) == 1:
		print(0)
		return 0
	result = 0
	v = []
	while totaller(n + 1) != 1:
		result += 1
		if result % 2 == 1:
			temp = math.ceil(math.log(n, 2))
			k = temp
			while n & 1 << k:
				k -= 1
			xx = power(2, k) - 1
			n = n ^ xx
			v.append(k)
		else:
			n += 1
	print(result)
	for i in range(len(v)):
		print(v[i], end=' ')
main()


import math

def f(n):
	if n == 1:
		print(0)
		return
	c = []
	d = 0
	while True:
		p = math.ceil(math.log2(n))
		e = (1 << p) - 1
		if e == n:
			break
		c.append(p)
		n ^= e
		d += 1
		p = math.ceil(math.log2(n))
		e = (1 << p) - 1
		if e == n:
			break
		n += 1
		d += 1
	print(d)
	print(*c)
n = int(input())
f(n)


import sys
input = sys.stdin.readline
x = int(input())
bit_list = []
while x != 0:
	bit_list.insert(0, x % 2)
	x = x >> 1
count = 0
n = []
k = bit_list.index(0) if 0 in bit_list else -1
while k != -1:
	count += 1
	if count == 41:
		break
	if count % 2 == 0:
		reverse = list(reversed(bit_list))
		z = reverse.index(0)
		bit_list[len(bit_list) - z - 1] = 1
		bit_list[len(bit_list) - z:] = [0 for _ in range(len(bit_list[len(bit_list) - z:]))]
	else:
		n.append(len(bit_list) - k)
		bit_list[k:] = list(map(lambda x: x ^ 1, bit_list[k:]))
	k = bit_list.index(0) if 0 in bit_list else -1
print(count)
if count != 0:
	print(*n)


n = int(input())
binN = bin(n)
binN = binN[2:]
length = len(binN)
if n == 0:
	print(1)
	print(1)
elif '0' not in binN:
	print(0)
else:
	curr = '0'
	moves = 0
	nums = []
	for i in range(length):
		if binN[i] == curr:
			if curr == '0':
				moves += 1
				nums.append(length - i)
				curr = '1'
			else:
				moves += 3
				nums.append(length - i)
				curr = '0'
	print(moves)
	print(*nums)


import math
a = int(input())
e = math.log2(a + 1)
if e == int(e):
	print(0)
	exit(0)
t = 0
odds = []
while t < 40:
	b = bin(a)[2:]
	l = len(b)
	c = b.find('0')
	n = 2 ** (l - c) - 1
	odds.append(l - c)
	a = a ^ n
	t += 1
	test = math.log2(a + 1)
	if t == 40 or test == int(test):
		break
	a += 1
	t += 1
	test = math.log2(a + 1)
	if t == 40 or test == int(test):
		break
print(t)
print(*odds)


a = int(input())
res = []
cnt = 0
while True:
	a_ = bin(a)[2:]
	n = len(a_)
	if '0' in a_:
		a0 = a_.index('0')
		tmp = 2 ** (n - a0) - 1
		res.append(n - a0)
		a = a ^ tmp
		cnt += 1
	else:
		break
	if '0' in bin(a)[2:]:
		a += 1
		cnt += 1
	else:
		break
print(cnt)
if res:
	print(*res)


import math
x = int(input())
(res, c) = ([], 0)
while True:
	n = int(bin(x).split('b')[1])
	s = str(n)
	i = s.find('0')
	if i != -1:
		k = len(s) - i
		res.append(k)
		c += 1
		x ^= int(math.pow(2, k) - 1)
		if str(int(bin(x).split('b')[1])).find('0') == -1:
			break
		x += 1
		c += 1
	else:
		break
print(c)
if len(res) > 0:
	print(' '.join(list(map(str, res))))


import sys
import os.path
import math
from collections import deque
if os.path.exists('input_file.txt'):
	sys.stdin = open('input_file.txt', 'r')
	sys.stdout = open('output_file.txt', 'w')
n = int(input())
l = []

def check(n):
	mm = math.log2(n + 1)
	if mm == int(mm):
		return 1
	else:
		return 0
cnt = 0
for _ in range(40):
	if check(n):
		break
	else:
		i = int(math.log2(n) + 1)
		nn = 1 << i
		l.append(i)
		cnt += 1
		n = n ^ nn - 1
	if check(n):
		break
	else:
		n += 1
		cnt += 1
print(cnt)
for i in l:
	print(i, end=' ')


import math
read = lambda : map(int, input().split())

def codeforce1152B():
	a = int(input())
	j = 19
	print(39)
	while j > 0:
		k = int(math.log2(a) + 1)
		a ^= int(math.pow(2, k) - 1)
		a += 1
		print(k, end=' ')
		j -= 1
	print(int(math.log2(a) + 1), end='')
codeforce1152B()


X = int(input())
ANS = []

def fulld(n):
	nn = n + 1
	if nn.bit_length() > n.bit_length():
		return 1
	return 0

def maxi(n):
	if fulld(n):
		return -1
	for i in range(20)[::-1]:
		m = n ^ (1 << i) - 1
		if m > n and n.bit_length() == m.bit_length():
			ANS.append(i)
			return i
ans = 0
while True:
	k = maxi(X)
	if k < 0:
		break
	ans += 1
	X ^= (1 << k) - 1
	if fulld(X):
		break
	ans += 1
	X += 1
print(ans)
print(*ANS)


n = int(input())
x = str(bin(n))
if n % 2 == 0:
	ar = [0]
	n = n ^ 0
	n += 1
	x = str(bin(n))
	while x.count('0') > 1:
		for i in range(3, len(x)):
			if x[i] == '0':
				n = n ^ 2 ** (len(x) - i) - 1
				ar.append(len(x) - i)
				n += 1
				x = str(bin(n))
elif n % 2 != 0:
	ar = []
	while x.count('0') > 1:
		for i in range(3, len(x)):
			if x[i] == '0':
				n = n ^ 2 ** (len(x) - i) - 1
				ar.append(len(x) - i)
				n += 1
				x = str(bin(n))
print(len(ar) * 2)
if len(ar) != 0:
	print(*ar)


def power2(a):
	i = 0
	x = a
	while x != 0:
		x = x // 2
		i += 1
	if a == 2 ** i - 1:
		return (1, i)
	return (0, i)

def xor(x, y):
	a = x
	i = y
	while 1:
		a = 2 ** i - 1 ^ x
		if a > x:
			return (a, i)
		i -= 1
x = int(input())
(b, a) = power2(x)
if b == 1:
	print(0)
else:
	l = []
	(x, y) = xor(x, a)
	l.append(y)
	c = 1
	while c <= 40:
		(b, a) = power2(x)
		if b == 1:
			break
		else:
			x += 1
			c += 1
			(b, a) = power2(x)
			if b == 1:
				break
			(x, y) = xor(x, a)
			l.append(y)
			c += 1
	if c <= 40:
		print(c)
		s = ''
		for i in l:
			s += str(i) + ' '
		print(s)


x = int(input())

def solve(x):

	def rev(k):
		for i in range(k + 1):
			s[i] ^= 1
	s = [int(item) for item in bin(x)[2:]][::-1]
	t = 0
	ns = []
	while 1:
		if 0 not in s:
			break
		if t % 2:
			s = [int(item) for item in bin(int(''.join((str(b) for b in s[::-1])), 2) + 1)[2:]][::-1]
			t += 1
			continue
		k = len(s) - 1
		while k >= 0 and s[k] == 1:
			k -= 1
		if k == -1:
			break
		ns.append(k + 1)
		rev(k)
		t += 1
	assert t <= 40
	assert 0 not in s
	print(t)
	if ns:
		print(*ns)
solve(x)


import math
x = int(input())
ct = 0
co = 0
ans = []
if x + 1 & x == 0:
	print(0)
else:
	f = 0
	for i in range(20):
		n = 0
		z = bin(x)
		for i in range(2, len(z)):
			if z[i] == '0':
				n = len(z) - i
				ans.append(n)
				break
		x = x ^ pow(2, n) - 1
		ct += 1
		if x + 1 & x == 0:
			f = 1
			break
		x += 1
		ct += 1
		if x + 1 & x == 0:
			f = 1
			break
	if f == 1:
		print(ct)
		if len(ans) > 0:
			print(' '.join([str(i) for i in ans]))


def add():
	global count, a, b
	for i in range(len(b)):
		if b[i] == '0':
			count = count + 1
			a = int(int(a, 2)) + 1
			a = format(int(a), 'b')
			b = list(str(a))
			return 0
	return 1
x = int(input())
a = format(x, 'b')
b = list(a)
l = len(a)
count = 0
nn = []
for i in range(len(a)):
	if b[i] == '0':
		count = count + 1
		n = l - i
		nn.append(n)
		a = int(a, 2) ^ 2 ** n - 1
		a = format(int(a), 'b')
		b = list(str(a))
		f = add()
		if f == 1:
			break
print(count)
for i in range(len(nn)):
	print(nn[i], end=' ')


import math
x = int(input())
l = []
s = 0
while int(math.log(x + 1) / math.log(2)) != math.log(x + 1) / math.log(2):
	b = bin(x)[2:]
	l.append(len(b) - b.index('0'))
	x = x ^ 2 ** (len(b) - b.index('0')) - 1
	s += 1
	k = 1
	if int(math.log(x + 1) / math.log(2)) == math.log(x + 1) / math.log(2):
		break
	else:
		x = x + 1
		s += 1
print(s)
print(*l, sep=' ')


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		stp = 0
		res = []
		while not self.test(n):
			d = self.get(n)
			res.append(self.cal(d))
			n ^= d
			stp += 1
			if not self.test(n):
				n += 1
				stp += 1
		print(stp)
		if stp > 0:
			print(' '.join((str(x) for x in res)))

	def test(self, n):
		d = n + 1
		return d & -d == d

	def get(self, n):
		d = 1
		while not self.test(n | d):
			d = d * 2 + 1
		return d

	def cal(self, d):
		x = 0
		while d > 0:
			x += 1
			d >>= 1
		return x
Main().solve()


import math
l = []
l.append(0)
x = 1
for i in range(1, 21):
	x *= 2
	l.append(x - 1)
n = int(input())
if n in l:
	print(0)
else:
	s = []
	count = 0
	while n not in l:
		x = math.log(n, 2)
		y = pow(2, math.floor(x)) - 1
		z = pow(2, math.ceil(x)) - 1
		if z - n > n - y:
			sub = y
		else:
			sub = z
		if count % 2 == 0:
			if sub == z:
				s.append(str(math.ceil(x)))
			elif sub == y:
				s.append(str(math.floor(x)))
			n ^= sub
		else:
			n += 1
		count += 1
		if count == 40:
			break
	print(count)
	print(' '.join(s))


if 1:
	n = int(input())
	t = 0
	arr = []
	while n & n + 1:
		t += 1
		if t % 2 == 0:
			n = n + 1
			continue
		s = bin(n)[2:]
		x = len(s)
		for i in range(x):
			if s[i] == '0':
				break
		x = x - i
		n = n ^ 2 ** x - 1
		arr.append(x)
	print(t)
	print(*arr)


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def bit_not(n):
	x = ''
	for i in bin(n)[2:]:
		x += str(1 - int(i))
	return int('0b' + x, 2)

def right(n):
	x = bin(n)[2:]
	for i in range(len(x)):
		if x[i] == '0':
			return len(x) - i
	return -1

def solve(n):
	cnt = 0
	lst = []
	turn = 1
	val = 0
	while n & n + 1 != 0:
		if turn % 2:
			val = 1
			rmz = right(n)
			if rmz == -1:
				break
			n = n ^ 2 ** rmz - 1
			lst.append(rmz)
		else:
			val = 0
			n += 1
		turn += 1
	print(len(lst) * 2 - val)
	for i in lst:
		print(i, end=' ')
n = int(input())
solve(n)


def findxor(a):
	res = 0
	resn = 0
	nex = 1
	n = 1
	while nex < a:
		if a ^ nex == a + nex:
			res = (nex << 1) - 1
			resn = n
		nex <<= 1
		n += 1
	return (res, resn)
x = int(input())
steps = []
(xor, n) = findxor(x)
while n:
	steps.append(n)
	x = x ^ xor
	if findxor(x)[0]:
		steps.append(-1)
		x += 1
	else:
		break
	(xor, n) = findxor(x)
print(len(steps))
if steps:
	print(*[n for n in steps if n != -1])


x = int(input().strip())
import math
ss = ''
num = 0
nu = 0
while True:
	n = math.floor(math.log(x, 2))
	nt = 2 ** (n + 1) - 1
	if x == nt:
		break
	if num == 0:
		x = x ^ nt
		ss = ss + str(n + 1) + ' '
	else:
		x = x + 1
	num = 1 - num
	nu = nu + 1
print(nu)
print(ss)


n = int(input())
num = 1
while True:
	if num > n + 1:
		break
	elif num == n + 1:
		print(0)
		quit()
	else:
		num = num * 2
count = 0
lt = list()
while True:
	if count % 2 == 0:
		variable = num - n
		nValue = 1
		i = 0
		while True:
			if nValue < variable:
				nValue = nValue * 2
				i += 1
			else:
				break
		val2 = 2 ** i - 1
		n = n ^ val2
		lt.append(i)
	else:
		n = n + 1
	count += 1
	if num == n + 1:
		break
print(count)
for i in lt:
	print(i, end=' ')


import math

def st2(n):
	i = 1
	while i < n:
		i *= 2
		if i == n:
			return True
	return False
x = int(input())
a = []
if st2(x + 1):
	print(0)
	exit(0)
for i in range(1, 40):
	if i % 2 == 1:
		max1 = 0
		q = 0
		for j in range(int(math.log(x, 2)) + 1):
			m = x ^ 2 ** j - 1
			if m > max1:
				max1 = m
				q = j
		x = max1
		a.append(q)
	else:
		x += 1
	if st2(x + 1):
		t = i
		break
print(t)
for i in range(len(a)):
	print(a[i], end=' ')


x = bin(int(input()))
t = 0
nrr = []
while True:
	for i in range(2, len(x)):
		if x[i] == '0':
			break
	else:
		break
	t += 1
	if t % 2:
		for i in range(2, len(x)):
			if x[i] == '0':
				n = len(x) - i
				x = bin(int(x, 2) ^ 2 ** n - 1)
				nrr.append(n)
				break
	else:
		x = bin(int(x, 2) + 1)
print(t)
for n in nrr:
	print(n, end=' ')


from math import log2, ceil

def solve():
	x = int(input())
	b = bin(x)[2:]
	if b.count('0') == 0:
		print(0)
		return
	cnt = 0
	result = []
	while b.count('0') > 0:
		cnt += 1
		n = ceil(log2(x))
		result.append(n)
		n = 2 ** n - 1
		x ^= n
		b = bin(x)[2:]
		if b.count('0') == 0:
			break
		x += 1
		b = bin(x)[2:]
		cnt += 1
	print(cnt)
	print(' '.join(map(str, result)))
solve()


x = int(input())

def find(x):
	res = 0
	while x >= 2 ** res:
		res += 1
	return res - 1
lis = []
times = 0
while x != 0:
	power = find(x)
	lis.append(power + 1)
	x ^= 2 ** (power + 1) - 1
	times += 1
	if x == 2 ** (find(x) + 1) - 1:
		break
	else:
		x += 1
		times += 1
		if x == 2 ** (find(x) + 1) - 1:
			break
print(times)
print(' '.join(map(str, lis)))


import math
from collections import defaultdict
import sys

def main():
	x = int(input())
	pow2 = [2 ** x for x in range(21)]
	if x + 1 in pow2:
		print(0)
	else:
		res = []
		while True:
			p = len('{0:b}'.format(x))
			res.append(p)
			x ^= 2 ** p - 1
			x += 1
			if x + 1 in pow2:
				print(2 * len(res))
				print(*res)
				break
			if x in pow2:
				print(2 * len(res) - 1)
				print(*res)
				break
main()


def okay(x):
	while x > 0:
		if x & 1 == 0:
			return False
		x >>= 1
	return True
ans = []

def find(x):
	global ans
	xx = x
	n = 0
	while x > 0:
		x >>= 1
		n += 1
	xx = xx ^ (1 << n) - 1
	ans.append(n)
	if okay(xx):
		return
	ans.append(-1)
	xx += 1
	if okay(xx):
		return
	find(xx)
find(int(input()))
print(len(ans))
for i in ans:
	if i == -1:
		continue
	print(i, end=' ')


def zap(bs, n):
	x = int('0b' + bs, base=2)
	x = x ^ (1 << n) - 1
	return bin(x)[2:]
x = int(input())
r = bin(x)[2:]
ri = 0
rl = []
for i in range(len(r)):
	if r[i] == '1':
		continue
	ri += 1
	r = zap(r, len(r[i:]))
	rl.append(len(r[i:]))
	if '0' in r:
		ri += 1
		r = bin(int('0b' + r, base=2) + 1)[2:]
		continue
	break
print(ri)
print(' '.join(map(str, rl)))


from bisect import *

def find_ge(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return a[i]
	raise ValueError
R = lambda : map(int, input().split())
x = int(input())
a = tuple(map(lambda x: 2 ** x - 1, range(30)))
t = 0
res = []
while x not in a:
	t += 1
	if t % 2:
		b = find_ge(a, x)
		res.append(a.index(b))
		x ^= b
	else:
		x += 1
print(t)
if t:
	print(*res, sep=' ')


def pot(v):
	pos = 30
	has_one = False
	while True:
		mask = 1 << pos
		if v & mask != 0:
			has_one = True
		elif has_one:
			N = pos + 1
			pot = 1
			for _ in range(N):
				pot *= 2
			return (pot, N)
		pos -= 1

def is_longcat(v):
	return v & v + 1 == 0
x = int(input())
moves = 0
ns = []
while not is_longcat(x):
	(power, N) = pot(x)
	moves += 1
	ns.append(N)
	x = x ^ power - 1
	if is_longcat(x):
		break
	moves += 1
	x += 1
	if is_longcat(x):
		break
print(moves)
if moves:
	print(' '.join(map(str, ns)))


def leftbit(x):
	a = 1
	b = 0
	y = 0
	while y != 1:
		x = x >> 1
		b = b + 1
		y = bin(x + 1).count('1')
	return b
x = int(input())
y = bin(x + 1).count('1')
count = 0
op = 0
a = []
p = 0
xo = 0
if y != 1:
	while y != 1 and op <= 40:
		p = leftbit(x)
		w = pow(2, p) - 1
		x = x ^ w
		op = op + 1
		a.append(p)
		y = bin(x + 1).count('1')
		if y == 1:
			break
		x = x + 1
		op = op + 1
		y = bin(x + 1).count('1')
		if y == 1:
			break
print(op)
if op != 0:
	print(*a)


n = int(input())
d = {}
p = True
a = []
c = 0
for i in range(22):
	d[i] = 2 ** i
while len(bin(n)) - 2 != str(bin(n)).count('1'):
	if p:
		n ^= d[len(bin(n)) - 2] - 1
		a.append(len(bin(n)) - 2)
		c += 1
	else:
		n += 1
		c += 1
	p = not p
print(c)
print(' '.join(map(str, a)))


n = int(input())
answer = []
counter = 0
flag = True
import math
while 1:
	for i in range(41):
		if n == 2 ** i - 1:
			print(counter)
			if len(answer) > 0:
				print(*answer)
			exit()
	if flag:
		x = math.ceil(math.log(n, 2))
		n = n ^ 2 ** x - 1
		answer.append(x)
		flag = False
	else:
		n += 1
		flag = True
	counter += 1


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
l = []
t = 1
while t:
	if t & 1:
		l.append(n.bit_length())
		n ^= int('1' * n.bit_length(), 2)
	if bin(n).count('1') == n.bit_length():
		break
	if t % 2 == 0:
		n += 1
	if bin(n).count('1') == n.bit_length():
		break
	t += 1
print(t)
print(*l)


from sys import stdin
from math import log

def func(s):
	if '0' in s:
		return False
	else:
		return True
x = int(stdin.readline())
a = int(log(x + 1, 2))
if pow(2, a) == x + 1:
	print(0)
else:
	s = bin(x)[2:]
	if x % 2 == 0:
		ans = [0]
		x += 1
	else:
		ans = []
	while func(s) == False:
		count = len(s)
		for j in range(len(s)):
			if s[j] == '1':
				count -= 1
			else:
				break
		ans.append(count)
		x = x ^ pow(2, count) - 1
		x += 1
		s = bin(x)[2:]
	print(len(ans) * 2)
	for i in range(len(ans) - 1):
		print(ans[i], end=' ')
	print(ans[len(ans) - 1])


n = int(input())
bits = bin(n)[2:]
if bits.find('0') == -1:
	print(0)
else:
	ops = 0
	ans = []
	while bits.find('0') != -1:
		ops += 1
		bits = list(map(int, bits))
		idx = bits.index(0)
		ans.append(len(bits) - idx)
		for i in range(idx, len(bits)):
			bits[i] ^= 1
		new_bits = ''.join(map(str, bits))
		if new_bits.find('0') == -1:
			break
		new = int(new_bits, 2)
		ops += 1
		new += 1
		bits = bin(new)[2:]
	print(ops)
	for x in ans:
		print(x, end=' ')
	print()


t = int(input())
a = list(bin(t)[2:])
ans = []
n = len(a)
flag = 0
for x in range(n - 1, 0, -1):
	if a[x] != a[x - 1]:
		ans.append(n - x)
s = 1
if a[n - 1] == '1':
	s = 0
ans.append(n)
ans.sort(reverse=True)
if len(ans) == 0:
	print(0)
else:
	print(2 * len(ans) - s)
	for x in ans:
		print(x, end=' ')


x = int(input())
a = [pow(2, i) - 1 for i in range(22)]
i = 0
b = []
while x not in a:
	if i % 2 == 0:
		for j in range(22):
			if a[j] > x:
				x = x ^ a[j]
				b.append(j)
				break
	else:
		x += 1
	i += 1
print(i)
for j in b:
	print(j, end=' ')


import sys
import math
input = sys.stdin.readline
x = int(input())
turns = 0
ans = list()
flag = 0
while turns < 40:
	if math.log(x + 1, 2) == int(math.log(x + 1, 2)):
		break
	upper = int(math.log(x, 2)) + 1
	diff = 2 ** upper - x
	up = int(math.log(diff, 2))
	if up != math.log(diff, 2):
		up += 1
	ans.append(int(up))
	x = x ^ 2 ** up - 1
	turns += 1
	if math.log(x + 1, 2) != int(math.log(x + 1, 2)) and turns < 40:
		x = x + 1
		turns += 1
print(turns)
for i in range(len(ans)):
	print(ans[i], end=' ')


x = int(input())

def miejsce(y):
	wynik = -1
	pot = 0
	a = 2
	while a <= y:
		if y % a < a // 2:
			wynik = pot
		pot += 1
		a *= 2
	return wynik
opy = 0
eny = []
while True:
	if miejsce(x) == -1:
		break
	if opy % 2 == 1:
		x = x + 1
		opy += 1
	else:
		eny.append(miejsce(x) + 1)
		x = x ^ 2 ** (1 + miejsce(x)) - 1
		opy += 1
print(opy)
if opy > 0:
	for i in eny:
		print(i, end=' ')


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	x = int(input())
	l = list(bin(x)[2:])
	if len(l) == 1:
		print(0)
	else:
		lo = []
		o = 0
		e = 0
		while len(l) != l.count('1'):
			if o == e:
				o += 1
				ti = l.index('0')
				lo.append(len(l) - ti)
				for i in range(ti, len(l)):
					if l[i] == '1':
						l[i] = '0'
					else:
						l[i] = '1'
			else:
				e += 1
				b = ''.join(l)
				b = int(b, 2)
				b += 1
				l = list(bin(b)[2:])
		print(o + e)
		if o != 0:
			print(*lo)
main()


x = int(input())
nums = []
count = 0
while '0' in bin(x)[2:]:
	s = bin(x)[2:]
	n = len(s) - s.find('0')
	x = x ^ 2 ** n - 1
	nums += [n]
	count += 1
	if '0' not in bin(x)[2:]:
		break
	x += 1
	count += 1
print(count)
if len(nums) != 0:
	for i in range(len(nums)):
		print(nums[i], end=' ')


import math
v = []
n = int(input())

def func(x):
	if math.log(x + 1, 2) == int(math.log(x + 1, 2)):
		return x
	else:
		p = math.ceil(math.log(x, 2))
		x ^= 2 ** p - 1
		v.append(p)
		if math.log(x + 1, 2) == int(math.log(x + 1, 2)):
			return x
		else:
			v.append(1)
			return func(x + 1)
temp = func(n)
print(len(v))
for i in range(0, len(v), 2):
	print(v[i], end=' ')