atcoder#AGC028B. [AGC028B] Removing Blocks
[AGC028B] Removing Blocks
Score : points
Problem Statement
There are blocks arranged in a row, numbered to from left to right. Each block has a weight, and the weight of Block is . Snuke will perform the following operation on these blocks 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 and ( ) are connected when, for all ( ), Block is still not removed.
There are possible orders in which Snuke removes the blocks. For all of those orders, find the total cost of the operations, and calculate the sum of those total costs. As the answer can be extremely large, compute the sum modulo .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
For all of the orders, find the total cost of the operations, and print the sum of those total costs, modulo .
2
1 2
9
First, we will consider the order "Block -> Block ". In the first operation, the cost of the operation is , as Block and are connected. In the second operation, the cost of the operation is , as only Block remains. Thus, the total cost of the two operations for this order is .
Then, we will consider the order "Block -> Block ". In the first operation, the cost of the operation is , as Block and are connected. In the second operation, the cost of the operation is , as only Block remains. Thus, the total cost of the two operations for this order is .
Therefore, the answer is .
4
1 1 1 1
212
10
1 2 4 8 16 32 64 128 256 512
880971923