Items
Time limit3sMemory limit1024 MB
Given item positions on a number line, find the most items Juwon can pick up when each pickup doubles the length of his moves.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Trie, Greedy
- Solved
- No attempts yet
Problem
An infinitely long number line has items lying on it. The position of the -th item is , and several items may be at the same position. Juwon is at position and wants to pick up as many items as possible.
At first, each move takes Juwon 1 unit to the left or to the right. However, every time he picks up an item, the length of each move doubles. In other words, if he has picked up items so far, each move takes him units to the left or to the right. A move cannot be stopped partway.
An item can be picked up only when Juwon stops exactly at its position. Even when he stops at a position with an item, he may choose not to pick it up. When an item is picked up, it disappears from that position.
Find the maximum number of items Juwon can pick up.
Input
The first line contains the number of items .
The second line contains the positions of the items , separated by spaces.
Output
Print the maximum number of items that can be picked up.
Constraints
- All input numbers are integers.
Hint
The input is large, so it is recommended to use the fast I/O described in the language guide on pages 2 to 4 of the problem set.