#agc058b. [agc058_b]Adjacent Chmax

[agc058_b]Adjacent Chmax

Problem Statement

You are given a permutation P=(P1,P2,cdots,PN)P=(P_1,P_2,\\cdots,P_N) of (1,2,cdots,N)(1,2,\\cdots,N).

You may perform the following operation zero or more times.

  • Choose an integer ii (1leqileqN11 \\leq i \\leq N-1). Let v=max(Pi,Pi+1)v=\\max(P_i,P_{i+1}) and replace the values of PiP_i and Pi+1P_{i+1} with vv.

How many sequences are there that PP can be after your operations? Find the count modulo 998244353998244353.

Constraints

  • 2leqNleq50002 \\leq N \\leq 5000
  • (P1,P2,cdots,PN)(P_1,P_2,\\cdots,P_N) is a permutation of (1,2,cdots,N)(1,2,\\cdots,N).
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN P1P_1 P2P_2 cdots\\cdots PNP_N

Output

Print the answer.


Sample Input 1

3
1 3 2

Sample Output 1

4

The four sequences that PP can become are (1,3,2)(1,3,2), (3,3,2)(3,3,2), (1,3,3)(1,3,3), and (3,3,3)(3,3,3).


Sample Input 2

4
2 1 3 4

Sample Output 2

11

Sample Input 3

10
4 9 6 3 8 10 1 2 7 5

Sample Output 3

855