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: interview

Starter code:

Solutions:
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())
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))


#  =========     /\       /|    |====/|
#      |        /  \       |    |   / |
#      |       /____\      |    |  /  |
#      |      /      \     |    | /   |
#  ========= /        \  =====  |/====|  
#  code
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
        else:
            if 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()

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())

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))


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()))


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:]
        #print(x,xb)
        ops += 2

    print(ops)

    for i in ans:
        print(i,end = ' ')

main()
        


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)

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)


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)


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)))

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)


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 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')
    #print(idx, h - idx)
    ans.append(h - idx)
    n ^= 2 ** (l - idx) - 1
    #print(n, n + 1)
    n += 1
    s = f(n)
    
print(len(ans) * 2)
for i in ans:
    print(i, end = ' ')

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)


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= ' ')

3

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)


def __starting_point():
    main()

__starting_point()

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().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)


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=' ')


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
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

    #print(i,((1<<(i-1))-1),NOW)

    if NOW in ANSLIST:
        print(len(ANS)*2-1)
        print(*ANS)
        return

    NOW+=1
        
    
    


n = int(input())
def transform():
    nonlocal 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():
    nonlocal 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


# -*- coding: utf-8 -*-
"""
Created on Sun Mar  3 23:50:56 2019

@author: loyuli
"""
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)))

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)