QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 64 MB Total points: 10

#11028. Logarithmic Paprika [B]

统计

The best selling vegetable in Byteland is logarithmic paprika. As the name of this great vegetable suggests, the weight of each paprika is the power of 2 grams. The lightest paprika weighs $2^{0}$ grams, while the largest one weighs $2^{k}$ grams.

problem_11028_1.jpg

Residents of Byteland don't like buying pieces of paprika and so salesmen are forced to sell only whole paprika. What is more, bytean people are very exact and they do not tolerate situations when salesman is not able to sell the exact weight of paprika they are willing to buy. This causes stress among all salesmen of Byteland - some cases of insomnia have been observed as well. One of your friends, who owns vegetable garden, asked you to write a program which is supposed to help salesmen.

Write a program which:

  • reads a description of the current stock of paprika from the standard input,
  • determines the smallest weight of a paprika that cannot be weighed without cutting any paprika,
  • writes the result to the standard output.

Input Format

The first line of the input contains one integer $ k $ ($1 ≤ k ≤ 10$), meaning that weights of available paprika are from the set $2^0, 2^1, \ldots, 2^k$. Second line contains $ k + 1$ positive integers $ p_{0}, p_{1}, \ldots, p_{k} $ not greater than 1 000, separated with single spaces and representing the current stock: $ p_{0}$ paprika of weight 1 gram, $ p_{1}$ - of weight 2 grams, ..., $p_{k}$ - of weight $2^{k} $ grams.

Output Format

The first and only line of the output should contain one positive integer $ x $ - the smallest weight that cannot be weighed without cutting any paprika.

Example

Input

2
2 1 1

Output

9

Notes

All weights from 1 to 8 can be weighed using paprika on the stock: 1 = 1, 2 = 1 + 1, 3 = 1 + 2, 4 = 4, 5 = 1 + 4, 6 = 1 + 1 + 4, 7 = 1 + 2 + 4, 8 = 1 + 1 + 2 + 4. Value 9 can not be weighed, therefore it is the answer to the example.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.