CF BUDDY
← Problems·

1045H · Self-exploration

2400 · math

Problem: Being bored of exploring the Moon over and over again Wall-B decided to explore something he is made of — binary numbers. He took a binary number and decided to count how many times different substrings of length two appeared. He stored those values in c00c_{00}, c01c_{01}, c10c_{10} and c11c_{11}, representing how many times substrings 00, 01, 10 and 11 appear in the number respectively. For example:

10111100c00=1, c01=1, c10=2, c11=310111100 \rightarrow c_{00} = 1, \ c_{01} = 1,\ c_{10} = 2,\ c_{11} = 3

10000c00=3, c01=0, c10=1, c11=010000 \rightarrow c_{00} = 3,\ c_{01} = 0,\ c_{10} = 1,\ c_{11} = 0

10101001c00=1, c01=3, c10=3, c11=010101001 \rightarrow c_{00} = 1,\ c_{01} = 3,\ c_{10} = 3,\ c_{11} = 0

1c00=0, c01=0, c10=0, c11=01 \rightarrow c_{00} = 0,\ c_{01} = 0,\ c_{10} = 0,\ c_{11} = 0

Wall-B noticed that there can be multiple binary numbers satisfying the same c00c_{00}, c01c_{01}, c10c_{10} and c11c_{11} constraints. Because of that he wanted to count how many binary numbers satisfy the constraints cxyc_{xy} given the interval [A,B][A, B]. Unfortunately, his processing power wasn't strong enough to handle large intervals he was curious about. Can you help him? Since this number can be large print it modulo 109+710^9 + 7.

Input Format: First two lines contain two positive binary numbers AA and BB (1AB<21000001 \leq A \leq B < 2^{100\,000}), representing the start and the end of the interval respectively. Binary numbers AA and BB have no leading zeroes.

Next four lines contain decimal numbers c00c_{00}, c01c_{01}, c10c_{10} and c11c_{11} (0c00,c01,c10,c111000000 \leq c_{00}, c_{01}, c_{10}, c_{11} \leq 100\,000) representing the count of two-digit substrings 00, 01, 10 and 11 respectively.

Output Format: Output one integer number representing how many binary numbers in the interval [A,B][A, B] satisfy the constraints mod 109+710^9 + 7.

Note: Example 1: The binary numbers in the interval [10,1001][10,1001] are 10,11,100,101,110,111,1000,100110,11,100,101,110,111,1000,1001. Only number 110 satisfies the constraints: c00=0,c01=0,c10=1,c11=1c_{00} = 0, c_{01} = 0, c_{10} = 1, c_{11} = 1.

Example 2: No number in the interval satisfies the constraints

Sample Cases

Case 1

Input

10
1001
0
0
1
1

Output

1

Case 2

Input

10
10001
1
2
3
4

Output

0

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback