QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 512 MB 満点: 100 ハック可能 ✓

#9902. Summation

統計

Given two arrays $a$ and $b$ of length $n$.

Please calculate:

$$ \sum_{i=1}^n \sum_{j=1}^n \min(|a_i - a_j|, |b_i - b_j|) $$

Input

The first line contains a positive integer $n$ ($1 \leq n \leq 10^5$), representing the length of the arrays.

The second line contains $n$ positive integers, representing the array $a_i$ ($1 \leq a_i \leq 10^6$).

The third line contains $n$ positive integers, representing the array $b_i$ ($1 \leq b_i \leq 10^6$).

Output

Output a single integer representing the answer.

Examples

Input 1

2
5 2
2 8

Output 1

6

Input 2

5
7 2 8 4 1
2 2 6 4 3

Output 2

34

Note

For $30\%$ of the test cases: $n \leq 1000$.

For another $20\%$ of the test cases: $a_i, b_i \leq 50$.

For another $30\%$ of the test cases: $a_i = b_i$.

For all test cases: $1 \leq n \leq 10^5, 1 \leq a_i, b_i \leq 10^6$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.