It is Argentina vs France in the football world cup final of 2022 in a parallel universe.
You are a supporter of Argentina. 120 minutes of play has ended in a draw. So, penalty shootout will begin. You know the scoring probabilities for each of the 22 players on the field. You also know that both teams would send shooters in an optimal order. And the order must be submitted to the referee before the shootout begins. Argentina start first. The rules of penalty shootout are as follows:
Teams take shots alternately.
For any consecutive 11 shots of a team, a player can shoot exactly once.
If both teams have taken equal number of shots and each team has taken at least 5 shots, then the leading team wins. If scores are still tied, they continue shooting until a team wins.
We denote a goal with and a miss with .
The shootout begins. The scorecard after 5 shots per team is:
This means Argentina missed its 4th shot and France missed its 1st shot. The score is tied at 4-4.
You are losing your sanity from the suspense. You know the first 5 shooters went in optimal order which was submitted before the shootout began. Now you calculate the probability of Argentina winning the world cup. This means you calculate it after 5 shots per team was taken and before Argentina’s 6th shot. Print the number modulo .
Formally, let the probability be an irreducible fraction . Print the value mod . Where is an integer such that mod . Input data for this problem was made such that exists.
A player might need to take multiple shots in the shootout. The outcome of any shot does not change his scoring probability.
Some possible outcomes of the shootout continuing from the current situation:
After 6 shots per team, France lead. So France wins.
After 9 shots per team, Argentina lead by 7-6. So Argentina wins.
After 24 shots per team, Argentina lead by 14-13. So Argentina wins.
The input consists of lines, each containing space separated integers.
The -th integer on the first line indicates that scoring probability for the -th player of Argentina is .
The -th integer on the second line indicates that scoring probability for the -th player of France is .
Input is not necessarily given in the optimal shooting order.
Print a single integer, the probability of Argentina winning modulo .
99 99 99 99 99 99 99 99 99 99 99 1 1 1 1 1 1 1 1 1 1 1
The actual probability is .
41 49 94 58 69 65 98 57 39 7 71 85 5 4 90 8 46 21 75 84 41 93
The actual probability is . Which is roughly equal to .
50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50
The probability is .