Problem9525--ABC221 —— E - LEQ

9525: ABC221 —— E - LEQ

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

Given is a sequence of $N$ integers: $A = (A_1, A_2, \dots, A_N)$.

Find the number of (not necessarily contiguous) subsequences $A'=(A'_1,A'_2,\ldots,A'_k)$ of length at least $2$ that satisfy the following condition:

-   $A'_1 \leq A'_k$.

Since the count can be enormous, print it modulo $998244353$.

Here, two subsequences are distinguished when they originate from different sets of indices, even if they are the same as sequences.

Input

Input is given from Standard Input in the following format:

```
$N$
$A_1$ $A_2$ $\ldots$ $A_N$
```

Output

Print the number of (not necessarily contiguous) subsequences $A'=(A'_1,A'_2,\ldots,A'_k)$ of length at least $2$ that satisfy the condition in Problem Statement.

Constraints

-   $2 \leq N \leq 3 \times 10^5$
-   $1 \leq A_i \leq 10^9$
-   All values in input are integers.

Sample 1 Input

3
1 2 1

Sample 1 Output

3

A=(1,2,1) has four (not necessarily contiguous) subsequences of length at least 2: (1,2), (1,1), (2,1), (1,2,1).

Three of them, (1,2), (1,1), (1,2,1), satisfy the condition in Problem Statement.

Sample 2 Input

3
1 2 2

Sample 2 Output

4

Note that two subsequences are distinguished when they originate from different sets of indices, even if they are the same as sequences.

In this Sample, there are four subsequences, (1,2), (1,2), (2,2), (1,2,2), that satisfy the condition.

Sample 3 Input

3
3 2 1

Sample 3 Output

0
There may be no subsequence that satisfies the condition.

10
198495780 28463047 859606611 212983738 946249513 789612890 782044670 700201033 367981604 302538501

830

Source/Category