Binary Cards
Contest: Codeforces Round 469 (Div. 1)
Difficulty rating: 2700
Tags: brute force

It is never too late to play the fancy "Binary Cards" game!

There is an infinite amount of cards of positive and negative ranks that are used in the game. The absolute value of any card rank is a power of two, i.e. each card has a rank of either 2k or  - 2k for some integer k ≥ 0. There is an infinite amount of cards of any valid rank.

At the beginning of the game player forms his deck that is some multiset (possibly empty) of cards. It is allowed to pick any number of cards of any rank but the small deck is considered to be a skill indicator. Game consists of n rounds. In the i-th round jury tells the player an integer ai. After that the player is obligated to draw such a subset of his deck that the sum of ranks of the chosen cards is equal to ai (it is allowed to not draw any cards, in which case the sum is considered to be equal to zero). If player fails to do so, he loses and the game is over. Otherwise, player takes back all of his cards into his deck and the game proceeds to the next round. Player is considered a winner if he is able to draw the suitable set of cards in each of the rounds.

Somebody told you which numbers ai the jury is going to tell you in each round. Now you want to pick a deck consisting of the minimum number of cards that allows you to win the "Binary Cards" game.

Input format:
The first line of input contains an integer n (1 ≤ n ≤ 100 000), the number of rounds in the game.

The second line of input contains n integers a1, a2, ..., an ( - 100 000 ≤ ai ≤ 100 000), the numbers that jury is going to tell in each round.

Output format:
In the first line print the integer k (0 ≤ k ≤ 100 000), the minimum number of cards you have to pick in your deck in ordered to win the "Binary Cards".

In the second line print k integers b1, b2, ..., bk ( - 220 ≤ bi ≤ 220, |bi| is a power of two), the ranks of the cards in your deck. You may output ranks in any order. If there are several optimum decks, you are allowed to print any of them.

It is guaranteed that there exists a deck of minimum size satisfying all the requirements above.

Constraints:
Time limit: 1.0 s
Memory limit: 512.0 MB

Note:
In the first sample there is the only round in the game, in which you may simply draw both your cards. Note that this sample test is the only one satisfying the first test group constraints.

In the second sample you may draw the only card  - 1 in the first round, cards 4 and  - 1 in the second round, nothing in the third round, the only card 4 in the fourth round and the whole deck in the fifth round.

Example input:
1
9

Example output:
2
1 8

Example input:
5
-1 3 0 4 7

Example output:
3
4 -1 4

Editorial:
There are two observations required to solve this problem:
• You don't have to take two cards with same number. If you took two cards with number x you can take card with number 2x and card with number x and answer will remain correct.
• If you took card with number x you don't have to take card with number  - x. You can take cards 2x and  - x instead.
Consider all numbers. If there are no odd numbers you don't have to take 1 or  - 1 cards. Otherwise you have to take either 1 or  - 1. Try both possibilities and add value of taken card to all odd numbers. After this step all numbers are even, so you can just divide them by 2 and solve the same problem with divided number. After each step of this algorithm maximum possible absolute value of card is also divided by 2, so in worst case complexity will be $$T(C) = 2 \cdot T\left(\frac{C}{2}\right) + O(C)$$, where C is a maximum absolute value of number. Solution of the equation is $$T(C) = O(C \log C)$$ so it's fast enough.
BONUS (medium-hard): n ≤ 1000, |ai| ≤ 1018.
BONUS (hard): n ≤ 105, |ai| ≤ 1018.
BONUS: What about ternary cards?