cswork / OAOpen practice workspace

AmazonOA #172

Find Minimum Dist.

Estimated EasyJudge-ready

Topics (AI-labelled)GreedyIn-place Arrays

There are n servers and n data centers on a line. Each is used exactly once to form a pair, and the cost of a pair is the absolute difference of their coordinates; minimize the total cost. The one-to-one semantics are established by the source's pairing example: a server cannot be used more than once.

Input

The first line contains n, the second line the server coordinates, and the third line the center coordinates. 1≤n≤100000, coordinates 1..10^9.

Output

Output a single integer, the answer.

Example 1

Input:

2
1 10
9 2

Output:

2

Example 2

Input:

2
3 3
3 3

Output:

0

Example 3

Input:

1
1
1000000000

Output:

999999999

Example notes

Example 1: 1 pairs with 2 and 10 with 9, total 2. Example 2: all points coincide, cost 0. Example 3: the only possible pairing, distance 999999999.

Editorial

Loading solution…