#FT0000205. Hai lần rút thăm (Double Chance)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hai lần rút thăm (Double Chance)
Double Chance
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are numbered cards; card carries the integer .
For each , consider a bag containing cards through . Draw a uniformly random card, record its value , and return it to the bag. Independently draw again and record .
Find the expected value of for each , modulo . If this expectation is the reduced fraction , output the unique integer in such that .
Input
- The first line contains , the number of cards.
- The second line contains integers , the values written on the cards.
Output
Print lines. The -th line contains the modular expected value of when the bag contains its first cards.
Subtasks
-
Subtask 1 (20 points): ; for all .
-
Subtask 2 (30 points): ; for all .
-
Subtask 3 (50 points): ; for all .
Examples
Input
3
5 7 5
Output
5
499122183
443664163
Explanation
For both draws yield , so the expectation is . For , the four equally likely ordered draws have maxima ; their average is , represented modulo by . For , four ordered pairs have maximum and five have maximum , giving and modular result .