QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 256 MB مجموع النقاط: 100 الصعوبة: [عرض]

#1065. Continuous Subsequence

الإحصائيات

We define the T. M. sequence $\{T_n\}$ as a boolean sequence of the following form:

  • $T_0 = 0$;
  • $T_{2n} = T_n$;
  • $T_{2n+1} = 1 - T_n$.

Here we provide the first few terms of the T. M. sequence: $01101001100101101001011001101001 \dots$.

The T. M. sequence is an infinite sequence, and it has many contiguous subsequences. For example, $0$, $1$, $10100$, $10011$, and $011001$ are all its contiguous subsequences, while $111$ and $1000$ are not.

Given a boolean sequence (a $01$ string) $S$ and a non-negative integer $k$, count how many contiguous subsequences $T$ of the T. M. sequence satisfy:

  • $S$ is a prefix of $T$;
  • $T$ is formed by appending exactly $k$ terms to the right of $S$.

Input

The first line contains an integer $T$, representing the total number of test cases.

Following this, there are $T$ lines, each containing a $01$ string $S$ (representing a boolean sequence) and a non-negative integer $k$ for each test case.

Output

For each test case, output a single line containing an integer representing the number of contiguous subsequences that satisfy the conditions. Since the value can be very large, output the result modulo $10^9 + 9$.

Examples

Input 1

5
1001 3
11001 10
00111 10
0011 20
0 100

Output 1

3
4
0
6
164

Subtasks

  • Subtask 1: (20 points) $1 \le T \le 100$, the length of the given boolean sequence does not exceed $100$, and $0 \le k \le 100$.
  • Subtask 2: (20 points) $1 \le T \le 100$, the length of the given boolean sequence does not exceed $100$, and $0 \le k \le 50000$.
  • Subtask 3: (60 points) $1 \le T \le 100$, the length of the given boolean sequence does not exceed $100$, and $0 \le k \le 10^{18}$.

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.