Why cows cross the road is still an open question, but it is well known that Farmer John's cows cross the road often. They cross so often that they sometimes bump into each other on the way, and John wants to fix this.
The farm has one straight road with N pastures on each side (1≤N≤100000). Pastures for different breeds are built so differently that each pasture can hold only one specific breed: pasture i can hold only cow breed i. When a cow crosses the road, it moves to the pasture on the opposite side that holds its own breed.
John did not pay attention when he built the pastures, so their order is jumbled, and the paths of a cow of breed a and a cow of breed b may cross. Call such a pair (a,b) a "crossing pair".
To reduce the number of crossing pairs, John came up with a way to rearrange the farm. He picks an integer k with 0≤k<N and moves the last k pastures on one side of the road to the front, keeping their order. For example, if the pastures are numbered 3, 7, 1, 2, 5, 4, 6 in order and k=2, then after the move they are numbered 4, 6, 3, 7, 1, 2, 5. He may apply the move to either the left side or the right side of the road, but only to one of them.
Help John make the number of crossing pairs as small as possible.