#d2814. 排队
排队
Queuing Up
Problem Description
On an ancient planet, a group of people gather every year for a grand anniversary celebration. Before entering the venue, everyone lines up into two teams at the entrance, each team having exactly people. In the first team the -th person has height , and in the second team the -th person has height .
While queuing, people like to chat amiably with the partner standing at the same position in the other team. However, if the two people differ too much in height, they feel a bit awkward. The awkwardness index of the two is related to their height difference by .
To minimize the awkwardness as much as possible, people in each team may swap positions with an adjacent neighbor any number of times, but only within their own team. What is the minimum number of swaps needed so that the total awkwardness is minimized? If the answer is too large, output this minimum number of swaps modulo .
It is guaranteed that within each team all heights are pairwise distinct.
Input Format
The input consists of three lines. The first line is a positive integer , the number of people in each team. The second line contains integers separated by spaces, the heights of the first team. The third line contains integers separated by spaces, the heights of the second team.
Output Format
Output one integer: the minimum number of swaps.
Sample Input
4
2 3 1 4
3 2 1 4
Sample Output
1
Sample Explanation
We only need to swap the first two people of the first team, or swap the first two people of the second team. Then everyone chats with a partner of exactly the same height, making the total awkwardness , which is minimal.
Constraints
, ; it is guaranteed that within each team all heights are pairwise distinct.