QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#9902. 求和

Statistics

给定两个长度为 $n$ 的数组 $a, b$。

请计算:

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

Input

第一行一个正整数 $n$ ($1 \leq n \leq 10^5$) 表示数组的长度。

第二行 $n$ 个正整数,表示数组 $a_i$ ($1 \leq a_i \leq 10^6$)。

第三行 $n$ 个正整数,表示数组 $b_i$ ($1 \leq b_i \leq 10^6$)。

Output

一行一个整数表示答案。

Examples

Input

2
5 2
2 8

Output

6

Input

5
7 2 8 4 1
2 2 6 4 3

Output

34

Notes

对于 $30\%$ 的测试点: $n \leq 1000$。

对于另外 $20\%$ 的测试点: $a_i, b_i \leq 50$。

对于另外 $30\%$ 的测试点: $a_i = b_i$。

对于所有测试点:$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: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.