#ARC117B. [ARC117B] ARC Wrecker

[ARC117B] ARC Wrecker

Score : 400400 points

Problem Statement

There are NN buildings along AtCoder road. Initially, the ii-th building from the left has AiA_i stories.

Takahashi, the president of ARC Wrecker, Inc., can do the following operation any number of times, possibly zero:

  • Choose a positive integer XX that he likes and shoot a cannonball at that height, which decreases by 11 the number of stories in each building with XX or more stories.

Find the number of possible final sceneries of buildings, modulo (109+710^{9} + 7).

We consider two sceneries A and B different when the following holds:

  • let PiP_i be the number of stories of the ii-th building from the left in scenery A;
  • let QiQ_i be the number of stories of the ii-th building from the left in scenery B;
  • we consider sceneries A and B different when PiQiP_i \neq Q_i for one or more indices ii.

Constraints

  • 1N1000001 \leq N \leq 100000
  • 1Ai1091 \leq A_i \leq 10^{9}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answer.

2
1 2
4

There are four possible combinations of heights of the buildings, as follows:

  • (Building 11, Building 22) = (0,0)(0, 0)
  • (Building 11, Building 22) = (0,1)(0, 1)
  • (Building 11, Building 22) = (1,1)(1, 1)
  • (Building 11, Building 22) = (1,2)(1, 2)
6
5 3 4 1 5 2
32
7
314 159 265 358 979 323 846
492018656

There are 2019249216000020192492160000 possible final sceneries. The correct output is that number modulo 109+710^{9} + 7, which is 492018656492018656.