//libraries
#include<bits/stdc++.h>
    
//namespace
using namespace std;
    
//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;
    
//define
#define i(x) cin>>x;
#define il(X) ll X; cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define inpv(a,n) vector<ll> a(n); for(ll i=0;i<n;i++){cin>>a[i];}
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define iniv(A,n,p) vector<ll> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(ll i=a;i<=b;i++)
#define forde(i,a,b) for(ll i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
const long long inf=(long long)1e18;
long long MOD=(long long)(1e9+7);
ll mod=MOD;
    
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll modi(ll a)
{
    return binpow(a,mod-2,mod);
}
// ll n,m;
// vector<unordered_set<ll> > adj(100001);
// vector<unordered_set<ll> > adj_rev(100001);
// iniv(vis,100001,0);
// stack<ll> s;

// void dfs(ll x)
// {
//     if(vis[x]) return;
//     for(auto p:adj[x])
//     {
//         if(!vis[p]) dfs(p);
//     }
//     s.push(x);
// }


int main() 
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt" , "r" , stdin);
        // freopen ("OUTPUT.txt" , "w" , stdout);
    #endif
    fio;
    ll tt=1; //cin>>tt;
    while(tt--)
    {
        il(n);
        inpv(a,n);
        vector<vll> adj(200001);
        iniv(vis,200001,0);
        ll ans=0;
        forin(i,0,n-1)
        {
            if(!vis[a[i]])
            {
                vis[a[i]]=1;
                ans++;
            }
        }
        ll l=0,r=n-1;
        while(l<r)
        {
            adj[a[l]].pb(a[r]);
            adj[a[r]].pb(a[l]);
            l++;
            r--;
        }
        forin(i,1,200000)
        {
            if(vis[i])
            {
                ans--;
                stack<ll> s;
                s.push(i);
                while(!s.empty())
                {
                    ll x=s.top();
                    s.pop();
                    if(!vis[x]) continue;
                    vis[x]=0;
                    for(auto p:adj[x])
                    {
                        if(vis[p])
                        {
                            s.push(p);
                        }
                    }
                }
            }
        }
        ol(ans);
    }
}
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first
 
typedef map<int, int> mi;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
 
signed main() {
    #ifndef ONLINE_JUDGE
        freopen("inputf.txt", "r", stdin);
        freopen("outputf.txt", "w", stdout);
    #endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int h, w, x, y;
    cin >> h >> w >> x >> y;

    string s[h];

    for(int i=0; i<h; i++) {
        cin >> s[i];
    }

    x--;
    y--;
    int count=1;

    for(int i=x; i<h and s[i][y]!='#'; i++) {
        count++;
    }

    for(int i=x; i>=0 and s[i][y]!='#'; i--) {
        count++;
    }

    for(int i=y; i<w and s[x][i]!='#'; i++) {
        count++;
    }

    for(int i=y; i>=0 and s[x][i]!='#'; i--) {
        count ++;
    }

    cout << count-4;

    return 0;
}