#abc234g. [abc234_g]Divide a Sequence

[abc234_g]Divide a Sequence

Problem Statement

Given is a sequence AA of NN numbers.

There are 2N12^{N-1} ways to divide AA into non-empty contiguous subsequences B1,B2,ldots,BkB_1,B_2,\\ldots,B_k. Find the value below for each of those ways, and print the sum, modulo 998244353998244353, of those values.

  • prodi=1k(max(Bi)min(Bi))\\prod_{i=1}^{k} (\\max(B_i)-\\min(B_i))

Here, for a sequence Bi=(Bi,1,Bi,2,ldots,Bi,j)B_i=(B_{i,1},B_{i,2},\\ldots,B_{i,j}), max(Bi)\\max(B_i) and min(Bi)\\min(B_i) are defined to be the maximum and minimum values of an element of BiB_i, respectively.

Constraints

  • 1leqNleq3times1051 \\leq N \\leq 3 \\times 10^5
  • 1leqAileq1091 \\leq A_i \\leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN A1A_1 A2A_2 ldots\\ldots ANA_N

Output

Print the sum, modulo 998244353998244353, of the values found.


Sample Input 1

3
1 2 3

Sample Output 1

2

There are 44 ways to divide A=(1,2,3)A=(1,2,3) into non-empty contiguous subsequences, as follows.

  • (1)(1), (2)(2), (3)(3)
  • (1)(1), (2,3)(2,3)
  • (1,2)(1,2), (3)(3)
  • (1,2,3)(1,2,3)

prodi=1k(max(Bi)min(Bi))\\prod_{i=1}^{k} (\\max(B_i)-\\min(B_i)) for these divisions are 00, 00, 00, 22, respectively. The sum of them, 22, should be printed.


Sample Input 2

4
1 10 1 10

Sample Output 2

90

Sample Input 3

10
699498050 759726383 769395239 707559733 72435093 537050110 880264078 699299140 418322627 134917794

Sample Output 3

877646588

Be sure to print the sum modulo 998244353998244353.