Perfect Pairing

View as PDF

Submit solution


Points: 100
Time limit: 1.0s
Memory limit: 977M

Problem type

You are given two arrays A and B, each containing n integers.

You must pair every element of A with exactly one element of B, and every element of B must be used in exactly one pair.

If you pair values x and y, that pair contributes |x - y| to the total cost.

Find the minimum possible total cost over all perfect pairings.

Input

The first line contains an integer n.

The second line contains n integers a_1, a_2, \dots, a_n.

The third line contains n integers b_1, b_2, \dots, b_n.

Output

Print one integer: the minimum possible total cost.

Constraints

  • 1 \le n \le 2 \cdot 10^5
  • -10^9 \le a_i, b_i \le 10^9

Example 1

Input
3
4 1 8
2 9 5
Output
3

Example 2

Input
5
7 -3 12 0 6
10 -1 8 5 -4
Output
6

Comments

There are no comments at the moment.