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

const int MAXN = 1e5 + 10;

int arr[MAXN], n;
int minim[MAXN];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> arr[i];
	int r_max = -1e8;
	for(int i = n; i > 0; i--) {
		minim[i] = max(0, r_max + i + 1);
		r_max = max(r_max, arr[i] - i);
	}
	minim[1] = max(1, minim[1]);
	int curr = 0, ans = 0;
	for(int i = 1; i <= n; i++) {
		if(minim[i] > curr) {
			assert(curr + 1 == minim[i]);
			ans += curr - arr[i];
			curr++;
		} else if(curr == arr[i]) {
			curr++;
		} else {
			ans += curr - arr[i] - 1;
		}
	}
	cout << ans << '\n';
	/* for(int i = 1; i <= n; i++) {
		cerr << minim[i] << " ";
	}
	cerr << endl; */
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  ll ans=0;
  ll d[n+1];
  d[n]=0;
  rrep(i,n) d[i]=max(a[i],d[i+1]-1);
  rep(i,n) d[i+1]=max(d[i+1],d[i]);
  rep(i,n) {
    if(!a[i]) ans+=d[i];
    else ans+=d[i]-a[i];
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  int a[n];
  rep(i,n) R a[i];
  ll ans=0,x=0,y=0;
  REP(i,1,n) {
    if(!a[i]) {
      ans+=x-y;
      x++;
    } else {
      y=min(y,x-a[i]);
      ans-=y-(x-a[i]);
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 100005
int n;
ll m[MAX];

ll solve(int i,int p){
    if(i>n) return 0;
    if(m[i]>=p) return LLONG_MAX;
    return p-1-m[i]+min(solve(i+1,p),solve(i+1,p+1));
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%I64d",&m[i]);
    cout<<solve(1,1);
}


#include<bits/stdc++.h>
using namespace std;
#define INF 10000000000000
#define ll long long int
#define MAX 100005
int n;
ll m[MAX];

ll solve(int i,ll p){
    if(i>n) return 0;
    if(m[i]>=p) return INF;
    return p-1-m[i]+min(solve(i+1,p),solve(i+1,p+1));
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%I64d",&m[i]);
    cout<<solve(1,1);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX 100005
int ara[MAX];
int tree[MAX*5];
ll Sum[MAX*5];
#define Left (node*2)
#define Right (node*2+1)
#define mid ((lo+hi)/2)

ll nC2(ll a,ll b){return (b*(b+1))/2-(a*(a-1))/2;}

//lazy propagation
int lazy[MAX*5];
void lazyPropagation(int node,int lo,int hi){
    if(lazy[node]){
        tree[node]=(hi-lo+1)*lazy[node];
        Sum[node]=nC2(lo,hi);
        if(lo != hi) {lazy[node*2]=1; lazy[node*2+1]=1;}
        lazy[node] = 0;
    }
}

void updateRange(int node, int lo, int hi, int i, int j){
    lazyPropagation(node,lo,hi);
    if(lo>hi) return;
    else if(lo>j || hi<i) return;
    if(lo>=i && hi<=j) {lazy[node]=1;  lazyPropagation(node,lo,hi);  return;}
    updateRange(Left,lo,mid,i,j);
    updateRange(Right,mid+1,hi,i,j);
    tree[node]=tree[Left]+tree[Right];
    Sum[node]=Sum[Left]+Sum[Right];
}

int query1(int node,int lo,int hi,int i,int j){
    if(lo>hi) return 0;
    else if(lo>j || hi<i) return 0;
    lazyPropagation(node,lo,hi);
    if(lo>=i && hi <= j) return tree[node];
    int p1=query1(Left,lo,mid,i,j);
    int p2=query1(Right,mid+1,hi,i,j);
    return p1+p2;
}

ll query2(int node,int lo,int hi,int i,int j){
    if(lo>hi) return 0;
    else if(lo>j || hi<i) return 0;
    lazyPropagation(node,lo,hi);
    if(lo>=i && hi <= j) return Sum[node];
    ll p1=query2(Left,lo,mid,i,j);
    ll p2=query2(Right,mid+1,hi,i,j);
    return p1+p2;
}

int Free(int x,int i,int n){
    return (i-x)-query1(1,1,n,x,i-1);
}

int BS(int i,int n,int Need){
    int lo=1;
    int hi=i-1;
    while(hi-lo>1){
        if(Free(mid,i,n)>=Need) lo=mid;
        else hi=mid;
    }
    if(Free(hi,i,n)>=Need) return hi;
    else return lo;
}

int main(){
    int n;
    scanf("%d",&n);
    ll Ans=0;
    int p,Size=0;

    for(int i=1;i<=n;i++){
        int p;
        scanf("%d",&p);

        if(p<Size) Ans+=Size-p-1;
        else{
            ll Need=p-Size; Size=p+1;
            updateRange(1,1,n,i,i);
            if(!Need) continue;

            ll L=BS(i,n,Need);
            ll Sum=query2(1,1,n,L,i-1);
            Sum=nC2(L,i-1)-Sum;
            Sum=i*Need-Sum;
            Ans+=Sum;
            updateRange(1,1,n,L,i-1);
        }
    }
    cout<<Ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    int n;
    scanf("%d",&n);
    ll Ans=0;
    int p,Size=0;

    for(int i=1;i<=n;i++){
        int p;
        scanf("%d",&p);

        if(p<Size) Ans+=Size-p-1;
        else {Ans+=(p-Size); Size=p+1; Ans+=Size-p-1;}
    }
    cout<<Ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    int n;
    scanf("%d",&n);
    ll Ans=0;
    int p,Size=0;

    for(int i=1;i<=n;i++){
        int p;
        scanf("%d",&p);

        if(p<Size) Ans+=Size-p-1;
        else {Size=p+1; Ans+=p-1; Ans+=Size-p-1;}
    }
    cout<<Ans<<endl;
}


#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int n, m;

int a[110000];
int h[110000];
long long ans;

int main()
{
	scanf("%d", &n);

	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
		h[i] = a[i] + 1;
		if (i > 0 && h[i] < h[i - 1]) h[i] = h[i - 1];
	}

	for (int i = n - 2; i >= 0; --i)
	{
		if (h[i] < h[i + 1] - 1) h[i] = h[i + 1] - 1;
	}

	for (int i = 0; i < n; ++i)
	{
		ans += h[i] - a[i] - 1;
	}

	printf("%I64d\n", ans);

	return 0;
}


#define yuki(x, y) for(int i = x, __yuki = y; i < __yuki; ++i)
#define yukj(x, y) for(int j = x, __yukj = y; j < __yukj; ++j)
#define yukii(x, y) for(int i = x, __yukii = y; i <= __yukii; ++i)
#define yukji(x, y) for(int j = x, __yukji = y; j <= __yukji; ++j)
#define yuk(x, y, z) for(int x = y, __yuk = z; x < __yuk; ++x)
#define yui(x, y, z) for(int x = y, __yui = z; x >= __yui; --x)
#define ft first
#define sc second
#define mp make_pair
#define sclr1(x) memset(x, -1, sizeof(x))
#define scl(x, y) memset(x, y, sizeof(x))
#define sclr(x) memset(x, 0, sizeof(x))
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long lol;
int n, a[100100];
map<int, int> pos;
void sread()
{
	scanf("%d", &n);
	yuki(0, n)
	{
		scanf("%d", a+i);
		if(!pos.count(a[i])) pos[a[i]] = i;
	}
}
int main(int argc, char **argv)
{
	sread();
	lol ans = 0;
	int cur = pos.rbegin()->ft, p = n-1, pc = pos.rbegin()->sc;
	auto itr = pos.rbegin();
	while(p >= 0)
		if(p >= pc)
			ans += cur-a[p--];
		else
		{
			do{
			do ++itr; while(itr->sc >= pc);
			while(itr->ft < cur-1)
			{
				pc = p;
				--cur;
				ans += cur-a[p--];
			}
			}while(itr->sc >= pc);
			cur = itr->ft,pc = itr->sc;
		}
	printf("%I64d\n", ans);
	return 0;
}


#define yuki(x, y) for(int i = x, __yuki = y; i < __yuki; ++i)
#define yukj(x, y) for(int j = x, __yukj = y; j < __yukj; ++j)
#define yukii(x, y) for(int i = x, __yukii = y; i <= __yukii; ++i)
#define yukji(x, y) for(int j = x, __yukji = y; j <= __yukji; ++j)
#define yuk(x, y, z) for(int x = y, __yuk = z; x < __yuk; ++x)
#define yui(x, y, z) for(int x = y, __yui = z; x >= __yui; --x)
#define ft first
#define sc second
#define mp make_pair
#define sclr1(x) memset(x, -1, sizeof(x))
#define scl(x, y) memset(x, y, sizeof(x))
#define sclr(x) memset(x, 0, sizeof(x))
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long lol;
int n, a[100100];
map<int, int> pos;
void sread()
{
	scanf("%d", &n);
	yuki(0, n)
	{
		scanf("%d", a+i);
		if(!pos.count(a[i])) pos[a[i]] = i;
	}
}
int main(int argc, char **argv)
{
	sread();
	lol ans = 0;
	int cur = pos.rbegin()->ft, p = n-1, pc = pos.rbegin()->sc;
	auto itr = pos.rbegin();
	while(p >= 0)
		if(p >= pc)
			ans += cur-a[p--];
		else
		{
			do ++itr; while(itr->sc >= pc);
			while(itr->ft < cur-1)
			{
				pc = p;
				--cur;
				ans += cur-a[p--];
			}
			cur = itr->ft,pc = itr->sc;
		}
	printf("%I64d\n", ans);
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <map>
#include <set>
#include <queue>

#define LL long long

using namespace std;

const int N = 1e5+10;

int n;
stack<int>Q;
int cnt[N], cur = 0;

int main()
{
	//freopen("test_in.txt", "r", stdin);
	//freopen("test_out.txt", "w", stdout);
	cin>>n;
	LL ans = 0;
	cin>>ans;
	cur = 1;
	for(int i = 2; i <= n; i++)
	{
		int t;
		scanf("%d", &t);
		if(t < cur)
		{
			ans += cur-t-1;
			Q.push(i);
		}else
		{
			for(int k = 1; k < t-cur+1; k++)
			{
				int x = Q.top(); Q.pop();
				ans += i-x;
			}
			cur = t+1;
		}
	}
	cout<<ans<<endl;
}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <map>
#include <set>
#include <queue>

#define LL long long

using namespace std;

const int N = 1e5+10;

int n;
stack<int>Q;
int cnt[N], cur = 0;

int main()
{
	//freopen("test_in.txt", "r", stdin);
	//freopen("test_out.txt", "w", stdout);
	cin>>n;
	int ans = 0;
	cin>>ans;
	Q.push(0);
	cur = 1;
	for(int i = 2; i <= n; i++)
	{
		int t;
		scanf("%d", &t);
		if(t < cur)
		{
			ans += cur-t-1;
			cnt[t+1]++;
			Q.push(i);
		}else
		{
			for(int k = 1; k < t-cur+1; k++)
			{
				int x = Q.top(); Q.pop();
				ans += i-x;
			}
			cur = t+1;
		}
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.H>

#define MAXN (100010)
#define ll long long

int n;
int m[MAXN], sm[MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i) {
		scanf("%d", m + i);
		sm[i] = m[i] + 1 - i;
	}
	for (int i = n - 1; ~i; -- i) {
		sm[i] = std::max(sm[i], sm[i + 1]);
	}
	ll ans = 0;
	int x = 0;
	for (int i = 0; i < n; ++ i) {
		if (x - i < sm[i]) {
			++ x;
		}
		ans += x - 1 - m[i];
	}
	printf("%I64d\n", ans);
	return 0;
}


#include <bits/stdc++.H>

#define MAXN (100010)
#define ll long long

int n;
int m[MAXN], sm[MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i) {
		scanf("%d", m + i);
		sm[i] = m[i] + 1 - i;
	}
	sm[n] = INT_MIN;
	for (int i = n - 1; ~i; -- i) {
		sm[i] = std::max(sm[i], sm[i + 1]);
	}
	ll ans = 0;
	int x = 1;
	for (int i = 1; i < n; ++ i) {
		if (x - i < sm[i]) {
			++ x;
		}
		ans += x - 1 - m[i];
	}
	printf("%I64d\n", ans);
	return 0;
}


#include <bits/stdc++.H>

#define MAXN (100010)
#define ll long long

int n;
int m[MAXN], sm[MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i) {
		scanf("%d", m + i);
		sm[i] = m[i] + 1 - i;
	}
	for (int i = n - 1; ~i; -- i) {
		sm[i] = std::max(sm[i], sm[i + 1]);
	}
	ll ans = 0;
	int x = 0;
	for (int i = 0; i < n; ++ i) {
		if (x - i < sm[i + 1]) {
			++ x;
		}
		ans += x - 1 - m[i];
	}
	printf("%I64d\n", ans);
	return 0;
}


/*input
6
0 1 0 3 0 2
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 100005;
int a[N], st[N], p;

int main(){
	int n; cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];

	int cur = 1;
	int64_t Ans = 0;

	for(int i = 1; i <= n; ++ i) {
		if(a[i] == 0) {
			st[++ p] = i;
			Ans += cur - 1;
			continue;
		}
		if(cur > a[i]) {
			Ans += cur - a[i] - 1;
			continue;
		}
		while(cur < a[i]) {
			if(st[p] < 0) {
				-- Ans, -- p;
				continue;
			}
			++ cur, Ans += (i - st[p --]);
		}
		st[++ p] = - i; ++ cur;
	}
	cout << Ans << endl;
}


/*input
6
0 1 1 2 2 4
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 100005;
int a[N], st[N], p;

int main(){
	int n; cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];

	int cur = 1;
	int64_t Ans = 0;

	for(int i = 1; i <= n; ++ i) {
		if(cur > a[i]) {
			st[++ p] = i;
			Ans += cur - a[i] - 1;
			continue;
		}
		while(cur < a[i]) ++ cur, Ans += (i - st[p --]);
		++ cur;
	}
	cout << Ans << endl;
}


/*input
5
0 1 1 2 2
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 100005;
int a[N], st[N], p;

int main(){
	int n; cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];

	int cur = 1;
	int64_t Ans = 0;

	for(int i = 1; i <= n; ++ i) {
		if(a[i] == 0) {
			st[++ p] = i;
			Ans += cur - 1;
			continue;
		}
		if(cur > a[i]) {
			Ans += cur - a[i] - 1;
			continue;
		}
		while(cur < a[i]) ++ cur, Ans += (i - st[p --]);
		++ cur;
	}
	cout << Ans << endl;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>

#define MAXN 100001

using namespace std;

int N,a[MAXN],min_mark[MAXN],mark=1;

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>a[i];
	min_mark[N-1]=0;
	for(int i=N-1;i>0;i--)
		min_mark[i-1]=max(min_mark[i]-1,a[i]);
	int ans=0;
	for(int i=1;i<N;i++)
	{
		if(a[i]==mark||mark<min_mark[i])
		{
			ans+=mark-a[i];
			++mark;
		}
		else
			ans+=mark-a[i]-1;
	}
	cout<<ans<<endl;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>

#define MAXN 100001

using namespace std;

int N,a[MAXN],min_mark[MAXN],mark=1;

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>a[i];
	min_mark[N-1]=a[N-1];
	for(int i=N-1;i>0;i--)
		min_mark[i-1]=max(min_mark[i]-1,a[i]);
	long long ans=0;
	for(int i=1;i<N;i++)
	{
		if(a[i]==mark||mark<min_mark[i])
		{
			ans+=mark-a[i];
			++mark;
		}
		else
			ans+=mark-a[i]-1;
	}
	cout<<ans<<endl;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>

#define MAXN 100001

using namespace std;

int N,a[MAXN],min_mark[MAXN],mark=1;

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>a[i];
	min_mark[N-1]=a[N-1];
	for(int i=N-1;i>0;i--)
		min_mark[i-1]=max(min_mark[i]-1,a[i]);
	int ans=0;
	for(int i=1;i<N;i++)
	{
		if(a[i]==mark||mark<min_mark[i])
		{
			ans+=mark-a[i];
			++mark;
		}
		else
			ans+=mark-a[i]-1;
	}
	cout<<ans<<endl;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>

#define MAXN 100001

using namespace std;

int N,a[MAXN],min_mark[MAXN],mark=1;

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
		cin>>a[i];
	min_mark[N-1]=0;
	for(int i=N-1;i>0;i--)
		min_mark[i-1]=a[i];
	int ans=0;
	for(int i=1;i<N;i++)
	{
		if(a[i]==mark||mark<min_mark[i])
		{
			ans+=mark-a[i];
			++mark;
		}
		else
			ans+=mark-a[i]-1;
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define P pair<int, int>
#define F first
#define S second
#define MP make_pair
using namespace std;

int n, a[100100], c[100100], mx[100100];
long long ans;

int main(void) {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mx[i] = max(mx[i - 1], a[i]);
  }
  for(int i = n; i >= 1; i--) {
    c[i] = max(c[i + 1] - 1, mx[i]);
    ans += c[i] - a[i];
  }
  printf("%lld\n", ans);
  return 0;
}


#include <bits/stdc++.h>
#define P pair<int, int>
#define F first
#define S second
#define MP make_pair
using namespace std;

int n, a[100100], c[100100], mx[100100], ans;

int main(void) {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    mx[i] = max(mx[i - 1], a[i]);
  }
  for(int i = n; i >= 1; i--) {
    c[i] = max(c[i + 1] - 1, mx[i]);
    ans += c[i] - a[i];
  }
  printf("%d\n", ans);
  return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

const int maxN = 1e5+100;

int a[maxN], b[maxN];
int n, m;

int main() {
    cin >> n;
    m = 0;
    long long sum = 0;
    for(int i=1; i<=n; i++) {
        scanf("%d", &a[i]);
    }
    b[n] = a[n]+1;
    for(int i=n-1; i>0; i--)
        b[i] = max(b[i+1]-1, a[i]+1);
    for(int i=1; i<=n; i++)
        b[i] = max(b[i-1], b[i]);
    for(int i=1; i<=n; i++) {
        int delta = b[i-1]-a[i];
        if (b[i] == b[i-1])
            --delta;
        sum += max(delta, 0);
    }
    cout << sum;
}


/**
  * @file pc.cpp
  * @brief codeforces

  *

  * @author yao
  * @date 2018-03-27
  */
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <utility>
#include <algorithm>
#define N 131072
#ifdef DBG
#   define dbg_pri(x...) printf(x)
#else
#   define dbg_pri(x...)
#endif //DBG

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

int a[N],m[N];

int main()
{
    int n,num=0;
    lli sum=0;
    scanf("%d\n",&n);
    for(int i=1; i<=n; ++i) scanf("%d",a+i), m[i] = std::max(a[i],m[i-1]);
    for(int i=n; i>0; --i)
    {
        num = std::max(num-1,m[i]);
        sum += num - a[i];
    }
    printf( "%I64d\n", sum );
    return 0;
}


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

const int N = 1e5 + 5;
int a[N], b[N];

int main()
{
	ios::sync_with_stdio(0);
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		b[i] = max(a[i] + 1, b[i - 1]);
	}
	for (int i = n - 1; i; i--) b[i] = max(b[i], b[i + 1] - 1);
	long long ans = 0;
	for (int i = 1; i <= n; i++) ans += b[i] - a[i] - 1;
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int N = 1e5 + 5;

int a[N], s[N], sum[N];

int main()
{
	int n; scanf("%d", &n);
	int maxv = 0, minv = 0, tot = 0;
	for (int i = 0; i < n; i++)
	{
		int x; cin >> x;
		if (x == 0 && i) s[tot++] = i;
		while (maxv - x < minv - 1)
		{
			sum[s[--tot]]++;
			sum[i]--;
			maxv++;
		}
		a[i] = maxv - x;
		minv = min(minv, a[i]);
	}
	maxv = minv = 0;
	ll ans = 0, tmp = 0;
	for (int i = 0; i < n; i++)
	{
		tmp += sum[i];
		a[i] += tmp;
//		cout << a[i] << endl;
		maxv = max(maxv, a[i]);
		minv = min(minv, a[i]);
		ans += a[i] - minv;
	}
	printf("%I64d\n", ans);
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int N = 1e5 + 5;

int a[N], s[N], sum[N];

int main()
{
	int n; scanf("%d", &n);
	int maxv = 0, minv = 0, tot = 0;
	for (int i = 0; i < n; i++)
	{
		int x; cin >> x;
		if (x == 0 && i) s[tot++] = i;
		while (maxv - x < minv - 1)
		{
			assert(tot);
			sum[s[--tot]]++;
			sum[i]--;
			maxv++;
		}
		a[i] = maxv - x;
		minv = min(minv, a[i]);
	}
	maxv = minv = 0;
	ll ans = 0, tmp = 0;
	for (int i = 0; i < n; i++)
	{
		tmp += sum[i];
		a[i] += tmp;
		maxv = max(maxv, a[i]);
		minv = min(minv, a[i]);
		ans += a[i] - minv;
	}
	printf("%I64d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 1e5 + 7;
int n, m[N], dp[N];
int main() {
    scanf("%d", &n);
    rep(i, 0, n) scanf("%d", m + i);
    dp[n] = 0;
    per(i, 0, n) dp[i] = max(m[i], dp[i + 1] - 1);
	rep(i, 1, n) dp[i] = max(dp[i], dp[i - 1]);
	ll ans = 0;
	rep(i, 0, n) ans += dp[i] - m[i];
	cout << ans;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int N;
int m[100000];
int num[100000];

int main()
{
	cin >> N;
	for(int i=0;i<N;i++)
		cin >> m[i];
	for(int i=0;i<N;i++)
		num[i] = m[i] + 1;
	for(int i=1;i<N;i++)
		num[i] = max(num[i], num[i-1]);
	for(int i=N-2;i>=0;i--)
		num[i] = max(num[i], num[i+1] - 1);
	long long ans = 0;
	for(int i=0;i<N;i++)
		ans += num[i] - m[i] - 1;
	cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define maxn 100010

int n,a[maxn],b[maxn],ans;

inline max(int a,int b){return a>b?a:b;}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],b[i]=a[i];
	int tot=0;
	for(int i=1;i<=n;i++){
		if(a[i]>tot) tot=a[i];
		else a[i]=tot;
	}
	for(int j=n;j>1;j--){
		a[j-1]=max(a[j-1],a[j]-1);
	}
	for(int i=1;i<=n;i++) ans+=a[i]-b[i];
	cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define maxn 100010

LL n,a[maxn],b[maxn],ans;

inline max(LL a,LL b){return a>b?a:b;}

int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],b[i]=a[i];
	int tot=0;
	for(int i=1;i<=n;i++){
		if(a[i]>tot) tot=a[i];
		else a[i]=tot;
	}
	for(int j=n;j>1;j--){
		a[j-1]=max(a[j-1],a[j]-1);
	}
	for(int i=1;i<=n;i++) ans+=a[i]-b[i];
	cout<<ans;

    return 0;
}


#include<iostream>
#include <bits/stdc++.h>
#define MAX 10000005
#define ll long  long
#define upperlimit 1000100
#define INF 1e18
#define inf 1e9
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>

#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mod 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a)printf("check%d\n",a)
#define ios ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
int a[100006];
int main()
{
    int n;
    cin>>n;
    set<pii>s;
    for(int i=1;i<=n;i++){cin>>a[i];s.insert(mp(-a[i],i));}
    ll ans=0;
    int li=n+1;
    int last=-s.begin()->FF+1;
    while(!s.empty())
    {
        int ind=s.begin()->SS;
        if(a[ind]+1<last)
        {
            int j;
            for(int i=li-1;i>=ind&&last>a[ind]+1;i--)
            {
                ans+=(ll)(last-1-a[i]);
                last--;
                j=i;
            }
            for(int i=ind+1;i<j;i++)
            {
                ans+=(ll)(a[ind]-a[i]);
            }
            if(j>ind)last=a[ind];
        }
        else
        {
            for(int i=li-1;i>=ind;i--)
            {
                ans+=(ll)(a[ind]-a[i]);
            }
            last=a[ind];
        }
        for(int i=ind;i<li;i++)s.erase(mp(-a[i],i));
        li=ind;
       // s.erase(s.begin());
    }
    cout<<ans<<endl;

}


#include<iostream>
#include <bits/stdc++.h>
#define MAX 10000005
#define ll long  long
#define upperlimit 1000100
#define INF 1e18
#define inf 1e9
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>

#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mod 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a)printf("check%d\n",a)
#define ios ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
int a[100006];
int main()
{
    int n;
    cin>>n;
    set<pii>s;
    for(int i=1;i<=n;i++){cin>>a[i];s.insert(mp(-a[i],i));}
    int mx=-1;
    ll ans=0;

    for(int i=n;i>=2;i--)
    {

        int z=-s.begin()->FF;
        if(z+1<mx)
        {
            ans+=(ll)(mx-1LL-a[i]);
            mx--;
            s.erase(mp(-a[i],i));
        }
        else
        {
            s.erase(mp(-a[i],i));
            z=-s.begin()->FF+1;
            z=max(z,mx);
            z=max(z,a[i]);
            ans+=(ll)(max(0,z-a[i]-1));
        }
        mx=max(mx,a[i]);
    }
    cout<<ans<<endl;

}


#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <map>
#include <set>
#include <queue>

#define LL long long

using namespace std;

const int N = 1e5+10;

int n;
stack<int>Q;
int cnt[N], cur = 0;

int main()
{
	//freopen("test_in.txt", "r", stdin);
	//freopen("test_out.txt", "w", stdout);
	cin>>n;
	LL ans = 0;
	cin>>ans;
	cur = 1;
	for(int i = 2; i <= n; i++)
	{
		int t;
		scanf("%d", &t);
		if(t < cur)
		{
			ans += cur-t-1;
			Q.push(i);
		}else
		{
			for(int k = 1; k < t-cur+1; k++)
			{
				int x = Q.top(); Q.pop();
				ans += i-x;
			}
			cur = t+1;
		}
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define si(x) (int)((x).size())
#define rep(i, a, b) for (__typeof(b) i = (a)-((a)>(b)); i != (b)-((a)>(b)); i += 1 - 2 * ((a) > (b)))
#define repi(i, a, b) for (__typeof(b) i = (a); i != (b); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <vi> vvi;
typedef vector <pi> vpi;
typedef vector <string> vs;

int main() {
    unsigned int n;
    ll A,c1,c2,m;
    cin>>n>>A>>c1>>c2>>m;
    vpi a(n+1);
    vi s(n+1);
    a[0] = mp(-1,0);
    repi (i,1,n+1) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    sort(all(a));
    s[0] = 0;
    repi (i,1,n+1) {
        s[i] = s[i-1] + a[i].fi;
    }
    int ansf = 0, ansm = (int) a[1].fi;
    ll maxv = 0;
    repi (f,0,n+1) {
        ll req = A*f - (s[n] - s[n-f]);
        if (m < req) break;
        ll left = m - req;
        int l = (int)a[1].fi, h = (int)A;
        while (l < h) {
            int mid = (l + h + 1)/2;
            int ll = 1, hh = n-f;
            while (ll <= hh) {
                int mm = (ll + hh)/2;
                if (a[mm].fi > mid) hh = mm-1;
                else ll = mm + 1;
            }
            req = mid*(ll-1) - (s[ll-1]-s[0]);
            if (req <= left) {
                l = mid;
                if (h == mid) break;
            }
            else h = mid - 1;
        }
        ll val = f*c1 + c2*l;
        if (val > maxv) {
            maxv = val;
            ansf = f;
            ansm = l;
        }
    }
    if (n == 100000 && A == 1000000000 && c1 == 300)
        cout << s[n] << " ";
        cout << ansf << " " << ansm << endl;
    cout << maxv << endl;
    repi (i,0,ansf) {
        a[n-i].fi = A;
    }
    int i = 1;
    while (a[i].fi < ansm) {a[i].fi = ansm; i++;}
    repi (ii,1,n+1) {
        ll t = a[ii].fi;
        a[ii].fi = a[ii].se;
        a[ii].se = t;
    }
    sort(all(a));
    repi (ii,1,n+1) {
        cout << a[ii].se << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define si(x) (int)((x).size())
#define rep(i, a, b) for (__typeof(b) i = (a)-((a)>(b)); i != (b)-((a)>(b)); i += 1 - 2 * ((a) > (b)))
#define repi(i, a, b) for (__typeof(b) i = (a); i != (b); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <vi> vvi;
typedef vector <pi> vpi;
typedef vector <string> vs;

int main() {
    unsigned int n;
    ll A,c1,c2,m;
    cin>>n>>A>>c1>>c2>>m;
    vpi a(n+1);
    vi s(n+1);
    a[0] = mp(-1,0);
    repi (i,1,n+1) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    sort(all(a));
    s[0] = 0;
    repi (i,1,n+1) {
        s[i] = s[i-1] + a[i].fi;
    }
    int ansf = 0, ansm = (int) a[1].fi;
    ll maxv = 0;
    repi (f,0,n+1) {
        ll req = A*f - (s[n] - s[n-f]);
        if (m < req) break;
        ll left = m - req;
        int l = (int)a[1].fi, h = (int)A;
        while (l < h) {
            int mid = (l + h + 1)/2;
            int ll = 1, hh = n-f;
            while (ll <= hh) {
                int mm = (ll + hh)/2;
                if (a[mm].fi > mid) hh = mm-1;
                else ll = mm + 1;
            }
            req = mid*(ll-1) - s[ll-1];
            if (req <= left) {
                l = mid;
                if (h == mid) {
                    if (n == 100000 && A == 1000000000 && c1 == 300)
                        cout << mid << " " << ll << " " << s[ll-1] << " " << req << " " << left << endl;
                    break;
                }
            }
            else h = mid - 1;
        }
        ll val = f*c1 + c2*l;
        if (val > maxv) {
            maxv = val;
            ansf = f;
            ansm = l;
        }
    }
    if (n == 100000 && A == 1000000000 && c1 == 300)
        cout << s[n] << " " << ansf << " " << ansm << endl;
    cout << maxv << endl;
    repi (i,0,ansf) {
        a[n-i].fi = A;
    }
    int i = 1;
    while (a[i].fi < ansm) {a[i].fi = ansm; i++;}
    repi (ii,1,n+1) {
        ll t = a[ii].fi;
        a[ii].fi = a[ii].se;
        a[ii].se = t;
    }
    sort(all(a));
    repi (ii,1,n+1) {
        cout << a[ii].se << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define si(x) (int)((x).size())
#define rep(i, a, b) for (__typeof(b) i = (a)-((a)>(b)); i != (b)-((a)>(b)); i += 1 - 2 * ((a) > (b)))
#define repi(i, a, b) for (__typeof(b) i = (a); i != (b); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <vi> vvi;
typedef vector <pi> vpi;
typedef vector <string> vs;

int main() {
    unsigned int n;
    ll A,c1,c2,m;
    cin>>n>>A>>c1>>c2>>m;
    vpi a(n+1);
    vi s(n+1);
    a[0] = mp(-1,0);
    repi (i,1,n+1) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    sort(all(a));
    s[0] = 0;
    repi (i,1,n+1) {
        s[i] = s[i-1] + a[i].fi;
    }
    int ansf = 0, ansm = (int) a[1].fi;
    ll maxv = 0;
    repi (f,0,n+1) {
        ll req = A*f - (s[n] - s[n-f]);
        if (m < req) break;
        ll left = m - req;
        int l = (int)a[1].fi, h = (int)A;
        while (l < h) {
            int mid = (l + h + 1)/2;
            int ll = 1, hh = n-f;
            while (ll <= hh) {
                int mm = (ll + hh)/2;
                if (a[mm].fi > mid) hh = mm-1;
                else ll = mm + 1;
            }
            req = (ll)mid*(ll-1) - s[ll-1];
            if (req <= left) {
                l = mid;
                if (h == mid) {
                    break;
                }
            }
            else h = mid - 1;
        }
        ll val = f*c1 + c2*l;
        if (val > maxv) {
            maxv = val;
            ansf = f;
            ansm = l;
        }
    }
    cout << maxv << endl;
    repi (i,0,ansf) {
        a[n-i].fi = A;
    }
    int i = 1;
    while (a[i].fi < ansm) {a[i].fi = ansm; i++;}
    repi (ii,1,n+1) {
        ll t = a[ii].fi;
        a[ii].fi = a[ii].se;
        a[ii].se = t;
    }
    sort(all(a));
    repi (ii,1,n+1) {
        cout << a[ii].se << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define si(x) (int)((x).size())
#define rep(i, a, b) for (__typeof(b) i = (a)-((a)>(b)); i != (b)-((a)>(b)); i += 1 - 2 * ((a) > (b)))
#define repi(i, a, b) for (__typeof(b) i = (a); i != (b); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <vi> vvi;
typedef vector <pi> vpi;
typedef vector <string> vs;

int main() {
    unsigned int n;
    ll A,c1,c2,m;
    cin>>n>>A>>c1>>c2>>m;
    vpi a(n+1);
    vi s(n+1);
    a[0] = mp(-1,0);
    repi (i,1,n+1) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    sort(all(a));
    s[0] = 0;
    repi (i,1,n+1) {
        s[i] = s[i-1] + a[i].fi;
    }
    int ansf = 0, ansm = (int) a[1].fi;
    ll maxv = 0;
    repi (f,0,n+1) {
        ll req = A*f - (s[n] - s[n-f]);
        if (m < req) break;
        ll left = m - req;
        int l = (int)a[1].fi, h = (int)A;
        while (l < h) {
            int mid = (l + h + 1)/2;
            int lll = 1, hh = n-f;
            while (lll <= hh) {
                int mm = (lll + hh)/2;
                if (a[mm].fi > mid) hh = mm-1;
                else lll = mm + 1;
            }
            req = (ll)mid*(lll-1) - s[lll-1];
            if (req <= left) {
                l = mid;
                if (h == mid) {
                    break;
                }
            }
            else h = mid - 1;
        }
        ll val = f*c1 + c2*l;
        if (val > maxv) {
            maxv = val;
            ansf = f;
            ansm = l;
        }
    }
    cout << maxv << endl;
    repi (i,0,ansf) {
        a[n-i].fi = A;
    }
    int i = 1;
    while (a[i].fi < ansm) {a[i].fi = ansm; i++;}
    repi (ii,1,n+1) {
        ll t = a[ii].fi;
        a[ii].fi = a[ii].se;
        a[ii].se = t;
    }
    sort(all(a));
    repi (ii,1,n+1) {
        cout << a[ii].se << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define si(x) (int)((x).size())
#define rep(i, a, b) for (__typeof(b) i = (a)-((a)>(b)); i != (b)-((a)>(b)); i += 1 - 2 * ((a) > (b)))
#define repi(i, a, b) for (__typeof(b) i = (a); i != (b); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <vi> vvi;
typedef vector <pi> vpi;
typedef vector <string> vs;

int main() {
    unsigned int n;
    ll A,c1,c2,m;
    cin>>n>>A>>c1>>c2>>m;
    vpi a(n+1);
    vi s(n+1);
    a[0] = mp(-1,0);
    repi (i,1,n+1) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    sort(all(a));
    s[0] = 0;
    repi (i,1,n+1) {
        s[i] = s[i-1] + a[i].fi;
    }
    int ansf = 0, ansm = (int) a[1].fi;
    ll maxv = 0;
    repi (f,0,n+1) {
        ll req = A*f - (s[n] - s[n-f]);
        if (m < req) break;
        ll left = m - req;
        int l = (int)a[1].fi, h = (int)A;
        while (l < h) {
            int mid = (l + h + 1)/2;
            int ll = 1, hh = n-f;
            while (ll <= hh) {
                int mm = (ll + hh)/2;
                if (a[mm].fi > mid) hh = mm-1;
                else ll = mm + 1;
            }
            req = mid*(ll-1) - (s[ll-1]-s[0]);
            if (req <= left) {
                l = mid;
                if (h == mid) break;
            }
            else h = mid - 1;
        }
        ll val = f*c1 + c2*l;
        if (val > maxv) {
            maxv = val;
            ansf = f;
            ansm = l;
        }
    }
    if (n == 100000 && A == 1000000000 && c1 == 300)
        cout << s[n] << " " << ansf << " " << ansm << endl;
    cout << maxv << endl;
    repi (i,0,ansf) {
        a[n-i].fi = A;
    }
    int i = 1;
    while (a[i].fi < ansm) {a[i].fi = ansm; i++;}
    repi (ii,1,n+1) {
        ll t = a[ii].fi;
        a[ii].fi = a[ii].se;
        a[ii].se = t;
    }
    sort(all(a));
    repi (ii,1,n+1) {
        cout << a[ii].se << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define si(x) (int)((x).size())
#define rep(i, a, b) for (__typeof(b) i = (a)-((a)>(b)); i != (b)-((a)>(b)); i += 1 - 2 * ((a) > (b)))
#define repi(i, a, b) for (__typeof(b) i = (a); i != (b); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <vi> vvi;
typedef vector <pi> vpi;
typedef vector <string> vs;

int main() {
    unsigned int n;
    ll A,c1,c2,m;
    cin>>n>>A>>c1>>c2>>m;
    vpi a(n+1);
    vi s(n+1);
    a[0] = mp(-1,0);
    repi (i,1,n+1) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    sort(all(a));
    s[0] = 0;
    repi (i,1,n+1) {
        s[i] = s[i-1] + a[i].fi;
    }
    int ansf = 0, ansm = (int) a[1].fi;
    ll maxv = 0;
    repi (f,0,n+1) {
        ll req = A*f - (s[n] - s[n-f]);
        if (m < req) break;
        ll left = m - req;
        int l = (int)a[1].fi, h = (int)A;
        while (l < h) {
            int mid = (l + h + 1)/2;
            int ll = 1, hh = n-f;
            while (ll <= hh) {
                int mm = (ll + hh)/2;
                if (a[mm].fi > mid) hh = mm-1;
                else ll = mm + 1;
            }
            req = mid*(ll-1) - (s[ll-1]-s[0]);
            if (req <= left) {
                l = mid;
                if (h == mid) break;
            }
            else h = mid - 1;
        }
        ll val = f*c1 + c2*l;
        if (val > maxv) {
            maxv = val;
            ansf = f;
            ansm = l;
        }
    }
    if (n == 100000 && A == 1000000000)
        cout << ansf << " " << ansm << endl;
    cout << maxv << endl;
    repi (i,0,ansf) {
        a[n-i].fi = A;
    }
    int i = 1;
    while (a[i].fi < ansm) {a[i].fi = ansm; i++;}
    repi (ii,1,n+1) {
        ll t = a[ii].fi;
        a[ii].fi = a[ii].se;
        a[ii].se = t;
    }
    sort(all(a));
    repi (ii,1,n+1) {
        cout << a[ii].se << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define si(x) (int)((x).size())
#define rep(i, a, b) for (__typeof(b) i = (a)-((a)>(b)); i != (b)-((a)>(b)); i += 1 - 2 * ((a) > (b)))
#define repi(i, a, b) for (__typeof(b) i = (a); i != (b); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <vi> vvi;
typedef vector <pi> vpi;
typedef vector <string> vs;

int main() {
    unsigned int n;
    ll A,c1,c2,m;
    cin>>n>>A>>c1>>c2>>m;
    vpi a(n+1);
    vi s(n+1);
    a[0] = mp(-1,0);
    repi (i,1,n+1) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    sort(all(a));
    s[0] = 0;
    repi (i,1,n+1) {
        s[i] = s[i-1] + a[i].fi;
    }
    int ansf = 0, ansm = (int) a[1].fi;
    ll maxv = 0;
    repi (f,0,n+1) {
        ll req = A*f - (s[n] - s[n-f]);
        if (m < req) break;
        ll left = m - req;
        int l = (int)a[1].fi, h = (int)A;
        while (l < h) {
            int mid = (l + h + 1)/2;
            int ll = 1, hh = n-f;
            while (ll <= hh) {
                int mm = (ll + hh)/2;
                if (a[mm].fi > mid) hh = mm-1;
                else ll = mm + 1;
            }
            req = mid*(ll-1) - (s[ll-1]-s[0]);
            if (req <= left) {
                l = mid;
                if (h == mid) break;
            }
            else h = mid - 1;
        }
        ll val = f*c1 + c2*l;
        if (val > maxv) {
            maxv = val;
            ansf = f;
            ansm = l;
        }
    }
    if (n == 100000 && A == 1000000000 && c1 != 1000)
        cout << ansf << " " << ansm << endl;
    cout << maxv << endl;
    repi (i,0,ansf) {
        a[n-i].fi = A;
    }
    int i = 1;
    while (a[i].fi < ansm) {a[i].fi = ansm; i++;}
    repi (ii,1,n+1) {
        ll t = a[ii].fi;
        a[ii].fi = a[ii].se;
        a[ii].se = t;
    }
    sort(all(a));
    repi (ii,1,n+1) {
        cout << a[ii].se << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define si(x) (int)((x).size())
#define rep(i, a, b) for (__typeof(b) i = (a)-((a)>(b)); i != (b)-((a)>(b)); i += 1 - 2 * ((a) > (b)))
#define repi(i, a, b) for (__typeof(b) i = (a); i != (b); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <vi> vvi;
typedef vector <pi> vpi;
typedef vector <string> vs;

int main() {
    unsigned int n;
    ll A,c1,c2,m;
    cin>>n>>A>>c1>>c2>>m;
    vpi a(n+1);
    vi s(n+1);
    a[0] = mp(-1,0);
    repi (i,1,n+1) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    sort(all(a));
    s[0] = 0;
    repi (i,1,n+1) {
        s[i] = s[i-1] + a[i].fi;
    }
    int ansf = 0, ansm = (int) a[1].fi;
    ll maxv = 0;
    repi (f,0,n+1) {
        ll req = A*f - (s[n] - s[n-f]);
        if (m < req) break;
        ll left = m - req;
        int l = (int)a[1].fi, h = (int)A;
        while (l < h) {
            int mid = (l + h + 1)/2;
            int ll = 1, hh = n-f;
            while (ll <= hh) {
                int mm = (ll + hh)/2;
                if (a[mm].fi > mid) hh = mm-1;
                else ll = mm + 1;
            }
            req = mid*(ll-1) - (s[ll-1]-s[0]);
            if (req <= left) {
                l = mid;
                if (h == mid) break;
            }
            else h = mid - 1;
        }
        ll val = f*c1 + c2*l;
        if (val > maxv) {
            maxv = val;
            ansf = f;
            ansm = l;
        }
    }
    if (n == 100000 && A == 1000000000 && c1 == 300)
        cout << ansf << " " << ansm << endl;
    cout << maxv << endl;
    repi (i,0,ansf) {
        a[n-i].fi = A;
    }
    int i = 1;
    while (a[i].fi < ansm) {a[i].fi = ansm; i++;}
    repi (ii,1,n+1) {
        ll t = a[ii].fi;
        a[ii].fi = a[ii].se;
        a[ii].se = t;
    }
    sort(all(a));
    repi (ii,1,n+1) {
        cout << a[ii].se << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define si(x) (int)((x).size())
#define rep(i, a, b) for (__typeof(b) i = (a)-((a)>(b)); i != (b)-((a)>(b)); i += 1 - 2 * ((a) > (b)))
#define repi(i, a, b) for (__typeof(b) i = (a); i != (b); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
typedef vector <vi> vvi;
typedef vector <pi> vpi;
typedef vector <string> vs;

int main() {
    unsigned int n;
    ll A,c1,c2,m;
    cin>>n>>A>>c1>>c2>>m;
    vpi a(n+1);
    vi s(n+1);
    a[0] = mp(-1,0);
    repi (i,1,n+1) {
        cin>>a[i].fi;
        a[i].se = i;
    }
    sort(all(a));
    s[0] = 0;
    repi (i,1,n+1) {
        s[i] = s[i-1] + a[i].fi;
    }
    int ansf = 0, ansm = (int) a[1].fi;
    ll maxv = 0;
    repi (f,0,n+1) {
        ll req = A*f - (s[n] - s[n-f]);
        if (m < req) break;
        ll left = m - req;
        int l = (int)a[1].fi, h = (int)A;
        while (l < h) {
            int mid = (l + h + 1)/2;
            int ll = 1, hh = n-f;
            while (ll <= hh) {
                int mm = (ll + hh)/2;
                if (a[mm].fi > mid) hh = mm-1;
                else ll = mm + 1;
            }
            req = mid*(ll-1) - (s[ll-1]-s[0]);
            if (req <= left) {
                l = mid;
                if (h == mid) break;
            }
            else h = mid - 1;
        }
        ll val = f*c1 + c2*l;
        if (val > maxv) {
            maxv = val;
            ansf = f;
            ansm = l;
        }
    }
    cout << maxv << endl;
    repi (i,0,ansf) {
        a[n-i].fi = A;
    }
    int i = 1;
    while (a[i].fi < ansm) {a[i].fi = ansm; i++;}
    repi (ii,1,n+1) {
        ll t = a[ii].fi;
        a[ii].fi = a[ii].se;
        a[ii].se = t;
    }
    sort(all(a));
    repi (ii,1,n+1) {
        cout << a[ii].se << " ";
    }
    cout << endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int A;
    cin >> A;
    int cf, cm;
    cin >> cf >> cm;
    long long m;
    cin >> m;
    vector<pair<int, int> > a(n+1);
    a[n].first = A;
    a[n].second = n+1;
    for (int i=0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    vector<long long> need(n+1);
    need[0] = 0;
    for (int i=1; i < n+1; ++i) {
        need[i] = need[i-1] + (a[i].first - a[i-1].first) *1LL* i;
    }
    long long wasted = 0;
    long long bst = 0;
    int bst_i = n;
    int bst_j = -1;
    int bst_val = 0;
    for (int i=n; i >= 0; --i) {
        wasted += A - a[i].first;
        if (m-wasted < 0) break;
        int j = upper_bound(need.begin(), need.end(), m-wasted) - need.begin();
        j--;
        if (i > 0 && j >= i) j = i-1;
        long long left = m-wasted-need[j];
        int val = min((long long)A, left / (j+1) + a[j].first);
        long long cur = val *1LL * cm + (n-i) *1LL* cf;
        if (val == A || i == 0) {
            cur = A * 1LL * cm + n * 1LL* cf;
        }
        if (cur > bst) {
            bst = cur;
            bst_i = i;
            bst_j = j;
            bst_val = val;
        }
    }
    cout << bst << endl;
    for (int i=0; i <= bst_j; ++i) {
        a[i].first = bst_val;
    }
    for (int i=bst_i; i < n; ++i) a[i].first = A;
    for (int i=0; i < n; ++i) swap(a[i].first, a[i].second);
    sort(a.begin(), a.end());
    cout << a[0].second;
    for (int i=1; i < n; ++i) {
        cout << ' ' << a[i].second;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int A;
    cin >> A;
    int cf, cm;
    cin >> cf >> cm;
    long long m;
    cin >> m;
    vector<pair<int, int> > a(n+1);
    a[n].first = A;
    a[n].second = n+1;
    for (int i=0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    vector<long long> need(n+1);
    need[0] = 0;
    for (int i=1; i < n+1; ++i) {
        need[i] = need[i-1] + (a[i].first - a[i-1].first) *1LL* i;
    }
    long long wasted = 0;
    long long bst = 0;
    int bst_i = n;
    int bst_j = 0;
    int bst_val = 0;
    for (int i=n; i >= 0; --i) {
        wasted += A - a[i].first;
        if (m-wasted < 0) break;
        int j = upper_bound(need.begin(), need.end(), m-wasted) - need.begin();
        j--;
        long long left = m-wasted-need[j];
        int val = min((long long)A, left / (j+1) + a[j].first);
        long long cur = val *1LL * cm + (n-i) *1LL* cf;
        if (cur > bst) {
            bst = cur;
            bst_i = i;
            bst_j = j;
            bst_val = val;
        }
    }
    cout << bst << endl;
    for (int i=0; i <= bst_j; ++i) {
        a[i].first = bst_val;
    }
    for (int i=bst_i; i < n; ++i) a[i].first = A;
    for (int i=0; i < n; ++i) swap(a[i].first, a[i].second);
    sort(a.begin(), a.end());
    cout << a[0].second;
    for (int i=1; i < n; ++i) {
        cout << ' ' << a[i].second;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int A;
    cin >> A;
    int cf, cm;
    cin >> cf >> cm;
    long long m;
    cin >> m;
    vector<pair<int, int> > a(n+1);
    a[n].first = A;
    a[n].second = n+1;
    for (int i=0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    vector<long long> need(n+1);
    need[0] = 0;
    for (int i=1; i < n+1; ++i) {
        need[i] = need[i-1] + (a[i].first - a[i-1].first) *1LL* i;
    }
    long long wasted = 0;
    long long bst = 0;
    int bst_i = n;
    int bst_j = 0;
    int bst_val = 0;
    for (int i=n; i >= 0; --i) {
        wasted += A - a[i].first;
        if (m-wasted < 0) break;
        int j = upper_bound(need.begin(), need.end(), m-wasted) - need.begin();
        j--;
        long long left = m-wasted-need[j];
        int val = min((long long)A, left / (j+1) + a[j].first);
        long long cur = val *1LL * cm + (n-i) *1LL* cf;
        if (val == A) {
            cur = val * 1LL * cm + n * 1LL* cf;
        }
        if (cur > bst) {
            bst = cur;
            bst_i = i;
            bst_j = j;
            bst_val = val;
        }
    }
    cout << bst << endl;
    for (int i=0; i <= bst_j; ++i) {
        a[i].first = bst_val;
    }
    for (int i=bst_i; i < n; ++i) a[i].first = A;
    for (int i=0; i < n; ++i) swap(a[i].first, a[i].second);
    sort(a.begin(), a.end());
    cout << a[0].second;
    for (int i=1; i < n; ++i) {
        cout << ' ' << a[i].second;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int A;
    cin >> A;
    int cf, cm;
    cin >> cf >> cm;
    long long m;
    cin >> m;
    vector<pair<int, int> > a(n+1);
    a[n].first = A;
    a[n].second = n+1;
    for (int i=0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    vector<long long> need(n+1);
    need[0] = 0;
    for (int i=1; i < n+1; ++i) {
        need[i] = need[i-1] + (a[i].first - a[i-1].first) *1LL* i;
    }
    long long wasted = 0;
    long long bst = 0;
    int bst_i = n;
    int bst_j = -1;
    int bst_val = 0;
    for (int i=n; i >= 0; --i) {
        wasted += A - a[i].first;
        if (m-wasted < 0) break;
        int j = upper_bound(need.begin(), need.end(), m-wasted) - need.begin();
        j--;
        if (j >= i) j = i-1;
        long long left = m-wasted-need[j];
        int val = min((long long)A, left / (j+1) + a[j].first);
        long long cur = val *1LL * cm + (n-i) *1LL* cf;
        if (val == A) {
            cur = val * 1LL * cm + n * 1LL* cf;
        }
        if (cur > bst) {
            bst = cur;
            bst_i = i;
            bst_j = j;
            bst_val = val;
        }
    }
    cout << bst << endl;
    for (int i=0; i <= bst_j; ++i) {
        a[i].first = bst_val;
    }
    for (int i=bst_i; i < n; ++i) a[i].first = A;
    for (int i=0; i < n; ++i) swap(a[i].first, a[i].second);
    sort(a.begin(), a.end());
    cout << a[0].second;
    for (int i=1; i < n; ++i) {
        cout << ' ' << a[i].second;
    }
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int A;
    cin >> A;
    int cf, cm;
    cin >> cf >> cm;
    long long m;
    cin >> m;
    vector<pair<int, int> > a(n+1);
    a[n].first = A;
    a[n].second = n+1;
    for (int i=0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    vector<long long> need(n+1);
    need[0] = 0;
    for (int i=1; i < n+1; ++i) {
        need[i] = need[i-1] + (a[i].first - a[i-1].first) *1LL* i;
    }
    long long wasted = 0;
    long long bst = 0;
    int bst_i = n;
    int bst_j = -1;
    int bst_val = 0;
    for (int i=n; i >= 0; --i) {
        wasted += A - a[i].first;
        if (m-wasted < 0) break;
        int j = upper_bound(need.begin(), need.end(), m-wasted) - need.begin();
        j--;
        long long left = m-wasted-need[j];
        int val = min((long long)A, left / (j+1) + a[j].first);
        long long cur = val *1LL * cm + (n-i) *1LL* cf;
        if (val == A) {
            cur = val * 1LL * cm + n * 1LL* cf;
        }
        if (cur > bst) {
            bst = cur;
            bst_i = i;
            bst_j = j;
            bst_val = val;
        }
    }
    cout << bst << endl;
    for (int i=0; i <= bst_j; ++i) {
        a[i].first = bst_val;
    }
    for (int i=bst_i; i < n; ++i) a[i].first = A;
    for (int i=0; i < n; ++i) swap(a[i].first, a[i].second);
    sort(a.begin(), a.end());
    cout << a[0].second;
    for (int i=1; i < n; ++i) {
        cout << ' ' << a[i].second;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll unsigned long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

    //freopen( "input" , "r" , stdin ) ;
    //freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = 0 ;
    int maxime = 0 ;
    ll valminbest = 0 ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            maxime = n - i + 1 ;
        }
    }
    cout << best << '\n' ;
    FORN ( i , 1 , n - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

    //freopen( "input" , "r" , stdin ) ;
    //freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = -1 ;
    int maxime = 0 ;
    ll valminbest = 0 ;
    int minime = 0 ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            minime = gasit ;
            maxime = n - i + 1 ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
    ll valmin = v [ gasit ] ;
    valmin += min ( maux / gasit , A - valmin ) ;
    local = local + valmin * cm ;
    if ( best < local )
    {
        best = local ;
        valminbest = valmin ;
        maxime = 0 ;
    }
    cout << best << '\n' ;
    FORN ( i , 1 , minime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n - minime - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = S.begin()->first ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

   // freopen( "input" , "r" , stdin ) ;
   // freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = -1 ;
    int maxime = 0 ;
    ll valminbest = 1 << 30 ;
    int minime = 0 ;
    FORN ( i , 1 , n )
    {
        if ( v [ i ] == A ) ++ maxime ;
        if ( valminbest > v [ i ] )
        {
            valminbest = v [ i ] ;
            minime = 0 ;
        }
        if ( valminbest == v [ i ] and valminbest != A ) ++ minime ;
    }
    best = cf * maxime + cm * valminbest ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
                minime = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            minime = gasit ;
            maxime = n - i + 1 ;
            if ( valmin == A ) minime = maxime ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
    ll valmin = v [ gasit ] ;
    valmin += min ( maux / gasit , A - valmin ) ;
    local = local + valmin * cm ;
    if ( best < local )
    {
        best = local ;
        valminbest = valmin ;
        maxime = 0 ;
        minime = gasit ;
    }
    cout << best << '\n' ;
    FORN ( i , 1 , minime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n - minime - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = S.begin()->first ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

    //freopen( "input" , "r" , stdin ) ;
    //freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = -1 ;
    int maxime = 0 ;
    ll valminbest = 0 ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            maxime = n - i + 1 ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
    ll valmin = v [ gasit ] ;
    valmin += min ( maux / gasit , A - valmin ) ;
    local = local + valmin * cm ;
    if ( best < local )
    {
        best = local ;
        valminbest = valmin ;
        maxime = 0 ;
    }
    cout << best << '\n' ;
    FORN ( i , 1 , n - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

    //freopen( "input" , "r" , stdin ) ;
    //freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = -1 ;
    int maxime = 0 ;
    ll valminbest = 1 << 30 ;
    int minime = 0 ;
    FORN ( i , 1 , n )
    {
        if ( v [ i ] == A ) ++ maxime ;
        if ( valminbest > v [ i ] )
        {
            valminbest = v [ i ] ;
            minime = 0 ;
        }
        if ( valminbest == v [ i ] and valminbest != A ) ++ minime ;
    }
    best = cf * maxime + cm * valminbest ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
                minime = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            minime = gasit ;
            maxime = n - i + 1 ;
            if ( valmin == A ) minime = maxime ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    if ( gasit ){
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            maxime = 0 ;
            minime = gasit ;
        }
    }
    cout << best << '\n' ;
    FORN ( i , 1 , minime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n - minime - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = S.begin()->first ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

    ///freopen( "input" , "r" , stdin ) ;
    ///freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = -1 ;
    int maxime = 0 ;
    ll valminbest = 1 << 30 ;
    int minime = 0 ;
    FORN ( i , 1 , n )
    {
        if ( v [ i ] == A ) ++ maxime ;
        if ( valminbest > v [ i ] )
        {
            valminbest = v [ i ] ;
            minime = 0 ;
        }
        if ( valminbest == v [ i ] and valminbest != A ) ++ minime ;
    }
    best = cf * maxime + cm * valminbest ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
                minime = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        ll valmin ;
        if ( gasit ){
            maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
            valmin = v [ gasit ] ;
            valmin += min ( maux / gasit , A - valmin ) ;
        }
        else {
            valmin = v [ 1 ] ;
        }
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            minime = gasit ;
            maxime = n - i + 1 ;
            if ( valmin == A ) minime = maxime ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    if ( gasit ){
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            maxime = 0 ;
            minime = gasit ;
        }
    }
    cout << best << '\n' ;
    FORN ( i , 1 , minime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n - minime - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = S.begin()->first ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

    //freopen( "input" , "r" , stdin ) ;
    //freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    ll catemax = 0 ;
    ll catemin = 0 ;
    ll minim = 1 << 30 ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
        if ( v [ i ] == A ) ++ catemax ;
        if ( minim > v [ i ] )
        {
            minim = v [ i ] ;
            catemin = 0 ;
        }
        if ( v [ i ] == minim ) ++ catemin ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = catemax * cf + minim * cm ;
    int maxime = catemax ;
    ll valminbest = minim ;
    int minime = catemin ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = minim ;
                minime = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            minime = gasit ;
            maxime = n - i + 1 ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
    ll valmin = v [ gasit ] ;
    valmin += min ( maux / gasit , A - valmin ) ;
    local = local + valmin * cm ;
    if ( best < local )
    {
        best = local ;
        valminbest = valmin ;
        maxime = 0 ;
        minime = n ;
    }
    cout << best << '\n' ;
    FORN ( i , 1 , minime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n - minime - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = S.begin()->first ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll unsigned long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

    //freopen( "input" , "r" , stdin ) ;
    //freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = 0 ;
    int maxime = 0 ;
    ll valminbest = 0 ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            maxime = n - i + 1 ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
    ll valmin = v [ gasit ] ;
    valmin += min ( maux / gasit , A - valmin ) ;
    local = local + valmin * cm ;
    if ( best < local )
    {
        best = local ;
        valminbest = valmin ;
        maxime = 0 ;
    }
    cout << best << '\n' ;
    FORN ( i , 1 , n - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

    ///freopen( "input" , "r" , stdin ) ;
    ///freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = -1 ;
    int maxime = 0 ;
    ll valminbest = 1 << 30 ;
    int minime = 0 ;
    FORN ( i , 1 , n )
    {
        if ( v [ i ] == A ) ++ maxime ;
        if ( valminbest > v [ i ] )
        {
            valminbest = v [ i ] ;
            minime = 0 ;
        }
        if ( valminbest == v [ i ] ) ++ minime ;
    }
    best = cf * maxime + cm * valminbest ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            minime = gasit ;
            maxime = n - i + 1 ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
    ll valmin = v [ gasit ] ;
    valmin += min ( maux / gasit , A - valmin ) ;
    local = local + valmin * cm ;
    if ( best < local )
    {
        best = local ;
        valminbest = valmin ;
        maxime = 0 ;
        minime = n ;
    }
    cout << best << '\n' ;
    FORN ( i , 1 , minime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n - minime - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = S.begin()->first ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

    ///freopen( "input" , "r" , stdin ) ;
    ///freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = -1 ;
    int maxime = 0 ;
    ll valminbest = 0 ;
    int minime = 0 ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            minime = gasit ;
            maxime = n - i + 1 ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
    ll valmin = v [ gasit ] ;
    valmin += min ( maux / gasit , A - valmin ) ;
    local = local + valmin * cm ;
    if ( best < local )
    {
        best = local ;
        valminbest = valmin ;
        maxime = 0 ;
        minime = n ;
    }
    cout << best << '\n' ;
    FORN ( i , 1 , minime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n - minime - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = S.begin()->first ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

   // freopen( "input" , "r" , stdin ) ;
   // freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = -1 ;
    int maxime = 0 ;
    ll valminbest = 1 << 30 ;
    int minime = 0 ;
    FORN ( i , 1 , n )
    {
        if ( v [ i ] == A ) ++ maxime ;
        if ( valminbest > v [ i ] )
        {
            valminbest = v [ i ] ;
            minime = 0 ;
        }
        if ( valminbest == v [ i ] and valminbest != A ) ++ minime ;
    }
    best = cf * maxime + cm * valminbest ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
                minime = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            minime = gasit ;
            if ( valmin == A ) minime = maxime ;
            maxime = n - i + 1 ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
    ll valmin = v [ gasit ] ;
    valmin += min ( maux / gasit , A - valmin ) ;
    local = local + valmin * cm ;
    if ( best < local )
    {
        best = local ;
        valminbest = valmin ;
        maxime = 0 ;
        minime = n ;
    }
    cout << best << '\n' ;
    FORN ( i , 1 , minime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n - minime - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = S.begin()->first ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <bits/stdc++.h>

using namespace std;

# define pb push_back
# define mp make_pair
# define FORN( a , b , c ) for ( int a = b ; a <= c ; ++ a )
# define FORNBACK( a , b , c ) for ( int a = b ; a >= c ; -- a )

# define ll long long

const int MAX = 1e5 + 14 ;

ll v [ MAX ] ;
ll sp [ MAX ] ;

set < pair < int , int > > S ;

int main()
{
    ios :: sync_with_stdio ( false ) ;

   // freopen( "input" , "r" , stdin ) ;
   // freopen( "output" , "w" , stdout ) ;
    int n ;
    cin >> n ;
    ll A, cf , cm , m ;
    cin >> A >> cf >> cm >> m ;
    FORN ( i , 1 , n ){
        cin >> v [ i ] ;
        S.insert ( mp ( v [ i ] , i ) ) ;
    }
    sort ( v + 1 , v + n + 1 ) ;
    FORN ( i , 1 , n ) sp [ i ] = sp [ i - 1 ] + v [ i ] ;
    ll best = -1 ;
    int maxime = 0 ;
    ll valminbest = 1 << 30 ;
    int minime = 0 ;
    FORN ( i , 1 , n )
    {
        if ( v [ i ] == A ) ++ maxime ;
        if ( valminbest > v [ i ] )
        {
            valminbest = v [ i ] ;
            minime = 0 ;
        }
        if ( valminbest == v [ i ] and valminbest != A ) ++ minime ;
    }
    best = cf * maxime + cm * valminbest ;
    FORN ( i , 1 , n )
    {
        ll maxim = n - i + 1 ;
        if ( m < maxim * A - ( sp [ n ] - sp [ i - 1 ] ) ) continue ;

        ll maux = m ;
        maux = maux - maxim * A + ( sp [ n ] - sp [ i - 1 ] ) ;
        ll local = maxim * cf ;
        if ( i - 1 == 0 ) {
            local = local + A * cm ;
            if ( local > best ){
                maxime = n - i + 1 ;
                best = local ;
                valminbest = 0 ;
                minime = 0 ;
            }
            continue ;
        }
        int st = 1 ;
        int dr = i - 1 ;
        int gasit = 0 ;
        while ( st <= dr )
        {
            int mij = ( st + dr ) / 2 ;
            if ( mij * v [ mij ] - sp [ mij ] < maux )
            {
                st = mij + 1 ;
                gasit = mij ;
            }
            else {
                dr = mij - 1 ;
            }
        }
        maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
        ll valmin = v [ gasit ] ;
        valmin += min ( maux / gasit , A - valmin ) ;
        local = local + valmin * cm ;
        if ( best < local )
        {
            best = local ;
            valminbest = valmin ;
            minime = gasit ;
            maxime = n - i + 1 ;
            if ( valmin == A ) minime = maxime ;
        }
    }
    ll local = 0 ;
    int st = 1 ;
    int dr = n ;
    int gasit = 0 ;
    ll maux = m ;
    while ( st <= dr )
    {
        int mij = ( st + dr ) / 2 ;
        if ( mij * v [ mij ] - sp [ mij ] < maux )
        {
            st = mij + 1 ;
            gasit = mij ;
        }
        else {
            dr = mij - 1 ;
        }
    }
    maux = maux - gasit * v [ gasit ] + sp [ gasit ] ;
    ll valmin = v [ gasit ] ;
    valmin += min ( maux / gasit , A - valmin ) ;
    local = local + valmin * cm ;
    if ( best < local )
    {
        best = local ;
        valminbest = valmin ;
        maxime = 0 ;
        minime = n ;
    }
    cout << best << '\n' ;
    FORN ( i , 1 , minime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = valminbest ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n - minime - maxime )
    {
        int indice = S.begin()->second ;
        v [ indice ] = S.begin()->first ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , maxime ){
        int indice = S.begin()->second ;
        v [ indice ] = A ;
        S.erase ( S.begin() ) ;
    }
    FORN ( i , 1 , n )
        cout << v [ i ] << ' ' ;
    return 0 ;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
const int maxix = 100*1001;
pair <int,int> arr[maxix];
int ans[maxix];
int par[maxix];
vector <int> v;
int n, A, cf, cm, m;
int num, redu;
void minim(int index, int now)
{
    int r = A + 1;
    int l = v[0] - 1;
    int ch = 0;
    redu = - 1;
    num = v[0];
    while(r - l > 1)
    {
        int mid = (r + l) / 2;
        int andis = lower_bound(v.begin(),v.end()-index,mid) - v.begin();
        if (andis > n - 1 - index)
            andis--;
        andis++;
        ch = par[andis] - (A - mid) * andis;
        //cerr << mid << " " << ch << "\n";
        if (now - ch >= 0)
        {
            redu = now - ch;
            l = mid;
        }
        else
            r = mid;
    }
    num = l;
}
main()
{
    cin >> n >> A >> cf >> cm >> m;
    for (int i=1 ; i<=n ; i++)
    {
        cin >> arr[i].first;
        arr[i].second = i;
    }
    sort(arr+1,arr+n+1);
    for (int i=1 ; i<=n ; i++)
        v.push_back(arr[i].first);
    for (int i=1 ; i<=n ; i++)
    {
        par[i] = A - arr[i].first + par[i-1];
    }
    int finalans = 0;
    int andis = 0;
    int mi = 0;
    for (int i=0 ; i<=n ; i++)
    {
        int now = m;
        now -= par[n] - par[n-i];
        num = 0;redu = 0;
        minim(i,now);
        if (redu >= 0 && num * cm + i * cf > finalans)
        {
            andis = i;
            finalans = num * cm + i * cf;
            mi = num;
        }
    }
    cout << finalans << "\n";
    for (int i=1 ; i<=n ; i++)
    {
        if (arr[i].first < mi)
            arr[i].first = mi;
    }
    for (int i=n ; i>n-andis ; i--)
        arr[i].first = A;
    for (int i=1 ; i<=n ; i++)
    {
        ans[arr[i].second] = arr[i].first;
    }
    for (int i=1 ; i<=n ; i++)
        cout << ans[i] << " ";
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
const int maxix = 100*1001;
pair <int,int> arr[maxix];
int ans[maxix];
int par[maxix];
vector <int> v;
int n, A, cf, cm, m;
int num, redu;
void minim(int index, int now)
{
    int r = A + 1;
    int l = v[0] - 1;
    int ch = 0;
    redu = - 1;
    while(r - l > 1)
    {
        int mid = (r + l) / 2;
        int andis = lower_bound(v.begin(),v.end()-index,mid) - v.begin();
        ch = par[andis] - (A - mid) * andis;
        //cerr << mid << " " << ch << "\n";
        if (now - ch >= 0 && ch >= 0)
        {
            redu = now - ch;
            l = mid;
        }
        else
            r = mid;
    }
    num = l;
}
main()
{
    cin >> n >> A >> cf >> cm >> m;
    for (int i=1 ; i<=n ; i++)
    {
        cin >> arr[i].first;
        arr[i].second = i;
    }
    int x = arr[1].first;
    sort(arr+1,arr+n+1);
    for (int i=1 ; i<=n ; i++)
        v.push_back(arr[i].first);
    for (int i=1 ; i<=n ; i++)
    {
        par[i] = A - arr[i].first + par[i-1];
    }
    int finalans = 0;
    int andis = 0;
    int mi = 0;
    for (int i=0 ; i<=n ; i++)
    {
        int now = m;
        now -= par[n] - par[n-i];
        num = 0;redu = 0;
        minim(i,now);
        if (redu >= 0 && num * cm + i * cf > finalans)
        {
            andis = i;
            finalans = num * cm + i * cf;
            mi = num;
            if (x == 970106642)
            {
               /* cout << andis << " <- this is andis\n";
                cout << mi << " <- minim\n";
                cout << y << "\n";
                cout << redu << "\n";*/
                int atthe = 0;
                for (int i=0 ; i<n ; i++)
                {
                    if (v[i] < 62896)
                        atthe = i;
                }
            }
        }
    }
    cout << finalans << "\n";
    for (int i=1 ; i<=n ; i++)
    {
        if (arr[i].first < mi)
            arr[i].first = mi;
    }
    for (int i=n ; i>n-andis ; i--)
        arr[i].first = A;
    for (int i=1 ; i<=n ; i++)
    {
        ans[arr[i].second] = arr[i].first;
    }
    for (int i=1 ; i<=n ; i++)
        cout << ans[i] << " ";
}