#P6155. 修改

修改

Description

Given an integer sequence aia_i of length nn, and an integer sequence bib_i of length nn.

You can do some modifications. Each time, you may increase one aia_i by 11, and the cost is bib_i. You need to make all aia_i pairwise distinct, and at the same time minimize the total cost.

However, zbw thinks this is too easy, so he specifies that before making modifications, you may perform the following operation an unlimited number of times: swap bib_i and bjb_j (1i,jn)(1 \leq i,j \leq n).

Find the minimum cost.

Since the answer may be very large, output the value modulo 2642^{64}.

Input Format

The first line contains an integer nn.

The second line contains nn integers; the ii-th number denotes aia_i.

The third line contains nn integers; the ii-th number denotes bib_i.

Output Format

Output one integer in one line, which is the answer modulo 2642^{64}.

3
3 3 3
1 2 3
4
3
3 3 4
3 2 1
2
3
3 4 5
2 1 3
0

Hint

Sample 11: do not change bb. Increase a1a_1 by 22 and a2a_2 by 11, and the total cost is 44.

Sample 22: swap b1b_1 and b3b_3. Increase a1a_1 by 22, and the total cost is 22.

Sample 33: do not change anything.

The input size of this problem is large, so please use fast input.

Test Point nn aia_i Special Property
1,21,2 10\leq 10 109\leq 10^9 None
363\sim6 103\leq 10^3
7107\sim10 106\leq 10^6 106\leq 10^6
111411\sim14 109\leq 10^9 All bib_i are equal
152015\sim20 None

Constraints: for all testdata, 1n1061 \leq n \leq 10^6, 1ai,bi1091 \leq a_i,b_i \leq 10^9.

Translated by ChatGPT 5