Tree Count

루트 트리의 DFS 순서와 BFS 순서가 주어질 때, 두 순서를 모두 만족하는 모든 트리의 높이 평균을 구한다.

어려움8트리DFSBFS조합론아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

We know that a rooted tree can be traversed via depth-first search (DFS) and breadth-first search (BFS) to obtain the DFS and BFS orderings of their vertices. Two different trees can have the same DFS ordering, and at the same time their BFS orderings can also be the same. For example, the following two trees both have a DFS ordering of 1 2 4 5 3 and a BFS ordering of 1 2 3 4 5.

Given a DFS and BFS ordering, we would like to know the average height of all rooted trees satisfying the condition. For example, if there are K different rooted trees simultaneously possessing the DFS and BFS orderings, and their heights are respectively h1, h2, …, hK, then you are asked to output the value of (h1 + h2 + … + hK)/K.

입력

The first line contains a single positive integer n, representing the number of vertices.

The second line contains n positive integers (each between 1 and n, inclusive), representing the DFS ordering.

The third line contains n positive integers (each between 1 and n, inclusive), representing the BFS ordering.

The input guarantees that at least one tree satisfying the two orderings will exist.

출력

Output a single real number, representing the average height of the trees. The answer will be considered correct if the absolute error is at most 0.001.

If a rooted tree has only one vertex, then its height is 1. Otherwise, it's height is equal to 1 plus the maximum height across all of the subtrees rooted at each children.

제한

2 ≤ n ≤ 200000