#include using namespace std; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector A(h), B(h); cin >> A >> B; int cnt1 = 0, cnt2 = 0; for(int y = 0; y < h; y++){ for(int x = 0; x < w; x++){ cnt1 += A[y][x] != B[y][x]; cnt2 += A[h - 1 - y][w - 1 - x] != B[y][x]; } } double ans = 0, p = 1, div = 1; for(int i = 0; i < 100; i++){ if (i % 2 == 0 && cnt1 == h * w){ ans += p * (1 - div) * (i + 1); p *= div; } else if(i % 2 == 1 && cnt2 == h * w){ ans += p * (1 - div) * (i + 1); p *= div; } div /= 2; } cout << fixed << setprecision(15) << ans << '\n'; }