Bear and Bowling 3
Practice
3.6 (36 votes)
Ready
Basic programming
Easy Medium
Problem
76% Success 3210 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
40 votes
Tags:
ApprovedData StructuresMathMediumStacks
Points:30
107 votes
Tags:
Number TheoryData StructuresEasy-MediumGreedy algorithmReadyApproved
Points:30
5 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMathMediumOpen