#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    ll A[N], B[N]; F0R(i, N) cin >> A[i] >> B[i];
    vl ops; ll sum = 0;
    F0R(i, N) {
        sum += A[i]; ops.pb(2*A[i] + B[i]);
    }
    sort(all(ops)); reverse(all(ops));
    int ans = 0;
    F0R(i, N) {
        ans++; sum -= ops[i];
        if (sum < 0) break;
    }
    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
const double PI = 3.141593;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
template <class T>
bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}


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