Mukjjippa
시간 제한2초메모리 제한1024 MB
각 턴에서 두 선수의 선택 확률이 주어질 때, mukjjippa 게임에서 A가 이길 확률을 구한다.
문제
Two players A and B are playing a game called mukjjippa.
The game consists of several turns.
At the -th turn ():
- Each player chooses exactly one from (meaning rock, scissors, and paper, respectively).
- Let and be the choices of A and B, respectively.
- If , then A becomes an attacker for the -th turn and the game continues.
- Otherwise, if , then B becomes an attacker for the -th turn and the game continues.
- Otherwise, if there is an attacker for the -th turn, then the attacker becomes a winner and the game ends.
- Otherwise, there is no attacker for the -th turn and the game continues.
Note that there is no attacker for the first turn.
If the game does not end until the beginning of the -th turn, nobody is a winner.
The probability distribution of each choice is given. All choices are independent.
Find the probability that A wins.
입력
The first line contains an integer .
The -th of the next lines contains three integers , , and . This means that the probabilities that is , , and are , , and , respectively.
The -th of the next lines contains three integers , , and . This means that the probabilities that is , , and are , , and , respectively.
출력
Let be the probability that A wins, where and are coprime integers, and and .
Print the integer such that and .
It can be proved that such an integer always exists and is uniquely determined, under the constraints of this problem.
제한
- ()
- ()
- ()
- ()