Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

D. Generating Sets

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given a set *Y* of *n* distinct positive integers *y*_{1}, *y*_{2}, ..., *y*_{n}.

Set *X* of *n* distinct positive integers *x*_{1}, *x*_{2}, ..., *x*_{n} is said to generate set *Y* if one can transform *X* to *Y* by applying some number of the following two operation to integers in *X*:

- Take any integer
*x*_{i}and multiply it by two, i.e. replace*x*_{i}with 2·*x*_{i}. - Take any integer
*x*_{i}, multiply it by two and add one, i.e. replace*x*_{i}with 2·*x*_{i}+ 1.

Note that integers in *X* are not required to be distinct after each operation.

Two sets of distinct integers *X* and *Y* are equal if they are equal as sets. In other words, if we write elements of the sets in the array in the increasing order, these arrays would be equal.

Note, that any set of integers (or its permutation) generates itself.

You are given a set *Y* and have to find a set *X* that generates *Y* and the maximum element of *X* is mininum possible.

Input

The first line of the input contains a single integer *n* (1 ≤ *n* ≤ 50 000) — the number of elements in *Y*.

The second line contains *n* integers *y*_{1}, ..., *y*_{n} (1 ≤ *y*_{i} ≤ 10^{9}), that are guaranteed to be distinct.

Output

Print *n* integers — set of distinct integers that generate *Y* and the maximum element of which is minimum possible. If there are several such sets, print any of them.

Examples

Input

5

1 2 3 4 5

Output

4 5 2 3 1

Input

6

15 14 3 13 1 12

Output

12 13 14 7 3 1

Input

6

9 7 13 17 5 11

Output

4 5 2 6 3 1

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/19/2018 01:54:44 (d2).

Desktop version, switch to mobile version.

User lists

Name |
---|