#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
static const LL MODVAL = 1000000007;
LL MUL(LL x, LL y) { return (x*y)%MODVAL; }
LL FACT(LL x) {return x<=1 ? 1 : MUL(x, FACT(x-1));}
class DrawingBlackCrosses { public:
map<int, LL> memo;
LL rec(int must, int mustNot, int i, vector<int>& mask, int full)
{
int key = mustNot*20+i;
if( memo.count(key) )
return memo[key];
if( i == mask.size() ) {
if( must==0 ) {
int b = 0;
for(int i=0; (1<<i)<=mustNot; ++i)
if( mustNot & (1<<i) )
++b;
return FACT(b);
}
else
return 0;
}
LL cnt = 0;
// select this row
int seled = mustNot | mask[i];
int notDone = full &~ seled;
for(int k=0; (1<<k)<=notDone; ++k)
if( (1<<k) & notDone ) {
LL c = rec(must&~(1<<k), mustNot|(1<<k), i+1, mask, full);
cnt = (cnt + c) % MODVAL;
}
// don't select
LL c = rec(must|notDone, mustNot, i+1, mask, full);
cnt = (cnt + c) % MODVAL;
return memo[key] = cnt;
}
int count(vector <string> field)
{
vector<int> mask;
for(int i=0; i<field.size(); ++i) {
int m = 0;
for(int j=0; j<field[i].size(); ++j)
m |= (field[i][j]=='B')<<j;
mask.push_back(m);
}
int full = (1<<field[0].size()) - 1;
return rec(0, 0, 0, mask, full);
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, DrawingBlackCrosses().count(field));}
int main(){
CASE(0)
string field_[] = {"."};
vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_));
int _ = 1;
END
CASE(1)
string field_[] = {"BBB",
"BBB"};
vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_));
int _ = 1;
END
CASE(2)
string field_[] = {"...",
"BB."};
vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_));
int _ = 5;
END
CASE(3)
string field_[] = {"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"...................."};
vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_));
int _ = 563200757;
END
CASE(4)
string field_[] = {"B..B",
"B.B.",
"...B",
"BB.B",
"...."};
vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_));
int _ = 324;
END
/*
CASE(5)
string field_[] = ;
vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_));
int _ = ;
END
CASE(6)
string field_[] = ;
vector <string> field(field_, field_+sizeof(field_)/sizeof(*field_));
int _ = ;
END
*/
}
// END CUT HERE