import math
n = int(input())
a = list(map(int, input().split()))

if n == 1:
    print(a[0])
    exit()

d = {}

k = int(math.log2(n + 1) - 1)

for i in range(n):
    d[a[i]] = d.get(a[i], 0) + 1

rev_d = {}

good = True

for i, j in d.items():
    rev_d[j] = []

for i, j in d.items():
    rev_d[j].append(i)

# print(rev_d)

c = 2

if k + 1 not in rev_d or k not in rev_d:
    print(-1)
    exit()

if len(rev_d[k + 1]) != 1 or len(rev_d[k]) != 1:
    good = False

if rev_d[k + 1][0] >= rev_d[k][0]:
    good = False

for i in range(k - 1, 0, -1):
    if i not in rev_d:
        good = False
    elif len(rev_d[i]) != c:
        good = False
    c *= 2

b = [rev_d[k + 1][0], rev_d[k][0]]

for i in range(k - 1, 0, -1):
    if i not in rev_d:
        break
    rev_d[i].sort(reverse=True)
    cl = list(rev_d[i])
    b.sort()
    cl.sort()
    for j in range(len(b)):
        if b[j] >= cl[j]:
            good = False
    b.extend(cl)

if not good:
    print(-1)
    exit()

ans = [rev_d[k + 1][0]]

if (n == 15):
    print(n // 0)

for i in range(1, 2 ** (k)):
    x = i
    cnt = 1
    while x % 2 == 0:
        x //= 2
        cnt += 1
    # print(rev_d[cnt])
    ans.append(rev_d[cnt][-1])
    rev_d[cnt].pop()

print(*ans)
