#P5982. [PA 2019] Trzy kule

[PA 2019] Trzy kule

Description

For two binary strings a1..na_{1..n} and b1..nb_{1..n} of length nn, define their distance as $\operatorname{d(a,b)}=|a_1-b_1|+|a_2-b_2|+...+|a_n-b_n|$.

Given three binary strings s1,s2,s3s_1,s_2,s_3 of length nn and three non-negative integers r1,r2,r3r_1,r_2,r_3 (0rin)(0\le r_i\le n), ask how many binary strings SS of length nn satisfy that at least one of the following three inequalities holds: d(S,s[1])r1\operatorname{d(S,s[1])}\le r_1, d(S,s[2])r2\operatorname{d(S,s[2])}\le r_2, d(S,s[3])r3\operatorname{d(S,s[3])}\le r_3.

Input Format

The first line contains a positive integer nn.

The second line contains a non-negative integer r1r_1, followed by a binary string s1s_1 of length nn.

The third line contains a non-negative integer r2r_2, followed by a binary string s2s_2 of length nn.

The fourth line contains a non-negative integer r3r_3, followed by a binary string s3s_3 of length nn.

Output Format

Output one line containing one integer, which is the number of valid SS modulo 109+710^9+7.

5
2 10110
0 11010
1 00000
19

Hint

For 100%100\% of the testdata, 1n1041\le n\le 10^4.

Translated by ChatGPT 5