atcoder#ARC125D. [ARC125D] Unique Subsequence

[ARC125D] Unique Subsequence

Score : 700700 points

Problem Statement

Given is a sequence of NN integers A1,A2,,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 1idx(1)suchthat1 \leq idx(1) such that A_{idx(i)}=s_i$ (1ik1 \leq i \leq k), where s=(s1,s2,,sk)s=(s_1,s_2,\cdots,s_k).

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 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.

3
1 2 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.

4
4 2 1 3
15
12
1 2 3 6 9 2 3 3 9 6 1 6
1178