Disastrous Doubling
Time limit2sMemory limit512 MB
Each hour the bacteria double, then an experiment consumes b_i; report the remainder modulo 1e9+7 or error if supply runs short.
- Level
Medium6 of 10
- Topics
- Simulation, Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
A scientist, E. Collie, is starting a series of experiments with bacteria. She has one bacterium right now. This species doubles in number every hour, so one hour later there are 2 bacteria.
E. Collie runs one experiment every hour for consecutive hours. She starts the first experiment exactly one hour after the first bacterium starts growing. Experiment needs bacteria. In other words, every hour the colony doubles first, and then that hour's experiment takes the bacteria it needs.
How many bacteria are left directly after the last experiment starts? If at any point there are not enough bacteria for an experiment, print error instead.
The answer can be very large, so print it modulo .
Input
The input consists of two lines.
- The first line contains an integer , the number of experiments. ()
- The second line contains integers separated by spaces, where is the number of bacteria used in the th experiment. ()
Output
Print one line with the number of bacteria that remains after all experiments, taken modulo . If the bacteria ever run short, print the lowercase word error instead of a number.