PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000048. Điều chỉnh các phần quà (Gifts Fixing)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Điều chỉnh các phần quà (Gifts Fixing)

Gifts Fixing

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn gifts, gift ii containing aia_i candies and bib_i oranges. One move on a gift removes one candy, one orange, or one of each simultaneously. Make all gifts identical in both quantities with the fewest moves.

Input

Line 1: nn. Line 2: nn numbers aia_i. Line 3: nn numbers bib_i.

Output

Print the minimum number of moves.

Subtasks

  • Subtask 1 (20 points): 1≤n≤41\le n\le 4; 1≤ai,bi≤1091\le a_i,b_i\le 10^9 for every ii.
  • Subtask 2 (30 points): 1≤n≤151\le n\le 15; 1≤ai,bi≤1091\le a_i,b_i\le 10^9 for every ii.
  • Subtask 3 (50 points): 1≤n≤501\le n\le 50; 1≤ai,bi≤1091\le a_i,b_i\le 10^9 for every ii.

Examples

Input

3
3 5 6
3 2 3

Output

6

Explanation

The best common quantities are 3 candies and 2 oranges. The gifts require max⁡(0,1)=1\max(0,1)=1, max⁡(2,0)=2\max(2,0)=2, and max⁡(3,1)=3\max(3,1)=3 moves, totaling 6.