Roughly speaking, a treap is a BST (a binary search tree) and also a heap. Assume that we have different keys, and a fixed integer . Every key is independently associated with a priority (a random integer chosen uniformly from the interval ). Let be the key with the largest priority. Then, the treap for the set of pairs (key, priority) is the BST with at its root, the treap for the pairs with keys smaller than as its left subtree, and the treap for the pairs with keys larger than as its right subtree.
For instance, suppose that the keys are and . Then, the pairs (key, priority) could be (40, 189), (41, 350), (42, 960), (49, 234), (70, 800) and (80, 780). In this case, we would have the treap to the left:
$$\pstree[levelsep=40pt,treesep=30pt]{\Tcircle{\mbox{\color{blue} \scriptsize 42} \, \mbox{\color{red} \tiny (960)}}}{ \pstree{\Tcircle{\mbox{\color{blue} \scriptsize 41} \, \mbox{\color{red} \tiny (350)}}} { \pstree{\Tcircle{\mbox{\color{blue} \scriptsize 40} \, \mbox{\color{red} \tiny (189)}}} {} \Tn } \pstree{\Tcircle{\mbox{\color{blue} \scriptsize 70} \, \mbox{\color{red} \tiny (800)}}} { \pstree{\Tcircle{\mbox{\color{blue} \scriptsize 49} \, \mbox{\color{red} \tiny (234)}}} {} \pstree{\Tcircle{\mbox{\color{blue} \scriptsize 80} \, \mbox{\color{red} \tiny (780)}}} {} } } \enspace \pstree[levelsep=40pt,treesep=30pt]{\Tcircle{\mbox{\color{blue} \scriptsize 3} \, \mbox{\color{red} \tiny (42)}}}{ \Tn \pstree{\Tcircle{\mbox{\color{blue} \scriptsize 5} \, \mbox{\color{red} \tiny (42)}}} {} } \qquad \pstree[levelsep=40pt,treesep=30pt]{\Tcircle{\mbox{\color{blue} \scriptsize 5} \, \mbox{\color{red} \tiny (42)}}}{ \pstree{\Tcircle{\mbox{\color{blue} \scriptsize 3} \, \mbox{\color{red} \tiny (42)}}} {} \Tn } \qquad \pstree[levelsep=40pt,treesep=30pt]{\Tcircle{\mbox{\color{blue} \scriptsize 3} \, \mbox{\color{red} \tiny (42)}}}{ \pstree{\Tcircle{\mbox{\color{blue} \scriptsize 2} \, \mbox{\color{red} \tiny (23)}}} {} \pstree{\Tcircle{\mbox{\color{blue} \scriptsize 5} \, \mbox{\color{red} \tiny (23)}}} {} }$$
If we only look at the keys (in blue), we have a BST. If we only look at the priorities (in red), we have a sort of a heap (the largest at the top; the same property holds recursively).
This definition is usually good enough in many practical situations. However, there is a caveat: With repeated priorities, we can have more than one possible treap. For example, the second and the third treaps above are possible for the pairs (3, 42) and (5, 42).
Note that we can have a unique treap with repeated priorities. Consider for instance the pairs (2, 23), (3, 42) and (5, 23). The only possible treap is the fourth above.
Given and , what is the probability that the treap is unique?
Input consists of several cases, each with and . Assume and .
For every case, print the probability that the treap is unique with four digits after the decimal point. The input cases have no precision issues.
Input
1 100 2 2 3 3 50 5000
Output
1.0000 0.5000 0.3333 0.9656