#arc125d. [arc125_d]Unique Subsequence

[arc125_d]Unique Subsequence

Problem Statement

Given is a sequence of NN integers A1,A2,cdots,ANA_1,A_2,\\cdots,A_N.

Find the number of non-empty subsequences ss of AA satisfying the following condition, modulo 998244353998244353.

  • There is only one way to extract ss from AA. Formally, there uniquely exists a sequence of indices 1leqidx(1)<idx(2)<cdots<idx(k)leqN1 \\leq idx(1)<idx(2)<\\cdots<idx(k) \\leq N such that Aidx(i)=siA_{idx(i)}=s_i (1leqileqk1 \\leq i \\leq k), where s=(s1,s2,cdots,sk)s=(s_1,s_2,\\cdots,s_k).

Constraints

  • 1leqNleq2times1051 \\leq N \\leq 2 \\times 10^5
  • 1leqAileqN1 \\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\\cdots ANA_N

Output

Print the answer.


Sample Input 1

3
1 2 1

Sample Output 1

5

The following five subsequences satisfy the condition.

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

The subsequence (1)(1) does not satisfy the condition since there are two ways to extract it.


Sample Input 2

4
4 2 1 3

Sample Output 2

15

Sample Input 3

12
1 2 3 6 9 2 3 3 9 6 1 6

Sample Output 3

1178