A - 数値列の一致 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 233

問題文

高橋君は長さ N の整数列 A = (A_1, A_2, \dots, A_N) を、青木君は同じく長さ N の整数列 B = (B_1, B_2, \dots, B_N) を持っています。

高橋君と青木君は、2人の整数列を各要素ごとに一致させたいと考えています。そのために、以下の操作を何度でも繰り返し行うことができます。なお、同じインデックスを複数回選ぶこともできます。

1回の操作では、インデックス i1 \leq i \leq N)を1つ選び、以下の4つのうちちょうど1つを行います。

  • A_i の値を 1 増やす
  • A_i の値を 1 減らす
  • B_i の値を 1 増やす
  • B_i の値を 1 減らす

すべての i1 \leq i \leq N)について A_i = B_i となる状態にするために必要な操作回数の最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq A_i \leq 10^91 \leq i \leq N
  • -10^9 \leq B_i \leq 10^91 \leq i \leq N
  • 入力はすべて整数である。

入力

N
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N
  • 1 行目には、整数列の長さを表す整数 N が与えられる。
  • 2 行目には、高橋君の整数列の要素 A_1, A_2, \dots, A_N がスペース区切りで与えられる。
  • 3 行目には、青木君の整数列の要素 B_1, B_2, \dots, B_N がスペース区切りで与えられる。

出力

すべての i について A_i = B_i とするために必要な操作回数の最小値を 1 行で出力せよ。


入力例 1

3
1 3 5
2 1 5

出力例 1

3

入力例 2

5
3 -1 0 7 -5
-2 4 0 10 -5

出力例 2

13

入力例 3

8
1000000000 -999999999 500000000 0 -100 42 -7 123456789
-1000000000 999999999 -500000000 0 200 -58 7 -987654321

出力例 3

6111111522

Score : 233 pts

Problem Statement

Takahashi has an integer sequence of length N: A = (A_1, A_2, \dots, A_N), and Aoki has an integer sequence of the same length N: B = (B_1, B_2, \dots, B_N).

Takahashi and Aoki want to make their two integer sequences match element by element. To achieve this, they can perform the following operation any number of times. The same index may be chosen multiple times.

In one operation, choose an index i (1 \leq i \leq N) and perform exactly one of the following four actions:

  • Increase the value of A_i by 1
  • Decrease the value of A_i by 1
  • Increase the value of B_i by 1
  • Decrease the value of B_i by 1

Find the minimum number of operations required to reach a state where A_i = B_i for all i (1 \leq i \leq N).

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • -10^9 \leq B_i \leq 10^9 (1 \leq i \leq N)
  • All inputs are integers.

Input

N
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N
  • The first line contains an integer N representing the length of the integer sequences.
  • The second line contains the elements of Takahashi's integer sequence A_1, A_2, \dots, A_N, separated by spaces.
  • The third line contains the elements of Aoki's integer sequence B_1, B_2, \dots, B_N, separated by spaces.

Output

Print the minimum number of operations required to make A_i = B_i for all i, on a single line.


Sample Input 1

3
1 3 5
2 1 5

Sample Output 1

3

Sample Input 2

5
3 -1 0 7 -5
-2 4 0 10 -5

Sample Output 2

13

Sample Input 3

8
1000000000 -999999999 500000000 0 -100 42 -7 123456789
-1000000000 999999999 -500000000 0 200 -58 7 -987654321

Sample Output 3

6111111522