## Bubble Cup V9 D Potions homework

View as PDF

Points: 5
Time limit: 0.1s
Java 8 0.6s
Python 0.6s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe is sulky as usual. Due to his angst fueled by disappointment in his own life, he has given them a lot of homework in Potions class.

Each of the students have been assigned a single task. Some students do certain tasks faster than others. Thus, they want to redistribute the tasks so that each student still does exactly one task, and that all tasks are finished.

Each student has their own laziness level, and each task has its own difficulty level. Professor Snipe is trying hard to improve their work ethics, so each student's laziness level is equal to their task's difficulty level.

Both sets of values are given in the array , where represents both the laziness level of the student and the difficulty of their task. The time a student needs to finish a task is equal to the product of their laziness level and the task's difficulty.

They have asked you what is the shortest possible (total) time they must spend to finish all tasks.

#### Input Specification

The first line of input contains the integer , which represents the total number of tasks. The next lines contain exactly one integer each, which represents the difficulty of the task and the laziness of the student who initially received the task.

#### Output Specification

Your output should consist of only one line – the minimum time needed to finish all tasks, modulo .

#### Example Input

2
1
3

#### Example Output

6

#### Explanation

If the students switch their tasks, they will be able to finish them in time units.