Problem C. Ringland
时间限制 3000 ms
内存限制 128 MB
Patrick Star found the Ringland! It's marriage season in Ringland!
Ringland has a form of a circle's boundary of length $L$.
There are $N$ bridegrooms and $N$ brides, and bridegrooms decided to marry brides.
Of course, each bridegroom should choose exactly one bride, and each bride should be chosen by exactly one bridegroom.
All objects in Ringland are located on the boundary of the circle, including the capital, bridegrooms' castles and brides' palaces. The castle of the i-th bridegroom is located at the distance $a_i$ from the capital in clockwise direction, and the palace of the i-th bride is located at the distance $b_i$ from the capital in clockwise direction.
Let's define the inconvenience of a marriage the summary distance of every bride should walk along the circle from her palace to her bridegroom's castle in the shortest direction (in clockwise or counter-clockwise direction).
Help Patrick Star to calculate the smallest inconvenience among all marriages !
输入数据
输出数据
For each test case print one line,
This line contain only one integer, the smallest possible inconvenience of the wedding.
样例输入
样例输出
$ Mathjax font initiator $