#include <bits/stdc++.h>
#define inc(i, j, k) for (int i = j; i < k; i++)
using namespace std;

int f[17][1 << 17], n, g[17][17], x[17], y[17], z[17];
int dp(int i, int s) {
	if (f[i][s] != -1) return f[i][s];
	f[i][s] = 0x3fffffff;
	inc(j, 0, n)
		if ((s & (1 << j)) == 0) f[i][s] = min(f[i][s], dp(j, s | (1 << j)) + g[i][j]);
	return f[i][s];
}
int main() {
	scanf("%d", &n); inc(i, 0, n) scanf("%d%d%d", &x[i], &y[i], &z[i]);
	inc(i, 0, n) inc(j, 0, n) g[i][j] = abs(x[j] - x[i]) + abs(y[j] - y[i]) + max(0, z[j] - z[i]);
	inc(i, 1, n) inc(j, 0, 1 << n) f[i][j] = -1;
	f[0][0] = -1; f[0][(1 << n) - 1] = 0; inc(i, 1, (1 << n) - 1) f[0][i] = 0x3fffffff;
	printf("%d", dp(0, 0)); return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
char inverse_char(char c) {
  if(isupper(c)) return tolower(c);
  else return toupper(c);
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
  ll H, W, X, Y; cin >> H >> W >> X >> Y; X--; Y--;
  vector<string> S(H); REP(i, H) cin >> S[i];
  ll ans = 0;
  for(int i = X; i < H; ++i) {
    if(S[i][Y] == '#') break;
    ans++;
  }

  for(int i = X; i >= 0; --i) {
    if(S[i][Y] == '#') break;
    ans++;
  }

  for(int i = Y; i < W; ++i) {
    if(S[X][i] == '#') break;
    ans++;
  }

  for(int i = Y; i >= 0; --i) {
    if(S[X][i] == '#') break;
    ans++;
  }
  cout << ans - 3 << endl;
}