QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 128 MB 満点: 100

#5019. Integer

統計

Adapted from a problem of unknown origin.

There is an array $a$ of $n$ non-negative integers in a computer, where the element at index $i$ ($0 \leq i < n$) has a value in the range $[0, R_i]$.

Due to certain special reasons, the computer will crash if specific combinations of bits appear at the same binary position across these $n$ numbers.

Specifically, let $b_x = \sum_{i=0}^{n-1} \left( \left\lfloor \frac{a_i}{2^x} \right\rfloor \bmod 2 \right) \cdot 2^i$. The computer will not crash if and only if $\forall x \geq 0, b_x \in S$.

Find the number of ways to choose the values of the array such that the computer remains safe. Output the answer modulo 998244353.

Input

The first line contains a positive integer $n$. The next line contains $n$ non-negative integers representing $R_{0 \sim n-1}$.

The last line contains a binary string $s$ of length $2^n$ describing the set of non-negative integers $S$, where the $i$-th character being '1' indicates that $i-1 \in S$ (using 0-based indexing for the string, so the $j$-th character corresponds to the integer $j$).

Output

Output a single integer representing the answer modulo 998244353.

Examples

Input 1

2
4 5
1110

Output 1

19

Input 2

3
7 4 5
11100101

Output 2

80

Subtasks

For all test cases, it is guaranteed that $1 \leq n \leq 18$, $0 \leq R_i < 2^{60}$, and $s_0$ is '1'.

Test Case ID Special Constraints
$1 \sim 4$ $n \leq 2$
$5 \sim 7$ $\forall i, R_i \leq 3$
$8 \sim 10$ $n \leq 9$
$11 \sim 13$ $n \leq 11$
$14 \sim 16$ $n \leq 13$
$17 \sim 20$ None

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.