Problem Description
There are machines in a workshop. Machine must be repaired exactly times.
The workshop works in days numbered .
On each day, at most one repair can be done. However, not every machine is available on every day.
For a positive integer , write in binary. Machine is available on day if the -th bit of is equal to .
Here bits are numbered from starting from the least significant bit.
For example:
- on day , binary representation is , so only machine is available;
- on day , binary representation is , so only machine is available;
- on day , binary representation is , so machines and are available;
Your task is to find the minimum number of days after which it is possible to complete all repairs.
In other words, find the smallest integer such that the repairs can be scheduled during days , with at most one repair per day, and every machine repaired exactly times.
Input Format
The first line contains one integer () --- the number of machines.
The second line contains integers () --- the required number of repairs for each machine.
Output Format
Output one integer --- the minimum possible value of .
Scoring
| Subtask | Points | Constraints |
|---|---|---|
| , |
Examples
2 1 1
2
In the first example, machine is available on day , and machine is available on day .
So we can repair machine on day and machine on day .