luogu#P16329. bloom
bloom
Problem Description
You are given and two sequences and of length . Some values of are fixed, while some are unknown. Each position also has a type, either or . You need to assign values to the unknown so that and .
For every possible assignment of , consider the following game. Compute the sum of the game's weight over all assignments of , modulo .
-
The game consists of rounds. At the beginning of the -th round, the health of the -th player, denoted by , is set to , and their type is determined by the -th bit in the binary representation of . Here, is indexed from .
-
At the beginning of each round, all people of type start moving to the right simultaneously, while people of type stay still. Everyone moves one cell per unit time.
-
Whenever a type- person meets a type- person, suppose their indices are , and let . Then perform simultaneously: . Any person with disappears.
-
The weight of this round is the product of the initial values of all people still existing after units of time.
-
The weight of the game is the sum of the weights of all rounds.
Input Format
The first line contains two positive integers .
The second line contains non-negative integers , where indicates that this position is undetermined.
The third line contains positive integers , representing the initial weight of each person.
Output Format
Output a single integer — the sum of the game weights over all valid assignments, modulo .
2 3
1 2
2 2
14
4 4
1 1 0 0
2 2 3 3
239
6 10
0 1 1 0 0 2
743619643 294476845 718152187 194051637 59774782 188785641
285625840
Hint
Sample Explanation 1
The game lasts for rounds:
- In the -st round, the types of the two players are and . Both of them survive until the end, so the weight is .
- In the -nd round, the types of the two players are and . After unit of time, they collide, and their health becomes and . Only the second player survives, so the weight is .
- In the -rd round, the types of the two players are and . Both of them survive until the end, so the weight is .
- In the -th round, the types of the two players are and . Both of them survive until the end, so the weight is .
Thus, the answer is .
Constraints
For all test cases, , , , and it is guaranteed that there exists at least one valid assignment of .
| Subtask | Special Property | Score | |
|---|---|---|---|
| None | |||
| Yes | |||
| None |
- Special property: It is guaranteed that .