#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
typedef long long ll;


void Main() {
    int N, t[2000];
    double l[2000], r[2000];
    cin >> N ;
    for (int i = 0; i < N; ++i) {
        cin >> t[i] >> l[i] >> r[i] ;
        if (t[i] == 2 || t[i] == 4) { // 右が開なら少し狭く
            r[i] -= 0.2;
        }
        if (t[i] == 3 || t[i] == 4) {
            l[i] += 0.2;
        }
    }
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            //[a, b], [c, d]が交わるかどうか：max(a, c) <= min(c, d)
            // printf("[l[%d], r[%d]] = [%f, %f], [l[%d], r[%d]] = [%f, %f], max(l[%d], l[%d]) = %f, min(r[%d], r[%d]) = %f\n", i, i, l[i], r[i], j, j, l[j], r[j], i, j, max(l[i], l[j]), i, j, min(l[i], l[j]));
            if (max(l[i], l[j]) <= min(r[i], r[j])) {
                ++ans;
            }
        }
    }

    cout << ans << endl;
}

int main(void) {
    Main();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define m7          1000000007
#define m9          1000000009
#define ll          long long
#define boost       ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define F           first
#define S           second
#define pb          push_back
#define f1(i,n)     for(int i=0;i<n;i++)
#define all(c)      c.begin(),c.end()
#define ldb         long double




 
int main() {
     

    int t;
   // cin>>t;
    t = 1;
    while(t--)
    {
        int n,m,x,y;
        cin>>n>>m>>x>>y;
        vector<string> vec(n);
        f1(i,n)
        {
        	cin>>vec[i];
        }

        x--;
        y--;
        int ans = 1;
        for(int i=y-1;i>=0;i--)
        {
        	if(vec[x][i] == '.')
        		ans++;
        	else
        		break;

        }
        for(int i=x-1;i>=0;i--)
        {
        	if(vec[i][y] == '.')
        		ans++;
        	else
        		break;

        }
        for(int i=y+1;i<m;i++)
        {
        	if(vec[x][i] == '.')
        		ans++;
        	else
        		break;

        }
        for(int i=x+1;i<n;i++)
        {
        	if(vec[i][y] == '.')
        		ans++;
        	else
        		break;

        }
        cout<<ans<<'\n';



    }
	return 0;
}