## Yet Another Contest 1 P1 - Mixed Doubles

View as PDF

Points: 7 (partial)
Time limit: 0.3s
Java 1.0s
Python 1.0s
Memory limit: 256M

Author:
Problem types

Mike is in charge of coaching a tennis club, and the mixed doubles tournament against other clubs is soon approaching!

The club contains men and women, and Mike must form pairs; each pair must contain a man and a woman, such that each player is in exactly one pair.

The -th man has a skill level of , and the -th woman has a skill level of . If the -th man and -th woman are paired, then the skill level of the pair is . Mike wants the team to do well as a whole, so he aims to maximise the total skill level of all pairs.

There are minutes before the tournament starts. In each minute, Mike can train exactly one man or woman, increasing their skill level by .

What is the maximum possible sum of the skill level of all pairs once the tournament starts? Because the answer may be very large, output the answer modulo .

#### Input Specification

The first line contains two space separated integers , .

The next line contains space separated integers, , representing the initial skill level of the men.

The next line contains space separated integers, , representing the initial skill level of the women.

#### Output Specification

On a single line, print the maximum possible sum of the skill levels of all pairs, modulo .

#### Sample Input

3 2
4 7 6
2 5 6

#### Sample Output

94

#### Explanation

In the first minute, Mike can increase the skill level of the second man.

In the second minute, Mike can increase the skill level of the third woman.

Mike can then pair the first man and the first woman, the second man and the third woman, as well as the third man and the second woman.

The total sum of skill levels of all pairs would be . It can be shown that this is the maximum possible total skill level.