#P10407. 「SMOI-R1」Game

「SMOI-R1」Game

Background

myz really enjoys playing a virus game.

Problem Description

In this game, there are initially nn viruses, and each virus has a hazard value of 11.

After some time, a virus mutates and splits into two viruses. The virus on the right has a hazard value 11 higher than the virus on the left. A virus that has mutated will not mutate again.

Each virus has a mutation limit bib_i. When the virus mutates up to bib_i, it stops mutating. That is, the ii-th virus will finally split into a virus sequence with hazard values {1,2,3,,bi}\{1,2,3,\ldots,b_i\}. When all viruses have finished mutating, the game starts. The final sequence is $\{1,2,3,\ldots,b_1,1,2,3,\ldots,b_2,\ldots,1,2,3,\ldots,b_n\}$.

In each game, the system selects an interval, and myz needs to kill all viruses in this interval. If the maximum hazard value among the viruses in this interval is xx, then myz needs to spend xx energy to eliminate them.

Since myz does not know which interval the system will choose, he wants to know the sum of the energy values required for every interval.

Because the answer is too large, output the answer modulo 998244353998244353.

Input Format

The first line contains an integer nn, indicating that there are initially nn viruses.

The second line contains nn integers. The ii-th integer is bib_i, indicating the mutation limit of the ii-th virus.

Output Format

Output one integer, representing the total energy myz needs to spend, modulo 998244353998244353.

2
2 3
33

Hint

Sample Explanation

In the first sample, the viruses finally split into {1,2,1,2,3}\{1,2,1,2,3\}. The sum of the minimum costs for intervals $[1,1],[1,2],[1,3],[1,4],[1,5],[2,2],[2,3],[2,4],[2,5],[3,3],[3,4],[3,5],[4,4],[4,5],[5,5]$ is 1+2+2+2+3+2+2+2+3+1+2+3+2+3+3=331+2+2+2+3+2+2+2+3+1+2+3+2+3+3=33.

Constraints

This problem uses bundled testdata.

subtask ID nn\leq bib_i\leq Special Property Score
11 10210^2 10210^2 None 2020
22 10410^4
33 10610^6 10910^9 A
44 None 4040

Special Property A: b1b2bnb_1 \leq b_2 \leq \ldots \leq b_n.

For 100%100\% of the testdata, it is guaranteed that 1n1061\le n\le10^6 and 1bi1091\le b_i\le 10^9.

Translated by ChatGPT 5