#P1477F. Nezzar and Chocolate Bars
Nezzar and Chocolate Bars
No submission language available for this problem.
Description
Nezzar buys his favorite snack — chocolate bars with lengths . However, chocolate bars might be too long to store them properly!
In order to solve this problem, Nezzar designs an interesting process to divide them into small pieces. Firstly, Nezzar puts all his chocolate bars into a black box. Then, he will perform the following operation repeatedly until the maximum length over all chocolate bars does not exceed .
- Nezzar picks a chocolate bar from the box with probability proportional to its length .
- After step , Nezzar uniformly picks a real number and divides the chosen chocolate bar into two chocolate bars with lengths and .
- Lastly, he puts those two new chocolate bars into the black box.
Nezzar now wonders, what is the expected number of operations he will perform to divide his chocolate bars into small pieces.
It can be shown that the answer can be represented as , where and are coprime integers and (). Print the value of .
The first line contains two integers and ().
The second line contains integers (, ).
Print a single integer — the expected number of operations Nezzar will perform to divide his chocolate bars into small pieces modulo .
Input
The first line contains two integers and ().
The second line contains integers (, ).
Output
Print a single integer — the expected number of operations Nezzar will perform to divide his chocolate bars into small pieces modulo .