FIICode 2025 Qualifying Round - Studenți | Frumusel

This was the problem page during the contest. Access the current page here.
Time limit: 2s Memory limit: 256MB Input: Output:

Task

Given an number nn and an array a=[a1,a2,...,an]a=[a_1,a_2,...,a_n], we define its beauty f(a)f(a) as follows:

f(a)=i=1naia(imodn)+1=a1a2+a2a3++an1an+ana1f(a)=\sum_{i=1}^{n} \left| a_i-a_{(i \bmod n) +1} \right|=|a_1-a_2|+|a_2-a_3|+\ldots+|a_{n-1}-a_n|+|a_n-a_1|.

You are given a number nn and an array v=[v1,v2,...,vn]v=[v_1,v_2,...,v_n] consisting of nn distinct positive integers.
You must find out the average beauty of all permutations of aa modulo 109+710^9+7.

Input data

The first line of input contains a single integer nn (1n31051 \le n \le 3 \cdot 10^5) - the length of array vv.

The second line of input contains nn integers v1,v2,..,vnv_1,v_2,..,v_n (0vi1090 \le v_i \le 10^9) - the elements of array vv.

Output data

It is guaranteed that the real answer is of form pq\frac {p}{q} where pp, qq are nonnegative integers .
You need to print the number pq1mod(109+7)p\cdot q^{-1}\bmod(10^9+7).

Example 1

stdin

3
8 6 1

stdout

14

Example 2

stdin

4
10 0 1 7

stdout

24

Log in or sign up to be able to send submissions!