#ABC150E. [ABC150E] Change a Little Bit

[ABC150E] Change a Little Bit

Score : 500500 points

Problem Statement

For two sequences SS and TT of length NN consisting of 00 and 11, let us define f(S,T)f(S, T) as follows:

  • Consider repeating the following operation on SS so that SS will be equal to TT. f(S,T)f(S, T) is the minimum possible total cost of those operations.
    • Change SiS_i (from 00 to 11 or vice versa). The cost of this operation is D×CiD \times C_i, where DD is the number of integers jj such that SjTj(1jN)S_j \neq T_j (1 \leq j \leq N) just before this change.

There are 2N×(2N1)2^N \times (2^N - 1) pairs (S,T)(S, T) of different sequences of length NN consisting of 00 and 11. Compute the sum of f(S,T)f(S, T) over all of those pairs, modulo (109+7)(10^9+7).

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Ci1091 \leq C_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

C1C_1 C2C_2 \cdots CNC_N

Output

Print the sum of f(S,T)f(S, T), modulo (109+7)(10^9+7).

1
1000000000
999999993

There are two pairs (S,T)(S, T) of different sequences of length 22 consisting of 00 and 11, as follows:

  • S=(0),T=(1):S = (0), T = (1): by changing S1S_1 to 11, we can have S=TS = T at the cost of 10000000001000000000, so f(S,T)=1000000000f(S, T) = 1000000000.
  • S=(1),T=(0):S = (1), T = (0): by changing S1S_1 to 00, we can have S=TS = T at the cost of 10000000001000000000, so f(S,T)=1000000000f(S, T) = 1000000000.

The sum of these is 20000000002000000000, and we should print it modulo (109+7)(10^9+7), that is, 999999993999999993.

2
5 8
124

There are 1212 pairs (S,T)(S, T) of different sequences of length 33 consisting of 00 and 11, which include:

  • S=(0,1),T=(1,0)S = (0, 1), T = (1, 0)

In this case, if we first change S1S_1 to 11 then change S2S_2 to 00, the total cost is 5×2+8=185 \times 2 + 8 = 18. We cannot have S=TS = T at a smaller cost, so f(S,T)=18f(S, T) = 18.

5
52 67 72 25 79
269312