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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;


int main() {
    ll x, y, a, b;
    cin >> x >> y >> a >> b;
    
    ll ans = 0;
    while (1) {
        if (y / a <= x) break;
        if (a * x >= y) break;
        if (a * x > x + b) break;
        x *= a;
        ++ans;
    }

    ans += (y - 1 - x) / b;
    cout << ans << endl;

    return 0;
}
#include <bits/stdc++.h>
using namespace std; 
 
#define ll          long long int
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(i=a;i<b;i++)
#define mod         1000000007
 
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

const int N = 2e6 + 5;

void solve()
{
    ll n, i, aoki = 0, taki = 0, ans = 0;
    cin >> n;
    ll a[n], b[n];
    vector<pair<ll,int>> v(n);
    rep(i, 0, n)
    {
    	cin >> a[i] >> b[i];
    	v[i].F = 2*a[i] + b[i];
    	v[i].S = i;
    	aoki += a[i];
    }
    sort(all(v));
    reverse(all(v));
    for(i = 0 ; taki <= aoki && i < n; i++)
    {
    	int idx = v[i].S;
        taki += a[idx] + b[idx];
        aoki -= a[idx];
        ans++;
    }
    cout << ans;
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}