#arc140d. [arc140_d]One to One
[arc140_d]One to One
Problem Statement
For an integer sequence of length whose elements are all between and (inclusive), consider the question below, and let be the answer.
There is an undirected graph with vertices (and possibly multi-edges and self-loops). has edges, the -th of which connects Vertex and Vertex . Find the number of connected components in .
You are given an integer sequence of length , where each is an integer between and (inclusive) or .
Consider an integer sequence of length whose elements are all between and such that . Find the sum of over all such , modulo .
Constraints
- is between and (inclusive) or .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Prin the answer.
Sample Input 1
3
-1 1 3
Sample Output 1
5
There are three sequences satisfying the requirement, as follows.
- , for which the answer to the question is .
- , for which the answer to the question is .
- , for which the answer to the question is .
Thus, the answer is .
Sample Input 2
1
1
Sample Output 2
1
Sample Input 3
8
-1 3 -1 -1 8 -1 -1 -1
Sample Output 3
433760