atcoder#ARC124E. [ARC124E] Pass to Next

[ARC124E] Pass to Next

Score : 800800 points

Problem Statement

NN people called Person 1,2,,N1, 2, \ldots, N are standing in a circle.

For each 1iN11 \leq i \leq N-1, Person ii's neighbor to the right is Person i+1i+1, and Person NN's neighbor to the right is Person 11.

Person ii initially has aia_i balls.

They will do the following procedure just once.

  • Each person chooses some (possibly zero) of the balls they have.
  • Then, each person simultaneously hands the chosen balls to the neighbor to the right.
  • Now, make a sequence of length NN, where the ii-th term is the number of balls Person ii has at the moment.

Let SS be the set of all sequences that can result from the procedure. For example, when a=(1,1,1)a=(1,1,1), we have $S= \{(0,1,2),(0,2,1),(1,0,2),(1,1,1),(1,2,0),(2,0,1),(2,1,0) \}$.

Compute xSi=1Nxi\sum_{x \in S} \prod_{i=1}^{N} x_i, modulo 998244353998244353.

Constraints

  • All values in input are integers.
  • 3N1053 \leq N \leq 10^5
  • 0ai1090 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

NN

a1a_{1} a2a_{2} \cdots aNa_{N}

Output

Print xSi=1Nxi\sum_{x \in S} \prod_{i=1}^{N} x_i, modulo 998244353998244353.

3
1 1 1
1
  • We have $S= \{(0,1,2),(0,2,1),(1,0,2),(1,1,1),(1,2,0),(2,0,1),(2,1,0) \}$.
  • xSi=1Nxi\sum_{x \in S} \prod_{i=1}^{N} x_i is 11.
3
2 1 1
6
20
5644 493 8410 8455 7843 9140 3812 2801 3725 6361 2307 1522 1177 844 654 6489 3875 3920 7832 5768
864609205
  • Be sure to compute it modulo 998244353998244353.