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

#GD0000059. Lựa chọn gần nhất chưa chắc tối ưu (Local Nearest Choice Counterexample)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Lựa chọn gần nhất chưa chắc tối ưu (Local Nearest Choice Counterexample)

Local Nearest Choice Counterexample

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Two groups of nn positions aia_i (processed in input order) and bib_i must be matched one-to-one, minimizing the sum of absolute distances. Compare a local nearest strategy that processes aia_i in input order and chooses the nearest unused bjb_j (breaking ties by smaller position, then smaller original index), versus the global optimum. Print both costs.

Input

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

Output

Print two integers: local-nearest cost and globally optimal cost.

Subtasks

  • Subtask 1 (20 points): 1≤n≤41\le n\le 4; −109≤ai,bi≤109-10^9\le a_i,b_i\le 10^9 for every ii.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; −109≤ai,bi≤109-10^9\le a_i,b_i\le 10^9 for every ii.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; −109≤ai,bi≤109-10^9\le a_i,b_i\le 10^9 for every ii.

Examples

Input

2
10 0
9 20

Output

21 19

Explanation

For a1=10a_1=10, the local choice is 9 (cost 1), leaving 20 for a2=0a_2=0 (cost 20), total 21. Matching 0 with 9 and 10 with 20 costs just 9+10=199+10=19.