1033: Double Chance
Description
There are cards called card , card , , card . On card , an integer is written.
For , solve the following problem.
We have a bag that contains cards: card , card , , card .
Let us perform the following operation twice, and let and be the numbers recorded, in the recorded order.Draw a card from the bag uniformly at random, and record the number written on that card. Then, return the card to the bag.
Print the expected value of , modulo (see Notes).
Here, denotes the value of the greater of and (or if they are equal).
Input
The input is given from Standard Input in the following format:
- All values in the input are integers.
Output
Sample Input Copy
3
5 7 5
Sample Output Copy
5
499122183
443664163
HINT
For instance, the answer for is found as follows.
The bag contains card and card , with and written on them, respectively.
- If you draw card in the first draw and card again in the second draw, we have , so .
- If you draw card in the first draw and card in the second draw, we have and , so .
- If you draw card in the first draw and card in the second draw, we have and , so .
- If you draw card in the first draw and card again in the second draw, we have , so .
These events happen with the same probability, so the sought expected value is . We have , so should be printed.