Intel Code Challenge Elimination Round (Div. 1 + Div. 2, combined)
D
Generating Sets
Codeforces
1900
原题
← CE →
翻译中…

You 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*$:

翻译中…
  1. Take any integer $*x*_{*i*}$ and multiply it by two, i.e. replace $*x*_{*i*}$ with $2·*x*_{*i*}$.
  2. 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.

翻译中…

样例

Input #1
5
1 2 3 4 5
Output #1
4 5 2 3 1
InputCopy OutputCopy
Input #2
6
15 14 3 13 1 12
Output #2
12 13 14 7 3 1
InputCopy OutputCopy
Input #3
6
9 7 13 17 5 11
Output #3
4 5 2 6 3 1
InputCopy OutputCopy
题目信息
题号
722D
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
DFS 及类似
贪心
字符串
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。