304241: CF809A. Do you want a date?

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

Description

Do you want a date?

题意翻译

## 题目描述 给定含有$n$ 个正整数的数字集合$A$ ,求$$\sum_{a\subseteq A,a\ne\oslash}F(a)$$ 其中$F(a)$ 表示集合$a$ 中所有数字之间差值的最大值,既$F(a)=max_{(i,j)\in a}{|x_i-x_j|}$ 。 ## 输入 第一行一个整数$n$ 接下来$n$ 个数分别是$x_1,x_2\dots x_n$ ## 输出 一行一个整数表示答案,答案对$10^9+7$ ## 数据范围 $1 \le n \le 3* 10^5$ $1 \le x_i \le 10^9$ ,保证$x_i$ 互不相同 感谢@Youngsc 提供的翻译

题目描述

Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to $ n $ computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on the same straight line, due to the reason that there is the only one straight street in Vičkopolis. Let's denote the coordinate system on this street. Besides let's number all the hacked computers with integers from $ 1 $ to $ n $ . So the $ i $ -th hacked computer is located at the point $ x_{i} $ . Moreover the coordinates of all computers are distinct. Leha is determined to have a little rest after a hard week. Therefore he is going to invite his friend Noora to a restaurant. However the girl agrees to go on a date with the only one condition: Leha have to solve a simple task. Leha should calculate a sum of $ F(a) $ for all $ a $ , where $ a $ is a non-empty subset of the set, that consists of all hacked computers. Formally, let's denote $ A $ the set of all integers from $ 1 $ to $ n $ . Noora asks the hacker to find value of the expression ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809A/cea75a525aa2db29242dd52fe9572e2a35b5dc28.png). Here $ F(a) $ is calculated as the maximum among the distances between all pairs of computers from the set $ a $ . Formally, ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809A/5303368a897ba372fe1511b71f765e2d891629f6.png). Since the required sum can be quite large Noora asks to find it modulo $ 10^{9}+7 $ . Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.

输入输出格式

输入格式


The first line contains one integer $ n $ $ (1<=n<=3·10^{5}) $ denoting the number of hacked computers. The second line contains $ n $ integers $ x_{1},x_{2},...,x_{n} $ $ (1<=x_{i}<=10^{9}) $ denoting the coordinates of hacked computers. It is guaranteed that all $ x_{i} $ are distinct.

输出格式


Print a single integer — the required sum modulo $ 10^{9}+7 $ .

输入输出样例

输入样例 #1

2
4 7

输出样例 #1

3

输入样例 #2

3
4 3 1

输出样例 #2

9

说明

There are three non-empty subsets in the first sample test:![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809A/fa024599e9d01131594c263586f48bf07d6d1531.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809A/29878a444c021e77c93169d2e3fc058f4612310c.png) and ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809A/9959f41b05210c32c90a620fa854227a39ff5d35.png). The first and the second subset increase the sum by $ 0 $ and the third subset increases the sum by $ 7-4=3 $ . In total the answer is $ 0+0+3=3 $ . There are seven non-empty subsets in the second sample test. Among them only the following subsets increase the answer: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809A/17db0df6a19a7abc4fdce8cb6d8033efaf13af0a.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809A/46a691d7e1328fdf750d91429f3d39ecaba23415.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809A/cbc666f8f8dcd95a86e2090cf2c5eeaf74da6566.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF809A/d01b6e328f9e4a49990c66594ad28c36f483ba81.png). In total the sum is $ (4-3)+(4-1)+(3-1)+(4-1)=9 $ .

Input

题意翻译

## 题目描述 给定含有$n$ 个正整数的数字集合$A$ ,求$$\sum_{a\subseteq A,a\ne\oslash}F(a)$$ 其中$F(a)$ 表示集合$a$ 中所有数字之间差值的最大值,既$F(a)=max_{(i,j)\in a}{|x_i-x_j|}$ 。 ## 输入 第一行一个整数$n$ 接下来$n$ 个数分别是$x_1,x_2\dots x_n$ ## 输出 一行一个整数表示答案,答案对$10^9+7$ ## 数据范围 $1 \le n \le 3* 10^5$ $1 \le x_i \le 10^9$ ,保证$x_i$ 互不相同 感谢@Youngsc 提供的翻译

加入题单

算法标签: