QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#8639. Elimination

Statistics

A 01 sequence is called good if and only if it can be reduced to an empty sequence by repeatedly applying the following operation:

  • In each operation, you may choose a 0 and remove it along with the element immediately to its left, or choose a 1 and remove it along with the element immediately to its right. Note that you must remove exactly two elements in each operation. For example, you cannot choose the 0 in 011, nor can you choose the 1 in 001.

Here are some examples:

  • A sequence like 0100 is good, because you can first choose the 1 to get 00, and then choose the second 0 to get an empty sequence.
  • A sequence like 0101 is not good, because regardless of whether you choose the first 1 or the second 0, the sequence becomes 01.

Given a sequence containing only 0, 1, and ?, you need to calculate the sum of the number of ways to replace each ? with 0 or 1 such that the resulting 01 sequence is good, for every subsequence of the given sequence. Output the sum of all these answers modulo $998244353$.

Input

The input is read from standard input.

The input consists of two lines.

The first line contains a positive integer $n$.

The second line is a string of length $n$ containing only 0, 1, and ?.

Output

Output to standard output.

Output a single integer representing the sum of the answers as described in the problem, modulo $998244353$.

Examples

Input 1

4
1?1?

Output 1

16

Input 2

10
1?0?1?????

Output 2

8078

Constraints

For $10\%$ of the data, $n \le 8$.

For $50\%$ of the data, $n \le 5000$.

For all test data, $1 \le n \le 10^6$.

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.