QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 2048 MB

#22846. Professor JAG's Language

统计

Professor JAG, a researcher of sequences, is developing a new expression language. You are given an integer $N$ and a string $O = O_1 O_2 \cdots O_{N-1}$ consisting of + and |. Throughout this problem, a sequence with elements $a_1, a_2, \ldots, a_k$ is denoted by $[a_1, a_2, \ldots, a_k]$.

Consider the following expression:

$$[1]\ O_1\ [2]\ O_2\ \ldots\ O_{N-1}\ [N]$$

Here, $O_i$ is the $i$-th character of the input string $O$ and is used as the operator between $[i]$ and $[i + 1]$.

Since operator precedence is not defined, we consider all possible ways to fully parenthesize this expression without changing the order of its operands or operators. Each expression obtained in this way is called a valid expression.

For each expression $Z$, let $S(Z)$ denote the set of sequences represented by $Z$. The set $S(Z)$ is defined recursively as follows.

  • If $Z$ has the form [i] for some $i$ ($1 \le i \le N$), then $S(Z)$ consists only of the one-element sequence $[i]$.
  • If $Z$ has the form (X + Y), where $X$ and $Y$ are its left and right subexpressions, then $S(Z)$ consists of every sequence obtained by concatenating a sequence in $S(X)$ with a sequence in $S(Y)$. For example, if $S(X)$ contains $[1, 3]$ and $S(Y)$ contains $[2, 4]$, then $S(Z)$ contains $[1, 3, 2, 4]$.
  • If $Z$ has the form (X | Y), where $X$ and $Y$ are its left and right subexpressions, then $S(Z) = S(X) \cup S(Y)$.

Different valid expressions may represent the same sequence. Find the number of distinct sequences represented by at least one valid expression. Since the answer may be large, output it modulo $998\,244\,353$.

Input

The input consists of a single test case in the following format.

$$\begin{aligned} &N \\ &O \end{aligned}$$

The first line contains an integer $N$ ($2 \le N \le 10^6$). The second line contains a string $O$ consisting of + and | ($|O| = N - 1$).

Output

Output the number of distinct sequences that can be represented, modulo $998\,244\,353$.

Example

Input 1

4
+|+

Output 1

4

Input 2

7
||+|||

Output 2

17

Input 3

17
+|||+|+++||||+|+

Output 3

1774

Note

For the first sample, the expression is [1]+[2]|[3]+[4].

The following five valid expressions can be obtained by adding parentheses:

  • ((([1]+[2])|[3])+[4])
  • (([1]+[2])|([3]+[4]))
  • (([1]+([2]|[3]))+[4])
  • ([1]+(([2]|[3])+[4]))
  • ([1]+([2]|([3]+[4])))

The following four distinct sequences are represented by at least one of these valid expressions:

  • $[1, 2]$
  • $[1, 2, 4]$
  • $[1, 3, 4]$
  • $[3, 4]$

Therefore, the answer is $4$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2905EditorialOpenNew Editorial for Problem #22846louyuxuanView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.