#include <iostream>
#include <vector>
#include <iomanip>

signed main(){
    int N;
    std::cin >> N;
    std::vector<std::string> S(N);
    for(auto &si:S) std::cin >> si;
    std::vector<std::vector<int>> A(N,std::vector<int> (N));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            A[i][j]=S[i][j]-'0';
        }
        A[i][i]=1;
    }
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(A[i][k]+A[k][j]==2) A[i][j]=1;
            }
        }
    }
    double answer=0;
    for(int i=0;i<N;i++){
        double go=0;
        for(int j=0;j<N;j++){
            if(A[j][i]==1) go++;
        }
        answer+=1/go;
    }
    std::cout << std::fixed << std::setprecision(10) << answer << '\n';
}
#include <bits/stdc++.h>
using namespace std;
typedef long double LD; 
typedef long long ll; 
#define int ll 
#define ff(i,a,b) for (int i = a; i < b; i++) 
#define bf(i,a,b) for (int i = a; i >= b; i--) 
#define all(v) v.begin(),v.end() 
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define F first 
#define S second
#define pb push_back
#define mp make_pair
#define lb lower_bound   
#define ub upper_bound
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define one cout<<"-1"<<endl
#define pi 3.141592653589793238
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
#define intmx INT_MAX 
#define intmi INT_MIN
const int MOD=1e9+7;
int test=1;
void solve(){
    int n,m;
    cin>>n>>m;
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    string s[n];
    ff(i,0,n)
    cin>>s[i];
    int cnt=0;
    int i=x,j=y;
    i++;
    while(i<n&&s[i][j]=='.'){
        cnt++;
        i++;
    }
    i=x-1;
    while(i>=0&&s[i][j]=='.'){
        cnt++;
        i--;
    }
    i=x;j=y+1;
    while(j<m&&s[i][j]=='.'){
        cnt++;
        j++;
    }
    j=y-1;
    while(j>=0&&s[i][j]=='.'){
        cnt++;
        j--;
    }
    if(s[x][y]=='.')
    cnt++;
    cout<<cnt<<endl;
}

signed main() {
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}
