CF809A.Do you want a date?
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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
. Here F(a) is calculated as the maximum among the distances between all pairs of computers from the set a. Formally,
. Since the required sum can be quite large Noora asks to find it modulo 109 + 7.
Though, Leha is too tired. Consequently he is not able to solve this task. Help the hacker to attend a date.
莱哈决定搬到安静的小镇维克波利斯(Vičkopolis),因为他厌倦了在班科波利斯(Bankopolis)的生活。抵达后,他立刻开始扩展自己所黑入的计算机网络。一周之内,莱哈成功获取了镇上 n 台计算机的访问权限。巧合的是,所有被莱哈黑入的计算机都位于同一条直线上,这是因为维克波利斯只有一条笔直的街道。
我们在这条街道上建立一个坐标系。此外,将所有被黑入的计算机用从 1 到 n 的整数编号。第 i 台被黑入的计算机位于坐标 xi 处。并且,所有计算机的坐标互不相同。
经过辛苦的一周,莱哈决心稍作休息。因此,他打算邀请朋友诺拉(Noora)去一家餐厅。然而,这位姑娘只答应赴约,但有一个前提条件:莱哈必须解决一个简单的问题。
莱哈需要计算所有非空子集 a 对应的 F(a) 之和,其中 a 是由所有被黑入计算机构成的集合的一个非空子集。形式化地,令 A 表示由整数 1 到 n 构成的集合。诺拉要求黑客计算表达式
的值。其中 F(a) 定义为集合 a 中所有计算机两两之间距离的最大值。形式化地,
。由于所求的和可能非常大,诺拉要求输出该和对 109+7 取模的结果。
然而,莱哈实在太累了,因此无法解决这个问题。请帮助这位黑客成功赴约。
输入格式
The first line contains one integer n (1 ≤ n ≤ 3·105) denoting the number of hacked computers.
The second line contains n integers _x_1, _x_2, ..., x__n (1 ≤ x__i ≤ 109) denoting the coordinates of hacked computers. It is guaranteed that all x__i are distinct.
第一行包含一个整数 n(1≤n≤3⋅105),表示被黑计算机的数量。
第二行包含 n 个整数 x1,x2,...,xn(1≤xi≤109),表示被黑计算机的坐标。保证所有 xi 互不相同。
输出格式
Print a single integer — the required sum modulo 109 + 7.
输出一个整数——所求的和对 109+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:
,
and
. 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:
,
,
,
. In total the sum is (4 - 3) + (4 - 1) + (3 - 1) + (4 - 1) = 9.
第一个样例测试中有三个非空子集:
、
和
。前两个子集使总和增加 0,第三个子集使总和增加 7 − 4 = 3。因此答案为 0 + 0 + 3 = 3。
第二个样例测试中有七个非空子集。其中仅有以下子集对答案有贡献:
、
、
、
。总和为 (4 − 3) + (4 − 1) + (3 − 1) + (4 − 1) = 9。
输入解题思路,AI测评打分。不知道怎么写?