P29313 [洛谷] Modification
提高-
题目描述

Problem Description

Given a sequence of integers \( a_i \) of length \( n \), and another sequence of integers \( b_i \) of the same length \( n \).

You can perform some modifications. Each modification allows you to increase an \( a_i \) by 1, with a cost of \( b_i \). Your goal is to make all \( a_i \) distinct with the minimum total cost.

However, zbw thinks this is too simple, so he allows you to perform an unlimited number of the following operations before making any modifications: swap \( b_i \) and \( b_j \) where \( 1 \leq i, j \leq n \).

Find the minimum cost.

Since the answer may be very large, output the answer modulo \( 2^{64} \).

Input Format

The first line contains an integer \( n \).

The second line contains \( n \) integers, the \( i \)-th of which represents \( a_i \).

The third line contains \( n \) integers, the \( i \)-th of which represents \( b_i \).

Output Format

Output a single integer, which is the answer modulo \( 2^{64} \).

Sample Input and Output

Sample Input #1

3
3 3 3
1 2 3

Sample Output #1

4

Sample Input #2

3
3 3 4
3 2 1

Sample Output #2

2

Sample Input #3

3
3 4 5
2 1 3

Sample Output #3

0

Notes

Sample 1: Without changing \( b \), increase \( a_1 \) by 2 and \( a_2 \) by 1, with a total cost of 4.

Sample 2: Swap \( b_1 \) and \( b_3 \), then increase \( a_1 \) by 2, with a total cost of 2.

Sample 3: No changes are needed.

This problem has a large input size, please use input optimization.

Test Case \( n \) \( a_i \) Special Property
1, 2 \(\leq 10\) \(\leq 10^9\) None
3-6 \(\leq 10^3\) \(\leq 10^9\) None
7-10 \(\leq 10^6\) \(\leq 10^6\) None
11-14 \(\leq 10^6\) \(\leq 10^9\) All \( b_i \) are equal
15-20 \(\leq 10^6\) \(\leq 10^9\) None

For all data, \( 1 \leq n \leq 10^6 \), \( 1 \leq a_i, b_i \leq 10^9 \).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 3 3 3 1 2 3
样例输出
4