#include #include #include #define Add(x, y) (x + y >= mod) ? (x + y - mod) : (x + y) #define lowbit(x) x & (-x) #define pi pair #define pii pair> #define iip pair, ll> #define ppii pair, pair> #define ls(k) k << 1 #define rs(k) k << 1 | 1 #define fi first #define se second #define full(l, r, x) for(auto it = l; it != r; ++it) (*it) = x #define Full(a) memset(a, 0, sizeof(a)) #define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout); #define For(i, l, r) for(register int i = l; i <= r; ++i) #define _For(i, l, r) for(register int i = r; i >= l; --i) using namespace std; using namespace __gnu_pbds; typedef double db; typedef unsigned long long ull; typedef long long ll; bool Begin; const int N = 4e5 + 10; inline ll read(){ ll x = 0, f = 1; char c = getchar(); while(c < '0' || c > '9'){ if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void write(ll x){ if(x < 0){ putchar('-'); x = -x; } if(x > 9) write(x / 10); putchar(x % 10 + '0'); } ll n, a, b, w; ll s[N], d[N], T[N]; namespace Tree{ ll cnt; struct Line{ ll k, b; }h[N]; struct Node{ ll l, r; ll id; }X[N << 2]; ll check(ll x, ll y){ if(x - y > 0) return 1; if(y - x > 0) return -1; return 0; } inline ll Fun(ll x, ll id){ return h[id].k * x + h[id].b; } inline void build(ll k, ll l, ll r){ X[k].l = l, X[k].r = r; if(l == r) return ; ll mid = (l + r) >> 1; build(k << 1, l, mid); build(k << 1 | 1, mid + 1, r); } inline void update(ll k, ll l, ll r, ll id){ if(!id) return ; ll mid = (X[k].l + X[k].r) >> 1; if(X[k].l == l && r == X[k].r){ ll op = check(Fun(mid, id), Fun(mid, X[k].id)); if(op == -1 || (!op && id < X[k].id)) swap(X[k].id, id); op = check(Fun(l, id), Fun(l, X[k].id)); if(op == -1 || (!op && id < X[k].id)) update(k << 1, l, mid, id); op = check(Fun(r, id), Fun(r, X[k].id)); if(op == -1 || (!op && id < X[k].id)) update(k << 1 | 1, mid + 1, r, id); return ; } if(r <= mid) update(k << 1, l, r, id); else if(l > mid) update(k << 1 | 1, l, r, id); else{ update(k << 1, l, mid, id); update(k << 1 | 1, mid + 1, r, id); } } inline ll query(ll k, ll i){ if(X[k].l == i && i == X[k].r) return X[k].id; db t = Fun(i, X[k].id); ll mid = (X[k].l + X[k].r) >> 1, h = 0; if(i <= mid) h = query(k << 1, i); else h = query(k << 1 | 1, i); if(Fun(i, h) < t) return h; if(!check(Fun(i, h), t)) return min(X[k].id, h); return X[k].id; } inline void add(ll k, ll b){ h[++cnt] = {k, b}; update(1, 0, n + 1, cnt); } inline ll ask(ll x){ ll id = query(1, x); return Fun(x, id); } }; bool End; int main(){ // open("A.in", "A.out"); n = read(), a = read(), b = read(), w = read(); Tree::h[0].b = 2e18; Tree::build(1, 0, n + 1); s[0] = s[1] = w; T[0] = s[0] + a; Tree::add(0, T[0]); for(ll i = 2; i <= n + 1; ++i){ d[i] = read(); s[i] = Tree::ask(i) + (i * (i - 1) >> 1) * b - i * a; s[i] = min(s[i], s[i - 1] + d[i]); T[i - 1] = s[i - 1] + d[i] + i * a + (i * (i - 1) >> 1) * b; Tree::add(-(i - 1) * b, T[i - 1]); } write(s[n + 1]); cerr << '\n' << abs(&Begin - &End) / 1048576 << "MB"; return 0; }