Niebieskie ksi.eczki
III Olympiad in Informatics 1995/1996

Task: FIB
Author: Wojciech Rytter
Fibonacci words

II stage contest  

Fibonacci words are defined similarly to Fibonacci numbers:  
    FIB1 = b     FIB2 = a     FIBk+2 = FIBk+1*FIBk for k >= 1,
where * denotes operation of connecting words (concatenation). 

Hence we have:
FIB3 = ab;     FIB4 = aba;     FIB5 = abaab;     FIB6 = abaababa.

 

Task

Write a program that:

Input

In the first line of the text file FIB.IN there is written one word. The word is composed of at least one and at most 30 characters a or b. In the second line there is written one positive integer n <= 200.

Output

In the text file FIB.OUT there should be written one nonnegative integer. It should be equal to the number of times the given word appears in the Fibonacci word FIBn.  

Example

For the input file FIB.IN:
aba
6

In the output file FIB.OUT should be written one integer:
3

Your program should look for the file FIB.IN in the current directory and produce the output file FIB.OUT in the current directory too. The file containing the source code of your program should have a name FIB.???, whereas you should put three-letter abbreviation of the used programming language name instead of ???. The same program in executable form should be written in the file FIB.EXE