When you can guess the solution, it's a shame to think at it.
After helping Don identify the intruders, he has put his trust in you. Therefore, to prevent the appearance of other intruders, Don has given you the number and two sequences and of natural numbers.
We denote the absolute value of by .
For a sequence of integers, we define the minimum value of the sum for an integer .
You can form any sequence of natural numbers with the property that or for each from to .
Task
To keep your job as an advisor to the organization, you need to find the minimum value of for all the sequences that you can form.
Input data
The first line of the input file gadfadar3.in
contains a non-zero natural number . The second line contains natural numbers, separated by spaces, representing the sequence . The third line contains natural numbers, separated by spaces, representing the sequence .
Output data
The first line of the output file gadfadar3.out
will contain a single integer, representing the minimum value of among all the sequences that you can form.
Constraints and clarifications
# | Score | Constraints |
---|---|---|
1 | 5 | and |
2 | 9 | |
3 | 11 | and |
4 | 17 | |
5 | 22 | and |
6 | 36 | No other constraints |
Example 1
gadfadar3.in
5
2 6 10 2 5
3 9 3 1 2
gadfadar3.out
5
Explanation
We can form the sequence , and if we choose .
Example 2
gadfadar3.in
7
1 2 5 0 9 30 7
11 30 30 5 8 0 7
gadfadar3.out
17
Explanation
We can form the sequence , and if we choose .