William is not only interested in trading but also in betting on sports matches. nn teams participate in each match. Each team is characterized by strength aiai. Each two teams i- William is not only interested in trading but also in betting on sports matches. nn teams participate in each match. Each team is characterized by strength aiai. Each two teams i

William is not only interested in trading but also in betting on sports matches. nn teams participate in each match. Each team is characterized by strength aiai. Each two teams i<ji<j play with each other exactly once. Team ii wins with probability aiai+ajaiai+aj and team jj wins with probability ajai+ajajai+aj.

The team is called a winner if it directly or indirectly defeated all other teams. Team aa defeated (directly or indirectly) team bb if there is a sequence of teams c1c1c2c2, … ckck such that c1=ac1=ack=bck=b and team cici defeated team ci+1ci+1 for all ii from 11 to k1k−1. Note that it is possible that team aa defeated team bb and in the same time team bb defeated team aa.

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 nn (1n141≤n≤14), which is the total number of teams participating in a match.

The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1061≤ai≤106)  — 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 109+7109+7.

Formally, let M=109+7M=109+7. It can be demonstrated that the answer can be presented as a irreducible fraction pqpq, where pp and qq are integers and q≢0(modM)q≢0(modM). Output a single integer equal to pq1modMp⋅q−1modM. In other words, output an integer xx such that 0x<M0≤x<M and xqp(modM)x⋅q≡p(modM).

Examples

input Sports Betting solution codeforces

Copy

2
1 2

input

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 (aba→b means that aa defeated bb):

  • 121→2
  • 232→3
  • 313→1
  • 141→4
  • 151→5
  • 242→4
  • 252→5
  • 343→4
  • 353→5
  • 454→5

Or more clearly in the picture:

In this case every team from the set {1,2,3}{1,2,3} directly or indirectly defeated everyone. I.e.:

  • 11st defeated everyone because they can get to everyone else in the following way 121→21231→2→3141→4151→5.
  • 22nd defeated everyone because they can get to everyone else in the following way 232→32312→3→1242→4252→5.
  • 33rd defeated everyone because they can get to everyone else in the following way 313→13123→1→2343→4353→5.

Therefore the total number of winners is 33.

William is not only interested in trading but also in betting on sports matches. nn teams participate in each match. Each team is characterized by strength aiai. Each two teams i

Leave a Comment

fastnewsxpress