Rock Skipping#2652

Rock Skipping

1 second
64 megabytes
Very hard

You are skipping rocks on a lake. To skip a rock, you throw the rock horizontally with its flattest edge down and parallel to the lake and spin it as it leaves your hand. The rock will skim the surface of the water, leap back into the air for a distance, then skim again, repeating this process until it sinks. The spin keeps the rock flat as it travels, and its direction stays constant. The path of the rock as it skips across the lake is unusual due to the imperfect surfaces of both the rock and the lake. On average, the distances of the rock's skips decrease as it gets further, probably due to the resistance of the water and air. However, sometimes the rock may skip further than before. If the rock lands on a lily pad, it immediately sinks after sliding over it. The number of skips appears relatively consistent (unless it hits a lily pad).

As a computer scientist, you are to devise a function to calculate the probability that a skipping rock will avoid all the lily pads. The function takes two inputs: the lily pad pattern () in the direction you are throwing, and the maximum distance () that the rock will skip after striking the water for the first time.

is input as a string. Each character in the string represents a space on the lake: for open water and for a lily pad. Assume the lake continues infinitely to the right with the given pattern repeating. For example, the pattern corresponds to the infinite lake .\textbf{X}.\textbf{X}... \textbf{X}.\textbf{X}... \textbf{X}.\textbf{X}.. extending to the right. You throw your rock from the left, aiming so that the rock lands on the first space (the first character of , which is always open water). Assume the horizontal direction of the rock does not change (i.e., movement is always along the lily pad pattern).

represents how hard you throw the rock. For the first skip, the maximum distance is lake spaces. After each skip, the maximum distance decreases by one, so for skip (starting from ), the maximum is maxDist - N. The rock sinks when N = maxDist or when the rock lands on a lily pad. For skip , the rock is equally likely to land at any integral distance from to maxDist - N (assume it always lands at the center of a space).

The output should be a probability between and , representing the percentage chance that the rock does not hit any lily pads.

Input

The first line contains the string . It will have between and characters, each either or .

The second line contains . It will be between and , inclusive.

Output

Output a single value: the probability, from to . Your answer will be accepted if its relative or absolute error does not exceed 10^{-9} of the correct answer.

Examples

Example 1

Loading
Loading