Fibonacci Words

No attempts yetTime limit1sMemory limit128 MB

Problem

Fibonacci words are defined in a way similar to Fibonacci numbers:

FIB1=b,FIB2=a,FIBk+2=FIBk+1FIBk(k1)\mathrm{FIB}_1 = \texttt{b}, \quad \mathrm{FIB}_2 = \texttt{a}, \quad \mathrm{FIB}_{k+2} = \mathrm{FIB}_{k+1} \oplus \mathrm{FIB}_k \quad (k \ge 1)

where \oplus denotes concatenation of two words.

The first few Fibonacci words are therefore FIB3=ab\mathrm{FIB}_3 = \texttt{ab}, FIB4=aba\mathrm{FIB}_4 = \texttt{aba}, FIB5=abaab\mathrm{FIB}_5 = \texttt{abaab}, FIB6=abaababa\mathrm{FIB}_6 = \texttt{abaababa}.

You are given a pattern word made only of the letters a and b, together with an integer nn. Count how many times the pattern appears as a contiguous fragment of the nn-th Fibonacci word FIBn\mathrm{FIB}_n. Two occurrences may overlap, so every starting position whose fragment equals the pattern is counted separately.

Input

The first line contains the pattern word. It consists of between 11 and 3030 characters, each of which is a or b.

The second line contains one positive integer nn with n200n \le 200.

Output

Print one nonnegative integer: the number of times the pattern word appears in FIBn\mathrm{FIB}_n. The answer can be very large and may not fit in a 64-bit integer.