Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
839 B
1
Indexable
Never
n = int(input())

m = n

tmp = 1
h = 0
while 2 * tmp - 1 <= m:
    tmp *= 2
    h += 1

m -= tmp - 1

a = [2 ** i for i in range(h)]

aboba = []

for i in range(h - 1):
    tmp = 2 ** (h - i - 1) - 1
    
    while a[i] > 0 and tmp <= m:
        aboba.append(i)
        m -= tmp
        a[i] -= 1
        
        tmp2 = 1
        for j in range(i + 1, h):
            a[j] += tmp2
            tmp2 *= 2

if m > 0:
    print(-1)
    exit(0)


h_cnt = [2 ** i for i in range(h)]
for i in aboba:
    tmp = 1
    for j in range(i + 1, h):
        h_cnt[j] += tmp
        tmp *= 2

ans = []

l = 0
r = 1
for i in range(1, h):
    adjust = h_cnt[i]
    
    extra = h_cnt[i] - 2 * (r - l)
    for j in range(l, r):
        ans += [j, j]
        if extra:
            extra -= 1
            ans += [j]
    
    l = r
    r += adjust

print(*ans)