CF1817E.Half-sum

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You're given a multiset of non-negative integers {a1,a2,,an}\{a_1, a_2, \dots, a_n\} .

In one step you take two elements xx and yy of the multiset, remove them and insert their mean value x+y2\frac{x + y}{2} back into the multiset.

You repeat the step described above until you are left with only two numbers AA and BB . What is the maximum possible value of their absolute difference AB|A-B| ?

Since the answer is not an integer number, output it modulo 109+710^9+7 .

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1001 \le t \le 100 ). Description of the test cases follows.

The first line of each test case contains a single integer nn ( 2n1062 \le n \le 10^6 ) — the size of the multiset.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 0ai1090 \le a_i \le 10^9 ) — the elements of the multiset.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6 .

输出格式

For each test case, output a single integer, the answer to the problem modulo 109+710^9+7 .

Formally, let M=109+7M = 10^9+7 . It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q} , where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M} . Output the integer equal to pq1modMp \cdot q^{-1} \bmod M . In other words, output an integer xx such that 0x<M0 \le x < M and xqp(modM)x \cdot q \equiv p \pmod{M} .

输入输出样例

  • 输入#1

    5
    2
    7 3
    4
    1 2 10 11
    3
    1 2 3
    6
    64 32 64 16 64 0
    4
    1 1 1 1

    输出#1

    4
    9
    500000005
    59
    0

说明/提示

In the first case, you can't do any operations, so the answer is 73=4|7-3|=4 .

In the second case, one of the optimal sequence of operations:

  1. Substitute 11 and 22 with 1.51.5 ;
  2. Substitute 1010 and 1111 with 10.510.5 ;
  3. The difference between 1.51.5 and 10.510.5 is 99 .

In the third case, the exact answer is 32\frac{3}{2} , and 50000000523(mod109+7)500\,000\,005 \cdot 2 \equiv 3 \pmod{10^9+7} .

首页