Grammy and Oscar bought a big cake. They like it very much, so dividing the cake becomes difficult. In order to divide the cake in a relatively fair way, they decided to play a game to earn more part of the cake for themselves.
The game consists of two phases.
For phase

, Grammy and Oscar will play on a tree rooted at vertex

. Each edge of the tree has a number

or

. Initially, there is a horse on the root.
They take turns moving the horse, with Grammy moving first. At each turn, suppose the horse is at vertex

, the player must select some child of

and move the horse to that child of

. Phase

ends when

has no children. As a result of phase

, we will get a string

formed by concatenating the numbers on edges the horse has passed by. Note that

consists of only

and

.
For phase

, Grammy and Oscar will play on the string

they obtained in phase

. Let

be the length of

. Firstly, Oscar will divide the cake into

parts (some parts can be empty). Then

steps follow. At the

-th step, if the

-th character of

is

, Grammy will choose one part and get it; otherwise, Oscar will choose one part and get it.
Both of them hope to maximize the cake they get, and they both play optimally. Please calculate the fraction of cake Grammy gets.