//satyaki3794
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int n, reachable[ ( 1 << 14 ) + 2 ] [ 15 ] ;;
vector< int > adj[ 20 ] ;
ll DP[ ( 1 << 14 ) + 2 ] [ 15 ] ;
int dfs( int mask, int v) {
int & ans = reachable[ mask] [ v] ;
if ( ans ! = - 1 ) return ans;
ans = ( 1 << v) ;
for ( auto vv : adj[ v] ) {
if ( ( mask >> vv) & 1 ) continue ;
ans | = dfs( mask| ( 1 << vv) , vv) ;
}
return ans;
}
ll dp( int mask, int v) {
ll & ans = DP[ mask] [ v] ;
if ( ans ! = - 1 ) return ans;
if ( reachable[ mask] [ v] == ( 1 << v) ) {
return 1 ;
}
ans = 0 ;
for ( auto vv : adj[ v] ) {
if ( ( mask >> vv) & 1 ) continue ;
ans + = dp( mask| ( 1 << vv) , vv) * dp( mask| ( reachable[ mask| ( 1 << vv) ] [ vv] ) , v) ;
}
return ans;
}
class DFSCount{
public :
ll count( vector< string> G) {
n = ( int ) G.size ( ) ;
for ( int i= 0 ; i< n; i++ )
for ( int j= 0 ; j< n; j++ )
if ( G[ i] [ j] == 'Y' )
adj[ i] .pb ( j) ;
memset ( reachable, - 1 , sizeof ( reachable) ) ;
for ( int mask= 0 ; mask< ( 1 << n) ; mask++ )
for ( int i= 0 ; i< n; i++ )
if ( ( mask >> i) & 1 ) {
reachable[ mask] [ i] = dfs( mask, i) ;
}
memset ( DP, - 1 , sizeof ( DP) ) ;
ll ans = 0 ;
for ( int i= 0 ; i< n; i++ )
ans + = dp( ( 1 << i) , i) ;
return ans;
}
} ;
Ly9zYXR5YWtpMzc5NAojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBwYiBwdXNoX2JhY2sKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKCmludCBuLCByZWFjaGFibGVbKDE8PDE0KSsyXVsxNV07Owp2ZWN0b3I8aW50PiBhZGpbMjBdOwpsbCBEUFsoMTw8MTQpKzJdWzE1XTsKCmludCBkZnMoaW50IG1hc2ssIGludCB2KXsKCiAgICBpbnQgJmFucyA9IHJlYWNoYWJsZVttYXNrXVt2XTsKICAgIGlmKGFucyAhPSAtMSkgICByZXR1cm4gYW5zOwoKICAgIGFucyA9ICgxPDx2KTsKICAgIGZvcihhdXRvIHZ2IDogYWRqW3ZdKXsKICAgICAgICBpZigobWFzayA+PiB2dikgJiAxKSAgICBjb250aW51ZTsKICAgICAgICBhbnMgfD0gZGZzKG1hc2t8KDE8PHZ2KSwgdnYpOwogICAgfQogICAgcmV0dXJuIGFuczsKfQoKbGwgZHAoaW50IG1hc2ssIGludCB2KXsKICAgIGxsICZhbnMgPSBEUFttYXNrXVt2XTsKICAgIGlmKGFucyAhPSAtMSkgICByZXR1cm4gYW5zOwogICAgaWYocmVhY2hhYmxlW21hc2tdW3ZdID09ICgxPDx2KSl7CiAgICAgICAgcmV0dXJuIDE7CiAgICB9CiAgICBhbnMgPSAwOwogICAgZm9yKGF1dG8gdnYgOiBhZGpbdl0pewogICAgICAgIGlmKChtYXNrID4+IHZ2KSAmIDEpICAgIGNvbnRpbnVlOwogICAgICAgIGFucyArPSBkcChtYXNrfCgxPDx2diksIHZ2KSAqIGRwKG1hc2t8KHJlYWNoYWJsZVttYXNrfCgxPDx2dildW3Z2XSksIHYpOwogICAgfQogICAgcmV0dXJuIGFuczsKfQoKCgpjbGFzcyBERlNDb3VudHsKICAgIHB1YmxpYzoKICAgICAgICBsbCBjb3VudCh2ZWN0b3I8c3RyaW5nPiBHKXsKCiAgICAgICAgICAgIG4gPSAoaW50KUcuc2l6ZSgpOwogICAgICAgICAgICBmb3IoaW50IGk9MDtpPG47aSsrKQogICAgICAgICAgICAgICAgZm9yKGludCBqPTA7ajxuO2orKykKICAgICAgICAgICAgICAgICAgICBpZihHW2ldW2pdID09ICdZJykKICAgICAgICAgICAgICAgICAgICAgICAgYWRqW2ldLnBiKGopOwoKCiAgICAgICAgICAgIG1lbXNldChyZWFjaGFibGUsIC0xLCBzaXplb2YocmVhY2hhYmxlKSk7CiAgICAgICAgICAgIGZvcihpbnQgbWFzaz0wO21hc2s8KDE8PG4pO21hc2srKykKICAgICAgICAgICAgICAgIGZvcihpbnQgaT0wO2k8bjtpKyspCiAgICAgICAgICAgICAgICAgICAgaWYoKG1hc2sgPj4gaSkgJiAxKXsKICAgICAgICAgICAgICAgICAgICAgICAgcmVhY2hhYmxlW21hc2tdW2ldID0gZGZzKG1hc2ssIGkpOwogICAgICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgIG1lbXNldChEUCwgLTEsIHNpemVvZihEUCkpOwogICAgICAgICAgICBsbCBhbnMgPSAwOwogICAgICAgICAgICBmb3IoaW50IGk9MDtpPG47aSsrKQogICAgICAgICAgICAgICAgYW5zICs9IGRwKCgxPDxpKSwgaSk7CiAgICAgICAgICAgIHJldHVybiBhbnM7CiAgICAgICAgfQp9Owo=