#d1903. 宝箱
宝箱
Treasure Chests
Problem Description
On the -axis there are keys and treasure chests. The player starts at position and may move one step to or 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 , the number of chests and keys.
The next line contains positive integers , where is the position of chest .
The third line contains positive integers , where is the position of key .
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, , , with and .