6518: ABC234 —— G - Divide a Sequence
[Creator : ]
Description
Given is a sequence $A$ of $N$ numbers.
There are $2^{N-1}$ ways to divide $A$ into non-empty contiguous subsequences $B_1,B_2,\ldots,B_k$. Find the value below for each of those ways, and print the sum, modulo $998244353$, of those values.
There are $2^{N-1}$ ways to divide $A$ into non-empty contiguous subsequences $B_1,B_2,\ldots,B_k$. Find the value below for each of those ways, and print the sum, modulo $998244353$, of those values.
- $\prod_{i=1}^{k} (\max(B_i)-\min(B_i))$
Input
Input is given from Standard Input in the following format:
$N$
$A_1\ A_2\ \dots\ A_N$
$N$
$A_1\ A_2\ \dots\ A_N$
Output
Print the sum, modulo $998244353$, of the values found.
Constraints
$1≤N≤3×10^5$
$1 \leq A_i \leq 10^9$
All values in input are integers.
$1 \leq A_i \leq 10^9$
All values in input are integers.
Sample 1 Input
3
1 2 3
Sample 1 Output
2
There are $4$ ways to divide $A=(1,2,3)$ into non-empty contiguous subsequences, as follows.
- $(1), (2), (3)$
- $(1), (2,3)$
- $(1,2), (3)$
- $(1,2,3)$
Sample 2 Input
4
1 10 1 10
Sample 2 Output
90
Sample 3 Input
10
699498050 759726383 769395239 707559733 72435093 537050110 880264078 699299140 418322627 134917794
Sample 3 Output
877646588