Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

C. Potions Homework

time limit per test

1 secondmemory limit per test

256 megabytesinput

standard inputoutput

standard outputHarry 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 *n* students has 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 by the sequence *a*, where *a*_{i} represents both the laziness level of the *i*-th student and the difficulty of his 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 are wondering, what is the minimum possible total time they must spend to finish all tasks if they distribute them in the optimal way. Each person should receive one task and each task should be given to one person. Print the answer modulo 10 007.

Input

The first line of input contains integer *n* (1 ≤ *n* ≤ 100 000) — the number of tasks. The next *n* lines contain exactly one integer number *a*_{i} (1 ≤ *a*_{i} ≤ 100 000) — both the difficulty of the initial task and the laziness of the *i*-th students.

Output

Print the minimum total time to finish all tasks modulo 10 007.

Example

Input

2

1

3

Output

6

Note

In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units.

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Apr/30/2017 16:00:23 (c4).

Desktop version, switch to mobile version.
User lists

Name |
---|