#P7468. [NOI Online 2021 提高组] 愤怒的小 N

[NOI Online 2021 提高组] 愤怒的小 N

Problem Description

The extremely angry Little N played a game to vent his anger.

This game has a total of nn levels: Level 00, Level 11, Level 22, \cdots, Level n1n-1. Some of these levels are normal levels, and the others are bonus levels.

The distribution of normal and bonus levels in this game is special. Let character a\texttt{a} represent a normal level, and character b\texttt{b} represent a bonus level. Then the string formed by Level 00, Level 11, Level 22, \cdots, Level n1n-1 in order is a prefix of an infinite string ss, and ss can be constructed as follows:

  1. Initially, ss is the string containing a single character a\texttt{a}.

  2. Replace every character a\texttt{a} in ss with b\texttt{b}, and every character b\texttt{b} in ss with a\texttt{a} to obtain a string tt, then append tt to the end of ss.

  3. Repeat step 2 continuously. The resulting string is the final ss.

We can see that s=abbabaabbaababbas=\texttt{abbabaabbaababba}\cdots. Therefore, Level 00 of this game is a normal level, Level 11 is a bonus level, Level 22 is a bonus level, Level 33 is a normal level, and so on.

Passing Level ii gives f(i)f(i) points, where f(x)=a0+a1x+a2x2++ak1xk1f(x)=a_0+a_1x+a_2x^2+\cdots+a_{k-1}x^{k-1} is a fixed polynomial of degree k1k-1.

When Little N cleared the game in a fit of anger, he passed all bonus levels and ignored all normal levels, and then uninstalled the game. Now, thinking back, he wants to know the result of his total score before uninstalling the game modulo 109+710^9+7.

Input Format

The first line contains a positive integer nn, which is the number of levels in the game. For convenience, nn is given in binary.

The second line contains a positive integer kk, which is one plus the degree of the polynomial.

The third line contains kk non-negative integers a0,a1,a2,,ak1a_0,a_1,a_2,\cdots,a_{k-1}, which are the coefficients of the polynomial terms.

Output Format

Output one line containing a non-negative integer, which is Little N's total score before uninstalling the game modulo 109+710^9 + 7.

1000
3
3 2 1
110

11111100101
4
2 0 2 1
143901603

1001011001101001
16
1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1
184740992

Hint

For all test points: 0log2n<5×1050\le \log_2n<5\times 10^5, 1k5001\le k\le 500, 0ai<109+70\le a_i < 10^9 + 7, ak10a_{k-1}\ne 0.

Test Point ID log2n\log_2n\le kk\le
121\sim2 1010 500500
343\sim4 2020
585\sim8 100100
9109\sim10 500500
111211\sim12 5×1055\times 10^5 11
131613\sim16 100100
172017\sim20 500500

Thanks to s_r_f for providing the testdata.

Translated by ChatGPT 5