Two Frogs
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

In the Lonely Mountain, there are a lot of treasure well protected by dwarfs. Later, one day, the last dragon Smaug came and sensed the treasure being. As known to all, dragons are always much too greedy for treasure. So definitely, the war between dwarfs and Smaug begins.

During the war, two goblins Alice and Bob are turned into frogs by Gandalf, The Grey. In front of them, there are n lotus leaves in a line. In order to break the spell, they must jump from the 1-st lotus leaf to the n-th lotus leaf. If the frog is now on the i-th lotus leaf instead of the n-th lotus leaf, it can jump to a lotus leaf in range .

Goblins are lack of intelligence and it's also true even after turned into frogs. So Alice and Bob will jump randomly, which means, they will separately pick an available lotus leaf in every jump uniformly at random.

Since Alice and Bob have already being playing games for decades, so they want to know the probability that they jump to the n-th lotus leaf with the same count of jumps.

输入描述:

The first line contains an integer n , denoting the number of lotus leaf.

The second line contains n-1 integers , where the i-th integer a_i indicates the range of lotus leaves that can be reached from the i-th lotus leaf.

输出描述:

Output a line containing a single integer, indicating the probability that Alive and Bob jump to n-th lotus leaf with the same count of jumps, taken modulo .

Formally speaking, let the result, which is a rational number, be as an irreducible fraction, you need to output , where is a number such that . You may safely assume that such always exists.
示例1

输入

复制
5
1 1 1 1

输出

复制
1
示例2

输入

复制
5
4 3 2 1

输出

复制
440198031