#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define deb(x...) cout << #x << " = ["; _print(x)
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// =================
#define f(i, k, n) for (int i = k; i < n; i++)
#define r(i, k, n) for (int i = k; i >= n; i--)
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define len(s) s.size()
#define all(v) v.begin(), v.end()
#define tr(it, v) for (auto &it : v)
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
// =================

const int mod = 1e9+7;
const int N = 3e5 + 1;

void solve()
{
    ll x,y;
    int a,b;
    cin>>x>>y>>a>>b;
    int req=(b+a-2)/(a-1);
    ll days=0;
    while (1ll*x*a<req && 1ll*x*a<y && 1ll*x*a>0)
    {
        x*=a;
        days++;
    }
    // if(x*a<x+b && x*a<y && 1ll*x*a>0) {
    //     x*=a;
    //     days++;
    // } 
    // else if(x+b<y && x+b>0) {
    //     x+=b;
    //     days++;
    // }
    if(x<y && x>0) {
        days+=(y-1-x)/b;
    }
    cout<<days;
}

signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int t = 1;
    while (t--)
        solve();
    return 0;
}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <cstring>
 
using namespace std;
 
const int MOD = 1e9 + 7;
const int INF = 200001;
using ll = long long;
using db = double;
#define FOR(i, x, n) for (int i = x; i < n; i++)
#define TRAV(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define endl "\n"

int n;
ll a[INF];
ll ps1[INF], ps2[INF];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
 
  // ifstream fin(".in");
  // ofstream fout(".out");

	cin >> n;
	FOR(i, 1, n + 1) {
		cin >> a[i];
	}

	FOR(i, 1, n + 1) {
		ps1[i] = ps1[i - 1] + a[i];
	}
	FOR(i, 1, n + 1) {
		ps2[i] = max(ps1[i], ps2[i - 1]);
	}

	ll current = 0;
	ll ans = -1e9;
	FOR(i, 1, n + 1) {
		ans = max(ans, current + ps2[i]);
		current += ps1[i];
	}

	cout << ans << endl;

	return 0;
}

/*
	*
*/
