#ABC200F. [ABC200F] Minflip Summation

[ABC200F] Minflip Summation

Score : 600600 points

Problem Statement

We have a string SS consisting of 0, 1, and ?. Let TT be the concatenation of KK copies of SS. By replacing each ? in TT with 0 or 1, we can obtain 2Kq2^{Kq} strings, where qq is the number of ?s in SS. Solve the problem below for each of these strings and find the sum of all the answers, modulo (109+7)(10^9+7).

Let TT' be the string obtained by replacing ? in TT. We will repeatedly do the operation below to make all the characters in TT the same. At least how many operations are needed for this?

  • Choose integers ll and rr such that 1lrT1 \le l \le r \le |T'|, and invert the ll-th through rr-th characters of TT: from 0 and 1 and vice versa.

Constraints

  • 1S1051 \le |S| \le 10^5
  • 1K1091 \le K \le 10^9

Input

Input is given from Standard Input in the following format:

SS

KK

Output

Print the answer as an integer.

101
2
2

We have T=T= 101101, which does not contain ?, so we just need to solve the problem for the only T=T'= 101101. We can make all the characters the same in two operations as, for example, 101101 \rightarrow 110011 \rightarrow 111111. We cannot make all the characters the same in one or fewer operations.

?0?
1
3

We have four candidates for TT': 000, 001, 100, and 101.

10111?10??1101??1?00?1?01??00010?0?1??
998244353
235562598

Since the answer can be enormous, find it modulo (109+7)(10^9+7).