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.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.