Bus Stop
Time limit2sMemory limit512 MB
Each of n bus routes has independent waiting time uniform on [0, di]; find the expected minimum, output as a fraction modulo 998244353.
- Level
Hard8 of 10
- Topics
- Probability, Math, Sorting, Combinatorics
- Solved
- No attempts yet
Problem
You are waiting for a bus at a bus stop.
There are n bus routes passing through the bus stop. You know that buses of the i-th route arrive one by one with an interval of exactly di minutes. However, you have no information about the exact moment when the next bus of any route arrives, so you expect the time until a bus of route i arrives to be a real number distributed uniformly at random between 0 and di minutes.
Find the expected value of the time until a bus of any route arrives.
Input
The first line contains a single integer n (1 ≤ n ≤ 105), the number of routes.
The second line contains n integers d1, d2, . . . , dn (1 ≤ di ≤ 987 654 321) separated by spaces, where di is the interval in minutes between consecutive buses of route i.
Output
It can be shown that the answer can be represented as an irreducible fraction P/Q, where P and Q are positive coprime integers and Q ≠ 0 (mod 998 244 353). Print a single integer X = P·Q−1 (mod 998 244 353) (0 ≤ X < 998 244 353), where Q−1 is the inverse of Q modulo 998 244 353.
Hint
The answers for the first and the second sample tests are 3/2 and 275/168, respectively.