Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 3466
The Hive II

Time Limit: 5 Seconds      Memory Limit: 65536 KB

There is a hive in the village. Like this. There are 8 columns(from A to H) in this hive. Different colums have the same number of grids. Every grid has its own coordinate, which is formed by two uppercases, representing the row index and the column index. The row index starts from A. And the hive has less than ten rows in total. The following figure shows a hive with two rows.

Photo

There is honey in some grids. A naughty bee discovers this special hive and hopes to eat all honey in the hive. However, this strange bee sets some rules for itself while eating. They are descirbed as following:

  • It must eat the honey by choosing a circuit and then eat all honey that is in the chosen circuit.
  • Honey will disappear immediately after the bee eats it.
  • All grids which are in the circuit should has honey in it.
  • The length of the circuit should be no less than 3.
  • The bee can choose more than one circuit to eat honey.

Given the hive and the honey in it, how many different ways can this naughty bee eat all honey in the hive?

Input

There are multiple test cases.

For each case, there are two integers N(0 < N ≤ 10) and M(0 ≤ MN * 8) in the first line. N represents the size of the hive, which means there are N rows in the hive in total. All grids have honey in it except for those M grids listed in the following line. Each empty grid is described by its coordinate(using two uppercases).

Output

For each case, output the number of different ways the bee can eat all honey in the hive. It's guaranteed that the answer does not exceed 263 - 1.

Sample Input

3 5
BB CD BF AH CG

Sample Output

3

Hint

The following figure shows all different ways for the sample. The black grids represent those which are initially empty.

Photo

Author: MO, Luyi
Contest: ZOJ Monthly, January 2011
Submit    Status