atcoder#AGC026D. [AGC026D] Histogram Coloring
[AGC026D] Histogram Coloring
Score : points
Problem Statement
Let us consider a grid of squares with rows and columns. Let be the square at the -th column from the left and -th row from the bottom.
Snuke has cut out some part of the grid so that, for each , the bottom-most squares are remaining in the -th column from the left. Now, he will paint the remaining squares in red and blue. Find the number of the ways to paint the squares so that the following condition is satisfied:
- Every remaining square is painted either red or blue.
- For all and , there are exactly two squares painted red and two squares painted blue among the following four squares: and .
Since the number of ways can be extremely large, print the count modulo .
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the number of the ways to paint the squares, modulo .
9
2 3 5 4 1 2 4 2 1
12800
One of the ways to paint the squares is shown below:
#
## #
### #
#### ###
#########
2
2 2
6
There are six ways to paint the squares, as follows:
## ## ## ## ## ##
## ## ## ## ## ##
5
2 1 2 1 2
256
Every way to paint the squares satisfies the condition.
9
27 18 28 18 28 45 90 45 23
844733013
Remember to print the number of ways modulo .