#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long
int32_t main()
{
  int n; cin >> n;
  vi v(n);fr(i,n) cin >> v[i];
  vi pfx = v;
  rep(i,1,n-1) pfx[i] += pfx[i-1];
  vi mxpfx = pfx;
  rep(i,1,n-1) mxpfx[i] = max(mxpfx[i-1], pfx[i]);

  int mx = 0;
  rep(i,1,n-1) pfx[i] += pfx[i-1];
  rep(i,0,n-2) mx =  max(mx, pfx[i] + mxpfx[i+1]);
  mx = max(mx, pfx[n-1]);
  cout << mx;
  


}
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(ll i=0;i<N;i++) //0から


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    //a>=b
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

ll modexp(ll x, ll a, ll m){ //x^a mod m
    ll ret = 1;
    while (a > 0) {
        if (a & 1) ret = ret * x % m;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % m;
        a >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

ll modinv(ll a, ll m){ //a^{-1} mod m
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
    }
    u=(u+m)%m;
    return u;
}



//cout<<fixed<<setprecision(10);
int main(){
    ll a,b,x,y;
    cin>>a>>b>>x>>y;
    ll ans=0;
    if(a>b){
        ans=min(x+y*(a-b-1),x+2*x*(a-b-1));
    }
    else{
        ans=min(x+y*(b-a),x+2*x*(b-a));
    }
    cout<<ans<<endl;

    return 0;
}