Farmer John raises breeds of cows, and each of his fields is dedicated to grazing cows of one specific breed. For example, a field dedicated to breed can only be used by cows of breed , and not by cows of any other breed.
A long road runs through Farmer John's farm. There is a sequence of fields on one side of the road, one for each breed, and another sequence of fields on the other side, also one for each breed. When a cow crosses the road, she therefore travels between the two fields designated for her breed.
Had Farmer John planned more carefully, he would have arranged the fields in the same order on both sides of the road, so that the two fields for each breed would be directly opposite each other. This would allow cows to cross the road without cows of different breeds having to cross paths. Unfortunately, the orderings on the two sides of the road may be different, so some pairs of breeds may have crossing paths. A pair of distinct breeds is called a "crossing pair" if every possible path across the road for breed must intersect every possible path across the road for breed .
Farmer John would like to minimize the number of crossing pairs of breeds. For logistical reasons, he can rearrange the fields on one side of the road by applying a "cyclic shift." That is, for some 0 \le k < n, every field is shifted positions forward, with the fields in the last positions wrapping around to the first positions.
For example, if the fields on one side of the road are initially ordered by breed as 3, 7, 1, 2, 5, 4, 6 and are shifted by k = 2, the new order becomes 4, 6, 3, 7, 1, 2, 5.
Determine the minimum possible number of crossing pairs of breeds after applying an appropriate cyclic shift to the fields on one side of the road.
The first line contains n~(1 \le n \le 10^5).
The next lines describe the order, by breed ID, of the fields on one side of the road. Each breed ID is an integer from to .
The following lines describe the order, by breed ID, of the fields on the other side of the road.
Print the minimum possible number of crossing pairs of breeds after applying a cyclic shift to the fields on one side of the road. Either side may be shifted.
Example 1