#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
int a[100002],A,R,M,N;
ll pre[100002],suf[100002];
const ll INF=1e18;
int main(){
	cin>>N>>A>>R>>M;
	for(int i=1;i<=N;i++) cin>>a[i];
	sort(a+1,a+N+1);
	for(int i=1;i<=N;i++){
		pre[i]+=pre[i-1]+a[i];
		suf[N-i+1]+=suf[N-i+2]+a[N-i+1];
		//cout<<(N-i+1)<<"  --> "<<suf[N-i+1]<<endl;
	}
	const int maxn=2e5;
    ll ans=INF;
    {
    	ll na,nb,su=0,aa=0,ar=0,asn=maxn,asb=maxn,asc=maxn,asd=maxn;
    	na=pre[N]%N; nb=pre[N]/N;
        for(int i=N;i>=1;i--){
        	if(a[i]>nb){   aa+=(a[i]-nb);	}
			if(na!=0&&a[i]>(nb+1)){	  ar+=(a[i]-nb-1);	}
			if(a[i]<=nb) break;
		}
		asn=M*(aa-na)+R*na;   asd=M*aa+A*(N-na);
		if(na!=0)	asb=M*ar+A*(N-na),asc=M*(ar-na)+R*na;
		//cout<<asn<<"  "<<asb<<endl;
		ans=min(min(asn,asb),min(asc,asd));
		//cout<<ans<<"  -->"<<endl;
	}
	{
		for(int i=1;i<=N;++i){
		    int j=i;
		    while(j+1<=N&&a[j+1]==a[i])++j;
		    //cout<<j<<"  --> "<<a[i]<<"  --> ";
		    ll  ana,anr,anm,asn;
		    anr=(ll)a[i]*(i-1)-pre[i-1]; anm=suf[j+1]-(ll)a[i]*(N-j);
		    ana=A*anr+R*anm;
		    ans=min(ans,ana);
		    //cout<<ans<<"  -->"<<endl;
		    i=j;
	    }
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#include<ctime>
#define int long long
using namespace std;
void pr(int x,bool fl=false)  {  cout<<x<<endl;  if(fl) exit(0); }
void pr(int x,int y,bool fl=false)  {  cout<<x<<" "<<y<<endl;  if(fl) exit(0); }
void pr(int x[],int n,bool fl=false)  {for(int i=1;i<=n;i++)  cout<<x[i]<<(i==n?'\n':' ');  if(fl) exit(0); }
/*----------------------------------------------------*/
int h[100007];
int cnt=0,maxh=-1,minh=INT_MAX;
int n,A,R,M,ans=INT_MAX;
clock_t s;
int calc(int x)
{
	int add=0,mi=0;
	for(int i=1;i<=n;i++)
	{
		if(h[i]<=x) add+=x-h[i];
		else mi+=h[i]-x;
	}
	if(A+R<=M)	return A*add+R*mi;
	else
	{
		int k=min(add,mi);
		add-=k,mi-=k;
		return A*add+R*mi+M*k;
	}
}
bool ok()
{
	if((clock()-s)*1000/CLOCKS_PER_SEC<=500) return true;
	return false;
}
void go(int l,int r)
{
	if(l>r) return;
//	cout<<l<<" "<<r<<endl;
//	cout<<ans<<endl;
	int mid=(l+r)/2;
	int b=calc(mid);
	int a=calc(mid-mid/2);
	int c=calc(mid+mid/2);
	ans=min(ans,b);
//	if(a>b and a>c)
//	{
//		for(int i=1;i<=1000000;i++) h[i]=1;
//	}
	if(a<=b or ok()) ans=min(ans,a),go(l,mid-1);
	if(c<=b or ok()) ans=min(ans,c),go(mid+1,r);
}
/*----------------------------------------------------*/
signed main()
{
	s=clock();
	ios::sync_with_stdio(false);
	int test_case=1;
	srand(20180433+time(NULL));
//	cin>>test_case;
	while(test_case--)
	{
        cin>>n>>A>>R>>M;
        for(int i=1;i<=n;i++)
        {
        	cin>>h[i],cnt+=h[i],maxh=max(maxh,h[i]),minh=min(minh,h[i]);
		}
		go(minh,maxh);
		pr(ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
void pr(int x,bool fl=false)  {  cout<<x<<endl;  if(fl) exit(0); }
void pr(int x,int y,bool fl=false)  {  cout<<x<<" "<<y<<endl;  if(fl) exit(0); }
void pr(int x[],int n,bool fl=false)  {for(int i=1;i<=n;i++)  cout<<x[i]<<(i==n?'\n':' ');  if(fl) exit(0); }
/*----------------------------------------------------*/
int h[100007];
int cnt=0,maxh=-1,minh=INT_MAX;
int n,A,R,M,ans=INT_MAX;
int calc(int x)
{
	int add=0,mi=0;
	for(int i=1;i<=n;i++)
	{
		if(h[i]<=x) add+=x-h[i];
		else mi+=h[i]-x;
	}
	if(A+R<=M)	return A*add+R*mi;
	else
	{
		int k=min(add,mi);
		add-=k,mi-=k;
		return A*add+R*mi+M*k;
	}
}
void go(int l,int r)
{
	if(l>r) return;
//	cout<<l<<" "<<r<<endl;
//	cout<<ans<<endl;
	int mid=(l+r)/2;
	int b=calc(mid);
	int a=calc(mid-1);
	int c=calc(mid+1);
	ans=min(ans,b);
//	if(a>b and a>c)
//	{
//		for(int i=1;i<=1000000;i++) h[i]=1;
//	}
	if(a<=b) ans=min(ans,a),go(l,mid-1);
	if(c<=b) ans=min(ans,c),go(mid+1,r);
}
/*----------------------------------------------------*/
signed main()
{
	ios::sync_with_stdio(false);
	int test_case=1;
//	cin>>test_case;
	while(test_case--)
	{
        cin>>n>>A>>R>>M;
        for(int i=1;i<=n;i++)
        {
        	cin>>h[i],cnt+=h[i],maxh=max(maxh,h[i]),minh=min(minh,h[i]);
		}
		go(minh,maxh);
		pr(ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
void pr(int x,bool fl=false)  {  cout<<x<<endl;  if(fl) exit(0); }
void pr(int x,int y,bool fl=false)  {  cout<<x<<" "<<y<<endl;  if(fl) exit(0); }
void pr(int x[],int n,bool fl=false)  {for(int i=1;i<=n;i++)  cout<<x[i]<<(i==n?'\n':' ');  if(fl) exit(0); }
/*----------------------------------------------------*/
int h[100007];
int cnt=0,maxh=-1,minh=LLONG_MAX;
int n,A,R,M,ans=LLONG_MAX;
int calc(int x)
{
	int add=0,mi=0;
	for(int i=1;i<=n;i++)
	{
		if(h[i]<=x) add+=x-h[i];
		else mi+=h[i]-x;
	}
	if(A+R<=M)	return A*add+R*mi;
	else
	{
		int k=min(add,mi);
		add-=k,mi-=k;
		return A*add+R*mi+M*k;
	}
}
void go(int l,int r)
{
	if(l>r) return;
//	cout<<l<<" "<<r<<endl;
//	cout<<ans<<endl;
	int mid=(l+r)/2;
	int b=calc(mid);
	int a=calc(mid-1);
	int c=calc(mid+1);
	ans=min(ans,b);
//	if(a>b and a>c)
//	{
//		for(int i=1;i<=1000000;i++) h[i]=1;
//	}
	if(a<=b) ans=min(ans,a),go(l,mid-1);
	if(c<=b) ans=min(ans,c),go(mid+1,r);
}
/*----------------------------------------------------*/
signed main()
{
	ios::sync_with_stdio(false);
	int test_case=1;
//	cin>>test_case;
	while(test_case--)
	{
        cin>>n>>A>>R>>M;
        for(int i=1;i<=n;i++)
        {
        	cin>>h[i],cnt+=h[i],maxh=max(maxh,h[i]),minh=min(minh,h[i]);
		}
		go(minh,maxh);
		pr(ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
void pr(int x,bool fl=false)  {  cout<<x<<endl;  if(fl) exit(0); }
void pr(int x,int y,bool fl=false)  {  cout<<x<<" "<<y<<endl;  if(fl) exit(0); }
void pr(int x[],int n,bool fl=false)  {for(int i=1;i<=n;i++)  cout<<x[i]<<(i==n?'\n':' ');  if(fl) exit(0); }
/*----------------------------------------------------*/
int h[100007];
int cnt=0,maxh=-1,minh=INT_MAX;
int n,A,R,M,ans=INT_MAX;
int calc(int x)
{
	int add=0,mi=0;
	for(int i=1;i<=n;i++)
	{
		if(h[i]<=x) add+=x-h[i];
		else mi+=h[i]-x;
	}
	if(A+R<=M)	return A*add+R*mi;
	else
	{
		int k=min(add,mi);
		add-=k,mi-=k;
		return A*add+R*mi+M*k;
	}
}
void go(int l,int r)
{
	if(l>r) return;
//	cout<<l<<" "<<r<<endl;
//	cout<<ans<<endl;
	int mid=(l+r)/2;
	int b=calc(mid);
	int a=calc(mid-mid/2);
	int c=calc(mid+mid/2);
	ans=min(ans,b);
//	if(a>b and a>c)
//	{
//		for(int i=1;i<=1000000;i++) h[i]=1;
//	}
	if(a<=b or rand()%2) ans=min(ans,a),go(l,mid-1);
	if(c<=b or rand()%2) ans=min(ans,c),go(mid+1,r);
}
/*----------------------------------------------------*/
signed main()
{
	ios::sync_with_stdio(false);
	int test_case=1;
	srand(20180433+time(NULL));
//	cin>>test_case;
	while(test_case--)
	{
        cin>>n>>A>>R>>M;
        for(int i=1;i<=n;i++)
        {
        	cin>>h[i],cnt+=h[i],maxh=max(maxh,h[i]),minh=min(minh,h[i]);
		}
		go(minh,maxh);
		pr(ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
void pr(int x,bool fl=false)  {  cout<<x<<endl;  if(fl) exit(0); }
void pr(int x,int y,bool fl=false)  {  cout<<x<<" "<<y<<endl;  if(fl) exit(0); }
void pr(int x[],int n,bool fl=false)  {for(int i=1;i<=n;i++)  cout<<x[i]<<(i==n?'\n':' ');  if(fl) exit(0); }
/*----------------------------------------------------*/
int h[100007];
int cnt=0,maxh=-1,minh=INT_MAX;
int n,A,R,M,ans=INT_MAX;
int calc(int x)
{
	int add=0,mi=0;
	for(int i=1;i<=n;i++)
	{
		if(h[i]<=x) add+=x-h[i];
		else mi+=h[i]-x;
	}
	if(A+R<=M)	return A*add+R*mi;
	else
	{
		int k=min(add,mi);
		add-=k,mi-=k;
		return A*add+R*mi+M*k;
	}
}
void go(int l,int r)
{
	if(l>r) return;
//	cout<<l<<" "<<r<<endl;
//	cout<<ans<<endl;
	int mid=(l+r)/2;
	int b=calc(mid);
	int a=calc(mid-mid/2);
	int c=calc(mid+mid/2);
	ans=min(ans,b);
//	if(a>b and a>c)
//	{
//		for(int i=1;i<=1000000;i++) h[i]=1;
//	}
	if(a<=b) ans=min(ans,a),go(l,mid-1);
	if(c<=b) ans=min(ans,c),go(mid+1,r);
}
/*----------------------------------------------------*/
signed main()
{
	ios::sync_with_stdio(false);
	int test_case=1;
//	cin>>test_case;
	while(test_case--)
	{
        cin>>n>>A>>R>>M;
        for(int i=1;i<=n;i++)
        {
        	cin>>h[i],cnt+=h[i],maxh=max(maxh,h[i]),minh=min(minh,h[i]);
		}
		go(minh,maxh);
		pr(ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
void pr(int x,bool fl=false)  {  cout<<x<<endl;  if(fl) exit(0); }
void pr(int x,int y,bool fl=false)  {  cout<<x<<" "<<y<<endl;  if(fl) exit(0); }
void pr(int x[],int n,bool fl=false)  {for(int i=1;i<=n;i++)  cout<<x[i]<<(i==n?'\n':' ');  if(fl) exit(0); }
/*----------------------------------------------------*/
int h[100007];
int cnt=0,maxh=-1,minh=LLONG_MAX;
int n,A,R,M,ans=LLONG_MAX;
int calc(int x)
{
	int add=0,mi=0;
	for(int i=1;i<=n;i++)
	{
		if(h[i]<=x) add+=x-h[i];
		else mi+=h[i]-x;
	}
	if(A+R<=M)	return A*add+R*mi;
	else
	{
		int k=min(add,mi);
		add-=k,mi-=k;
		return A*add+R*mi+M*k;
	}
}
void go(int l,int r)
{
	if(l>r) return;
//	cout<<l<<" "<<r<<endl;
//	cout<<ans<<endl;
	int mid=(l+r)/2;
	int b=calc(mid);
	int a=calc(mid-1);
	int c=calc(mid+1);
	ans=min(ans,b);
//	if(a>b and a>c)
//	{
//		for(int i=1;i<=1000000;i++) h[i]=1;
//	}
	if(a<=b) ans=min(ans,a),go(l,mid-1);
	if(c<=b) ans=min(ans,c),go(mid+1,r);
}
/*----------------------------------------------------*/
signed main()
{
	ios::sync_with_stdio(false);
	int test_case=1;
//	cin>>test_case;  6

	while(test_case--)
	{
        cin>>n>>A>>R>>M;
        for(int i=1;i<=n;i++)
        {
        	cin>>h[i],cnt+=h[i],maxh=max(maxh,h[i]),minh=min(minh,h[i]);
		}
		go(minh,maxh);
		pr(ans);
	}
	return 0;
}


#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REV(i,a,b) for(int i = a; i >= b; i--)

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)

#define MOD 1000000007
ll binpow(ll x, ll y) {
	ll z = 1;
	while(y > 0) {
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
// a^-1 (mod m) = a^(m-2) (mod m) - m is prime
ll inv(ll x) {return binpow(x, MOD - 2);}
ll divide(ll x, ll y) {return x* inv(y);}

// ************* MAIN *******************

ll N, A, R, M, H[100000];

void solve() {
    cin >>N>>A>>R>>M;
    REP(i,0,N-1) cin >> H[i];
    ll l = 0, r = (ll)(1e9 + 100);

    ll ans=(ll)1e18;
    while (l < r) {
        ll h = (l + r)/2;
        // cout << h << endl;
        ll n[3] = {0}, e[3] = {0};
        REP(off,-1,1) {
            REP(i,0,N-1) {
                if (H[i]> h+off) e[off+1] += H[i]-h-off;
                else n[off+1] += h+off-H[i];
            }
        }

        ll cost[3] = {0};
        REP(off,0,2) {
            if (M <= A + R)
                cost[off] = min(e[off], n[off])*M + abs(e[off]-n[off])*((e[off]<n[off])? A : R);
            else
                cost[off] = e[off]*R + n[off]*A;
        }
        ans = min(ans, cost[1]);
        if (cost[0] < cost[2]) r = h;
        else l = h + 1;
    }
    cout << ans << endl;

}

/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test

./Test < in
*/
int main() {
    int _=1;
    // cin>>_;
    REP(t,1,_) {
        // cout << "Case #" << t << ": ";
        solve();
        // cout << ((solve())? "YES" : "NO") << endl;
        // cout << solve() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REV(i,a,b) for(int i = a; i >= b; i--)

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)

#define MOD 1000000007
ll binpow(ll x, ll y) {
	ll z = 1;
	while(y > 0) {
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
// a^-1 (mod m) = a^(m-2) (mod m) - m is prime
ll inv(ll x) {return binpow(x, MOD - 2);}
ll divide(ll x, ll y) {return x* inv(y);}

// ************* MAIN *******************

int N, A, R, M, H[100000];

void solve() {
    cin >>N>>A>>R>>M;
    REP(i,0,N-1) cin >> H[i];
    sort(H, H + N);
    int l = 0, r = (int)(1e9);

    ll ans=(ll)1e17;
    while (l < r) {
        int h = (l + r)/2;
        ll n[3] = {0}, e[3] = {0};
        REP(off,-1,1) {
            REP(i,0,N-1) {
                if (H[i]> h+off) e[off+1] += H[i]-h-off;
                else n[off+1] += h+off-H[i];
            }
        }

        ll cost[3] = {0};
        REP(off,0,2) {
            if (M <= A + R)
                cost[off] = min(e[off], n[off])*M + abs(e[off]-n[off])*((e[off]<n[off])? A : R);
            else
                cost[off] = e[off]*R + n[off]*A;
        }
        ans = min(ans, cost[1]);
        if (cost[0] < cost[2]) r = h;
        else l = h + 1;
    }
    cout << ans << endl;

}

/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test

./Test < in
*/
int main() {
    int _=1;
    // cin>>_;
    REP(t,1,_) {
        // cout << "Case #" << t << ": ";
        solve();
        // cout << ((solve())? "YES" : "NO") << endl;
        // cout << solve() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REV(i,a,b) for(int i = a; i >= b; i--)

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)

#define MOD 1000000007
ll binpow(ll x, ll y) {
	ll z = 1;
	while(y > 0) {
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
// a^-1 (mod m) = a^(m-2) (mod m) - m is prime
ll inv(ll x) {return binpow(x, MOD - 2);}
ll divide(ll x, ll y) {return x* inv(y);}

// ************* MAIN *******************

ll N, A, R, M, H[100000];

void solve() {
    cin >>N>>A>>R>>M;
    REP(i,0,N-1) cin >> H[i];
    ll l = 0, r = (ll)(1e12);

    ll ans=(ll)1e18;
    while (l < r) {
        ll h = (l + r)/2;
        // cout << h << endl;
        ll n[3] = {0}, e[3] = {0};
        REP(off,-1,1) {
            REP(i,0,N-1) {
                if (H[i]> h+off) e[off+1] += H[i]-h-off;
                else n[off+1] += h+off-H[i];
            }
        }

        ll cost[3] = {0};
        REP(off,0,2) {
            if (M <= A + R)
                cost[off] = min(e[off], n[off])*M + abs(e[off]-n[off])*((e[off]<n[off])? A : R);
            else
                cost[off] = e[off]*R + n[off]*A;
        }
        ans = min(ans, cost[1]);
        if (cost[0] < cost[2]) r = h;
        else l = h + 1;
    }
    cout << ans << endl;

}

/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test

./Test < in
*/
int main() {
    int _=1;
    // cin>>_;
    REP(t,1,_) {
        // cout << "Case #" << t << ": ";
        solve();
        // cout << ((solve())? "YES" : "NO") << endl;
        // cout << solve() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REV(i,a,b) for(int i = a; i >= b; i--)

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)

#define MOD 1000000007
ll binpow(ll x, ll y) {
	ll z = 1;
	while(y > 0) {
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
// a^-1 (mod m) = a^(m-2) (mod m) - m is prime
ll inv(ll x) {return binpow(x, MOD - 2);}
ll divide(ll x, ll y) {return x* inv(y);}

// ************* MAIN *******************

ll N, A, R, M, H[100000];

void solve() {
    cin >>N>>A>>R>>M;
    REP(i,0,N-1) cin >> H[i];
    ll l = 0, r = (ll)(1e9);

    ll ans=(ll)1e18;
    while (l < r) {
        ll h = (l + r)/2;
        ll n[3] = {0}, e[3] = {0};
        REP(off,-1,1) {
            REP(i,0,N-1) {
                if (H[i]> h+off) e[off+1] += H[i]-h-off;
                else n[off+1] += h+off-H[i];
            }
        }

        ll cost[3] = {0};
        REP(off,0,2) {
            if (M <= A + R)
                cost[off] = min(e[off], n[off])*M + abs(e[off]-n[off])*((e[off]<n[off])? A : R);
            else
                cost[off] = e[off]*R + n[off]*A;
        }
        ans = min(ans, cost[1]);
        if (cost[0] < cost[2]) r = h;
        else l = h + 1;
    }
    cout << ans << endl;

}

/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test

./Test < in
*/
int main() {
    int _=1;
    // cin>>_;
    REP(t,1,_) {
        // cout << "Case #" << t << ": ";
        solve();
        // cout << ((solve())? "YES" : "NO") << endl;
        // cout << solve() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REV(i,a,b) for(int i = a; i >= b; i--)

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)

#define MOD 1000000007
ll binpow(ll x, ll y) {
	ll z = 1;
	while(y > 0) {
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
// a^-1 (mod m) = a^(m-2) (mod m) - m is prime
ll inv(ll x) {return binpow(x, MOD - 2);}
ll divide(ll x, ll y) {return x* inv(y);}

// ************* MAIN *******************

ll N, A, R, M, H[100000];

void solve() {
    cin >>N>>A>>R>>M;
    REP(i,0,N-1) cin >> H[i];
    ll l = 0, r = (ll)(1e9);

    ll ans=(ll)1e17;
    while (l < r) {
        ll h = (l + r)/2;
        ll n[3] = {0}, e[3] = {0};
        REP(off,-1,1) {
            REP(i,0,N-1) {
                if (H[i]> h+off) e[off+1] += H[i]-h-off;
                else n[off+1] += h+off-H[i];
            }
        }

        ll cost[3] = {0};
        REP(off,0,2) {
            if (M <= A + R)
                cost[off] = min(e[off], n[off])*M + abs(e[off]-n[off])*((e[off]<n[off])? A : R);
            else
                cost[off] = e[off]*R + n[off]*A;
        }
        ans = min(ans, cost[1]);
        if (cost[0] < cost[2]) r = h;
        else l = h + 1;
    }
    cout << ans << endl;

}

/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test

./Test < in
*/
int main() {
    int _=1;
    // cin>>_;
    REP(t,1,_) {
        // cout << "Case #" << t << ": ";
        solve();
        // cout << ((solve())? "YES" : "NO") << endl;
        // cout << solve() << endl;
    }
    return 0;
}


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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pd;
typedef pair<ld,ld> pld;
typedef vector<int> v32;
typedef vector<ll> v64;
typedef vector<pd> vpd;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<v32> vv32;
typedef vector<v64> vv64;

#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }

const int inf=1000*1000*1000+9;
const ll infl=1ll*inf*inf;
int mod=1000*1000*1000+7;
// ---------------------------------------------------------------------------- --------------

ll cur_cost(v32 &h, ll a, ll r, ll m ){
  int n=sz(h);
  ll sum=0;
  for(int i:h) sum+=i;
  ll pre=0;
  ll ans=infl;
  for(int i=0;i<n;i++){
    pre+=h[i];
    int y=h[i];
    ll up=1ll*y*(i+1)-pre;
    ll down=sum-pre-1ll*(n-1-i)*y;
    if(up>down){
      ans=min(ans,1ll*down*m+(up-down)*1ll*a);
    }
    else {
      ans=min(ans,1ll*up*m+(down-up)*1ll*r);
    }
  }
  return ans;
}

void solve(){
  int n,a,r,m; cin>>n>>a>>r>>m;
  v32 h(n);
  ll sum=0;
  for(int i=0;i<n;i++) cin>>h[i], sum+=h[i];
  if(n==1){
    cout<<0<<endl; return;
  }
  ll ans=infl;
  int rem=sum%n ;
  // ans+=min(1ll*rem*r, 1ll*(n-rem)*a);
  sort(all(h));
  // if(m>a+r) m=a+r;
  if(m<a+r){
    ll pre=0;
    ans=min(ans,cur_cost(h,a,r,m));
    int pos[2]; pos[0]=sum/n; pos[1]= pos[0]+1;
    v64 up(2,0) , down(2,0);
    for(int i=0;i<n;i++){
      for(int j=0;j<2;j++){
        if(pos[j]>h[i]) up[j]+=pos[j]-h[i];
        if(pos[j]<h[i]) down[j]+=h[i]-pos[j];
      }
    }
    for(int j=0;j<2;j++){
      if(up[j]>down[j]){
        ans=min(ans,1ll*down[j]*m+1ll*a*(up[j]-down[j]));
      }
      else {
        ans=min(ans,1ll*up[j]*m+1ll*r*(down[j]-up[j]));
      }
    }
  }
  ll pre=0;
  for(int i=0;i<n;i++){
    pre+=h[i];
    int y=h[i];
    ll cost=(sum-pre-1ll*(n-1-i)*y)*r;
    cost+=(1ll*(i+1)*y-pre)*a;
    ans=min(ans,cost);
  }
  cout<<ans<<endl;
}

int main(){
  // clock_t beg=clock();
  // fast_io;
  int testcases=1;
  // freopen("student.in","r",stdin);
  // freopen("student.out","w",stdout);
  // cin>>testcases;
  cout << fixed << setprecision(13);
  int cs=1;
  while(testcases--){
    // cout<<"Case #"<<cs<<": ";
    cs++;
    solve();
  }
  // clock_t end=clock();
  // fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}


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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pd;
typedef pair<ld,ld> pld;
typedef vector<int> v32;
typedef vector<ll> v64;
typedef vector<pd> vpd;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<v32> vv32;
typedef vector<v64> vv64;

#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }

const int inf=1000*1000*1000+9;
const ll infl=1ll*inf*inf;
int mod=1000*1000*1000+7;
// ---------------------------------------------------------------------------- --------------

ll cur_cost(v32 &h, ll a, ll r, ll m ){
  int n=sz(h);
  ll sum=0;
  for(int i:h) sum+=i;
  ll pre=0;
  ll ans=infl;
  for(int i=0;i<n;i++){
    pre+=h[i];
    int y=h[i];
    ll up=y*(i+1)-pre;
    ll down=sum-pre-(n-1-i)*y;
    if(up>down){
      ans=min(ans,1ll*down*m+(up-down)*1ll*a);
    }
    else {
      ans=min(ans,1ll*up*m+(down-up)*1ll*r);
    }
  }
  return ans;
}

void solve(){
  int n,a,r,m; cin>>n>>a>>r>>m;
  v32 h(n);
  ll sum=0;
  for(int i=0;i<n;i++) cin>>h[i], sum+=h[i];
  if(n==1){
    cout<<0<<endl; return;
  }
  ll ans=infl;
  int rem=sum%n ;
  // ans+=min(1ll*rem*r, 1ll*(n-rem)*a);
  sort(all(h));
  if(m<a+r){
    ll pre=0;
    ans=min(ans,cur_cost(h,a,r,m));
    int pos[2]; pos[0]=sum/n; pos[1]= pos[0]+1;
    v64 up(2,0) , down(2,0);
    for(int i=0;i<n;i++){
      for(int j=0;j<2;j++){
        if(pos[j]>h[i]) up[j]+=pos[j]-h[i];
        if(pos[j]<h[i]) down[j]+=h[i]-pos[j];
      }
    }
    for(int j=0;j<2;j++){
      if(up[j]>down[j]){
        ans=min(ans,1ll*down[j]*m+1ll*a*(up[j]-down[j]));
      }
      else {
        ans=min(ans,1ll*up[j]*m+1ll*r*(down[j]-up[j]));
      }
    }
  }
  ll pre=0;
  for(int i=0;i<n;i++){
    pre+=h[i];
    int y=h[i];
    ll cost=(sum-pre-1ll*(n-1-i)*y)*r;
    cost+=(1ll*(i+1)*y-pre)*a;
    ans=min(ans,cost);
  }
  cout<<ans<<endl;
}

int main(){
  // clock_t beg=clock();
  // fast_io;
  int testcases=1;
  // freopen("student.in","r",stdin);
  // freopen("student.out","w",stdout);
  // cin>>testcases;
  cout << fixed << setprecision(13);
  int cs=1;
  while(testcases--){
    // cout<<"Case #"<<cs<<": ";
    cs++;
    solve();
  }
  // clock_t end=clock();
  // fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}


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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pd;
typedef pair<ld,ld> pld;
typedef vector<int> v32;
typedef vector<ll> v64;
typedef vector<pd> vpd;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<v32> vv32;
typedef vector<v64> vv64;

#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }

const int inf=1000*1000*1000+9;
const ll infl=1ll*inf*inf;
int mod=1000*1000*1000+7;
// ---------------------------------------------------------------------------- --------------

ll cur_cost(v32 &h, ll a, ll r, ll m ){
  int n=sz(h);
  ll sum=0;
  for(int i:h) sum+=i;
  ll pre=0;
  ll ans=infl;
  for(int i=0;i<n;i++){
    pre+=h[i];
    int y=h[i];
    ll up=1ll*y*(i+1)-pre;
    ll down=sum-pre-1ll*(n-1-i)*y;
    if(up>down){
      ans=min(ans,1ll*down*m+(up-down)*1ll*a);
    }
    else {
      ans=min(ans,1ll*up*m+(down-up)*1ll*r);
    }
  }
  return ans;
}

void solve(){
  int n,a,r,m; cin>>n>>a>>r>>m;
  v32 h(n);
  ll sum=0;
  for(int i=0;i<n;i++) cin>>h[i], sum+=h[i];
  if(n==1){
    cout<<0<<endl; return;
  }
  ll ans=infl;
  int rem=sum%n ;
  // ans+=min(1ll*rem*r, 1ll*(n-rem)*a);
  sort(all(h));
  if(m>a+r) m=a+r;
  if(m<a+r){
    ll pre=0;
    ans=min(ans,cur_cost(h,a,r,m));
    int pos[2]; pos[0]=sum/n; pos[1]= pos[0]+1;
    v64 up(2,0) , down(2,0);
    for(int i=0;i<n;i++){
      for(int j=0;j<2;j++){
        if(pos[j]>h[i]) up[j]+=pos[j]-h[i];
        if(pos[j]<h[i]) down[j]+=h[i]-pos[j];
      }
    }
    for(int j=0;j<2;j++){
      if(up[j]>down[j]){
        ans=min(ans,1ll*down[j]*m+1ll*a*(up[j]-down[j]));
      }
      else {
        ans=min(ans,1ll*up[j]*m+1ll*r*(down[j]-up[j]));
      }
    }
  }
  ll pre=0;
  for(int i=0;i<n;i++){
    pre+=h[i];
    int y=h[i];
    ll cost=(sum-pre-1ll*(n-1-i)*y)*r;
    cost+=(1ll*(i+1)*y-pre)*a;
    ans=min(ans,cost);
  }
  cout<<ans<<endl;
}

int main(){
  // clock_t beg=clock();
  // fast_io;
  int testcases=1;
  // freopen("student.in","r",stdin);
  // freopen("student.out","w",stdout);
  // cin>>testcases;
  cout << fixed << setprecision(13);
  int cs=1;
  while(testcases--){
    // cout<<"Case #"<<cs<<": ";
    cs++;
    solve();
  }
  // clock_t end=clock();
  // fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}


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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pd;
typedef pair<ld,ld> pld;
typedef vector<int> v32;
typedef vector<ll> v64;
typedef vector<pd> vpd;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<v32> vv32;
typedef vector<v64> vv64;

#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }

const int inf=1000*1000*1000+9;
const ll infl=1ll*inf*inf;
int mod=1000*1000*1000+7;
// ---------------------------------------------------------------------------- --------------

void solve(){
  int n,a,r,m; cin>>n>>a>>r>>m;
  v32 h(n);
  ll sum=0;
  for(int i=0;i<n;i++) cin>>h[i], sum+=h[i];
  if(n==1){
    cout<<0<<endl; return;
  }
  ll ans=infl;
  int rem=sum%n ;
  // ans+=min(1ll*rem*r, 1ll*(n-rem)*a);
  sort(all(h));
  if(m<a+r){
    int pos1=sum/n; int pos2=pos1+1;
    ll cost1=0, cost2=0;
    for(int i=0;i<n;i++){
      if(h[i]<pos1){
        cost1+=(-h[i]+pos1)*1ll*m;
      }
      else if(h[i]>pos1){
        int he=h[i];
        int sub=min(he-pos1,rem);
        rem-=sub;
        he-=sub;
        cost1+=1ll*(he-pos1)*m;
      }
    }
    rem=sum%n;
    cost1/=2;  cost1+=1ll*rem*r;
    int add=n-rem;
    for(int i=0;i<n;i++){
      if(h[i]<pos2){
        int he=h[i];
        int ad=min(pos2-he,add);
        add-=ad;
        he+=ad;
        cost2+=1ll*(pos2-he)*m;
      }
      else if(h[i]>pos2){
        cost2+=1ll*(h[i]-pos2)*m;
      }
    }
    cost2/=2; cost2+=1ll*(n-rem)*a;
    ans=min(cost2,cost1);
  }
  ll pre=0;
  for(int i=0;i<n;i++){
    pre+=h[i];
    int y=h[i];
    ll cost=(sum-pre-1ll*(n-1-i)*y)*r;
    cost+=(1ll*(i+1)*y-pre)*a;
    ans=min(ans,cost);
  }
  cout<<ans<<endl;
}

int main(){
  // clock_t beg=clock();
  // fast_io;
  int testcases=1;
  // freopen("student.in","r",stdin);
  // freopen("student.out","w",stdout);
  // cin>>testcases;
  cout << fixed << setprecision(13);
  int cs=1;
  while(testcases--){
    // cout<<"Case #"<<cs<<": ";
    cs++;
    solve();
  }
  // clock_t end=clock();
  // fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}


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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pd;
typedef pair<ld,ld> pld;
typedef vector<int> v32;
typedef vector<ll> v64;
typedef vector<pd> vpd;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<v32> vv32;
typedef vector<v64> vv64;

#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }

const int inf=1000*1000*1000+9;
const ll infl=1ll*inf*inf;
int mod=1000*1000*1000+7;
// ---------------------------------------------------------------------------- --------------

void solve(){
  int n,a,r,m; cin>>n>>a>>r>>m;
  v32 h(n);
  ll sum=0;
  for(int i=0;i<n;i++) cin>>h[i], sum+=h[i];
  if(n==1){
    cout<<0<<endl; return;
  }
  ll ans=infl;
  int rem=sum%n ;
  // ans+=min(1ll*rem*r, 1ll*(n-rem)*a);
  sort(all(h));
  if(m<a+r){
    ll pre=0;
    for(int i=0;i<n;i++){
      pre+=h[i];
      int y=h[i];
      ll up=y*(i+1)-pre;
      ll down=sum-pre-(n-1-i)*y;
      if(up>down){
        ans=min(ans,1ll*down*m+(up-down)*1ll*a);
      }
      else {
        ans=min(ans,1ll*up*m+(down-up)*1ll*r);
      }
    }
  }
  ll pre=0;
  for(int i=0;i<n;i++){
    pre+=h[i];
    int y=h[i];
    ll cost=(sum-pre-1ll*(n-1-i)*y)*r;
    cost+=(1ll*(i+1)*y-pre)*a;
    ans=min(ans,cost);
  }
  cout<<ans<<endl;
}

int main(){
  // clock_t beg=clock();
  // fast_io;
  int testcases=1;
  // freopen("student.in","r",stdin);
  // freopen("student.out","w",stdout);
  // cin>>testcases;
  cout << fixed << setprecision(13);
  int cs=1;
  while(testcases--){
    // cout<<"Case #"<<cs<<": ";
    cs++;
    solve();
  }
  // clock_t end=clock();
  // fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, add, rem, mov, sum = 0;
int a[N];

int calc(int x)
{
	int need = 0, extra = 0;
	for(int i = 1; i <= n; i++)
	{
		if(a[i] < x)
			need += x - a[i];
		else
			extra += a[i] - x;
	}
	int take = min(need, extra);
	int cost = take * mov;
	need -= take, extra -= take;
	cost += need * add;
	cost += extra * rem;
	return cost;
}

int ternary_search(int lo, int hi)
{
  int iter = 200;
	while(iter--)
	{
		int m1 = (lo * 2 + hi) / 3;
		int m2 = (lo + hi * 2) / 3;
		if(calc(m1) < calc(m2))
			hi = m2;
		else
			lo = m1;
	}
	int ans = calc(lo);
	for(int i = lo + 1; i <= hi; i++)
		ans = min(ans, calc(i));
	return ans;
}
int32_t main()
{
	IOS;
	cin >> n >> add >> rem >> mov;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	mov = min(mov, add + rem);
	int ans = ternary_search(0, 1e9);
	cout << ans;
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, add, rem, mov, sum = 0;
int a[N];

int calc(int x)
{
	int need = 0, extra = 0;
	for(int i = 1; i <= n; i++)
	{
		if(a[i] < x)
			need += x - a[i];
		else
			extra += a[i] - x;
	}
	int take = min(need, extra);
	int cost = take * mov;
	need -= take, extra -= take;
	cost += need * add;
	cost += extra * rem;
	return cost;
}

int ternary_search(int lo, int hi)
{
  int iter = 200;
	while(iter-- && hi - lo >= 10)
	{
		int m1 = (lo * 2 + hi) / 3;
		int m2 = (lo + hi * 2) / 3;
		if(calc(m1) < calc(m2))
			hi = m2;
		else
			lo = m1;
	}
	int ans = calc(lo);
	for(int i = lo + 1; i <= hi; i++)
		ans = min(ans, calc(i));
	return ans;
}
int32_t main()
{
	IOS;
	cin >> n >> add >> rem >> mov;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	mov = min(mov, add + rem);
	int ans = ternary_search(0, 1e9);
	cout << ans;
	return 0;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define SZ(v) (int)v.size()
#define endl "\n"
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 1e9;
const LL INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;

int n, a, r, m;
LL h[ N ];

LL calc(LL cur) {
  LL need = 0, rem = 0, ret = 0;
  for (int i = 1; i <= n; i++) {
    if (h[i] == cur) continue;
    if (h[i] > cur) rem += h[i] - cur;
    else need += cur - h[i];
  }
  LL x = min(need, rem);
  ret += x * m;
  need -= x, rem -= x;
  ret += need * a;
  ret += rem * r;
  return ret;
}

LL TernarySearchMIN(LL l, LL r) {
  LL lo = l, hi = r;
  int iteration = 300;
  while (iteration -- && hi - lo > 2) {
    LL midL = (2 * lo + hi)/3, midR = (lo + 2 * hi)/3;
    LL valL = calc(midL), valR = calc(midR);
    if (valL < valR) hi = midR;
    else lo = midL;
  }
  LL ret = calc(lo);
  for (LL i = lo + 1; i <= hi; i++) ret = min(ret, calc(i));
  return ret;
}

void solve() {
  cin >> n >> a >> r >> m;
  for (int i = 1; i <= n; i++) cin >> h[i];
  cout << TernarySearchMIN(0, 2 * inf) << endl;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif
  int t = 1;

  for (int tc = 1; tc <= t; tc++) solve();
  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, add, rem, mov, sum = 0;
int a[N];

int calc(int x)
{
	int need = 0, extra = 0;
	for(int i = 1; i <= n; i++)
	{
		if(a[i] < x)
			need += x - a[i];
		else
			extra += a[i] - x;
	}
	int take = min(need, extra);
	int cost = take * mov;
	need -= take, extra -= take;
	cost += need * add;
	cost += extra * rem;
	return cost;
}

int ternary_search(int lo, int hi)
{
	while(lo < hi - 2)
	{
		int m1 = (lo * 2 + hi) / 3;
		int m2 = (lo + hi * 2) / 3;
		if(calc(m1) < calc(m2))
			hi = m2;
		else
			lo = m1;
	}
	int ans = calc(lo);
	for(int i = lo + 1; i <= hi; i++)
		ans = min(ans, calc(i));
	return ans;
}
int32_t main()
{
	IOS;
	cin >> n >> add >> rem >> mov;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	mov = min(mov, add + rem);
	int ans = ternary_search(0, 1e9);
	cout << ans;
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, add, rem, mov, sum = 0;
int a[N];

int calc(int x)
{
	int need = 0, extra = 0;
	for(int i = 1; i <= n; i++)
	{
		if(a[i] < x)
			need += x - a[i];
		else
			extra += a[i] - x;
	}
	int take = min(need, extra);
	int cost = take * mov;
	need -= take, extra -= take;
	cost += need * add;
	cost += extra * rem;
	return cost;
}

int ternary_search(int lo, int hi)
{
  int iter = 200;
	while(iter-- && lo <= hi)
	{
		int m1 = (lo * 2 + hi) / 3;
		int m2 = (lo + hi * 2) / 3;
		if(calc(m1) < calc(m2))
			hi = m2;
		else
			lo = m1;
	}
	int ans = calc(lo);
	for(int i = lo + 1; i <= hi; i++)
		ans = min(ans, calc(i));
	return ans;
}
int32_t main()
{
	IOS;
	cin >> n >> add >> rem >> mov;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	mov = min(mov, add + rem);
	int ans = ternary_search(0, 1e9);
	cout << ans;
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAXN 100009
const int INF = 1.01e9;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl

vi arr(MAXN);
int n,a,r,m;

int solve(int x){
	int at = 0;
	int rt = 0;
	rep(i,0,n){
		if(arr[i]<x)at += (x-arr[i]);
		else if(arr[i]>x) rt += (arr[i]-x);
	}
	int p = 0;
	int eq = min(at,rt);
	if(m<=a+r){
		p = eq*m;
		if(eq==at){
			p+=(rt-eq)*r;
		}
		else{
			p+=(at-eq)*a;
		}
	}
	else{
		p = at*a+rt*r;
	}

	return p;

}

int main(){

	cin>>n>>a>>r>>m;
	arr.resize(n);
	set<int> modes;
	unordered_map<int,int> f;

	int min_ = 1e9+1;
	int max_ = -1;
	int mf = 0;
	int ss = 0;

	rep(i,0,n){
		cin>>arr[i];
		f[arr[i]]++;
		mf = max(f[arr[i]],mf);
		max_ = max(max_,arr[i]);
		min_ = min(min_,arr[i]);
		ss+=arr[i];

	}

	rep(i,0,n){
		if(f[arr[i]]==mf)
			modes.insert(arr[i]);
	}

	sort(arr.begin(), arr.end());
	int mean = ss/n;
	int median;
	if(n&1) median = arr[n/2];
	else median = (arr[(n-1)/2] + arr[n/2])/2;

	modes.insert(mean);
	modes.insert(median);
	modes.insert(max_);
	modes.insert(min_);

	ll ans = INT_MAX;
	for(auto qq:modes){
		ll temp = solve(qq);
		ans = min(temp,ans);
	}

	cout<<ans<<"\n";

}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAXN 100009
const int INF = 1.01e9;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl
#define int int64_t

vi arr(MAXN);
int n,a,r,m;

int solve(int x){
	int at = 0;
	int rt = 0;
	rep(i,0,n){
		if(arr[i]<x)at += (x-arr[i]);
		else if(arr[i]>x) rt += (arr[i]-x);
	}
	int p = 0;
	int eq = min(at,rt);
	if(m<=a+r){
		p = eq*m;
		if(eq==at){
			p+=(rt-eq)*r;
		}
		else{
			p+=(at-eq)*a;
		}
	}
	else{
		p = at*a+rt*r;
	}

	return p;

}

int32_t main(){

	cin>>n>>a>>r>>m;
	arr.resize(n);
	set<int> modes;
	unordered_map<int,int> f;

	int min_ = 1e9+1;
	int max_ = -1;
	int mf = 0;
	int ss = 0;

	rep(i,0,n){
		cin>>arr[i];
		f[arr[i]]++;
		if(f[arr[i]]>mf)
			mf = f[arr[i]];
		if(arr[i]>max_)
			max_= arr[i];
		if(arr[i]<min_)
			min_ = arr[i];
		ss+=arr[i];

	}

	rep(i,0,n){
		if(f[arr[i]]==mf)
			modes.insert(arr[i]);
	}

	sort(arr.begin(), arr.end());

	ll ans = INT64_MAX;

	int  l = 0;
	int  r = 1e9+1;
	while(l<=r){
		int mid = l + (r-l)/2;

		int s1 = solve(mid+1);
		int s2 = solve(mid);
		if(s1<ans)
			ans = s1;
		if(s2<ans)
			ans = s2;

		if(s1>s2){
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}

	cout<<ans<<"\n";
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAXN 100009
const int INF = 1.01e9;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl
#define int int64_t

vi arr(MAXN);
int n,a,r,m;

int solve(int x){
	int at = 0;
	int rt = 0;
	rep(i,0,n){
		if(arr[i]<x)at += (x-arr[i]);
		else if(arr[i]>x) rt += (arr[i]-x);
	}
	int p = 0;
	int eq = min(at,rt);
	if(m<=a+r){
		p = eq*m;
		if(eq==at){
			p+=(rt-eq)*r;
		}
		else{
			p+=(at-eq)*a;
		}
	}
	else{
		p = at*a+rt*r;
	}

	return p;

}

int32_t main(){

	cin>>n>>a>>r>>m;
	arr.resize(n);
	set<int> modes;
	unordered_map<int,int> f;

	int min_ = 1e9+1;
	int max_ = -1;
	int mf = 0;
	int ss = 0;

	rep(i,0,n){
		cin>>arr[i];
		f[arr[i]]++;
		if(f[arr[i]]>mf)
			mf = f[arr[i]];
		if(arr[i]>max_)
			max_= arr[i];
		if(arr[i]<min_)
			min_ = arr[i];
		ss+=arr[i];

	}

	rep(i,0,n){
		if(f[arr[i]]==mf)
			modes.insert(arr[i]);
	}

	sort(arr.begin(), arr.end());
	int mean = ss/n;
	int median;
	if(n&1) median = arr[n/2];
	else median = (arr[(n-1)/2] + arr[n/2])/2;

	modes.insert(mean);
	modes.insert(median);
	modes.insert(max_);
	modes.insert(min_);
	ll ans = INT64_MAX;
	for(auto qq:modes){
		ll temp = solve(qq);
		ans = min(temp,ans);
	}

	cout<<ans<<"\n";

}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAXN 100009
const int INF = 1.01e9;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl
#define int int64_t

vi arr(MAXN);
int n,a,r,m;

int solve(int x){
	int at = 0;
	int rt = 0;
	rep(i,0,n){
		if(arr[i]<x)at += (x-arr[i]);
		else if(arr[i]>x) rt += (arr[i]-x);
	}
	int p = 0;
	int eq = min(at,rt);
	if(m<=a+r){
		p = eq*m;
		if(eq==at){
			p+=(rt-eq)*r;
		}
		else{
			p+=(at-eq)*a;
		}
	}
	else{
		p = at*a+rt*r;
	}

	return p;

}

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(0);

	cin>>n>>a>>r>>m;
	arr.resize(n);
	set<int> modes;
	unordered_map<int,int> f;

	int min_ = 1e9+1;
	int max_ = -1;
	int mf = 0;
	int ss = 0;

	rep(i,0,n){
		cin>>arr[i];
		f[arr[i]]++;
		if(f[arr[i]]>mf)
			mf = f[arr[i]];
		if(arr[i]>max_)
			max_= arr[i];
		if(arr[i]<min_)
			min_ = arr[i];
		ss+=arr[i];

	}

	rep(i,0,n){
		if(f[arr[i]]==mf)
			modes.insert(arr[i]);
	}

	sort(arr.begin(), arr.end());

	ll ans = INT64_MAX;

	int  l = 0;
	int  r = 1e9+1;
	while(l<=r){
		int mid = l + (r-l)/2;

		int s1 = solve(mid+1);
		int s2 = solve(mid);
		if(s1<ans)
			ans = s1;
		if(s2<ans)
			ans = s2;

		if(s1>s2){
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}

	cout<<ans<<"\n";
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAXN 100009
const int INF = 1.01e9;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl
#define int int64_t

vi arr(MAXN);
int n,a,r,m;

int solve(int x){
	int at = 0;
	int rt = 0;
	rep(i,0,n){
		if(arr[i]<x)at += (x-arr[i]);
		else if(arr[i]>x) rt += (arr[i]-x);
	}
	int p = 0;
	int eq = min(at,rt);
	if(m<=a+r){
		p = eq*m;
		if(eq==at){
			p+=(rt-eq)*r;
		}
		else{
			p+=(at-eq)*a;
		}
	}
	else{
		p = at*a+rt*r;
	}

	return p;

}

int32_t main(){

	cin>>n>>a>>r>>m;
	arr.resize(n);
	set<int> modes;
	unordered_map<int,int> f;

	int min_ = 1e9+1;
	int max_ = -1;
	int mf = 0;
	int ss = 0;

	rep(i,0,n){
		cin>>arr[i];
		f[arr[i]]++;
		if(f[arr[i]]>mf)
			mf = f[arr[i]];
		if(arr[i]>max_)
			max_= arr[i];
		if(arr[i]<min_)
			min_ = arr[i];
		ss+=arr[i];

	}

	rep(i,0,n){
		if(f[arr[i]]==mf)
			modes.insert(arr[i]);
	}

	sort(arr.begin(), arr.end());
	int mean = ss/n;
	int median;
	if(n&1) median = arr[n/2];
	else median = (arr[(n-1)/2] + arr[n/2])/2;

	modes.insert(mean);
	modes.insert(median);
	modes.insert(max_);
	modes.insert(min_);
	if(mean-1>=0)
		modes.insert(mean-1);
	modes.insert(mean+1);
	ll ans = INT64_MAX;
	for(auto qq:modes){
		ll temp = solve(qq);
		ans = min(temp,ans);
	}

	cout<<ans<<"\n";

}


#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x)h & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;

const LL mod = 1e9 + 7;

LL ksm(LL a, LL b) {

    LL res = 1LL;

    while(b) {

        if(b & 1) res = res * a % mod;

        a = a * a % mod;

        b >>= 1;

    }

    return res;

}

LL a[N];

LL n, A, R, M;

LL f(LL x) {

    LL sm = 0, bg = 0;

    rep(i, 1, n) {

        if(a[i] < x) sm += x - a[i];

        if(a[i] > x) bg += a[i] - x;

    }

    if(M >= A + R) {

        LL tmp1 = 1LL * A * sm;

        LL tmp2 = 1LL * R * bg;

        return tmp1 + tmp2;

    }

    else {

        LL mi = min(sm, bg);

        sm -= mi;

        bg -= mi;

        LL tmp1 = 1LL * M * mi;

        LL tmp2 = 1LL * A * sm;

        LL tmp3 = 1LL * R * bg;

        return tmp1 + tmp2 + tmp3;

    }

}

void solve() {

    scanf("%lld %lld %lld %lld", &n, &A, &R, &M);

    LL sum = 0;

    rep(i, 1, n) {

       scanf("%lld", &a[i]);

       sum += a[i];

    }

    LL l = 0, r = sum;

    while(r - l > 1) {

        LL ll = (r + l * 2) / 3;

        LL rr = (r * 2 + l + 2) / 3;

        if(f(ll) < f(rr)) r = rr - 1;

        else l = ll + 1;

    }

    LL ans = min(f(l), f(r));

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

}

int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x)h & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;

const LL mod = 1e9 + 7;

LL ksm(LL a, LL b) {

    LL res = 1LL;

    while(b) {

        if(b & 1) res = res * a % mod;

        a = a * a % mod;

        b >>= 1;

    }

    return res;

}

LL a[N];

LL n, A, R, M;

LL f(LL x) {

    LL sm = 0, bg = 0;

    rep(i, 1, n) {

        if(a[i] < x) sm += x - a[i];

        if(a[i] > x) bg += a[i] - x;

    }

    if(M >= A + R) {

        LL tmp1 = 1LL * A * sm;

        LL tmp2 = 1LL * R * bg;

        return tmp1 + tmp2;

    }

    else {

        LL mi = min(sm, bg);

        sm -= mi;

        bg -= mi;

        LL tmp1 = 1LL * M * mi;

        LL tmp2 = 1LL * A * sm;

        LL tmp3 = 1LL * R * bg;

        return tmp1 + tmp2 + tmp3;

    }

}

void solve() {

    scanf("%lld %lld %lld %lld", &n, &A, &R, &M);

    LL sum = 0;

    rep(i, 1, n) {

       scanf("%lld", &a[i]);

       sum += a[i];

    }

    LL l = 0, r = sum;

    while(r - l > 1) {

        LL ll = (r + l * 2) / 3;

        LL rr = (r * 2 + l + 2) / 3;

        if(f(ll) <= f(rr)) r = rr - 1;

        else l = ll + 1;

    }

    LL ans = min(f(l), f(r));

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

}

int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x)h & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;

const LL mod = 1e9 + 7;

LL ksm(LL a, LL b) {

    LL res = 1LL;

    while(b) {

        if(b & 1) res = res * a % mod;

        a = a * a % mod;

        b >>= 1;

    }

    return res;

}

LL a[N];

LL n, A, R, M;

LL f(LL x) {

    LL sm = 0, bg = 0;

    rep(i, 1, n) {

        if(a[i] < x) sm += x - a[i];

        if(a[i] > x) bg += a[i] - x;

    }

    if(M >= A + R) {

        LL tmp1 = 1LL * A * sm;

        LL tmp2 = 1LL * R * bg;

        return tmp1 + tmp2;

    }

    else {

        if(sm > bg) {

            LL tmp1 = bg * M;

            LL tmp2 = (sm - bg) * A;

            return tmp1 + tmp2;

        }

        else {

            LL tmp1 = sm * M;

            LL tmp2 = (bg - sm) * R;

            return tmp1 + tmp2;

        }

    }

}

void solve() {

    scanf("%lld %lld %lld %lld", &n, &A, &R, &M);

    LL sum = 0;

    rep(i, 1, n) {

       scanf("%lld", &a[i]);

       sum += a[i];

    }

    LL l = 0, r = sum;

    while(r - l > 1) {

        LL ll = (r + l * 2) / 3;

        LL rr = (r * 2 + l + 2) / 3;

        if(f(ll) <= f(rr)) r = rr - 1;

        else l = ll + 1;

    }

    LL ans = min(f(l), f(r));

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

}

int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x)h & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;

const LL mod = 1e9 + 7;

LL ksm(LL a, LL b) {

    LL res = 1LL;

    while(b) {

        if(b & 1) res = res * a % mod;

        a = a * a % mod;

        b >>= 1;

    }

    return res;

}

LL a[N];

LL n, A, R, M;

LL f(LL x) {

    LL sm = 0, bg = 0;

    rep(i, 1, n) {

        if(a[i] < x) sm += x - a[i];

        if(a[i] > x) bg += a[i] - x;

    }

    if(M >= A + R) {

        LL tmp1 = 1LL * A * sm;

        LL tmp2 = 1LL * R * bg;

        return tmp1 + tmp2;

    }

    else {

        if(sm > bg) {

            LL tmp1 = bg * M;

            LL tmp2 = (sm - bg) * A;

            return tmp1 + tmp2;

        }

        else {

            LL tmp1 = sm * M;

            LL tmp2 = (bg - sm) * R;

            return tmp1 + tmp2;

        }

    }

}

void solve() {

    scanf("%lld %lld %lld %lld", &n, &A, &R, &M);

    LL sum = 0;

    LL mi = inf;

    LL ma = -inf;

    rep(i, 1, n) {

       scanf("%lld", &a[i]);

       sum += a[i];

       ma = max(ma, a[i]);

       mi = min(mi, a[i]);

    }

    LL l = mi, r = ma;

    while(r - l > 1) {

        LL ll = (r + l * 2) / 3;

        LL rr = (r * 2 + l + 2) / 3;

        if(f(ll) <= f(rr)) r = rr - 1;

        else l = ll + 1;

    }

    LL ans = min(f(l), f(r));

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

}

int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x)h & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;

const LL mod = 1e9 + 7;

LL ksm(LL a, LL b) {

    LL res = 1LL;

    while(b) {

        if(b & 1) res = res * a % mod;

        a = a * a % mod;

        b >>= 1;

    }

    return res;

}

LL a[N];

LL n, A, R, M;

LL f(LL x) {

    LL sm = 0, bg = 0;

    rep(i, 1, n) {

        if(a[i] < x) sm += x - a[i];

        if(a[i] > x) bg += a[i] - x;

    }

    if(M >= A + R) {

        LL tmp1 = 1LL * A * sm;

        LL tmp2 = 1LL * R * bg;

        return tmp1 + tmp2;

    }

    else {

        LL mi = min(sm, bg);

        sm -= mi;

        bg -= mi;

        LL tmp1 = 1LL * M * mi;

        LL tmp2 = 1LL * A * sm;

        LL tmp3 = 1LL * R * bg;

        return tmp1 + tmp2 + tmp3;

    }

}

void solve() {

    scanf("%lld %lld %lld %lld", &n, &A, &R, &M);

    LL sum = 0;

    rep(i, 1, n) {

       scanf("%lld", &a[i]);

       sum += a[i];

    }

    LL l = 0, r = sum;

    while(r - l > 1) {

        LL ll = (r + l * 2) / 3;

        LL rr = (r * 2 + l + 2) / 3;

        if(f(ll) <= f(rr)) r = rr - 1;

        else l = ll + 1;

    }

    LL ans = min(f(l), f(r));

    ans = min(ans, f(l - 1));

    ans = min(ans, f(r + 1));

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

}

int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x)h & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;

const LL mod = 1e9 + 7;

LL ksm(LL a, LL b) {

    LL res = 1LL;

    while(b) {

        if(b & 1) res = res * a % mod;

        a = a * a % mod;

        b >>= 1;

    }

    return res;

}

LL a[N];

LL n, A, R, M;

LL f(LL x) {

    LL sm = 0, bg = 0;

    rep(i, 1, n) {

        if(a[i] < x) sm += x - a[i];

        if(a[i] > x) bg += a[i] - x;

    }

    if(M >= A + R) {

        LL tmp1 = 1LL * A * sm;

        LL tmp2 = 1LL * R * bg;

        return tmp1 + tmp2;

    }

    else {

        LL mi = min(sm, bg);

        sm -= mi;

        bg -= mi;

        LL tmp1 = M * mi;

        LL tmp2 = A * sm;

        LL tmp3 = R * bg;

        return tmp1 + tmp2 + tmp3;

    }

}

void solve() {

    scanf("%lld %lld %lld %lld", &n, &A, &R, &M);

    LL sum = 0;

    rep(i, 1, n) {

       scanf("%lld", &a[i]);

       sum += a[i];

    }

    LL l = 0, r = sum;

    while(r - l > 1) {

        LL ll = (r + l * 2) / 3;

        LL rr = (r * 2 + l + 2) / 3;

        if(f(ll) <= f(rr)) r = rr - 1;

        else l = ll + 1;

    }

    LL ans = min(f(l), f(r));

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

}

int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


//_Hala Madrid_//

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

typedef long long            ll;
typedef double               db;
typedef long double          ldb;
typedef vector<int>          vi;
typedef pair<int, int>       pii;
#define fio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,start,end)     for(ll i=start;i<=end;i++)
#define FORD(i,start,end)    for(ll i=start;i>=end;i--)
#define br                   cout<<"\n"
#define test(t)              int t;cin>>t;while(t--)
#define rz                   return 0
#define all(s)               s.begin(),s.end()
#define sz                   size()
#define pb                   push_back
#define F                    first
#define S                    second

const int mod=1e9+7;

void solve(){
    bool flag=0,flag1=0;
    int m,n,k,l,r,sum=0,ans=0,pos,pos1,c1=0,c2=0,c3=0,c4=0,x,y,z,cnt=0,mx=0,mn=INT_MAX;
    string s1,s2;
    string str1="",str2="",str3="",res="";
    vi v;
    cin>>m>>n;
    string s[m],t[m];
    FOR(i,0,m-1){
        cin>>s[i];
        t[i]=s[i];
        //sort(all(s[i]));
    }
    FOR(i,0,m-1){
        FOR(j,i+1,m-1){
            reverse(all(s[j]));
            if(s[i]==s[j]){
                str1+=t[i];
                t[i]="ab";
                s[i]="ab";
                //reverse(all(s[j]));
                str2=t[j]+str2;
                t[j]="ab";
                s[j]="ab";
                flag=1;
            }
            reverse(all(s[j]));
        }
    }
    FOR(i,0,m-1){
        string p;
        p=t[i];
        reverse(all(p));
        if(t[i]==p){
            str3+=t[i];
            break;
        }
    }
    res=str1+str3+str2;
    cout<<res.sz;
    br;
    cout<<res;
    br;
    /*FOR(i,0,m-1){
        cout<<t[i]<<" ";
    }
    br;
    cout<<str3;*/
}
int main(){
    fio
    bool notc=0;
    int t=1;
    if(notc){
        cin>>t;
    }
    while(t--){

        #ifdef _DEBUG
	        freopen("input.txt", "r", stdin);
	        freopen("output.txt", "w", stdout);
        #endif

        solve();
    }
    rz;
}


//_Hala Madrid_//

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

typedef long long            ll;
typedef double               db;
typedef long double          ldb;
typedef vector<int>          vi;
typedef pair<int, int>       pii;
#define fio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,start,end)     for(ll i=start;i<=end;i++)
#define FORD(i,start,end)    for(ll i=start;i>=end;i--)
#define br                   cout<<"\n"
#define test(t)              int t;cin>>t;while(t--)
#define rz                   return 0
#define all(s)               s.begin(),s.end()
#define sz                   size()
#define pb                   push_back
#define F                    first
#define S                    second

const int mod=1e9+7;

void solve(){
    bool flag=0,flag1=0;
    int m,n,k,l,r,sum=0,ans=0,pos,pos1,c1=0,c2=0,c3=0,c4=0,x,y,z,cnt=0,mx=0,mn=INT_MAX;
    string s1,s2;
    string str1="",str2="",str3="",res="";
    vi v;
    cin>>m>>n;
    string s[m],t[m];
    FOR(i,0,m-1){
        cin>>s[i];
        t[i]=s[i];
        //sort(all(s[i]));
    }
    FOR(i,0,m-1){
        FOR(j,i+1,m-1){
            reverse(all(s[j]));
            if(s[i]==s[j]){
                str1+=t[i];
                t[i]="ab";
                s[i]="ab";
                reverse(all(s[j]));
                str2=t[j]+str2;
                t[j]="ab";
                s[j]="ab";
                flag=1;
            }
            reverse(all(s[j]));
        }
    }
    FOR(i,0,m-1){
        string p;
        p=t[i];
        reverse(all(p));
        if(t[i]==p){
            str3+=t[i];
            break;
        }
    }
    res=str1+str3+str2;
    cout<<res.sz;
    br;
    cout<<res;
    br;
    /*FOR(i,0,m-1){
        cout<<t[i]<<" ";
    }
    br;
    cout<<str3;*/
}
int main(){
    fio
    bool notc=0;
    int t=1;
    if(notc){
        cin>>t;
    }
    while(t--){

        #ifdef _DEBUG
	        freopen("input.txt", "r", stdin);
	        freopen("output.txt", "w", stdout);
        #endif

        solve();
    }
    rz;
}


//_Hala Madrid_//

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

typedef long long            ll;
typedef double               db;
typedef long double          ldb;
typedef vector<int>          vi;
typedef pair<int, int>       pii;
#define fio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,start,end)     for(ll i=start;i<=end;i++)
#define FORD(i,start,end)    for(ll i=start;i>=end;i--)
#define br                   cout<<"\n"
#define test(t)              int t;cin>>t;while(t--)
#define rz                   return 0
#define all(s)               s.begin(),s.end()
#define sz                   size()
#define pb                   push_back
#define F                    first
#define S                    second

const int mod=1e9+7;

void solve(){
    bool flag=0,flag1=0;
    int m,n,k,l,r,sum=0,ans=0,pos,pos1,c1=0,c2=0,c3=0,c4=0,x,y,z,cnt=0,mx=0,mn=INT_MAX;
    string s1,s2;
    string str1="",str2="",str3="",res="";
    vi v;
    cin>>m>>n;
    string s[m],t[m];
    FOR(i,0,m-1){
        cin>>s[i];
        t[i]=s[i];
        //sort(all(s[i]));
    }
    FOR(i,0,m-1){
        FOR(j,i+1,m-1){
            reverse(all(s[j]));
            if(s[i]==s[j]){
                str1+=t[i];
                t[i]="ab";
                s[i]="ab";
                reverse(all(s[j]));
                str2=t[j]+str2;
                t[j]="ab";
                s[j]="ab";
                flag=1;
            }
        }
    }
    FOR(i,0,m-1){
        string p;
        p=t[i];
        reverse(all(p));
        if(t[i]==p){
            str3+=t[i];
            break;
        }
    }
    res=str1+str3+str2;
    cout<<res.sz;
    br;
    cout<<res;
    br;
    /*FOR(i,0,m-1){
        cout<<t[i]<<" ";
    }
    br;
    cout<<str3;*/
}
int main(){
    fio
    bool notc=0;
    int t=1;
    if(notc){
        cin>>t;
    }
    while(t--){

        #ifdef _DEBUG
	        freopen("input.txt", "r", stdin);
	        freopen("output.txt", "w", stdout);
        #endif

        solve();
    }
    rz;
}


//_Hala Madrid_//

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

typedef long long            ll;
typedef double               db;
typedef long double          ldb;
typedef vector<int>          vi;
typedef pair<int, int>       pii;
#define fio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(i,start,end)     for(ll i=start;i<=end;i++)
#define FORD(i,start,end)    for(ll i=start;i>=end;i--)
#define br                   cout<<"\n"
#define test(t)              int t;cin>>t;while(t--)
#define rz                   return 0
#define all(s)               s.begin(),s.end()
#define sz                   size()
#define pb                   push_back
#define F                    first
#define S                    second

const int mod=1e9+7;

void solve(){
    bool flag=0,flag1=0;
    int m,n,k,l,r,sum=0,ans=0,pos,pos1,c1=0,c2=0,c3=0,c4=0,x,y,z,cnt=0,mx=0,mn=INT_MAX;
    string s1,s2;
    string str1="",str2="",str3="",res="";
    vi v;
    cin>>m>>n;
    string s[m],t[m];
    FOR(i,0,m-1){
        cin>>s[i];
        t[i]=s[i];
        //sort(all(s[i]));
    }
    FOR(i,0,m-1){
        FOR(j,i+1,m-1){
            reverse(all(s[j]));
            if(s[i]==s[j]){
                str1+=t[i];
                //t[i]="ab";
                s[i]="ab";
                //reverse(all(s[j]));
                str2=t[j]+str2;
                //t[j]="ab";
                s[j]="ab";
                flag=1;
            }
            reverse(all(s[j]));
        }
    }
    FOR(i,0,m-1){
        string p;
        p=t[i];
        reverse(all(p));
        if(t[i]==p){
            str3+=t[i];
            break;
        }
    }
    res=str1+str3+str2;
    cout<<res.sz;
    br;
    cout<<res;
    br;
    /*FOR(i,0,m-1){
        cout<<t[i]<<" ";
    }
    br;
    cout<<str3;*/
}
int main(){
    fio
    bool notc=0;
    int t=1;
    if(notc){
        cin>>t;
    }
    while(t--){

        #ifdef _DEBUG
	        freopen("input.txt", "r", stdin);
	        freopen("output.txt", "w", stdout);
        #endif

        solve();
    }
    rz;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int isPalindrome(string str)
{

    int l = 0;
    int h = str.size() - 1;

    while (h > l)
    {
        if (str[l++] != str[h--])
        {

            return 0;
        }
    }
    return 1;
}
int main() {
	ll n,m;
	cin>>n>>m;
	string a[n],b[n];
	string s,t="";
	for(ll i=0;i<n;i++)
	{        cin>>a[i];
	            b[i]=a[i];
	       if(isPalindrome(a[i]))
	       {

	           t+=a[i];
	           b[i]="";
	       }
	}
	  for(ll i=0;i<n;i++)
	  {
	      sort(a[i].begin(),a[i].end());

	  }
	    for(ll i=0;i<n;i++)
	    {

	        for(ll j=i+1;j<n;j++)
	        {
	            if(a[i]==a[j])
	            {
	                s+=b[i];
	                //cout<<s<<'\n';

	            }
	        }
	    }
	       string q=s;
	       reverse(q.begin(), q.end());
	       if(m&1)
	            s=s+q;
	        else
	            s=s+t+q;
	        cout<<s.size()<<"\n";
	        cout<<s;

	return 0;
}


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

int main() {
	ll n,m;
	cin>>n>>m;
	string a[n],middle;
	set<string> s;
	for(ll i=0;i<n;i++)
	{        cin>>a[i];
	       s.insert(a[i]);

	}
	vector<string> r,l;
    for(ll i=0;i<n;i++)
	{       string q=a[i];
	        reverse(q.begin(), q.end());
	        if(q==a[i])
	        {
	            middle=a[i];
	        }
	        else if(s.find(q)!=s.end())
	        {
	            l.push_back(a[i]);
	            r.push_back(q);
	            s.erase(a[i]);
	            s.erase(q);
	        }
	}
	cout<<l.size()*m*2+middle.size()<<"\n";
	for(string x:l)
	    cout<<x;
	cout<<middle;
	reverse(r.begin(),r.end());
	for(string y:r)
	   cout<<y;
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int isPalindrome(string str)
{

    int l = 0;
    int h = str.size() - 1;

    while (h > l)
    {
        if (str[l++] != str[h--])
        {

            return 0;
        }
    }
    return 1;
}
int main() {
	ll n,m;
	cin>>n>>m;
	string a[n],b[n];
	string s,t="";
	for(ll i=0;i<n;i++)
	{        cin>>a[i];
	       b[i]=a[i];

	}

	  for(ll i=0;i<n;i++)
	  {
	      sort(a[i].begin(),a[i].end());

	  }
	    for(ll i=0;i<n;i++)
	    {

	        for(ll j=i+1;j<n;j++)
	        {
	            if(a[i]==a[j])
	            {
	                s+=b[i];
	                //cout<<s<<'\n';

	            }
	        }
	    }
	    for(ll i=0;i<n;i++)
	    {
	        if(isPalindrome(b[i])&&(t.size()!=s.size()))
	           {

	            t+=b[i];

	            }
	    }
	       string q=s;
	       reverse(q.begin(), q.end());
	       if(m&1)
	            s=s+q;
	        else
	            s=s+t+q;
	        cout<<s.size()<<"\n";
	        cout<<s;

	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int isPalindrome(string str)
{

    int l = 0;
    int h = str.size() - 1;

    while (h > l)
    {
        if (str[l++] != str[h--])
        {

            return 0;
        }
    }
    return 1;
}
int main() {
	ll n,m;
	cin>>n>>m;
	string a[n],b[n];
	string s,t="";
	for(ll i=0;i<n;i++)
	{        cin>>a[i];
	       if(isPalindrome(a[i]))
	       {

	           t+=a[i];
	           a[i]="";
	       }
	}
	  for(ll i=0;i<n;i++)
	  {
	      sort(a[i].begin(),a[i].end());

	  }
	    for(ll i=0;i<n;i++)
	    {

	        for(ll j=i+1;j<n;j++)
	        {
	            if(a[i]==a[j])
	            {
	                s+=a[i];
	                //cout<<s<<'\n';

	            }
	        }
	    }
	       string q=s;
	       reverse(q.begin(), q.end());
	       if(m&1)
	            s=s+q;
	        else
	            s=s+t+q;
	        cout<<s.size()<<"\n";
	        cout<<s;

	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int isPalindrome(string str)
{

    int l = 0;
    int h = str.size() - 1;

    while (h > l)
    {
        if (str[l++] != str[h--])
        {

            return 0;
        }
    }
    return 1;
}
int main() {
	ll n,m;
	cin>>n>>m;
	string a[n],b[n];
	string s,t="";
	for(ll i=0;i<n;i++)
	{        cin>>a[i];
	            b[i]=a[i];
	       if(isPalindrome(a[i])&&(t.size()%2!=0||t.size()==0))
	       {

	           t+=a[i];
	           b[i]="";
	       }
	}
	  for(ll i=0;i<n;i++)
	  {
	      sort(a[i].begin(),a[i].end());

	  }
	    for(ll i=0;i<n;i++)
	    {

	        for(ll j=i+1;j<n;j++)
	        {
	            if(a[i]==a[j])
	            {
	                s+=b[i];
	                //cout<<s<<'\n';

	            }
	        }
	    }
	       string q=s;
	       reverse(q.begin(), q.end());
	       if(m&1)
	            s=s+q;
	        else
	            s=s+t+q;
	        cout<<s.size()<<"\n";
	        cout<<s;

	return 0;
}


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

int main() {
	ll n,m;
	cin>>n>>m;
	string a[n],b[n];
	string s,t;
	for(ll i=0;i<n;i++)
	{        cin>>a[i];
	           b[i]=a[i];
	}
	  for(ll i=0;i<n;i++)
	  {
	      sort(a[i].begin(),a[i].end());
	      string r=a[i];
	       reverse(r.begin(), r.end());
	        if(a[i]==r&&t.size()==0)
	        {
	            t+=b[i];
	        }
	  }
	    for(ll i=0;i<n;i++)
	    {

	        if(a[i]=="")
	            continue;
	        for(ll j=i+1;j<n;j++)
	        {
	            if(a[i]==a[j])
	            {
	                s+=b[i];
	                //cout<<s<<'\n';
	                a[j]="";
	            }
	        }
	    }
	       string q=s;
	       reverse(q.begin(), q.end());
	       if(m&1)
	            s=s+q;
	        else
	            s=s+t+q;
	        cout<<s.size()<<"\n";
	        cout<<s;

	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int isPalindrome(string str)
{

    int l = 0;
    int h = str.size() - 1;

    while (h > l)
    {
        if (str[l++] != str[h--])
        {

            return 0;
        }
    }
    return 1;
}
int main() {
	ll n,m;
	cin>>n>>m;
	string a[n],b[n];
	string s,t="";
	for(ll i=0;i<n;i++)
	{        cin>>a[i];
	       b[i]=a[i];
	       if(isPalindrome(a[i]))
	       {

	           t+=a[i];
	           b[i]="";
	       }
	}
	if(t.size()%2!=0&&(m&1))
	{

	    t.erase(0,m);
	}
	  for(ll i=0;i<n;i++)
	  {
	      sort(a[i].begin(),a[i].end());

	  }
	    for(ll i=0;i<n;i++)
	    {

	        for(ll j=i+1;j<n;j++)
	        {
	            if(a[i]==a[j])
	            {
	                s+=b[i];
	                //cout<<s<<'\n';

	            }
	        }
	    }
	       string q=s;
	       reverse(q.begin(), q.end());
	       if(m&1)
	            s=s+q;
	        else
	            s=s+t+q;
	        cout<<s.size()<<"\n";
	        cout<<s;

	return 0;
}


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

inline int read()
{
    int x=0,f=1;
    char ch = 0;
    while(!isdigit(ch)) {if(ch=='-') f = -1; ch = getchar();}
    while(isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();}
    return x*f;
}
inline int max(int a,int b) {return a>b?a:b;}
inline int min(int a,int b) {return a<b?a:b;}
typedef long long ll;

int n,m;
char s[102][60];
int dui[102];
int main()
{
    n = read(), m = read();
    for(int i=1; i<=n; i++)
        scanf("%s",s[i]+1);
    int flag;
    int cnt = 0;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        for(int j=i+1; j<=n; j++)
        {
            if(dui[j]) continue;
            flag = 1;
            for(int k=1; k<=m; k++)
            {
                if(s[i][k]!=s[j][m-k+1])
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            {
                dui[i] = j;
                dui[j] = i;
                cnt += 2;
                break;
            }
        }
    }
    int hui;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        hui = i;
        for(int j=1; j<=m/2; j++)
        {
            if(s[i][j]!=s[i][m-j+1])
            {
                hui = 0;
                break;
            }
        }
        if(hui) {cnt += 1; break;}
    }
    //for(int i=1; i<=n; i++) cout << dui[i] << ' ';
    //cout << endl;
    printf("%d\n",cnt*m);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]>i) printf("%s",s[i]+1);
    if(hui) printf("%s",s[hui]+1);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]<i) printf("%s",s[i]+1);
    printf("\n");
    return 0;
}


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

inline int read()
{
    int x=0,f=1;
    char ch = 0;
    while(!isdigit(ch)) {if(ch=='-') f = -1; ch = getchar();}
    while(isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();}
    return x*f;
}
inline int max(int a,int b) {return a>b?a:b;}
inline int min(int a,int b) {return a<b?a:b;}
typedef long long ll;

int n,m;
char s[102][60];
int dui[102];
int main()
{
    n = read(), m = read();
    for(int i=1; i<=n; i++)
        scanf("%s",s[i]+1);
    int flag;
    int cnt = 0;
    for(int i=1; i<=n; i++)
    {

        for(int j=i+1; j<=n; j++)
        {
            if(dui[j]) continue;
            flag = 1;
            for(int k=1; k<=m; k++)
            {
                if(s[i][k]!=s[j][m-k+1])
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            {
                dui[i] = j;
                dui[j] = i;
                cnt += 2;
                break;
            }
        }
    }
    int hui;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        hui = i;
        for(int j=1; j<=m/2; j++)
        {
            if(s[i][j]!=s[i][m-j+1])
            {
                hui = 0;
                break;
            }
        }
        if(hui) {cnt += 1; break;}
    }
    //for(int i=1; i<=n; i++) cout << dui[i] << ' ';
    //cout << endl;
    printf("%d\n",cnt*m);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]>i) printf("%s",s[i]+1);
    if(hui) printf("%s",s[hui]+1);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]<i) printf("%s",s[i]+1);
    printf("\n");
    return 0;
}


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

inline int read()
{
    int x=0,f=1;
    char ch = 0;
    while(!isdigit(ch)) {if(ch=='-') f = -1; ch = getchar();}
    while(isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();}
    return x*f;
}
inline int max(int a,int b) {return a>b?a:b;}
inline int min(int a,int b) {return a<b?a:b;}
typedef long long ll;

int n,m;
char s[102][60];
int dui[102];
int main()
{
    n = read(), m = read();
    for(int i=1; i<=n; i++)
        scanf("%s",s[i]+1);
    int flag;
    int cnt = 0;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        for(int j=i+1; j<=n; j++)
        {
            if(dui[j]) continue;
            flag = 1;
            for(int k=1; k<=m; k++)
            {
                if(s[i][k]!=s[j][m-k+1])
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            {
                dui[i] = j;
                dui[j] = i;
                cnt += 2;
                break;
            }
        }
    }
    int hui=0;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        hui = i;
        for(int j=1; j<=m; j++)
        {
            if(s[i][j]!=s[i][m-j+1])
            {
                hui = 0;
                break;
            }
        }
        if(hui) {cnt += 1; break;}
    }
    //for(int i=1; i<=n; i++) cout << dui[i] << ' ';
    //cout << endl;
    printf("%d\n",cnt*m);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]>i) printf("%s",s[i]+1);
    if(hui) printf("%s",s[hui]+1);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]<i) printf("%s",s[i]+1);
    printf("\n");
    return 0;
}


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

inline int read()
{
    int x=0,f=1;
    char ch = 0;
    while(!isdigit(ch)) {if(ch=='-') f = -1; ch = getchar();}
    while(isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();}
    return x*f;
}
inline int max(int a,int b) {return a>b?a:b;}
inline int min(int a,int b) {return a<b?a:b;}
typedef long long ll;

int n,m;
char s[102][60];
int dui[102];
int main()
{
    n = read(), m = read();
    for(int i=1; i<=n; i++)
        scanf("%s",s[i]+1);
    int flag;
    int cnt = 0;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        for(int j=i+1; j<=n; j++)
        {
            if(dui[j]) continue;
            flag = 1;
            for(int k=1; k<=m; k++)
            {
                if(s[i][k]!=s[j][m-k+1])
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            {
                dui[i] = j;
                dui[j] = i;
                cnt += 2;
                break;
            }
        }
    }
    int hui=0;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        hui = i;
        for(int j=1; j<=m; j++)
        {
            if(s[i][j]!=s[i][m-j+1])
            {
                hui = 0;
                break;
            }
        }
        if(hui) {cnt += 1; break;}
    }
    //for(int i=1; i<=n; i++) cout << dui[i] << ' ';
    //cout << endl;
    printf("%d\n",cnt*m);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]>i) printf("%s",s[i]+1);
    if(hui) printf("%s",s[hui]+1);
    for(int i=n; i>=1; i--)
        if(dui[i] && dui[i]>i) printf("%s",s[dui[i]]+1);
    printf("\n");
    return 0;
}


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

inline int read()
{
    int x=0,f=1;
    char ch = 0;
    while(!isdigit(ch)) {if(ch=='-') f = -1; ch = getchar();}
    while(isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();}
    return x*f;
}
inline int max(int a,int b) {return a>b?a:b;}
inline int min(int a,int b) {return a<b?a:b;}
typedef long long ll;

int n,m;
char s[102][60];
int dui[102];
int main()
{
    n = read(), m = read();
    for(int i=1; i<=n; i++)
        scanf("%s",s[i]+1);
    int flag;
    int cnt = 0;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        for(int j=i+1; j<=n; j++)
        {
            if(dui[j]) continue;
            flag = 1;
            for(int k=1; k<=m; k++)
            {
                if(s[i][k]!=s[j][m-k+1])
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            {
                dui[i] = j;
                dui[j] = i;
                cnt += 2;
                break;
            }
        }
    }
    int hui=0;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        hui = i;
        for(int j=1; j<=m/2; j++)
        {
            if(s[i][j]!=s[i][m-j+1])
            {
                hui = 0;
                break;
            }
        }
        if(hui) {cnt += 1; break;}
    }
    //for(int i=1; i<=n; i++) cout << dui[i] << ' ';
    //cout << endl;
    printf("%d\n",cnt*m);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]>i) printf("%s",s[i]+1);
    if(hui) printf("%s",s[hui]+1);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]<i) printf("%s",s[i]+1);
    printf("\n");
    return 0;
}


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

inline int read()
{
    int x=0,f=1;
    char ch = 0;
    while(!isdigit(ch)) {if(ch=='-') f = -1; ch = getchar();}
    while(isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();}
    return x*f;
}
inline int max(int a,int b) {return a>b?a:b;}
inline int min(int a,int b) {return a<b?a:b;}
typedef long long ll;

int n,m;
char s[102][60];
int dui[102];
int main()
{
    n = read(), m = read();
    for(int i=1; i<=n; i++)
        scanf("%s",s[i]+1);
    int flag;
    int cnt = 0;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        for(int j=i+1; j<=n; j++)
        {
            if(dui[j]) continue;
            flag = 1;
            for(int k=1; k<=m; k++)
            {
                if(s[i][k]!=s[j][m-k+1])
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            {
                dui[i] = j;
                dui[j] = i;
                cnt += 2;
                break;
            }
        }
    }
    int hui=0;
    for(int i=1; i<=n; i++)
    {
        if(dui[i]) continue;
        hui = i;
        for(int j=1; j<=m; j++)
        {
            if(s[i][j]!=s[i][m-j+1])
            {
                hui = 0;
                break;
            }
        }
        if(hui) {cnt += 1; break;}
    }
    //for(int i=1; i<=n; i++) cout << dui[i] << ' ';
    //cout << endl;
    printf("%d\n",cnt*m);
    for(int i=1; i<=n; i++)
        if(dui[i] && dui[i]>i) printf("%s",s[i]+1);
    if(hui) printf("%s",s[hui]+1);
    for(int i=n; i>=1; i--)
        if(dui[i] && dui[i]<i) printf("%s",s[i]+1);
    printf("\n");
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#define lli long long int
#define inf 1000000009
using namespace std;
long long int i,j,k;
int a[100005];
int b[100005];

int main()
{
    int n,m;
    cin>>n>>m;
    string s[n+1];
    string t[n+1];
    string p;
    map<string,int>mp;
    k = 0;
    int c = 0,mx=0;
    for(i=0; i<n; i++)
    {
        cin>>s[i];

    }
    for(i=0;i<n;i++)
    {
        string temp = s[i];
        reverse(temp.begin(),temp.end());
        for(j=0;j<n;j++)
        {
            if(temp==s[j]&&j!=i)
            {
                t[k]=s[i];
                k++;
                c++;
            }
            else if(temp==s[j]&&j==i)
            {
                mp[s[i]]++;
                if(mp[s[i]]>mx)
                    mx = max(mx,mp[s[i]]),p=s[i];
            }
        }
    }
    int ans ;
    ans = (k*m)+(mx*m);
    cout<<ans<<endl;
    sort(t,t+k);

    for(i=0;i<k;i++)
    {
       if(i%2==0)
       {
           cout<<t[i];
       }
    }
   for(i=0;i<mx;i++)
   {
       cout<<p;
   }
   for(i=k-1;i>0;i--)
   {
       if(i%2==1)
        cout<<t[i];
   }

}


#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#define lli long long int
#define inf 1000000009
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
long long int i,j,k;
int a[100005];
int b[100005];

int main()
{
    fast_cin;
    vector<string>v,a,b,c;
    map<string,int>mp;
    string st="";
    string s,p,t;
    int n,m;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>s;
        v.push_back(s);
    }
    int check = -1;
    for(i=0;i<n;i++)
    {
        string temp = v[i];
        reverse(temp.begin(),temp.end());
        for(j=0;j<n;j++)
        {
            if(temp==v[j]&&j!=i)
            {
                if(mp[v[j]]!=1)
                {
                 a.push_back(temp);
                 mp[temp]=1;
                 reverse(temp.begin(),temp.end());
                 b.push_back(temp);
                 mp[temp]=1;
                }
            }
            if(temp==v[j]&&j==i&&check==-1)
            {
               t = v[j];
               check = 1;
            }
        }
    }
    cout<<(a.size()*2*m)+(t.size())<<endl;
    vector<string>::iterator it;
    for(it=a.begin();it!=a.end();it++)
    {
        cout<<*it;
    }
    cout<<t;
    reverse(b.begin(),b.end());
    for(it=b.begin();it!=b.end();it++)
    {
        cout<<*it;
    }

}


#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#define lli long long int
#define inf 1000000009
using namespace std;
long long int i,j,k;
int a[100005];
int b[100005];

int main()
{
    vector<string>v,a,b,c;
    map<string,int>mp;
    string st="";
    string s,p,t;
    int n,m;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>s;
        v.push_back(s);
    }
    for(i=0;i<n;i++)
    {
        string temp = v[i];
        reverse(temp.begin(),temp.end());
        for(j=0;j<n;j++)
        {
            if(temp==v[j]&&j!=i)
            {
                if(mp[v[j]]!=1)
                {
                 a.push_back(temp);
                 mp[temp]=1;
                 reverse(temp.begin(),temp.end());
                 b.push_back(temp);
                 mp[temp]=1;
                }
            }
            if(temp==v[j]&&j==i)
            {
                t = st+v[j];
                p = t;
                reverse(t.begin(),t.end());
                if(t==p)
                {
                    st = st+v[j];
                }
            }
        }
    }
    cout<<(a.size()*2*m)+(st.size())<<endl;
    vector<string>::iterator it;
    for(it=a.begin();it!=a.end();it++)
    {
        cout<<*it;
    }
    cout<<st;
    reverse(b.begin(),b.end());
    for(it=b.begin();it!=b.end();it++)
    {
        cout<<*it;
    }

}


#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#define lli long long int
#define inf 1000000009
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
long long int i,j,k;
int a[100005];
int b[100005];

int main()
{
    fast_cin;
    vector<string>v,a,b,c;
    map<string,int>mp;
    string st="";
    string s,p,t;
    int n,m;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>s;
        v.push_back(s);
    }
    for(i=0;i<n;i++)
    {
        string temp = v[i];
        reverse(temp.begin(),temp.end());
        for(j=0;j<n;j++)
        {
            if(temp==v[j]&&j!=i)
            {
                if(mp[v[j]]!=1)
                {
                 a.push_back(temp);
                 mp[temp]=1;
                 reverse(temp.begin(),temp.end());
                 b.push_back(temp);
                 mp[temp]=1;
                }
            }
            if(temp==v[j]&&j==i)
            {
                t = st+v[j];
                p = t;
                reverse(t.begin(),t.end());
                if(t==p)
                {
                    st = st+v[j];
                }
            }
        }
    }
    cout<<(a.size()*2*m)+(st.size())<<endl;
    vector<string>::iterator it;
    for(it=a.begin();it!=a.end();it++)
    {
        cout<<*it;
    }
    cout<<st;
    reverse(b.begin(),b.end());
    for(it=b.begin();it!=b.end();it++)
    {
        cout<<*it;
    }

}


#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#define lli long long int
#define inf 1000000009
using namespace std;
long long int i,j,k;
int a[100005];
int b[100005];

int main()
{
    int n,m;
    cin>>n>>m;
    string s[n+1];
    string t[n+1];
    string p;
    map<string,int>mp;
    k = 0;
    int c = 0,mx=0;
    for(i=0; i<n; i++)
    {
        cin>>s[i];

    }
    for(i=0;i<n;i++)
    {
        string temp = s[i];
        reverse(temp.begin(),temp.end());
        for(j=0;j<n;j++)
        {
            if(temp==s[j]&&j!=i)
            {
                t[k]=s[i];
                k++;
                c++;
            }
            else if(temp==s[j]&&j==i)
            {
                mp[s[i]]++;
                if(mp[s[i]]>mx)
                    mx = max(mx,mp[s[i]]),p=s[i];
            }
        }
    }
    int ans ;
    ans = (k*m)+(mx*m);
    cout<<ans<<endl;
    sort(t,t+k);

    for(i=0;i<k;i++)
    {
       if(i%2==0)
       {
           cout<<t[i];
       }
    }
   for(i=0;i<mx;i++)
   {
       cout<<p;
   }
   for(i=k;i>0;i--)
   {
       if(i%2==1)
        cout<<t[i];
   }

}


#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#define lli long long int
#define inf 1000000009
using namespace std;
long long int i,j,k;
int a[100005];
int b[100005];

int main()
{
    int n,m;
    cin>>n>>m;
    string s[n+1];
    string t[n+1];
    string p;
    map<string,int>mp;
    k = 0;
    int c = 0,mx=0;
    for(i=0; i<n; i++)
    {
        cin>>s[i];
    }
    int flag = 0;
    for(i=0; i<n; i++)
    {
        string temp = s[i];
        reverse(temp.begin(),temp.end());
        for(j=0; j<n; j++)
        {
            if(temp==s[j]&&j!=i)
            {
                t[k]=s[i];
                k++;
                flag = 1;
            }
            else if(temp==s[j]&&j==i)
            {
                mp[s[i]]++;
                if(mp[s[i]]>mx)
                    mx = max(mx,mp[s[i]]),p=s[i];
            }
        }
    }

    int ans ;
    ans = (k*m)+(mx*m);
    cout<<ans<<endl;
    sort(t,t+k);

    for(i=0; i<k; i++)
    {
        if(i%2==0)
        {
            cout<<t[i];
        }
    }
    if(flag==1)
    {
        for(i=0; i<mx; i++)
        {

            cout<<p;
        }

    }

    for(i=k; i>0; i--)
    {
        if(i%2==1)
            cout<<t[i];
    }

}


#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#define lli long long int
#define inf 1000000009
using namespace std;
long long int i,j,k;
int a[100005];
int b[100005];

int main()
{
    vector<string>v,a,b,c;
    map<string,int>mp;
    string st="";
    string s,p,t;
    int n,m;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>s;
        v.push_back(s);
    }
    for(i=0;i<n;i++)
    {
        string temp = v[i];
        reverse(temp.begin(),temp.end());
        for(j=0;j<n;j++)
        {
            if(temp==v[j]&&j!=i)
            {

                 a.push_back(temp);
                 reverse(temp.begin(),temp.end());
                 b.push_back(temp);
                 i = j+1;

            }
            if(temp==v[j]&&j==i)
            {
                t = st+v[j];
                p = t;
                reverse(t.begin(),t.end());
                if(t==p)
                {
                    st = st+v[j];
                }
            }
        }
    }
    cout<<(a.size()*2*m)+(st.size())<<endl;
    vector<string>::iterator it;
    for(it=a.begin();it!=a.end();it++)
    {
        cout<<*it;
    }
    cout<<st;
    reverse(b.begin(),b.end());
    for(it=b.begin();it!=b.end();it++)
    {
        cout<<*it;
    }

}


#include<bits/stdc++.h>                   /*--------------->Logic%2==0---------------->*/
#define CASE(t)                 printf("Case %d: ",t)
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                ((a)*(b))/gcd(a,b)
#define PI                      2*acos(0.0)
#define ll                      long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,p=0,i,j;
    cin>>n>>m;
    vector<string>vv,sec;
    string s,ss,sss,a,v="",fst="";
    for(i=0; i<n; i++)
    {
        cin>>s;
        a=s;
        reverse(a.begin(),a.end());
        ss=a;
        if(ss==s && p==0)
        {
            v+=s;
            p=1;
        }
        else
        {
            vv.push_back(s);
        }

    }
    if(n==1 && p==1)
    {
        cout<<m<<endl;
        cout<<v<<endl;
        return 0;
    }
    if(n==1 && p==0)
    {
        cout<<0<<endl;
        return 0;
    }
    string x="123",t;
    for(i=0; i<vv.size()-1; i++)
    {
        reverse(vv[i].begin(),vv[i].end());
        sss=vv[i];

        for(j=i+1; j<vv.size(); j++)
        {

            if(sss==vv[j])
            {
                sec.push_back(sss);
                reverse(vv[j].begin(),vv[j].end());
                t=vv[j];
                fst+=t;
                x=x+'6';
                vv[i]=x;
                x=x+'7';
                vv[j]=x;
                break;
            }
        }
    }
    string mx_len="";
    if(fst.size()>0)
    {
        mx_len+=fst;
    }
    if(v.size()>0)
    {
        mx_len+=v;
    }
    if(sec.size()>0)
    {
        for(i=sec.size()-1;i>=0;i--)
        {
            mx_len+=sec[i];
        }
    }
    cout<<mx_len.size()<<endl;
    cout<<mx_len<<endl;
    /*---------->HaPpY CoDiNg----------->*/
    return 0;
}


#include<bits/stdc++.h>                   /*--------------->Logic%2==0---------------->*/
#define CASE(t)                 printf("Case %d: ",t)
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                ((a)*(b))/gcd(a,b)
#define PI                      2*acos(0.0)
#define ll                      long long int
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n,m,p=0,i,j;
cin>>n>>m;
vector<string>vv;
string s,ss,sss,a,v="",fst="",sec="";
for(i=0;i<n;i++)
{
    cin>>s;
a=s;
reverse(a.begin(),a.end());
ss=a;
if(ss==s && p==0)
{
    v+=s;
    p=1;
}
else{
    vv.push_back(s);
}

}
//cout<<v[0]<<"#"<<endl;
string x="123",t;
for(i=0;i<vv.size()-1;i++)
{
    reverse(vv[i].begin(),vv[i].end());
    sss=vv[i];

    for(j=i+1;j<vv.size();j++)
    {

        if(sss==vv[j])
        {
             cout<<sss<<" "<<vv[j]<<"*"<<endl;
            fst+=sss;
            reverse(vv[j].begin(),vv[j].end());
            t+=vv[j];
            sec+=t;;
            x=x+'6';
            vv[i]=x;
            x=x+'7';
            vv[j]=x;
            break;
        }
    }
}
string mx_len="";
if(t.size()>0)
{
    mx_len+=t;
}
if(v.size()>0)
{
    mx_len+=v;
}
if(fst.size()>0)
{
    mx_len+=fst;
}
cout<<mx_len.size()<<endl;
cout<<mx_len<<endl;
/*---------->HaPpY CoDiNg----------->*/
return 0;
}


#include<bits/stdc++.h>                   /*--------------->Logic%2==0---------------->*/
#define CASE(t)                 printf("Case %d: ",t)
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                ((a)*(b))/gcd(a,b)
#define PI                      2*acos(0.0)
#define ll                      long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,p=0,i,j;
    cin>>n>>m;
    vector<string>vv;
    string s,ss,sss,a,v="",fst="",sec="";
    for(i=0; i<n; i++)
    {
        cin>>s;
        a=s;
        reverse(a.begin(),a.end());
        ss=a;
        if(ss==s && p==0)
        {
            v+=s;
            p=1;
        }
        else
        {
            vv.push_back(s);
        }

    }
    string x="123",t;
    for(i=0; i<vv.size()-1; i++)
    {
        reverse(vv[i].begin(),vv[i].end());
        sss=vv[i];

        for(j=i+1; j<vv.size(); j++)
        {

            if(sss==vv[j])
            {
                fst+=sss;
                reverse(vv[j].begin(),vv[j].end());
                t+=vv[j];
                sec+=t;;
                x=x+'6';
                vv[i]=x;
                x=x+'7';
                vv[j]=x;
                break;
            }
        }
    }
    string mx_len="";
    if(t.size()>0)
    {
        mx_len+=t;
    }
    if(v.size()>0)
    {
        mx_len+=v;
    }
    if(fst.size()>0)
    {
        mx_len+=fst;
    }
    cout<<mx_len.size()<<endl;
    cout<<mx_len<<endl;
    /*---------->HaPpY CoDiNg----------->*/
    return 0;
}