#1143
Unrated
KOCKICE
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Author: Antonio Jurić

Mirko and Slavko are playing with bricks. Both of them have their own pile of bricks. The piles consist of N columns (where N is an odd number). The number of bricks in the ith column of Mirko's pile is labeled with mi and Slavko's pile with si. They have decided to create two equal piles constructed in a way that the heights of columns are strictly descending at first and then strictly ascending (see right image below) and the heights of adjacent columns differ exactly by 1 (see image). The lowest of the columns must have an equal number of columns to the left and to the right of it. The piles can be modified by removing one brick from the top of some column and throw it out the window (they cannot reuse it) or by taking one brick from the box and place it on the top of some column (there is an infinite amount of bricks in the box). Removing or placing a brick counts as one move. You have to determine the minimal number of moves so that Mirko and Slavko can rearrange their piles in the described way.

On the left, there is a pile with column heights 3, 2, 0, 1 and 4. On the right, there is one of the possible final layouts.

입력

The first line of input contains an odd number N. (1 ≤ N ≤ 300 000), the number of columns in both piles. The second line of input contains N integers mi (0 ≤ mi ≤ 1012), column heights in Mirko's pile. The third line of input contains N integers si (0 ≤ si ≤ 1012), column heights in Slavko's pile.

출력

The first and only line of output must contain the minimal number of moves.

예제 입력 1

3
1 2 3
3 2 2

예제 출력 1

3

예제 입력 2

5
2 3 0 1 4
3 3 2 3 1

예제 출력 2

10
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.