atcoder#AGC028B. [AGC028B] Removing Blocks

[AGC028B] Removing Blocks

Score : 600600 points

Problem Statement

There are NN blocks arranged in a row, numbered 11 to NN from left to right. Each block has a weight, and the weight of Block ii is AiA_i. Snuke will perform the following operation on these blocks NN times:

  • Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks xx and yy ( xyx \leq y ) are connected when, for all zz ( xzyx \leq z \leq y ), Block zz is still not removed.

There are N!N! possible orders in which Snuke removes the blocks. For all of those N!N! orders, find the total cost of the NN operations, and calculate the sum of those N!N! total costs. As the answer can be extremely large, compute the sum modulo 109+710^9+7.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 ...... ANA_N

Output

For all of the N!N! orders, find the total cost of the NN operations, and print the sum of those N!N! total costs, modulo 109+710^9+7.

2
1 2
9

First, we will consider the order "Block 11 -> Block 22". In the first operation, the cost of the operation is 1+2=31+2=3, as Block 11 and 22 are connected. In the second operation, the cost of the operation is 22, as only Block 22 remains. Thus, the total cost of the two operations for this order is 3+2=53+2=5.

Then, we will consider the order "Block 22 -> Block 11". In the first operation, the cost of the operation is 1+2=31+2=3, as Block 11 and 22 are connected. In the second operation, the cost of the operation is 11, as only Block 11 remains. Thus, the total cost of the two operations for this order is 3+1=43+1=4.

Therefore, the answer is 5+4=95+4=9.

4
1 1 1 1
212
10
1 2 4 8 16 32 64 128 256 512
880971923