#arc124e. [arc124_e]Pass to Next

[arc124_e]Pass to Next

Problem Statement

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

For each 1leqileqN11 \\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 sumxinSprodi=1Nxi\\sum_{x \\in S} \\prod_{i=1}^{N} x_i, modulo 998244353998244353.

Constraints

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

Input

Input is given from Standard Input in the following format:

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

Output

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


Sample Input 1

3
1 1 1

Sample Output 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) \\}$.
  • sumxinSprodi=1Nxi\\sum_{x \\in S} \\prod_{i=1}^{N} x_i is 11.

Sample Input 2

3
2 1 1

Sample Output 2

6

Sample Input 3

20
5644 493 8410 8455 7843 9140 3812 2801 3725 6361 2307 1522 1177 844 654 6489 3875 3920 7832 5768

Sample Output 3

864609205
  • Be sure to compute it modulo 998244353998244353.