Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ochkoz-kopaytmalar-minimumi

Minimum sum of products

Easy 1000 ms 128 MB 27%
Share

Two arrays are given: $a_{1}, \dots, a_{n}$ and $b_{1}, \dots, b_{n}$. Array $a$ stays as it is, while the elements of array $b$ may be rearranged in any order. Then the sum $a_{1} b_{1} + a_{2} b_{2} + \dots + a_{n} b_{n}$ is computed. Find its smallest value.

Two arrays: the smaller elements of a are paired with the larger elements of b

Input

The first line contains a positive integer $n$. The second line contains $n$ integers $a_{i}$, the third line contains $n$ integers $b_{i}$.

Output

One integer — the smallest value of the sum.

Note

$1 \le n \le 10^{5}$
$-10^{6} \le a_{i}, b_{i} \le 10^{6}$

Examples

Input #1
3
1 3 2
5 4 6
Output #1
28
Input #2
1
-3
7
Output #2
-21

Sign in to submit a solution

Signing up is free and takes a minute.