QOJ.ac

QOJ

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

#9902. 求和

الإحصائيات

给定两个长度为 $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$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.