大和証券プログラミングコンテスト2021 (AtCoder Regular Contest 128)
D
Neq Neq
AtCoder
⌀ 2554
原题
← CE →
翻译中…

Problem Statement

翻译中…

We have $N$ balls arranged in a row, numbered $1$ to $N$ from left to right. Ball $i$ has an integer $A_i$ written on it.

翻译中…

You can do the following operation any number of times.

翻译中…
  • Choose three consecutive balls $x, y, z$ $(1 \leq x < y < z \leq N$). Here, $A_x \neq A_y$ and $A_y \neq A_z$ must hold. Then, eat Ball $y$. After this operation, Balls $x$ and $z$ are considered adjacent.
翻译中…

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

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 200000$
  • $1 \leq A_i \leq N$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \cdots A_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
4
1 2 1 2
Output #1
3
There are three possible sets of balls remaining in the end: $\{1,2,3,4\},\{1,2,4\},\{1,3,4\}$.
Input #2
5
5 4 3 2 1
Output #2
8
Different sequences of operations are not distinguished if they result in the same set of balls.
Input #3
5
1 2 3 2 1
Output #3
8
Different sets of remaining balls are distinguished even if they have the same sequence of integers written on them.
Input #4
9
1 4 2 2 9 6 9 6 6
Output #4
14
题目信息
题号
arc128_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。