Moejy0viiiiiv is collecting red envelopes on a rectangular plane. She starts at . Every day at noon, she walks from to with probability , and to with probability , and stops immediately with probability (once she stops, she will never move again). Besides, she also stops after walking for days.
With a given constant integer , there’s a red envelope at each . There’re also barriers at (barriers never coincide with red envelopes). If she walks to a barrier, she will stop immediately.
Moejy0viiiiiv will collect each red envelope she passes by (including ). What’s the expected number of red envelopes Moejy0viiiiiv collects after days? Output the answer . Notice that .
输入格式
第一行两个整数 。
第二行四个整数 。
接下来 行,每行两个整数,第 行两个数为 。
The first line contains two positive integers .
The second line contains four positive integers .
The following lines each contains two integers, the -th line contains .
输出格式
一行一个数,表示期望抢的红包数量。
Output contains one integer, the expected number of red envelopes .
样例
样例输入1
1 1
2 2 5 1
1 0
样例输出 1
2
样例解释 1
共有 个地方有红包,。
由于 处是坑,所以无法抢 处的红包,而抢到其余两处红包的概率均为 。
注意,在本题中 不必为 。
样例输入 2
1 2
2 2 5 0
样例输出 2
6
Sample Input 1
1 1
2 2 5 1
1 0
Sample Output 1
2
Sample Explanation 1
There’re three red envelopes satisfies , .
As there’s a barrier at , the red envelope at is unreachable. The probability of getting the other two red envelopes are both .
doesn’t need to be .
Sample Input 2
1 2
2 2 5 0
Sample Output 2
6
数据范围与提示
对于所有数据,,
。
详细的数据限制及约定如下(留空表示和上述所有数据的约定相同):
Subtask #
分值(百分比)
-
-
-
-
For all test cases, ,
.
Detailed constraints and hints are as follows (blank grids denote the same constraints as mentioned above):