303710: CF717C. Potions Homework

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Potions Homework

题意翻译

有一长度为 $n$ 的数组 $a_i$,求其重排后的数组 $b_i$,使 $v=\sum\limits_{i=1}^na_ib_i$ 最小,输出 $v \bmod 10007$ 的结果。

题目描述

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 $ 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 $ 10007 $ .

输入输出格式

输入格式


The first line of input contains integer $ n $ ( $ 1<=n<=100000 $ ) — the number of tasks. The next $ n $ lines contain exactly one integer number $ a_{i} $ ( $ 1<=a_{i}<=100000 $ ) — both the difficulty of the initial task and the laziness of the $ i $ -th students.

输出格式


Print the minimum total time to finish all tasks modulo $ 10007 $ .

输入输出样例

输入样例 #1

2
1
3

输出样例 #1

6

说明

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

Input

题意翻译

有一长度为 $n$ 的数组 $a_i$,求其重排后的数组 $b_i$,使 $v=\sum\limits_{i=1}^na_ib_i$ 最小,输出 $v \bmod 10007$ 的结果。

加入题单

上一题 下一题 算法标签: