#P6155. 修改
修改
Description
Given an integer sequence of length , and an integer sequence of length .
You can do some modifications. Each time, you may increase one by , and the cost is . You need to make all 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 and .
Find the minimum cost.
Since the answer may be very large, output the value modulo .
Input Format
The first line contains an integer .
The second line contains integers; the -th number denotes .
The third line contains integers; the -th number denotes .
Output Format
Output one integer in one line, which is the answer modulo .
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 : do not change . Increase by and by , and the total cost is .
Sample : swap and . Increase by , and the total cost is .
Sample : do not change anything.
The input size of this problem is large, so please use fast input.
| Test Point | Special Property | ||
|---|---|---|---|
| None | |||
| All are equal | |||
| None |
Constraints: for all testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号