Image by Elisa Riva (
Pixabay),
Public Domain
If someone were to make a prediction that everyone thought
was doomed to failure, and it turned out to be correct,
wouldn’t it be shortsighted simply to dismiss this as a stroke
of luck? What if the person could do so over and over again?
Instead of explaining away those capable of such
prognostications, society has labelled them ‘geniuses’, and has
accepted that mere mortals are simply unable to comprehend
their godlike level of reasoning, reasoning that transcends
common sense.
Jimmy is not a genius, but he would like to fool people into
thinking he is one so that he can use this rarefied title on
his resume and land his dream job. He has come up with a
strategy that he claims will correctly predict at least
winners out of the
next tournaments of a
certain game, but nobody seems to believe in his
arbitrary-sounding strategy. However, if Jimmy’s claim turns
out to be correct, the doubters will quickly change their
minds, and he will earn the genius label that he so deeply
desires.
A tournament involves players, and is based on a
two-round, single-elimination system. In the first round,
players and
play each other, and
players and
play each other. In
the second round, the two first-round winners play each other,
and the resulting winner is crowned the champion of the entire
tournament. Each player has a strategy with positive weight
. If a player with a
strategy of weight
competes against a player with a strategy of weight
, then the first player
wins with probability (and therefore the
second player wins with probability ). The outcome of each
game is independent of all other games.
Jimmy’s strategy for determining tournament winners is taken
from an exercise in a number theory book he idly flipped
through in the library one day. First he chooses distinct prime
numbers and
, and then he uses them
to generate a sequence of nonnegative integers as
follows: (a) He randomly picks satisfying . (b) He
applies the formula mod for to compute the
remaining terms in the sequence. (c) He performs a
mod 4 operation on every term so that his sequence now
consists only of the integers . Finally, when the tournaments begin, Jimmy
predicts that the winner of tournament is player , the winner of tournament
is player , and so on.
Input
The first line of input contains five space-separated
integers, ,
, , , and , as described above, where
, , and . Each of the next lines contains four
space-separated integers , , and , the weights of the strategies
of players to
, respectively, where
the line
contains this weight information for the tournament
(). Each
weight is between and
, inclusive.
Output
Output a single floating-point number: the probability that
Jimmy is perceived as a genius by the general public and
therefore be able to get his dream job — in other words,
the probability that Jimmy’s strategy correctly predicts the
winner of at least out
of the tournaments.
Your answer must have an absolute or relative error of at most
.
Sample Input 1 |
Sample Output 1 |
2 4 7 13 5
1 2 3 4
4 3 2 1
2 2 2 2
4 6 3 5
|
0.2473950797
|