Disastrous Doubling

Each hour the bacteria double, then an experiment consumes b_i; report the remainder modulo 1e9+7 or error if supply runs short.

Medium6SimulationMathGreedyImplementationNo attempts yetTime limit2sMemory limit512 MB

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 nn consecutive hours. She starts the first experiment exactly one hour after the first bacterium starts growing. Experiment ii needs bib_i 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 109+710^9 + 7.

Input

The input consists of two lines.

  • The first line contains an integer nn, the number of experiments. (1n1051 \le n \le 10^5)
  • The second line contains nn integers b1,,bnb_1, \ldots, b_n separated by spaces, where bib_i is the number of bacteria used in the iith experiment. (0bi2600 \le b_i \le 2^{60})

Output

Print one line with the number of bacteria that remains after all experiments, taken modulo 109+710^9 + 7. If the bacteria ever run short, print the lowercase word error instead of a number.