Solitaire (Translated)

JOI Spring Training Camp 2015/16
Original Statement / Submission Site

Problem Statement

JOI is playing a game using a grid board that is 3 cells tall and N cells wide, along with several tokens. In the initial state of the game, some cells contain a token, and some cells do not.

The goal of the game is to place a token on each empty cell, one at a time, until all cells on the board contain a token. However, a token can only be placed on a cell if at least one of the following conditions is satisfied:

JOI is curious to know how many different sequences of token placements can lead from the initial state to the final state where all cells are filled.

Note that the number of possible sequences can be very large, so your task is to compute the number of valid sequences modulo 1,000,000,007.

Task

Given the initial state of the game, write a program to compute the number of valid sequences to complete the board, modulo 1,000,000,007.

Input

Output

Print a single line containing the number of valid sequences modulo 1,000,000,007.

Constraints

1 ≤ N ≤ 2,000

Subtasks

Sample Input 1

3
oxo
xxo
oxo

Sample Output 1

14

Explanation of Output 1

The initial board state is:

o x o
x x o
o x o

There are 14 valid sequences to place the tokens and complete the board. The sequences of placements are illustrated below (numbers indicate order of placement):

o 1 o     o 1 o     o 1 o     o 1 o     o 2 o     o 2 o     o 3 o     o 4 o     o 3 o     o 4 o     o 2 o     o 2 o     o 3 o     o 4 o
2 3 o     2 4 o     3 4 o     4 3 o     1 3 o     1 4 o     1 2 o     1 2 o     1 4 o     1 3 o     3 4 o     4 3 o     2 4 o     2 3 o
o 4 o     o 3 o     o 2 o     o 2 o     o 4 o     o 3 o     o 4 o     o 3 o     o 2 o     o 2 o     o 1 o     o 1 o     o 1 o     o 1 o

Sample Input 2

10
ooxooxoxoo
xooxxxoxxx
oxoxoooooo

Sample Output 2

149022720

Sample Input 3

10
ooxoxxoxoo
oxxxxxoxxx
oxooxoxoxo

Sample Output 3

0

In this case, it is impossible to fill all cells.

Sample Input 4

20
oxooxoxooxoxooxoxoxo
oxxxoxoxxxooxxxxxoox
oxooxoxooxooxooxoxoo

Sample Output 4

228518545