The team is called a winner if it directly or indirectly defeated all other teams. Teamdefeated (directly or indirectly) team if there is a sequence of teams , , … such that , and team defeated team for all from to . Note that it is possible that team defeated team and in the same time team defeated team .
William wants you to find the expected value of the number of winners.
Input Sports Betting solution codeforces
The first line contains a single integer( ), which is the total number of teams participating in a match.
The second line containsintegers ( ) — the strengths of teams participating in a match.
Output Sports Betting solution codeforces
Output a single integer — the expected value of the number of winners of the tournament modulo.
Formally, let. It can be demonstrated that the answer can be presented as a irreducible fraction , where and are integers and . Output a single integer equal to . In other words, output an integer such that and .
input Sports Betting solution codeforces
2 1 2
Copy Sports Betting solution codeforces
5 1 5 2 11 14
Note Sports Betting solution codeforces
To better understand in which situation several winners are possible let’s examine the second test:
One possible result of the tournament is as follows (means that defeated ):
Or more clearly in the picture:
- st defeated everyone because they can get to everyone else in the following way , , , .
- nd defeated everyone because they can get to everyone else in the following way , , , .
- rd defeated everyone because they can get to everyone else in the following way , , , .
Therefore the total number of winners is.