#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

vvl G;
vl visited;
vvl S;  // S[v] : 頂点vに辿り着ける頂点集合

void dfs(ll sv, ll v) {
    // 行きの処理はこのへんに書く
    S[v].pb(sv);
    visited[v] = 1;
    for(ll u : G[v]) { 
        if(!visited[u]) {
            dfs(sv, u);
        }
        // 帰りの処理はこのへんに書く
    }
}

int main() {
    ll n;
    cin >> n;

    G.resize(n);
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, n) {
            if(s[j] == '1') {
                G[i].pb(j);
            }
        }
    }
    
    S.resize(n);
    rep(sv, n) {
        visited.assign(n, 0);
        dfs(sv, sv);
    }

    double ans = 0.0;
    rep(v, n) {
        ans += 1.0/(double)S[v].size();
    }

    exout(ans);
    re0;
}
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    x--; y--;
    string s[h];
    rep(i,h) cin >> s[i];

    int ans = 1;
    srep(j,y+1,w){
        if(s[x][j] == '#') break;
        ans++;
    }
    drep(j,y){
        if(s[x][j] == '#') break;
        ans++;
    }
    srep(i,x+1,h){
        if(s[i][y] == '#') break;
        ans++;
    }
    drep(i,x){
        if(s[i][y] == '#') break;
        ans++;
    }

    cout << ans << endl;
    return 0;
}


