atcoder#ARC159F. [ARC159F] Good Division

[ARC159F] Good Division

Score : 900900 points

Problem Statement

A sequence XX is called good when the following holds.

  • XX can be emptied by repeating the following operation zero or more times.- Delete two adjacent elements xix_i and xi+1x_{i+1} of XX such that xixi+1x_i \neq x_{i+1}.
  • Delete two adjacent elements xix_i and xi+1x_{i+1} of XX such that xixi+1x_i \neq x_{i+1}.

You are given a sequence with 2N2N elements: A=(a1,,a2N)A=(a_1,\ldots,a_{2N}). Among the 22N12^{2N-1} ways to divide AA into one or more contiguous subsequences, how many are such that all those contiguous subsequences are good? Find the count modulo 998244353998244353.

Constraints

  • 1N5×1051 \leq N \leq 5 \times 10^5
  • 1ai2N1 \leq a_i \leq 2N
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

a1a_1 \ldots a2Na_{2N}

Output

Print the answer.

3
1 1 2 3 4 5
2

The following two divisions satisfy the condition.

  • (1,1,2,3,4,5)(1,1,2,3,4,5)
  • (1,1,2,3),(4,5)(1,1,2,3),(4,5)
1
1 2
1
1
1 1
0
12
4 2 17 12 18 15 17 4 22 6 9 20 21 16 23 16 13 2 20 15 16 3 7 15
2048