Foreign Postcards

Place postcards in random batches, flipping a batch when its top card is upside down, and compute the expected number left picture down.

Medium7ProbabilityDynamic programmingCombinatoricsNo attempts yetTime limit2sMemory limit512 MB

Problem

Fedor travels often, and over the years he has collected postcards from all over the world. Each postcard has a picture on one side and space for an address and a message on the other side.

During a party at his house, Fedor decided to lay every postcard on the table so the guests can see them. The postcards start as a single stack in his hands, and some of them sit upside down, picture facing down. Instead of inspecting each postcard and turning it over one at a time, Fedor repeats the following procedure.

  1. Let nn be the number of postcards left in his hands. He picks kk uniformly at random among the integers from 11 to nn and takes the top kk postcards off the stack.
  2. He looks at the topmost of those kk postcards. If that postcard is upside down, he turns all kk postcards over at once.
  3. He puts those kk postcards on the table without turning them again.
  4. If any postcards are still in his hands, he goes back to step 1.

Turning kk postcards over at once reverses the orientation of every postcard in the group. A postcard that was picture up ends picture down, and a postcard that was picture down ends picture up. Each choice of kk is independent of the earlier choices.

Compute the expected number of postcards that lie picture down on the table when the procedure ends.

Input

The first line contains a string ss made only of the characters C and W. The ii-th character of ss describes the ii-th postcard counted from the top of the starting stack. C is a postcard that is picture up, and W is a postcard that is picture down. The length of ss is between 11 and 200000200000.

Output

Print on one line the expected number of postcards that lie picture down on the table, rounded to exactly six digits after the decimal point. Print all six digits, including trailing zeros.