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
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const int N = 11;

int n, m, siz, pwn;
char ini[N][N], fin[N][N];

int main() {
	scanf("%d%d", &n, &m);
	siz = n*m;
	FOR(i,n) scanf("%s", ini[i]);
	FOR(i,n) scanf("%s", fin[i]);
	int pair_ini = 0, pair_fin = 0;
	int cnt = 0;
	FOR(i,n) FOR(j,m) {
		if (ini[i][j] == 'O') pair_ini += i+j;
		if (fin[i][j] == 'O') {
			pair_fin += i+j;
			pwn++;
			FOR(k,4) {
				int x = i+dx[k], y = j+dy[k];
				if (x<0 || x >= n || y<0 || y >= m) continue;
				if (fin[x][y] == '.') cnt++;
			}
		}
	}
	if (pair_ini%2 != pair_fin%2) {
		printf("0\n");
		return 0;
	}
	ll tot = 1;
	for (int i = siz-pwn; i <= siz-2; i++) tot *= i;
	for (int i = 1; i <= pwn-1; i++) tot /= i;
	tot *= n*(m-1) + (n-1)*m;
	cout << setprecision(15) << fixed << 1.0L * cnt / tot << "\n";
	return 0;
}