atcoder#ARC128D. [ARC128D] Neq Neq

[ARC128D] Neq Neq

Score : 700700 points

Problem Statement

We have NN balls arranged in a row, numbered 11 to NN from left to right. Ball ii has an integer AiA_i written on it.

You can do the following operation any number of times.

  • Choose three consecutive balls x,y,zx, y, z (1x<y<zN(1 \leq x < y < z \leq N). Here, AxAyA_x \neq A_y and AyAzA_y \neq A_z must hold. Then, eat Ball yy. After this operation, Balls xx and zz are considered adjacent.

Find the number of possible sets of balls remaining in the end, modulo 998244353998244353.

Constraints

  • 2N2000002 \leq N \leq 200000
  • 1AiN1 \leq A_i \leq N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answer.

4
1 2 1 2
3

There are three possible sets of balls remaining in the end: {1,2,3,4},{1,2,4},{1,3,4}\{1,2,3,4\},\{1,2,4\},\{1,3,4\}.

5
5 4 3 2 1
8

Different sequences of operations are not distinguished if they result in the same set of balls.

5
1 2 3 2 1
8

Different sets of remaining balls are distinguished even if they have the same sequence of integers written on them.

9
1 4 2 2 9 6 9 6 6
14