Bear and Bowling 3

3.6

36 votes
Ready, Basic Programming, Easy-Medium
Problem

Limak is an old brown bear. He often goes bowling with his friends.

For rolling a ball one gets a score - a non-negative integer number of points. Score for the i-th roll is multiplied by i and scores are summed up. For example, for rolls with scores 7, 10, 5 the total score is equal to 7×1 + 10×2 + 5×3 = 42.

Limak made N rolls and got a score Ai for the i-th of them.

Unfortunately, the bowling club's computer system isn't stable today. Any rolls can be erased! Then, the total score is calculated as if there were only non-erased rolls. There are 2N possible sequences of remaining (non-erased) rolls. Limak is curious about various statistics of this situation.

He asks you for one thing. Find the sum of total scores of all 2N possible sequences of remaining rolls. Print it modulo 109+7.

Input format

The first line contains a single integer N.

The second line contains N non-negative integers A1, A2, ..., AN.

Output format

In a single line print modulo 109+7 the sum of total scores of possible remaining sequences.

Constraints

1 ≤ N ≤ 200,000
0 ≤ Ai ≤ 109

Subtasks

Extra constraints Points Tests
N ≤ 15 10 1-2
N ≤ 200 20 3-4
N ≤ 4000 30 5-7
no extra constraints 40 8-11
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

There are eight possible remaining subsequences.

{} - 0
{6} - 6
{12} - 12
{8} - 8
{6, 12} - 30
{6, 8} - 22
{12, 8} - 28
{6, 12, 8} - 54

0 + 6 + 12 + 8 + 30 + 22 + 28 + 54 = 160

Editor Image

?