AT_abc468_e [ABC468E] Sum of Average
Description
You are given a positive integer $ N $ and a length- $ N $ integer sequence $ A=(A_1,A_2,\ldots,A_N) $ .
Define $ f(l,r) $ as the (arithmetic) mean of $ A_l,A_{l+1},\ldots,A_r $ .
Find $ \displaystyle \sum_{1\le l\le r\le N} f(l,r) $ , modulo $ 998244353 $ .
:::info[Definition of a rational number modulo $ 998244353 $]
Under the constraints of this problem, it can be proved that the rational number to be found is always an irreducible fraction $ \frac{P}{Q} $ such that $ Q {{}\not\equiv{}} 0 \pmod{998244353} $ . Thus, there is a unique integer $ R $ such that $ R \times Q \equiv P \pmod{998244353}, 0 \leq R
Input Format
The input is given from Standard Input in the following format:
> $ N $
> $ A_1 $ $ A_2 $ $ \ldots $ $ A_N $
Output Format
Output the answer.
Explanation/Hint
### Sample Explanation 1
We have $ \displaystyle f(1,1)=2,f(1,2)=\frac{2+3}2=\frac52,f(2,2)=3 $ . Thus, $ \displaystyle \sum_{1\le l\le r\le N} f(l,r)=2+\frac52+3=\frac{15}2 $ .
$ \displaystyle \frac{15}2 $ in modulo- $ 998244353 $ expression is $ 499122184 $ , so output $ 499122184 $ .
### Constraints
- $ 1\le N\le 5\times 10^5 $
- $ 0\le A_i < 998244353 $
- All input values are integers.