#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i=0;i<n;i++)
#define INF 1000000001
#define lINF 1000000000000001
using ll = long long;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
//1e9<int型の最大値<1e10
//1e18<long型の最大値<1e19
//配列直入れ↓
//g++ -std=c++17 -Wshadow -Wall -D_GLIBCXX_DEBUG -o a b.cpp && ./a

int main(){
    int h,w,x,y;
    cin>>h>>w>>x>>y;
    x--;
    y--;
    vector<string> s(h);
    rep(i,h) cin>>s[i];
    int ans=0;
    for(int i=x;i<h;i++){
        if(s[i][y]=='.') ans++;
        else break;
    }
    for(int i=x;i>=0;i--){
        if(s[i][y]=='.') ans++;
        else break;
    }
    for(int j=y;j<w;j++){
        if(s[x][j]=='.') ans++;
        else break;
    }
    for(int j=y;j>=0;j--){
        if(s[x][j]=='.') ans++;
        else break;
    }
    cout<<ans-3<<endl;



}
#include <bits/stdc++.h>
#define fi first
#define se second
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define V vector
#define TP template <class o>
#define TPP template <typename t1, typename t2>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = b; i >= a; i--)
#define FOR(i,n) rep(i,1,n)
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef unsigned ui;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int N = 110, size = 1 << 20, mod = 998244353, inf = 2e9;
const ll INF = 1e15;

// char buf[size],*p1=buf,*p2=buf;
TP void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
TP void qw(o x) {
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
TP void pr1(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(' ');
}
TP void pr2(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar('\n');
}

// math
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll power(ll a, ll b = mod - 2, ll p = mod) {
    ll c = 1;
    while (b) {
        if (b & 1)
            c = c * a % p;
        b /= 2;
        a = a * a % p;
    }
    return c;
}

TP void cmax(o& x, o y) {
    if (x < y)
        x = y;
}
TP void cmin(o& x, o y) {
    if (x > y)
        x = y;
}
TPP void ad(t1& x, t2 y) {
    x += y;
    if (x >= mod)
        x -= mod;
}
TPP void dl(t1& x, t2 y) {
    x -= y;
    if (x < 0)
        x += mod;
}

template<typename T>
struct BIT {
	T* c; int n; // require you to define 0 as the initial value !!
	BIT(int _n):n(_n){c=new T[n];c--; FOR(i,n) c[i]=T(0); }
	void add(int x,T y) { for( ;x<=n;x += x&-x) c[x]=c[x]+y; }
	T sum(int x) {T y=T(0); for( ;x;x &= x-1) y=y+c[x]; return y;}
};

int n, a[N], vis[N], lst[N], now;
char s[N][N]; 

void dfs(int x) {
	if(lst[x] == now) return;
	lst[x]=now; vis[x]++;
	FOR(y,n) if(s[x][y] == '1') dfs(y);
}

void solve() {
	qr(n);
	FOR(i,n) scanf("%s",s[i]+1);
	for(now=1;now<=n;now++) dfs(now);
	db ans=0;
	FOR(i,n) ans += 1.0/vis[i];
	printf("%.10lf\n",ans); 
} 

int main() {
    int T = 1;
//    qr(T);
    while (T--)
        solve();
    return 0;
}
