#d1903. 宝箱

宝箱

Treasure Chests

Problem Description

On the XX-axis there are NN keys and NN treasure chests. The player starts at position x=0x = 0 and may move one step to x+1x + 1 or x−1x - 1 each turn.

When the player reaches a position that has a key, they may pick it up. When the player reaches a position that has a treasure chest, they may choose to use a key to open it.

Find the minimum number of steps the player needs to open all the treasure chests.

Note: a position may simultaneously contain both a chest and a key, but no position contains more than one chest or more than one key.

Input Format

The first line contains a positive integer NN, the number of chests and keys.

The next line contains NN positive integers b1,b2,…,bnb_1, b_2, \dots, b_n, where bib_i is the position of chest ii.

The third line contains NN positive integers c1,c2,…,cnc_1, c_2, \dots, c_n, where cic_i is the position of key ii.

Output Format

One line containing a positive integer: the answer.

Sample Input 1

4
1 6 7 12
3 5 10 11

Sample Output 1

21

Sample Input 2

2
1 2
1 1000000000

Sample Output 2

1999999998

Constraints

For all data, 1≤N≤1051 \le N \le 10^5, 1≤bi,ci≤1091 \le b_i, c_i \le 10^9, with b1<b2<⋯<bnb_1 < b_2 < \dots < b_n and c1<c2<⋯<cnc_1 < c_2 < \dots < c_n.