Under construction

Still being built. Things may change

JOI Flag

Time limit5sMemory limit128 MB

Summary
Count fillings of an M by N grid with J, O, I (some cells fixed) that contain at least one L shape: J with O to its right and I below, modulo 100000.
Level

Medium5 of 10

Topics
Dynamic programming, Combinatorics, Implementation, Matrix
Solved
No attempts yet

Problem

A committee designed a flag based on the JOI logo. The flag is an M×NM \times N grid, and each cell holds exactly one of the three letters J, O, I.

A flag is called good if the following L-shaped arrangement appears at least once: some cell contains J, the cell immediately to its right contains O, and the cell immediately below the J contains I.

J O
I .

(The . cell may hold any letter; only the three marked cells matter.) Formally, the flag is good if there exist a row ii and a column jj with 1≤i≤M−11 \le i \le M-1 and 1≤j≤N−11 \le j \le N-1 such that the cell at row ii, column jj is J, the cell at row ii, column j+1j+1 is O, and the cell at row i+1i+1, column jj is I.

Some cells are already fixed to a specific letter. The remaining cells are still undecided and may become any of J, O, I. Given MM, NN, and which cells are fixed, count the number of ways to fill in the undecided cells so that the resulting flag is good. Print this count modulo 100000100000.

Input

The first line contains two integers MM and NN (2≤M,N≤202 \le M, N \le 20), the number of rows and columns of the flag.

Each of the next MM lines contains NN characters describing one row of the flag. Each character is J, O, I, or ?. A letter means the cell is already fixed to that letter; ? means the cell is still undecided.

Output

Print a single integer: the number of good flags, modulo 100000100000.

Hint

Only the three cells of the L shape are constrained; the cell diagonally opposite the J (the bottom-right of the 2×22 \times 2 block) may hold any letter. A single occurrence anywhere in the flag is enough to make it good, so it is often easier to count the flags that are not good and subtract from the total number of fillings.

Examples4

  1. Example 1

    Input
    2 3
    ??O
    IIJ
    
    Expected output
    4
    
  2. Example 2

    Input
    2 2
    ??
    ??
    
    Expected output
    3
    
  3. Example 3

    Input
    3 3
    ??I
    ???
    O?J
    
    Expected output
    53
    
  4. Example 4

    Input
    5 4
    JOI?
    ????
    ????
    ????
    ?JOI
    
    Expected output
    28218