atcoder#MUJINPC2017A. Robot Racing

Robot Racing

Score : 900900 points

Problem Statement

You are developing frog-shaped robots, and decided to race them against each other.

First, you placed NN robots onto a number line. These robots are numbered 11 through NN. The current coordinate of robot ii is xix_i. Here, all xix_i are integers, and 0<x1<x2<...<xN0 < x_1 < x_2 < ... < x_N.

You will repeatedly perform the following operation:

  • Select a robot on the number line. Let the coordinate of the robot be xx. Select the destination coordinate, either x1x-1 or x2x-2, that is not occupied by another robot. The robot now jumps to the selected coordinate.

When the coordinate of a robot becomes 00 or less, the robot is considered finished and will be removed from the number line immediately. You will repeat the operation until all the robots finish the race.

Depending on your choice in the operation, the NN robots can finish the race in different orders. In how many different orders can the NN robots finish the race? Find the answer modulo 109+710^9+7.

Constraints

  • 2N1052 \leq N \leq 10^5
  • xix_i is an integer.
  • 0<x1<x2<...<xN1090 < x_1 < x_2 < ... < x_N \leq 10^9

Partial Score

  • In a test set worth 500500 points, N8N \leq 8.

Input

The input is given from Standard Input in the following format:

NN

x1x_1 x2x_2 ...... xNx_N

Output

Print the number of the different orders in which the NN robots can finish the race, modulo 109+710^9+7.

3
1 2 3
4

There are four different orders in which the three robots can finish the race:

  • ((Robot 11 \to Robot 22 \to Robot 3)3)
  • ((Robot 11 \to Robot 33 \to Robot 2)2)
  • ((Robot 22 \to Robot 11 \to Robot 3)3)
  • ((Robot 22 \to Robot 33 \to Robot 1)1)
3
2 3 4
6

There are six different orders in which the three robots can finish the race:

  • ((Robot 11 \to Robot 22 \to Robot 3)3)
  • ((Robot 11 \to Robot 33 \to Robot 2)2)
  • ((Robot 22 \to Robot 11 \to Robot 3)3)
  • ((Robot 22 \to Robot 33 \to Robot 1)1)
  • ((Robot 33 \to Robot 11 \to Robot 2)2)
  • ((Robot 33 \to Robot 22 \to Robot 1)1)

For example, the order ((Robot 33 \to Robot 22 \to Robot 1)1) can be achieved as shown in the figure below:

a55aed48a00614569d4844f39807e2fb.png

8
1 2 3 5 7 11 13 17
10080
13
4 6 8 9 10 12 14 15 16 18 20 21 22
311014372

Remember to print the answer modulo 109+710^9+7. This case is not included in the test set for the partial score.