Problem I
IMO Harder Problem
After passing the final round of the Hunter Exam, Gon is now a Hunter! But before continuing his exciting journey, Gon decides to visit his home in ‘While Island’.
Aunt Mito is happy that Gon has become a Hunter and has visited home. But at the same time, she feels worried about Gon — the life of a Hunter is challenging. Thus, she will not allow Gon to leave ‘While Island’, unless Gon is able to solve a puzzle prepared by aunt Mito.
But what puzzle should Mito give to Gon? Mito opened ‘IMO 2019 Problems’ and found the following problem:
The Bank of Bath issues coins with an
on one side and a on the other. Prof. Tuy has of these coins arranged in a line from left to right. He repeatedly performs the following operation: if there are exactly coins showing , then he turns over the -th coin from the left; otherwise, all coins show and he stops. For example, if the process starting with the configuration would be: , which stops after three operations. Show that, for each initial configuration, Prof. Tuy stops after a finite number of operations.
‘This problem is too easy’ — Mito thought. ‘Gon will be able to solve it in no time’.
After some more thinking, Mito changed the above problem to the following harder version:
For each initial configuration
, let be the number of operations before Prof. Tuy stops. Given a sequence
consisting of , and , representing some initial state, where denotes an unknown state. Calculate the average value of over all possible sequences represented by .
Even though Gon is smart, he is still unable to solve this question. Please help Gon!
Input
The input contains a single non-empty line with at most
Output
The output must contain a single number — the average
value of
Your answer will be considered correct if its relative or
absolute error doesn’t exceed
Namely: let’s assume that your answer is
Sample Input 1 | Sample Output 1 |
---|---|
HH |
2.0 |
Sample Input 2 | Sample Output 2 |
---|---|
H? |
1.5 |
Sample Input 3 | Sample Output 3 |
---|---|
?? |
1.5 |