1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include<bits/stdc++.h>

#define st first
#define nd second
#define pb(x) push_back(x)
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
const int MN = 13;  
int n, m; 
int pocz[MN][MN];  
int kon[MN][MN]; 
ld prob[MN][MN];  
int parpocz[2]; 
int parkon[2]; 
const int RUND = 100000;   
vii G[MN][MN];  
pii d[4] = {{0,1}, {0, -1}, {-1, 0}, {1, 0} }; 
void read(){ 
	cin >> n >> m; 
	string row; 
	for(int i = 1; i <= n; i++){ 
		cin >> row; 
		for(int j = 1; j <= m ; j++){ 
			if(row[j-1] == 'O'){
				pocz[i][j] = 1;  
				parpocz[(i+j)%2]++; 
			}  
		}
	}
	for(int i = 1; i <= n; i++){ 
		cin >> row; 
		for(int j = 1; j <= m ; j++){ 
			if(row[j-1] == 'O'){ 
				kon[i][j] = 1;  
				parkon[(i+j)%2]++; 
			} 
		}
	}  
	for(int i = 1; i <= n; i++){ 
		for(int j = 1; j <=m ; j++){ 
			for(int k = 0; k < 4; k++){ 
				if( 1<= i + d[k].st && i + d[k].st <=n &&   1<= j + d[k].nd && j + d[k].nd <= m) 	
					G[i][j].pb(mp(d[k].st + i, d[k].nd + j)); 
				} 
			} 
	}  
	for(int i = 1; i <= n; i++){ 
		for(int j = 1; j <= m ; j++){ 
			cout << i  << ' ' << j << ": ";  
			for(auto x : G[i][j]) 
				cout << x.st  << ' ' << x.nd << " || "; 
			cout << "\n";
		} 
	}
	parpocz[0] %= 2; 
	parpocz[1] %= 2; 
	parkon[0] %= 2; 
	parkon[1] %=2 ; 
}  
ld amo;  
ld cop[MN][MN]; 
inline void round(){ 
	amo = 0; 
	for(int i = 1; i <= n; i++){ 
		for(int j =1; j<= m ;j++){ 
			amo += prob[i][j] * (ld)sz(G[i][j]); 
		} 
	}
	for(int i =1; i <= n; i++){ 
		for(int j =1; j <= m; j++){  
			cop[i][j] = prob[i][j] * ((amo-(ld)sz(G[i][j]))/amo);  
			//if(cop[i][j] < 0) 
				//cop[i][j] = 0; 
		} 
	} 
	for(int i =1; i <= n; i++){ 
		for(int j =1; j <= m; j++){ 
			for(auto x : G[i][j]){ 
				cop[x.st][x.nd] += prob[i][j] * ((ld)1/amo);  
			} 
		} 
	} 
	for(int i = 1;  i <= n; i++){ 
		for(int j =1; j <= m; j++){ 
			prob[i][j] = cop[i][j]; 
		} 
	}   
	/*cout << "||||||\n";  
	cout << amo << "\n"; 
	for(int  i = 1; i <= n; i++){ 
		for(int j =1; j <=m ; j++){ 
			cout << prob[i][j] << ' '; 
		} 
		cout << "\n"; 
	} 
	cout << "}}}}\n"; */  
}





void run(){ 
	for(int i = 1; i <= n; i++){ 
		for(int j =1; j <= n; j++){ 
			prob[i][j] = pocz[i][j]; 
		} 
	} 
	for(int  i = 1; i <= n; i++){ 
		for(int j =1; j <=m ; j++){ 
			cout << prob[i][j] << ' '; 
		} 
		cout << "\n"; 
	} 
	for(int i = 1; i <= n; i++){ 
		for(int j =1; j<=m ;j++){ 
			cout << sz(G[i][j]) << ' '; 
		} 
		cout << "\n";  
	} 
	for(int  i = 1; i <= n; i++){ 
		for(int j =1; j <=m ; j++){ 
			cout << pocz[i][j] << ' '; 
		} 
		cout << "\n"; 
	}
	for(int i = 0; i < RUND; i++){  
		round(); 
	} 
	ld result = 1; 
	for(int i = 1; i <= n; i++){ 
		for(int j = 1; j <=m; j++){ 
			if(kon[i][j]) 
				result *= prob[i][j];  
			} 
	}  
	for(int  i = 1; i <= n; i++){ 
		for(int j =1; j <=m ; j++){ 
			cout << prob[i][j] << ' '; 
		} 
		cout << "\n"; 
	}
	cout << setprecision(14) << result; 
}

int main(){
	read(); 
	if(!(parkon[1] == parpocz[1] && parpocz[0] == parkon[0])){ 
		cout <<  0; 
		return 0; 
	} 
	run();    
}