#P10407. Sum of Energy Consumption in Mutating Viruses

    ID: 12416 Type: Default 1000ms 256MiB

Sum of Energy Consumption in Mutating Viruses

Sum of Energy Consumption in Mutating Viruses

In this game, there are initially \(n\) viruses, each with a harmful value of \(1\). At fixed intervals, every virus mutates and splits into two viruses. The right virus has its harmful value increased by \(1\) compared to the left one, and once a virus mutates it will not mutate again. Each virus has a mutation limit \(b_i\). That is, the \(i\)th virus will stop mutating when its harmful value reaches \(b_i\). As a result, the \(i\)th virus produces a sequence of viruses with harmful values \(\{1,2,3,\ldots,b_i\}\). After all mutations are finished, the final virus sequence is the concatenation
\(\{1,2,3,\ldots,b_1,\;1,2,3,\ldots,b_2,\;\ldots,\;1,2,3,\ldots,b_n\}\).

During the game, the system selects an interval in the final sequence. To eliminate all viruses in that interval, if the maximum harmful value in the interval is \(x\) then \(x\) units of energy are needed. Since the system may choose any interval, you are to compute the sum of energy values required for all possible intervals. Output the answer modulo \(998244353\).

Note: Within an interval, the cost equals the maximum value present in that interval.

inputFormat

The first line contains an integer \(n\) (the number of viruses).
The second line contains \(n\) space‐separated integers \(b_1, b_2, \ldots, b_n\) indicating the mutation limit for each virus.

outputFormat

Output a single integer: the sum of energy required for all contiguous intervals in the final virus sequence, modulo \(998244353\).

sample

1
1
1

</p>