#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

class Data{
public:
	ll X,Y,Z;
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in();
	vector<Data> D(N);
	REP(i,N){
		D[i].X=in();
		D[i].Y=in();
		D[i].Z=in();
	}
	ll L = 1ll<<N;
	vvll dp(L,vll(N,1ll<<60));
	dp[0][0] = 0;
	REP(i,L){
		REP(j,N){
			REP(k,N){
				ll to = i | (1ll<<k);
				ll C = abs(D[j].X-D[k].X)+abs(D[j].Y-D[k].Y)+max(0ll,D[k].Z-D[j].Z);
				chmin(dp[to][k],dp[i][j]+C);
			}
		}
	}
	out(dp[L-1][0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

/*
    Author: Koushik Sahu
    Created: 03 April 2021 Sat 22:14:58
*/

const int nxM = 105;
int h, w, x, y;
string s[nxM];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>h>>w>>x>>y;
    for(int i=0; i<h; i++) cin>>s[i];
    x--, y--;
    int ans = 1;
    for(int i=x+1; i<h; i++){
        if(s[i][y]=='.') ans++;
        else break;
    }
    for(int i=x-1; i>=0; i--){
        if(s[i][y]=='.') ans++;
        else break;
    }
    for(int i=y+1; i<w; i++){
        if(s[x][i]=='.') ans++;
        else break;
    }
    for(int i=y-1; i>=0; i--){
        if(s[x][i]=='.') ans++;
        else break;
    }
    cout<<ans<<"\n";
    return 0;
}	