#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define fr(i,s,e) for(int i=s;i<e;++i)
#define fr1(i,s,e) for(int i=s;i>e;--i)
#define p0(a) cout << a <<" "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define INF (ll)1e18 + 100
#define v(d) vector<d>
#define pr pair<int, int>
#define pr1(d1,d2) pair<d1,d2>
#define pb push_back
#define f first
#define s second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void debug_arr(vector<int> &a){
	int len = a.size();
	fr(i,0,len){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}

const int  mod = 1e9 +7;
const int mod1= 998244353;
int n,k;
v(v(int)) graph;
v(int) course;
v(int) ans,color; // 0 white 1 grey 2 black
int cycle=0;

void dfs(int s){
	color[s]=1;
	for(auto v:graph[s]){
		if(color[v]==0){
			color[v] = 1;
			dfs(v);
			color[v]=2;
		}
		else if (color[v]==1){ cycle=1; }
	}
	color[s]=2;
	ans.pb(s);
}

void solve(){
cin>>n>>k;
color.resize(n+1);
graph.resize(n+1);

course.resize(k);
fr(i,0,k){
	cin>>course[i];
}
fr(i,1,n+1){
int a; cin>>a;
fr(j,0,a){
	int x; cin>>x;
	graph[i].pb(x);

}
}
fr(i,0,k){
	if(!color[course[i]] && !cycle) {
		dfs(course[i]);

	}
}
if(cycle) {cout<<-1<<endl; return;}

cout<<ans.size()<<endl;
debug_arr(ans);

  return;} // solve ends

signed main() {
	// your code goes here
	fast
	//int t; cin>>t; while(t--)
	{solve();}

	return 0;
}

/*

___________________▄▄▄▀▀▀▀▀▀▀▄
 _______________▄▀▀____▀▀▀▀▄____█
 ___________▄▀▀__▀▀▀▀▀▀▄___▀▄___█
 __________█▄▄▄▄▄▄_______▀▄__▀▄__█
 _________█_________▀▄______█____█_█
 ______▄█_____________▀▄_____▐___▐_▌
 ______██_______________▀▄___▐_▄▀▀▀▄
 ______█________██_______▌__▐▄▀______█
 ______█_________█_______▌__▐▐________▐
 _____▐__________▌_____▄▀▀▀__▌_______▐_____________▄▄▄▄▄▄
 ______▌__________▀▀▀▀________▀▀▄▄▄▀______▄▄████▓▓▓▓▓▓▓███▄
 ______▌____________________________▄▀__▄▄█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄
 ______▐__________________________▄▀_▄█▓▓▓▓▓▓▓▓▓▓_____▓▓____▓▓█▄
 _______▌______________________▄▀_▄█▓▓▓▓▓▓▓▓▓▓▓____▓▓_▓▓_▓▓__▓▓█
 _____▄▀▄_________________▄▀▀▌██▓▓▓▓▓▓▓▓▓▓▓▓▓__▓▓▓___▓▓_▓▓__▓▓█
 ____▌____▀▀▀▄▄▄▄▄▄▄▄▀▀___▌█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓__▓________▓▓___▓▓▓█
 _____▀▄_________________▄▀▀▓▓▓▓▓▓▓▓█████████████▄▄_____▓▓__▓▓▓█
 _______█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▄▄___▓▓▓▓▓█
 _______█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓███▓▓▓▓████▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▓▓▓▓▓█
 ________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓█▓▓██░░███████░██▓▓▓▓▓▓▓▓▓▓██▓▓▓▓▓█
 ________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓░░░░░█░░░░░██░░░░██▓▓▓▓▓▓▓▓▓██▓▓▓▓▌
 ________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓███░░░░░░░░____░██░░░░░░░██▓▓▓▓▓▓▓██▓▓▌
 ________▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓██░░░░░░░________░░░░░░░░░██████▓▓▓▓▓█▓▌
 ________▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓██░░░░░░___▓▓▓▓▓░░░░░░░███░░███▓▓▓▓▓█▓▌
 _________█▓▓▓▓▓▓▓▓▓▓▓▓▓██░░░░░___▓▓█▄▄▓░░░░░░░░___░░░░█▓▓▓▓▓█▓▌
 _________█▓▓▓▓▓▓▓▓▓▓▓▓▓█░░█░░░___▓▓██░░░░░░░░▓▓▓▓__░░░░█▓▓▓▓██
 _________█▓▓▓▓▓▓▓▓▓▓▓▓▓█░███░░____▓░░░░░░░░░░░█▄█▓__░░░░█▓▓█▓█
 _________▐▓▓▓▓▓▓▓▓▓▓▓▓▓█░█████░░░░░░░░░░░░░░░░░█▓__░░░░███▓█
 __________█▓▓▓▓▓▓▓▓▓▓▓▓█░░███████░░░░░░░░░░░░░░░▓_░░░░░██▓█
 __________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░███████░░░░░░░░░░░░░░_░░░░░██▓█
 __________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░███████░░░░░░░░░░░░░░░░░░░██▓█
 ___________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░░███████░░░░░░░░░░░█████░██░░░
 ___________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░░░░__███████░░░░░███████░░█░░░░
 ___________█▓▓▓▓▓▓▓▓▓▓▓▓▓█░░░░░░█▄▄▄▀▀▀▀████████████░░█░░░░
 ___________▐▓▓▓▓▓▓▓▓▓▓▓▓█░░░░░░██████▄__▀▀░░░███░░░░░█░░░
 ___________▐▓▓▓▓▓▓▓▓▓▓▓█▒█░░░░░░▓▓▓▓▓███▄░░░░░░░░░░░░░░░______▄▄▄
 ___________█▓▓▓▓▓▓▓▓▓█▒▒▒▒█░░░░░░▓▓▓▓▓█░░░░░░░░░░░░░░░▄▄▄_▄▀▀____▀▄
 __________█▓▓▓▓▓▓▓▓▓█▒▒▒▒█▓▓░░░░░░░░░░░░░░░░░░░░░____▄▀____▀▄_________▀▄
 _________█▓▓▓▓▓▓▓▓▓█▒▒▒▒█▓▓▓▓░░░░░░░░░░░░░░░░░______▐▄________█▄▄▀▀▀▄__█
 ________█▓▓▓▓▓▓▓▓█▒▒▒▒▒▒█▓▓▓▓▓▓▓░░░░░░░░░____________█_█______▐_________▀▄▌
 _______█▓▓▓▓▓▓▓▓█▒▒▒▒▒▒███▓▓▓▓▓▓▓▓▓▓▓█▒▒▄___________█__▀▄____█____▄▄▄____▐
 ______█▓▓▓▓▓▓▓█_______▒▒█▒▒██▓▓▓▓▓▓▓▓▓▓█▒▒▒▄_________█____▀▀█▀▄▀▀▀___▀▀▄▄▐
 _____█▓▓▓▓▓██▒_________▒█▒▒▒▒▒███▓▓▓▓▓▓█▒▒▒██________▐_______▀█_____________█
 ____█▓▓████▒█▒_________▒█▒▒▒▒▒▒▒▒███████▒▒▒▒██_______█_______▐______▄▄▄_____█
 __█▒██▒▒▒▒▒▒█▒▒____▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒____▒█▓█__▄█__█______▀▄▄▀▀____▀▀▄▄█
 __█▒▒▒▒▒▒▒▒▒▒█▒▒▒████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▓▓█▓▓▌_▐________▐____________▐
 __█▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒_______█▓▓▓█▓▌__▌_______▐_____▄▄____▐
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒_____█▓▓▓█▓▓▌__▌_______▀▄▄▀______▐
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████▓▓█▓▓▓▌__▀▄_______________▄▀
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒██▓▓▓▓▓▌___▀▄_________▄▀▀
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒█▓▓▓▓▓▀▄__▀▄▄█▀▀▀
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▓▓▓██▄▄▄▀
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▄▄▄▄▄
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒██▄▄
 __█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒█▄
 __█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 __█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 ___█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒▌
 ____█▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░▒▒▌
 ____█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█████████████▒▒▒▒▒█▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒░▒▌
 _____█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______▐▒▒▒▒█▒▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▌
 ______█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒█▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
 _______█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒█▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
 ________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒▒░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀
 __________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▒░░░▒▒▒▒▒░░░░░░░░▒▒▒█▀▀▀
 ___________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█░▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░█▀
 ____________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀
 _____________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▒▒▒▒▒▒▒▒▒▒▒▒█▀
 _____________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______▀▀▀███████▀▀
 ______________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _______________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 ________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 __________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒█
 ___________________█▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒█
 ___________________█▒▒▒▒▒▒▒▒████▒▒▒▒▒▒▒█
 ___________________█████████▒▒▒▒▒▒▒▒▒▒▒█
 ____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 ____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▌
 _____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▌
 ______________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▌
 _______________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░█
 ________________________█▒▒▒▒▒▒▒▒▒▒▒░░░█
 __________________________██▒▒▒▒▒▒░░░█▀
 _____________________________█░░░░░█▀
 _______________________________▀▀▀▀

 */


#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define fr(i,s,e) for(int i=s;i<e;++i)
#define fr1(i,s,e) for(int i=s;i>e;--i)
#define p0(a) cout << a <<" "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define INF (ll)1e18 + 100
#define v(d) vector<d>
#define pr pair<int, int>
#define pr1(d1,d2) pair<d1,d2>
#define pb push_back
#define f first
#define s second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void debug_arr(vector<int> &a){
	int len = a.size();
	fr(i,0,len){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}

const int  mod = 1e9 +7;
const int mod1= 998244353;
int n,k;
v(v(int)) graph;
v(bool) vis;
v(int) course;
v(int) ans,entry;
int f=1;
bool isbackedge(int u, int v){
	return (entry[v] < entry[u]);
}
void dfs(int s){
	vis[s]=true;
	for(auto v:graph[s]){
		if(!vis[v]){
			entry[v] = entry[s]+1;
			dfs(v);
		}
		else{ if(isbackedge(s,v))f=0;}
	}
	ans.pb(s);
}

void solve(){
cin>>n>>k;
entry.resize(n+1);
graph.resize(n+1);
vis.resize(n+1);

course.resize(k);
fr(i,0,k){
	cin>>course[i];
}
fr(i,1,n+1){
int a; cin>>a;
fr(j,0,a){
	int x; cin>>x;
	graph[i].pb(x);

}
}
fr(i,0,k){
	if(!vis[course[i]]) {
		entry[course[i]]=1;
		dfs(course[i]);

	}
}
if(!f) {cout<<-1<<endl; return;}

cout<<ans.size()<<endl;
debug_arr(ans);

  return;} // solve ends

signed main() {
	// your code goes here
	fast
	//int t; cin>>t; while(t--)
	{solve();}

	return 0;
}

/*

___________________▄▄▄▀▀▀▀▀▀▀▄
 _______________▄▀▀____▀▀▀▀▄____█
 ___________▄▀▀__▀▀▀▀▀▀▄___▀▄___█
 __________█▄▄▄▄▄▄_______▀▄__▀▄__█
 _________█_________▀▄______█____█_█
 ______▄█_____________▀▄_____▐___▐_▌
 ______██_______________▀▄___▐_▄▀▀▀▄
 ______█________██_______▌__▐▄▀______█
 ______█_________█_______▌__▐▐________▐
 _____▐__________▌_____▄▀▀▀__▌_______▐_____________▄▄▄▄▄▄
 ______▌__________▀▀▀▀________▀▀▄▄▄▀______▄▄████▓▓▓▓▓▓▓███▄
 ______▌____________________________▄▀__▄▄█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄
 ______▐__________________________▄▀_▄█▓▓▓▓▓▓▓▓▓▓_____▓▓____▓▓█▄
 _______▌______________________▄▀_▄█▓▓▓▓▓▓▓▓▓▓▓____▓▓_▓▓_▓▓__▓▓█
 _____▄▀▄_________________▄▀▀▌██▓▓▓▓▓▓▓▓▓▓▓▓▓__▓▓▓___▓▓_▓▓__▓▓█
 ____▌____▀▀▀▄▄▄▄▄▄▄▄▀▀___▌█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓__▓________▓▓___▓▓▓█
 _____▀▄_________________▄▀▀▓▓▓▓▓▓▓▓█████████████▄▄_____▓▓__▓▓▓█
 _______█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▄▄___▓▓▓▓▓█
 _______█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓███▓▓▓▓████▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▓▓▓▓▓█
 ________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓█▓▓██░░███████░██▓▓▓▓▓▓▓▓▓▓██▓▓▓▓▓█
 ________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓░░░░░█░░░░░██░░░░██▓▓▓▓▓▓▓▓▓██▓▓▓▓▌
 ________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓███░░░░░░░░____░██░░░░░░░██▓▓▓▓▓▓▓██▓▓▌
 ________▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓██░░░░░░░________░░░░░░░░░██████▓▓▓▓▓█▓▌
 ________▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓██░░░░░░___▓▓▓▓▓░░░░░░░███░░███▓▓▓▓▓█▓▌
 _________█▓▓▓▓▓▓▓▓▓▓▓▓▓██░░░░░___▓▓█▄▄▓░░░░░░░░___░░░░█▓▓▓▓▓█▓▌
 _________█▓▓▓▓▓▓▓▓▓▓▓▓▓█░░█░░░___▓▓██░░░░░░░░▓▓▓▓__░░░░█▓▓▓▓██
 _________█▓▓▓▓▓▓▓▓▓▓▓▓▓█░███░░____▓░░░░░░░░░░░█▄█▓__░░░░█▓▓█▓█
 _________▐▓▓▓▓▓▓▓▓▓▓▓▓▓█░█████░░░░░░░░░░░░░░░░░█▓__░░░░███▓█
 __________█▓▓▓▓▓▓▓▓▓▓▓▓█░░███████░░░░░░░░░░░░░░░▓_░░░░░██▓█
 __________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░███████░░░░░░░░░░░░░░_░░░░░██▓█
 __________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░███████░░░░░░░░░░░░░░░░░░░██▓█
 ___________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░░███████░░░░░░░░░░░█████░██░░░
 ___________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░░░░__███████░░░░░███████░░█░░░░
 ___________█▓▓▓▓▓▓▓▓▓▓▓▓▓█░░░░░░█▄▄▄▀▀▀▀████████████░░█░░░░
 ___________▐▓▓▓▓▓▓▓▓▓▓▓▓█░░░░░░██████▄__▀▀░░░███░░░░░█░░░
 ___________▐▓▓▓▓▓▓▓▓▓▓▓█▒█░░░░░░▓▓▓▓▓███▄░░░░░░░░░░░░░░░______▄▄▄
 ___________█▓▓▓▓▓▓▓▓▓█▒▒▒▒█░░░░░░▓▓▓▓▓█░░░░░░░░░░░░░░░▄▄▄_▄▀▀____▀▄
 __________█▓▓▓▓▓▓▓▓▓█▒▒▒▒█▓▓░░░░░░░░░░░░░░░░░░░░░____▄▀____▀▄_________▀▄
 _________█▓▓▓▓▓▓▓▓▓█▒▒▒▒█▓▓▓▓░░░░░░░░░░░░░░░░░______▐▄________█▄▄▀▀▀▄__█
 ________█▓▓▓▓▓▓▓▓█▒▒▒▒▒▒█▓▓▓▓▓▓▓░░░░░░░░░____________█_█______▐_________▀▄▌
 _______█▓▓▓▓▓▓▓▓█▒▒▒▒▒▒███▓▓▓▓▓▓▓▓▓▓▓█▒▒▄___________█__▀▄____█____▄▄▄____▐
 ______█▓▓▓▓▓▓▓█_______▒▒█▒▒██▓▓▓▓▓▓▓▓▓▓█▒▒▒▄_________█____▀▀█▀▄▀▀▀___▀▀▄▄▐
 _____█▓▓▓▓▓██▒_________▒█▒▒▒▒▒███▓▓▓▓▓▓█▒▒▒██________▐_______▀█_____________█
 ____█▓▓████▒█▒_________▒█▒▒▒▒▒▒▒▒███████▒▒▒▒██_______█_______▐______▄▄▄_____█
 __█▒██▒▒▒▒▒▒█▒▒____▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒____▒█▓█__▄█__█______▀▄▄▀▀____▀▀▄▄█
 __█▒▒▒▒▒▒▒▒▒▒█▒▒▒████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▓▓█▓▓▌_▐________▐____________▐
 __█▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒_______█▓▓▓█▓▌__▌_______▐_____▄▄____▐
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒_____█▓▓▓█▓▓▌__▌_______▀▄▄▀______▐
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████▓▓█▓▓▓▌__▀▄_______________▄▀
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒██▓▓▓▓▓▌___▀▄_________▄▀▀
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒█▓▓▓▓▓▀▄__▀▄▄█▀▀▀
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▓▓▓██▄▄▄▀
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▄▄▄▄▄
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒██▄▄
 __█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒█▄
 __█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 __█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 ___█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒▌
 ____█▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░▒▒▌
 ____█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█████████████▒▒▒▒▒█▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒░▒▌
 _____█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______▐▒▒▒▒█▒▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▌
 ______█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒█▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
 _______█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒█▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
 ________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒▒░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀
 __________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▒░░░▒▒▒▒▒░░░░░░░░▒▒▒█▀▀▀
 ___________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█░▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░█▀
 ____________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀
 _____________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▒▒▒▒▒▒▒▒▒▒▒▒█▀
 _____________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______▀▀▀███████▀▀
 ______________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _______________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 ________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 __________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒█
 ___________________█▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒█
 ___________________█▒▒▒▒▒▒▒▒████▒▒▒▒▒▒▒█
 ___________________█████████▒▒▒▒▒▒▒▒▒▒▒█
 ____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 ____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▌
 _____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▌
 ______________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▌
 _______________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░█
 ________________________█▒▒▒▒▒▒▒▒▒▒▒░░░█
 __________________________██▒▒▒▒▒▒░░░█▀
 _____________________________█░░░░░█▀
 _______________________________▀▀▀▀

 */


#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define fr(i,s,e) for(int i=s;i<e;++i)
#define fr1(i,s,e) for(int i=s;i>e;--i)
#define p0(a) cout << a <<" "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define INF (ll)1e18 + 100
#define v(d) vector<d>
#define pr pair<int, int>
#define pr1(d1,d2) pair<d1,d2>
#define pb push_back
#define f first
#define s second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void debug_arr(vector<int> &a){
	int len = a.size();
	fr(i,0,len){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}

const int  mod = 1e9 +7;
const int mod1= 998244353;
int n,k;
v(v(int)) graph;
v(bool) vis;
v(int) course;
v(int) ans;
int f=1;
void dfs(int s){
	vis[s]=true;
	for(auto v:graph[s]){
		if(!vis[v]){
			dfs(v);
		}
		else{ f=0;}
	}
	ans.pb(s);
}

void solve(){
cin>>n>>k;
graph.resize(n+1);
vis.resize(n+1);
course.resize(k);
fr(i,0,k){
	cin>>course[i];
}
fr(i,1,n+1){
int a; cin>>a;
fr(j,0,a){
	int x; cin>>x;
	graph[i].pb(x);

}
}
fr(i,0,k){
	if(!vis[course[i]]) {
		dfs(course[i]);
	}
}
if(!f) {cout<<-1<<endl; return;}

cout<<ans.size()<<endl;
debug_arr(ans);

  return;} // solve ends

signed main() {
	// your code goes here
	fast
	//int t; cin>>t; while(t--)
	{solve();}

	return 0;
}

/*

___________________▄▄▄▀▀▀▀▀▀▀▄
 _______________▄▀▀____▀▀▀▀▄____█
 ___________▄▀▀__▀▀▀▀▀▀▄___▀▄___█
 __________█▄▄▄▄▄▄_______▀▄__▀▄__█
 _________█_________▀▄______█____█_█
 ______▄█_____________▀▄_____▐___▐_▌
 ______██_______________▀▄___▐_▄▀▀▀▄
 ______█________██_______▌__▐▄▀______█
 ______█_________█_______▌__▐▐________▐
 _____▐__________▌_____▄▀▀▀__▌_______▐_____________▄▄▄▄▄▄
 ______▌__________▀▀▀▀________▀▀▄▄▄▀______▄▄████▓▓▓▓▓▓▓███▄
 ______▌____________________________▄▀__▄▄█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▄
 ______▐__________________________▄▀_▄█▓▓▓▓▓▓▓▓▓▓_____▓▓____▓▓█▄
 _______▌______________________▄▀_▄█▓▓▓▓▓▓▓▓▓▓▓____▓▓_▓▓_▓▓__▓▓█
 _____▄▀▄_________________▄▀▀▌██▓▓▓▓▓▓▓▓▓▓▓▓▓__▓▓▓___▓▓_▓▓__▓▓█
 ____▌____▀▀▀▄▄▄▄▄▄▄▄▀▀___▌█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓__▓________▓▓___▓▓▓█
 _____▀▄_________________▄▀▀▓▓▓▓▓▓▓▓█████████████▄▄_____▓▓__▓▓▓█
 _______█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▄▄___▓▓▓▓▓█
 _______█▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓███▓▓▓▓████▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▓▓▓▓▓█
 ________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓█▓█▓▓██░░███████░██▓▓▓▓▓▓▓▓▓▓██▓▓▓▓▓█
 ________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓░░░░░█░░░░░██░░░░██▓▓▓▓▓▓▓▓▓██▓▓▓▓▌
 ________█▓▓▓▓▓▓▓▓▓▓▓▓▓▓███░░░░░░░░____░██░░░░░░░██▓▓▓▓▓▓▓██▓▓▌
 ________▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓██░░░░░░░________░░░░░░░░░██████▓▓▓▓▓█▓▌
 ________▐▓▓▓▓▓▓▓▓▓▓▓▓▓▓██░░░░░░___▓▓▓▓▓░░░░░░░███░░███▓▓▓▓▓█▓▌
 _________█▓▓▓▓▓▓▓▓▓▓▓▓▓██░░░░░___▓▓█▄▄▓░░░░░░░░___░░░░█▓▓▓▓▓█▓▌
 _________█▓▓▓▓▓▓▓▓▓▓▓▓▓█░░█░░░___▓▓██░░░░░░░░▓▓▓▓__░░░░█▓▓▓▓██
 _________█▓▓▓▓▓▓▓▓▓▓▓▓▓█░███░░____▓░░░░░░░░░░░█▄█▓__░░░░█▓▓█▓█
 _________▐▓▓▓▓▓▓▓▓▓▓▓▓▓█░█████░░░░░░░░░░░░░░░░░█▓__░░░░███▓█
 __________█▓▓▓▓▓▓▓▓▓▓▓▓█░░███████░░░░░░░░░░░░░░░▓_░░░░░██▓█
 __________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░███████░░░░░░░░░░░░░░_░░░░░██▓█
 __________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░███████░░░░░░░░░░░░░░░░░░░██▓█
 ___________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░░███████░░░░░░░░░░░█████░██░░░
 ___________█▓▓▓▓▓▓▓▓▓▓▓▓█░░░░░░__███████░░░░░███████░░█░░░░
 ___________█▓▓▓▓▓▓▓▓▓▓▓▓▓█░░░░░░█▄▄▄▀▀▀▀████████████░░█░░░░
 ___________▐▓▓▓▓▓▓▓▓▓▓▓▓█░░░░░░██████▄__▀▀░░░███░░░░░█░░░
 ___________▐▓▓▓▓▓▓▓▓▓▓▓█▒█░░░░░░▓▓▓▓▓███▄░░░░░░░░░░░░░░░______▄▄▄
 ___________█▓▓▓▓▓▓▓▓▓█▒▒▒▒█░░░░░░▓▓▓▓▓█░░░░░░░░░░░░░░░▄▄▄_▄▀▀____▀▄
 __________█▓▓▓▓▓▓▓▓▓█▒▒▒▒█▓▓░░░░░░░░░░░░░░░░░░░░░____▄▀____▀▄_________▀▄
 _________█▓▓▓▓▓▓▓▓▓█▒▒▒▒█▓▓▓▓░░░░░░░░░░░░░░░░░______▐▄________█▄▄▀▀▀▄__█
 ________█▓▓▓▓▓▓▓▓█▒▒▒▒▒▒█▓▓▓▓▓▓▓░░░░░░░░░____________█_█______▐_________▀▄▌
 _______█▓▓▓▓▓▓▓▓█▒▒▒▒▒▒███▓▓▓▓▓▓▓▓▓▓▓█▒▒▄___________█__▀▄____█____▄▄▄____▐
 ______█▓▓▓▓▓▓▓█_______▒▒█▒▒██▓▓▓▓▓▓▓▓▓▓█▒▒▒▄_________█____▀▀█▀▄▀▀▀___▀▀▄▄▐
 _____█▓▓▓▓▓██▒_________▒█▒▒▒▒▒███▓▓▓▓▓▓█▒▒▒██________▐_______▀█_____________█
 ____█▓▓████▒█▒_________▒█▒▒▒▒▒▒▒▒███████▒▒▒▒██_______█_______▐______▄▄▄_____█
 __█▒██▒▒▒▒▒▒█▒▒____▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒____▒█▓█__▄█__█______▀▄▄▀▀____▀▀▄▄█
 __█▒▒▒▒▒▒▒▒▒▒█▒▒▒████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▓▓█▓▓▌_▐________▐____________▐
 __█▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒_______█▓▓▓█▓▌__▌_______▐_____▄▄____▐
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒_____█▓▓▓█▓▓▌__▌_______▀▄▄▀______▐
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████▓▓█▓▓▓▌__▀▄_______________▄▀
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒██▓▓▓▓▓▌___▀▄_________▄▀▀
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒█▓▓▓▓▓▀▄__▀▄▄█▀▀▀
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▓▓▓██▄▄▄▀
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████
 █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▄▄▄▄▄
 _█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒██▄▄
 __█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒█▄
 __█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 __█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 ___█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒▌
 ____█▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒█▒▒▒▒█▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░░▒▒▌
 ____█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█████████████▒▒▒▒▒█▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒░▒▌
 _____█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______▐▒▒▒▒█▒▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▌
 ______█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒█▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
 _______█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒█▒▒▒▒▒▒░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌
 ________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒▒▒░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█________█▒▒▒░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀
 __________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▒░░░▒▒▒▒▒░░░░░░░░▒▒▒█▀▀▀
 ___________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█░▒▒▒▒▒▒▒▒▒▒▒▒▒░░░░█▀
 ____________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀
 _____________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______█▒▒▒▒▒▒▒▒▒▒▒▒█▀
 _____________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█_______▀▀▀███████▀▀
 ______________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _______________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 ________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 __________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒█
 ___________________█▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒█
 ___________________█▒▒▒▒▒▒▒▒████▒▒▒▒▒▒▒█
 ___________________█████████▒▒▒▒▒▒▒▒▒▒▒█
 ____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 ____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
 _____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▌
 _____________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▌
 ______________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░▌
 _______________________█▒▒▒▒▒▒▒▒▒▒▒▒▒▒░░█
 ________________________█▒▒▒▒▒▒▒▒▒▒▒░░░█
 __________________________██▒▒▒▒▒▒░░░█▀
 _____________________________█░░░░░█▀
 _______________________________▀▀▀▀

 */


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

int n, k, cnt;
vector<int> graph[100010], other[100010], order, indeg(100010), visit(100010);
#define check(c)       cout<<#c<<" : "<<c<<endl;
#define check2(a, b)    cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<endl;

bool topoSort(){
    for(int i = 1; i <= n; ++i){
        for(auto x : graph[i]){
            ++indeg[x];
        }
    }

    queue<int> q;
    for(int i = 1; i <= n; i++){
        if(!indeg[i])
            q.push(i);
    }

    while(!q.empty()){
        int frt = q.front();
        order.push_back(frt);
        q.pop();
        for(int x : graph[frt]){
            --indeg[x];
            if(!indeg[x])
                q.push(x);
        }
    }
    return (order.size() == n);
}

void dfs(int node){
    visit[node] = 1;
    cnt += 1;
    for(auto x : other[node]){
        if(!visit[x]){
            dfs(x);
        }
    }
}

void testCase(){
    cin >> n >> k;

    vector<int> subs(k);
    for(int i = 0; i < k; i++){
        cin >> subs[i];
    }

    for(int i = 0; i < n; i++){
        int st; cin >> st;
        for(int j = 1; j <= st; j++){
            int x; cin >> x;
            graph[x].push_back(i + 1);
            other[i + 1].push_back(x);
        }
    }

    if(topoSort()){
        for(int i = 0; i < k; i++){
            if(!visit[subs[i]]){
                dfs(subs[i]);
            }
        }

        cout << cnt << endl;
        for(int i = 0; i < n; i++){
            if(visit[order[i]]){
                cout << order[i] << ' ';
            }
        } cout << endl;
    } else{
        for(int i = 0; i < k; i++){
            if(!other[subs[i]].size()){
                cnt += 1;
            }
        }
        if(cnt == k){
            cout << cnt << endl;
            for(int i = 0; i < k; i++){
                cout << subs[i] << ' ';
            } cout << endl;
        } else{
            cout << -1 << endl;
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

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

    int t = 1;
    // int t; cin >> t;
    while(t--)
        testCase();

    return 0;
}


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

int n, k, cycle;
vector<int> graph[100010], visit(100010), order;

void dfs(int node){
    if(visit[node] == 0){
        visit[node] = 1;
        for(int x : graph[node]){
            dfs(x);
        }
        visit[node] = 2;
        order.push_back(node);
    } else if(visit[node] == 1){
        cycle = 1;
    }
}

void testCase(){
    cin >> n >> k;

    vector<int> subs(k);
    for(int i = 0; i < k; i++){
        cin >> subs[i];
    }

    for(int i = 0; i < n; i++){
        int st; cin >> st;
        for(int j = 1; j <= st; j++){
            int x; cin >> x;
            graph[i + 1].push_back(x);
        }
    }

    for(int i = 0; i < k; i++){
        if(!visit[subs[i]]){
            dfs(subs[i]);
        }
    }

    if(cycle){
        cout << "-1" << endl;
    } else{
        cout << (int)order.size() << endl;
        for(auto x : order){
            cout << x << ' ';
        } cout << endl;
    }

}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

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

    int t = 1;
    // int t; cin >> t;
    while(t--)
        testCase();

    return 0;
}


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

int n, k, cnt;
vector<int> graph[100010], other[100010], order, indeg(100010), visit(100010);
#define check(c)       cout<<#c<<" : "<<c<<endl;
#define check2(a, b)    cout<<#a<<" : "<<a<<" | "<<#b<<" : "<<b<<endl;

bool topoSort(){
    for(int i = 1; i <= n; ++i){
        for(auto x : graph[i]){
            ++indeg[x];
        }
    }

    queue<int> q;
    for(int i = 1; i <= n; i++){
        if(!indeg[i])
            q.push(i);
    }

    while(!q.empty()){
        int frt = q.front();
        order.push_back(frt);
        q.pop();
        for(int x : graph[frt]){
            --indeg[x];
            if(!indeg[x])
                q.push(x);
        }
    }
    return (order.size() == n);
}

void dfs(int node){
    visit[node] = 1;
    cnt += 1;
    for(auto x : other[node]){
        if(!visit[x]){
            dfs(x);
        }
    }
}

void testCase(){
    cin >> n >> k;

    vector<int> subs(k);
    for(int i = 0; i < k; i++){
        cin >> subs[i];
    }

    for(int i = 0; i < n; i++){
        int st; cin >> st;
        for(int j = 1; j <= st; j++){
            int x; cin >> x;
            graph[x].push_back(i + 1);
            other[i + 1].push_back(x);
        }
    }

    if(topoSort()){
        for(int i = 0; i < k; i++){
            if(!visit[subs[i]]){
                dfs(subs[i]);
            }
        }

        cout << cnt << endl;
        for(int i = 0; i < n; i++){
            if(visit[order[i]]){
                cout << order[i] << ' ';
            }
        } cout << endl;
    } else{
        cout << -1 << endl;
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

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

    int t = 1;
    // int t; cin >> t;
    while(t--)
        testCase();

    return 0;
}


#include<iostream>
#include<vector>
#include<unordered_map>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define inf 1e9
#define INF 1e16
#define MOD 1000000007

ll n,k;

class Graph{
    unordered_map<ll, list<ll> >adj;
    vector<ll>reqExams;

    public:

    void addEdge(ll u, ll v, bool bidir=false){
        adj[u].push_back(v);
        if(bidir){
            adj[v].push_back(v);
        }
    }

    void takeReqExams(){
        reqExams.resize(k);
        ip(reqExams, k);
    }

    void TopologicalSort(){
        unordered_map<ll, bool>visited, inStack;
        vector<ll>ans;

        function<bool(ll)>helper;
        helper = [&](ll src)->bool{
            visited[src]=true;
            inStack[src]=true;

            for(ll child: adj[src]){
                if(inStack[child] || (!visited[child] && helper(child))){
                    return true;
                }
            }
            inStack[src]=true;
            ans.push_back(src);
            return false;
        };

        for(ll i: reqExams){
            if(!visited[i]){
                bool isCyclic = helper(i);
                if(isCyclic){
                    cout<<"-1\n";
                    return;
                }
            }
        }

        cout<<ans.size()<<endl;
        for(ll i: ans){
            cout<<i<<" ";
        }
        cout<<endl;
    }
};

int main(){

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

    cin>>n>>k;

    Graph g;

    g.takeReqExams();
    for(ll u=1; u<=n; u++){
        ll m;
        cin>>m;
        if(m){
            for(ll j=0; j<m; j++){
                ll v;
                cin>>v;
                g.addEdge(u,v);
            }
        }
    }

    g.TopologicalSort();

    return 0;
}


#include<iostream>
#include<vector>
#include<unordered_map>
#include<list>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define MOD 1000000007

ll n,k;
vector<ll> examdenahai;
unordered_map<ll, list<ll> >g;
vector<ll>ans;
bool isCyclic=false;
ll visited[100005]={0};

// here we basically used the same logic to detect cycle in directed graph but instad of using two diff vector visited and inSatck,
// we use the same, so for this purpose until the node is in stack we mark it as 1 and when we consider all its child withour encountr cycle,
// we mark it as 2. Initally all val is 0

void tps(ll src){
    if(visited[src]==2)return; // if already visited this node and all its child need to consider again as we have already pushed this node ans into ans vector.
    visited[src]=1; // for each new node set visited to 1 means we are visiting this node
    // it will remain 1 untill we have consider all its child after that we will make it 2 means now
    // we have considered this node with all its child.

    // if while visiting any child we get visiting of child as 1 means we there is cycle as its child are still in out stack
    // so set isCylic var

    for(ll child: g[src]){
        if(visited[child] == 1){ // means this child is aleady in stack so cycle present
            isCyclic=true;
            return;
        }
        tps(child); // otherwise make rec call
    }
    visited[src]=2; // now remnove this node from stack and mark it as visited completely
    ans.push_back(src);
}

void dsf(){
    for(auto node: examdenahai){
        tps(node);
        if(isCyclic)break;
    }

    if(isCyclic){
        cout<<"-1\n";
        return;
    }

    cout<<ans.size()<<endl;
    for(ll i: ans){
        cout<<i<<" ";
    }
    cout<<endl;
}

int main(){

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

    cin>>n>>k;
    for(ll i=0; i<k; i++){
        ll x;
        cin>>x;
        examdenahai.push_back(x);
    }

    for(ll u=1; u<=n; u++){
        ll m;
        cin>>m;
        if(m==0) continue;
        for(ll j=0; j<m; j++){
            ll v;
            cin>>v;
            g[u].push_back(v);
        }
    }
    dsf();
    return 0;
}


#include<iostream>
#include<vector>
#include<unordered_map>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define inf 1e9
#define INF 1e16
#define MOD 1000000007

ll n,k;

class Graph{
    unordered_map<ll, list<ll> >adj;
    vector<ll>reqExams;

    public:

    void addEdge(ll u, ll v, bool bidir=false){
        adj[u].push_back(v);
        if(bidir){
            adj[v].push_back(v);
        }
    }

    void takeReqExams(){
        reqExams.resize(k);
        ip(reqExams, k);
    }

    void TopologicalSort(){
        unordered_map<ll, bool>visited, inStack;
        vector<ll>ans;

        function<bool(ll)>helper;
        helper = [&](ll src)->bool{
            visited[src]=true;
            inStack[src]=true;

            for(ll child: adj[src]){
                if(inStack[child] || (!visited[child] && helper(child))){
                    return true;
                }
            }
            inStack[src]=false;
            ans.push_back(src);
            return false;
        };

        for(ll i: reqExams){
            if(!visited[i]){
                bool isCyclic = helper(i);
                if(isCyclic){
                    cout<<"-1\n";
                    return;
                }
            }
        }

        cout<<ans.size()<<endl;
        for(ll i: ans){
            cout<<i<<" ";
        }
        cout<<endl;
    }
};

int main(){

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

    cin>>n>>k;

    Graph g;

    g.takeReqExams();
    for(ll u=1; u<=n; u++){
        ll m;
        cin>>m;
        for(ll j=0; j<m; j++){
            ll v;
            cin>>v;
            g.addEdge(u,v);
        }
    }

    g.TopologicalSort();

    return 0;
}


#include<iostream>
#include<vector>
#include<unordered_map>
#include<list>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define MOD 1000000007

ll n,k;
vector<ll> examdenahai;
unordered_map<ll, list<ll> >g;
vector<ll>ans;
bool isCyclic=false;
ll visited[100005]={0};

void tps(ll src){
    if(visited[src]==2)return;
    visited[src]=1;

    for(ll child: g[src]){
        if(visited[child] == 1){
            isCyclic=true;
            return;
        }
        tps(child);
    }
    visited[src]=2;
    ans.push_back(src);
}

void dsf(){
    for(auto node: examdenahai){
        tps(node);
        if(isCyclic)break;
    }

    if(isCyclic){
        cout<<"-1\n";
        return;
    }

    cout<<ans.size()<<endl;
    for(ll i: ans){
        cout<<i<<" ";
    }
    cout<<endl;
}

int main(){

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

    cin>>n>>k;
    for(ll i=0; i<k; i++){
        ll x;
        cin>>x;
        examdenahai.push_back(x);
    }

    for(ll u=1; u<=n; u++){
        ll m;
        cin>>m;
        if(m==0) continue;
        for(ll j=0; j<m; j++){
            ll v;
            cin>>v;
            g[u].push_back(v);
        }
    }
    dsf();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vs vector<string>
#define vll vector<ll>
#define ii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define FOR(i, x, n) for(int i=x; i<=n; ++i)
#define ROF(i, x, n) for(int i=x; i>=n; --i)
#define MOD 1000000007
#define F first
#define S second
#define all(x) x.begin(), x.end()

vvi AL;
vi dfs_num, ans;
bool a[100005];
bool b[100005];
map<int, bool> mp;

void dfs(int u) {
    if(mp[u]) {
        printf("-1\n");
        exit(0);
    }
    dfs_num[u] = 1;
    mp[u] = 1;

    for(auto p: AL[u]) {
        dfs(p);
    }
    if(!b[u]) {
        b[u] = 1;
        ans.pb(u);
    }
}

int main() {

    int n, k;
    sc("%d %d", &n, &k);

    AL.assign(n+2, vi());
    dfs_num.assign(n+2, 0);

    FOR(i, 1, k) {
        int x;
        sc("%d", &x);
        a[x] = 1;
    }

    FOR(i, 1, n) {

        int t;
        sc("%d", &t);

        while(t--) {
            int x;
            sc("%d", &x);
            AL[i].pb(x);
        }
    }

    FOR(i, 1, n) {
        if(!dfs_num[i] && a[i]) {
            dfs(i);
            mp.clear();
        }
    }

    printf("%d\n", (int) ans.size());

    for(auto p: ans) {
        printf("%d ", p);
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vs vector<string>
#define vll vector<ll>
#define ii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define FOR(i, x, n) for(int i=x; i<=n; ++i)
#define ROF(i, x, n) for(int i=x; i>=n; --i)
#define MOD 1000000007
#define F first
#define S second
#define all(x) x.begin(), x.end()

vvi AL;
vi dfs_num, ans;
bool a[100005];
bool b[100005];

void dfs(int u) {
    if(dfs_num[u]) {
        printf("-1\n");
        exit(0);
    }
    dfs_num[u] = 1;

    for(auto p: AL[u]) {
        dfs(p);
    }
    dfs_num[u] = 0;
    if(!b[u]) {
        b[u] = 1;
        ans.pb(u);
    }
}

int main() {

    int n, k;
    sc("%d %d", &n, &k);

    AL.assign(n+2, vi());
    dfs_num.assign(n+2, 0);

    FOR(i, 1, k) {
        int x;
        sc("%d", &x);
        a[x] = 1;
    }

    FOR(i, 1, n) {

        int t;
        sc("%d", &t);

        while(t--) {
            int x;
            sc("%d", &x);
            AL[i].pb(x);
        }
    }

    FOR(i, 1, n) {
        if(!dfs_num[i] && a[i]) {
            dfs(i);
        }
    }

    printf("%d\n", (int) ans.size());

    for(auto p: ans) {
        printf("%d ", p);
    }
    printf("\n");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vs vector<string>
#define vll vector<ll>
#define ii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define FOR(i, x, n) for(int i=x; i<=n; ++i)
#define ROF(i, x, n) for(int i=x; i>=n; --i)
#define MOD 1000000007
#define F first
#define S second
#define all(x) x.begin(), x.end()

vvi AL;
vi dfs_num, ans;
bool a[100005];
bool b[100005];

void dfs(int u) {
    if(dfs_num[u]) {
        printf("-1\n");
        exit(0);
    }
    dfs_num[u] = 1;

    for(auto p: AL[u]) {
        dfs(p);
    }
    dfs_num[u] = 0;
    if(!b[u]) {
        b[u] = 1;
        ans.pb(u);
    }
}

int main() {

    int n, k;
    sc("%d %d", &n, &k);

    AL.assign(n+2, vi());
    dfs_num.assign(n+2, 0);

    FOR(i, 1, k) {
        int x;
        sc("%d", &x);
        a[x] = 1;
    }

    FOR(i, 1, n) {

        int t;
        sc("%d", &t);

        while(t--) {
            int x;
            sc("%d", &x);
            AL[i].pb(x);
        }
    }

    FOR(i, 1, n) {
        if(a[i]) {
            dfs(i);
        }
    }

    printf("%d\n", (int) ans.size());

    for(auto p: ans) {
        printf("%d ", p);
    }
    printf("\n");
}


#include<bits/stdc++.h>

using namespace std;

long long arr[100001];
long long su[100001];
long long n, a, r, m;

long long calc(long long lesser, long long greater) {
    if(a + r <= m) {
        return lesser*a+greater*r;
    } else {
        long long mini = min(lesser,greater);
        lesser -= mini;
        greater-=mini;
        return mini*m + lesser*a+greater*r;
    }
}

long long f(long long mid) {
    int z = lower_bound(arr+1,arr+n+1,mid)-arr;
    long long greater = (su[n]-su[z-1]) - (n-z+1)*mid;
    long long lesser = (z-1)*mid-su[z-1];
    //cout << lesser << " " << greater << endl;
    return calc(lesser,greater);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    //cin >> t;

    //while(t--) {
        cin >> n >> a >> r >> m;
        long long mini = 1e9+1;
        long long maxi = 0;
        long long plus = 0;
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
            maxi=max(arr[i],maxi);
            mini=min(arr[i],mini);
        }
        sort(arr+1,arr+n+1);
        for(int i = 1; i <= n; i++){
            plus+=arr[i];
            su[i]=plus;
        }
        long long ans=1e9;
        ans*=ans;
        while(mini<maxi){
            long long by3 = (maxi-mini)/3;
            long long m1 = mini + by3;
            long long m2 = maxi - by3;
            long long x = f(m1);
            long long y = f(m2);
            ans = min(ans,x);
            ans = min(ans,y);
            if(x<y) {
                maxi = m2-1;
            } else if(x==y) {
                mini = m1;
                maxi = m2;
            } else {
                mini = m1 + 1;
            }
        }
        cout << ans << endl;
    //}
}


#include<bits/stdc++.h>

using namespace std;

long long arr[100001];
long long su[100001];
long long n, a, r, m;

long long calc(long long lesser, long long greater) {
    if(a + r <= m) {
        return lesser*a+greater*r;
    } else {
        long long mini = min(lesser,greater);
        lesser -= mini;
        greater-=mini;
        return mini*m + lesser*a+greater*r;
    }
}

long long f(long long mid) {
    int z = lower_bound(arr+1,arr+n+1,mid)-arr;
    long long greater = (su[n]-su[z-1]) - (n-z+1)*mid;
    long long lesser = (z-1)*mid-su[z-1];
    //cout << lesser << " " << greater << endl;
    return calc(lesser,greater);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    //cin >> t;

    //while(t--) {
        cin >> n >> a >> r >> m;
        long long mini = 1e9+1;
        long long maxi = 0;
        long long plus = 0;
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
            maxi=max(arr[i],maxi);
            mini=min(arr[i],mini);
        }
        sort(arr+1,arr+n+1);
        for(int i = 1; i <= n; i++){
            plus+=arr[i];
            su[i]=plus;
        }
        long long ans = LLONG_MAX;
        int i = 1;
        while(i<=n)
            ans = min(ans,f(arr[i++]));
        cout << ans << endl;
    //}
}


#include<bits/stdc++.h>

using namespace std;

long long arr[100001];
long long su[100001];
long long n, a, r, m;

long long calc(long long lesser, long long greater) {
    if(a + r <= m) {
        return lesser*a+greater*r;
    } else {
        long long mini = min(lesser,greater);
        lesser -= mini;
        greater-=mini;
        return mini*m + lesser*a+greater*r;
    }
}

long long f(long long mid) {
    int z = lower_bound(arr+1,arr+n+1,mid)-arr;
    long long greater = (su[n]-su[z-1]) - (n-z+1)*mid;
    long long lesser = (z-1)*mid-su[z-1];
    //cout << lesser << " " << greater << endl;
    return calc(lesser,greater);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    //cin >> t;

    //while(t--) {
        cin >> n >> a >> r >> m;
        long long mini = 1e9+1;
        long long maxi = 0;
        long long plus = 0;
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
            maxi=max(arr[i],maxi);
            mini=min(arr[i],mini);
        }
        sort(arr+1,arr+n+1);
        for(int i = 1; i <= n; i++){
            plus+=arr[i];
            su[i]=plus;
        }
        long long ans=LLONG_MAX;
        while(maxi-mini>=3){
            long long by3 = (maxi-mini)/3;
            long long m1 = mini + by3;
            long long m2 = maxi - by3;
            long long x = f(m1);
            long long y = f(m2);
            //ans = min(ans,x);
            //ans = min(ans,y);
            if(x<y) {
                maxi = m2-1;
            } else if(x==y) {
                mini = m1;
                maxi = m2;
            } else {
                mini = m1 + 1;
            }
        }
        while(mini<=maxi)
            ans = min(ans,f(mini++));
        cout << ans << endl;
    //}
}


#include<bits/stdc++.h>

using namespace std;

long long arr[100001];
long long su[100001];
long long n, a, r, m;

long long calc(long long lesser, long long greater) {
    if(a + r <= m) {
        return lesser*a+greater*r;
    } else {
        long long mini = min(lesser,greater);
        lesser -= mini;
        greater-=mini;
        return mini*m + lesser*a+greater*r;
    }
}

long long f(int mid) {
    int z = lower_bound(arr+1,arr+n+1,mid)-arr;
    long long greater = (su[n]-su[z-1]) - (n-z+1)*mid;
    long long lesser = (z-1)*mid-su[z-1];
    //cout << lesser << " " << greater << endl;
    return calc(lesser,greater);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    //cin >> t;

    //while(t--) {
        cin >> n >> a >> r >> m;
        long long mini = 1e9+1;
        long long maxi = 0;
        long long plus = 0;
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
            maxi=max(arr[i],maxi);
            mini=min(arr[i],mini);
        }
        sort(arr+1,arr+n+1);
        for(int i = 1; i <= n; i++){
            plus+=arr[i];
            su[i]=plus;
        }
        long long ans = LLONG_MAX;
        while(maxi-mini>=3){
            long long by3 = (maxi-mini)/3;
            long long m1 = mini + by3;
            long long m2 = maxi - by3;
            long long x = f(m1);
            long long y = f(m2);
            if(x<y) {
                maxi = m2-1;
            }else {
                mini = m1 + 1;
            }
        }
        while(mini<=maxi)
            ans = min(ans,f(mini++));
        cout << ans << endl;
    //}
}


#include<bits/stdc++.h>

using namespace std;

long long arr[100001];
long long su[100001];
long long n, a, r, m;

long long calc(long long lesser, long long greater) {
    if(a + r <= m) {
        return lesser*a+greater*r;
    } else {
        long long mini = min(lesser,greater);
        lesser -= mini;
        greater-=mini;
        return mini*m + lesser*a+greater*r;
    }
}

long long f(int mid) {
    int z = lower_bound(arr+1,arr+n+1,mid)-arr;
    long long greater = (su[n]-su[z-1]) - (n-z+1)*mid;
    long long lesser = (z-1)*mid-su[z-1];
    //cout << lesser << " " << greater << endl;
    return calc(lesser,greater);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    //cin >> t;

    //while(t--) {
        cin >> n >> a >> r >> m;
        long long mini = 1e9+1;
        long long maxi = 0;
        long long plus = 0;
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
            maxi=max(arr[i],maxi);
            mini=min(arr[i],mini);
        }
        sort(arr+1,arr+n+1);
        for(int i = 1; i <= n; i++){
            plus+=arr[i];
            su[i]=plus;
        }
        long long ans=1e9;
        ans*=ans;
        while(mini<maxi){
            long long by3 = (maxi-mini)/3;
            long long m1 = mini + by3;
            long long m2 = maxi - by3;
            long long x = f(m1);
            long long y = f(m2);
            ans = min(ans,x);
            ans = min(ans,y);
            if(x<y) {
                maxi = m2-1;
            } else if(x==y) {
                mini = m1;
                maxi = m2;
            } else {
                mini = m1 + 1;
            }
        }
        cout << ans << endl;
    //}
}


#include<bits/stdc++.h>

using namespace std;

long long arr[100001];
long long su[100001];
long long n, a, r, m;

long long calc(long long lesser, long long greater) {
    if(a + r <= m) {
        return lesser*a+greater*r;
    } else {
        long long mini = min(lesser,greater);
        lesser -= mini;
        greater-=mini;
        return mini*m + lesser*a+greater*r;
    }
}

long long f(long long mid) {
    int z = lower_bound(arr+1,arr+n+1,mid)-arr;
    long long greater = (su[n]-su[z-1]) - (n-z+1)*mid;
    long long lesser = (z-1)*mid-su[z-1];
    //cout << lesser << " " << greater << endl;
    return calc(lesser,greater);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    //cin >> t;

    //while(t--) {
        cin >> n >> a >> r >> m;
        long long mini = 1e9+1;
        long long maxi = 0;
        long long plus = 0;
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
            maxi=max(arr[i],maxi);
            mini=min(arr[i],mini);
        }
        sort(arr+1,arr+n+1);
        for(int i = 1; i <= n; i++){
            plus+=arr[i];
            su[i]=plus;
        }
        long long ans=LLONG_MAX;
        while(mini<maxi){
            long long by3 = (maxi-mini)/3;
            long long m1 = mini + by3;
            long long m2 = maxi - by3;
            long long x = f(m1);
            long long y = f(m2);
            ans = min(ans,x);
            ans = min(ans,y);
            if(x<y) {
                maxi = m2-1;
            } else if(x==y) {
                mini = m1;
                maxi = m2;
            } else {
                mini = m1 + 1;
            }
        }
        cout << ans << endl;
    //}
}


#include<bits/stdc++.h>

using namespace std;

long long arr[100001];
long long su[100001];
long long n, a, r, m;

long long calc(long long lesser, long long greater) {
    if(a + r <= m) {
        return lesser*a+greater*r;
    } else {
        long long mini = min(lesser,greater);
        lesser -= mini;
        greater-=mini;
        return mini*m + lesser*a+greater*r;
    }
}

long long f(int mid) {
    int z = lower_bound(arr+1,arr+n+1,mid)-arr;
    long long greater = (su[n]-su[z-1]) - (n-z+1)*mid;
    long long lesser = (z-1)*mid-su[z-1];
    //cout << lesser << " " << greater << endl;
    return calc(lesser,greater);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    //cin >> t;

    //while(t--) {
        cin >> n >> a >> r >> m;
        long long mini = 1e9+1;
        long long maxi = 0;
        long long plus = 0;
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
            maxi=max(arr[i],maxi);
            mini=min(arr[i],mini);
        }
        sort(arr+1,arr+n+1);
        for(int i = 1; i <= n; i++){
            plus+=arr[i];
            su[i]=plus;
        }
        long long ans=1e9;
        ans*=ans;
        while(maxi-mini>=3){
            long long by3 = (maxi-mini)/3;
            long long m1 = mini + by3;
            long long m2 = maxi - by3;
            long long x = f(m1);
            long long y = f(m2);
            if(x<y) {
                maxi = m2-1;
            }else {
                mini = m1 + 1;
            }
        }
        while(mini<=maxi)
            ans = min(ans,f(mini++));
        cout << ans << endl;
    //}
}


#include<bits/stdc++.h>

using namespace std;

long long arr[100001];
long long su[100001];
long long n, a, r, m;

long long calc(long long lesser, long long greater) {
    if(a + r <= m) {
        return lesser*a+greater*r;
    } else {
        long long mini = min(lesser,greater);
        lesser -= mini;
        greater-=mini;
        return mini*m + lesser*a+greater*r;
    }
}

long long f(int mid) {
    int z = lower_bound(arr+1,arr+n+1,mid)-arr;
    long long greater = (su[n]-su[z-1]) - (n-z+1)*mid;
    long long lesser = (z-1)*mid-su[z-1];
    //cout << lesser << " " << greater << endl;
    return calc(lesser,greater);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t;
    //cin >> t;

    //while(t--) {
        cin >> n >> a >> r >> m;
        long long mini = 1e9+1;
        long long maxi = 0;
        long long plus = 0;
        for(int i = 1; i <= n; i++) {
            cin >> arr[i];
            maxi=max(arr[i],maxi);
            mini=min(arr[i],mini);
        }
        sort(arr+1,arr+n+1);
        for(int i = 1; i <= n; i++){
            plus+=arr[i];
            su[i]=plus;
        }
        long long ans=1e9;
        ans*=ans;
        while(mini<maxi){
            long long by3 = (maxi-mini)/3;
            long long m1 = mini + by3;
            long long m2 = maxi - by3;
            long long x = f(m1);
            long long y = f(m2);
            if(x<y) {
                maxi = m2-1;
            }else {
                mini = m1 + 1;
            }
        }
        while(mini<=maxi)
            ans = min(ans,f(mini++));
        cout << ans << endl;
    //}
}


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf (ll)1e18 + 7

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp(x,y) make_pair(x,y)

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb push_back
#define ppb pop_back

#define bitcoin __builtin_popcount

#define endl "\n"

#define in(x) insert(x)

#define sz(x) (int)x.size()

#define all(x) x.begin(),x.end()

#define pw2(x) (1ll<<x) //2^x

#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)

#define sqr(x) ((x) * 1ll * (x))

#define UpdateRandom srand (time(NULL));

#define int ll

using namespace std;

const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n,A,r,m,ans=inf;
int a[N],p[N];

int solve(int x){
	int pos=lower_bound(a+1,a+n+1,x)-a;
	int low=x*(pos-1)-p[pos-1];
	int up=(p[n]-p[pos-1])-((n-(pos-1))*x);
	int change=min(low,up);
	low-=change;
	up-=change;
	int res=change*m;
	res+=(A*low);
	res+=(r*up);
	//cout << x << ' ' << res << ' ' << change << ' ' << low << ' ' << up << endl;
	return res;
}

 main(){

	NFS

	cin >> n >> A >> r >> m;

	m=min(m,A+r);

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

	sort(a+1,a+n+1);

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

	int L=a[1],R=a[n];

	while(R-L>(int)1e2){
		int m1=L+(R-L)/3,m2=L+((R-L)/3)*2;
		if(solve(m1)>solve(m2))L=m1;
		else R=m2;
	}

	for(int i=L;i<=R;i++){
		ans=min(ans,solve(i));
	}

	cout << ans << endl;

	ioi
}


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf (ll)1e18 + 7

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp(x,y) make_pair(x,y)

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb push_back
#define ppb pop_back

#define bitcoin __builtin_popcount

#define endl "\n"

#define in(x) insert(x)

#define sz(x) (int)x.size()

#define all(x) x.begin(),x.end()

#define pw2(x) (1ll<<x) //2^x

#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)

#define sqr(x) ((x) * 1ll * (x))

#define UpdateRandom srand (time(NULL));

#define int ll

using namespace std;

const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n,A,r,m,ans=inf;
int a[N],p[N];

int solve(int x){
	int pos=lower_bound(a+1,a+n+1,x)-a;
	int low=x*(pos-1)-p[pos-1];
	int up=(p[n]-p[pos-1])-((n-(pos-1))*x);
	int change=min(low,up);
	low-=change;
	up-=change;
	int res=change*m;
	res+=(A*low);
	res+=(r*up);
	//cout << x << ' ' << res << ' ' << change << ' ' << low << ' ' << up << endl;
	return res;
}

 main(){

	NFS

	cin >> n >> A >> r >> m;

	m=min(m,A+r);

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

	sort(a+1,a+n+1);

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

	int L=a[1],R=a[n];

	while(R-L>(int)1e3){
		int m1=L+(R-L)/3,m2=L+((R-L)/3)*2;
		if(solve(m1)>solve(m2))L=m1;
		else R=m2;
	}

	for(int i=L;i<=R;i++){
		ans=min(ans,solve(i));
	}

	cout << ans << endl;

	ioi
}


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf (ll)1e18 + 7

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp(x,y) make_pair(x,y)

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb push_back
#define ppb pop_back

#define bitcoin __builtin_popcount

#define endl "\n"

#define in(x) insert(x)

#define sz(x) (int)x.size()

#define all(x) x.begin(),x.end()

#define pw2(x) (1ll<<x) //2^x

#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)

#define sqr(x) ((x) * 1ll * (x))

#define UpdateRandom srand (time(NULL));

#define int ll

using namespace std;

const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n,A,r,m,ans=inf;
int a[N],p[N];

int solve(int x){
	int pos=lower_bound(a+1,a+n+1,x)-a;
	int low=x*(pos-1)-p[pos-1];
	int up=(p[n]-p[pos-1])-((n-(pos-1))*x);
	int change=min(low,up);
	low-=change;
	up-=change;
	int res=change*m;
	res+=(A*low);
	res+=(r*up);
	//cout << x << ' ' << res << ' ' << change << ' ' << low << ' ' << up << endl;
	return res;
}

 main(){

	NFS

	cin >> n >> A >> r >> m;

	m=min(m,A+r);

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

	sort(a+1,a+n+1);

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

	int L=a[1],R=a[n];

	while(R-L>4){
		int m1=L+(R-L)/3,m2=L+((R-L)/3)*2;
		if(solve(m1)>solve(m2))L=m1;
		else R=m2;
	}

	for(int i=L;i<=R;i++){
		ans=min(ans,solve(i));
	}

	cout << ans << endl;

	ioi
}


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf (ll)1e18 + 7

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp(x,y) make_pair(x,y)

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb push_back
#define ppb pop_back

#define bitcoin __builtin_popcount

#define endl "\n"

#define in(x) insert(x)

#define sz(x) (int)x.size()

#define all(x) x.begin(),x.end()

#define pw2(x) (1ll<<x) //2^x

#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)

#define sqr(x) ((x) * 1ll * (x))

#define UpdateRandom srand (time(NULL));

#define int ll

using namespace std;

const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n,A,r,m,ans=inf;
int a[N],p[N];

int solve(int x){
	int pos=lower_bound(a+1,a+n+1,x)-a;
	int low=x*(pos-1)-p[pos-1];
	int up=(p[n]-p[pos-1])-((n-(pos-1))*x);
	int change=min(low,up);
	low-=change;
	up-=change;
	int res=change*m;
	res+=(A*low);
	res+=(r*up);
	//cout << x << ' ' << res << ' ' << change << ' ' << low << ' ' << up << endl;
	return res;
}

 main(){

	NFS

	cin >> n >> A >> r >> m;

	m=min(m,A+r);

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

	sort(a+1,a+n+1);

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

	int L=a[1],R=a[n];

	while(R-L>(int)1e1){
		int m1=L+(R-L)/3,m2=L+((R-L)/3)*2;
		if(solve(m1)>solve(m2))L=m1;
		else R=m2;
	}

	for(int i=L;i<=R;i++){
		ans=min(ans,solve(i));
	}

	cout << ans << endl;

	ioi
}


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf (ll)1e18 + 7

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define mp(x,y) make_pair(x,y)

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb push_back
#define ppb pop_back

#define bitcoin __builtin_popcount

#define endl "\n"

#define in(x) insert(x)

#define sz(x) (int)x.size()

#define all(x) x.begin(),x.end()

#define pw2(x) (1ll<<x) //2^x

#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)

#define sqr(x) ((x) * 1ll * (x))

#define UpdateRandom srand (time(NULL));

#define int ll

using namespace std;

const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n,A,r,m,ans=inf;
int a[N],p[N];

int solve(int x){
	int pos=lower_bound(a+1,a+n+1,x)-a;
	int low=x*(pos-1)-p[pos-1];
	int up=(p[n]-p[pos-1])-((n-(pos-1))*x);
	int change=min(low,up);
	low-=change;
	up-=change;
	int res=change*m;
	res+=(A*low);
	res+=(r*up);
	//cout << x << ' ' << res << ' ' << change << ' ' << low << ' ' << up << endl;
	return res;
}

 main(){

	NFS

	cin >> n >> A >> r >> m;

	m=min(m,A+r);

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

	sort(a+1,a+n+1);

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

	int L=a[1],R=a[n];

	while(R-L>1){
		int m1=L+(R-L)/3,m2=L+((R-L)/3)*2;
		if(solve(m1)>solve(m2))L=m1;
		else R=m2;
	}

	for(int i=L;i<=R;i++){
		ans=min(ans,solve(i));
	}

	cout << ans << endl;

	ioi
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 998244353

ll calc(ll x,ll y,ll m,ll a,ll r){
    ll an=0;
    if(x>=y){ an = y*m+((x-y)*a);  }
    else{ an = x*m+ ((y-x)*r); }
    return an;
}

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //memset(prime,true,sizeof(prime));
    //cin>>t;
    while(t--){
        int n,a,r,m; cin>>n>>a>>r>>m;
        m = min(m,a+r);
        ll ast[n+1],sum=0; for(int i=1;i<=n;i++){  cin>>ast[i]; sum+=ast[i]; }
        sort(ast+1,ast+n+1);
        ll st=1,en=1e9,mid,sm,grt,tp,sm2,grt2,ans=1e18;
        while(st<=en){
            mid = (st+en)/2;
            sm=0,grt=0;
            for(int i=1;i<=n;i++){
                if(ast[i]<mid){ sm+=(mid-ast[i]); }
                else if(ast[i]>mid){ grt+=(ast[i]-mid); }
            }
            ans = min(ans, calc(sm,grt,m,a,r));
            mid = mid+1;

            for(int i=1;i<=n;i++){
                if(ast[i]<mid){ sm2+=(mid-ast[i]); }
                else if(ast[i]>mid){ grt2+=(ast[i]-mid); }
            }
            ans = min(ans, calc(sm2,grt2,m,a,r));
            mid-=1;
            if(sm>grt){ en=mid-1; }
            else{ st=mid+1; }
        }

        ll c2=0,c=0,k1,k2;
        for(int i=1;i<=n;i++){
            k1 = ((i-1)*(ast[i]))-c;
            k2 = (sum-c-ast[i])-((n-i)*ast[i]);
            ans =min(ans,k1*a+k2*r);
            //cout<<k1<<" "<<k2<<endl;
            c=c+ast[i];
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 998244353
#define maxn 100009
ll ast[maxn];
ll n,a,r,m;

ll calc(ll h){
    ll g1=0,sm=0,ans;
    for(int i=1;i<=n;i++){
        if(ast[i]>h){ g1+=(ast[i]-h); }
        else if(ast[i]<h){ sm+=(h-ast[i]); }
    }
    //cout<<g1<<" "<<sm<<" "<<h<<endl;
    if(g1>sm){ ans = sm*m + (g1-sm)*r; }
    else{ ans = g1*m + (sm-g1)*a; }
    return ans;
}

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //memset(prime,true,sizeof(prime));
    //cin>>t;
    while(t--){
        cin>>n>>a>>r>>m; m=min(m,a+r);
        m = min(m,a+r);
        ll sum=0; for(int i=1;i<=n;i++){  cin>>ast[i]; sum+=ast[i]; }
        sort(ast+1,ast+n+1);
        ll st=1,en=1e9,mid,f_ans=1e18;
        while((en-st)>1){
            mid = (st+en)/2;
            //cout<<calc(mid)<<" "<<calc(mid+1)<<" "<<mid<<endl;
            if(calc(mid)<=calc(mid+1)){ f_ans=min(f_ans,calc(mid)); en=mid-1; }
            else{  f_ans=min(f_ans,calc(mid+1)); st=mid+1; }
        }
        //cout<<st<<" "<<en<<endl;
        for(ll i=st;i<=en;i++){ f_ans=min(f_ans,calc(i)); }
        cout<<f_ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 998244353

ll calc(ll x,ll y,ll m,ll a,ll r){
    ll an=0;
    if(x>=y){ an = y*m+((x-y)*a);  }
    else{ an = x*m+ ((y-x)*r); }
    return an;
}

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //memset(prime,true,sizeof(prime));
    //cin>>t;
    while(t--){
        int n,a,r,m,sum=0; cin>>n>>a>>r>>m;
        m = min(m,a+r);
        ll ast[n+1]; for(int i=1;i<=n;i++){  cin>>ast[i]; sum+=ast[i]; }
        sort(ast+1,ast+n+1);
        ll st=1,en=1e9,mid,sm,grt,tp,ans=1e16;
        while(st<=en){
            mid = (st+en)/2;
            sm=0,grt=0;
            for(int i=1;i<=n;i++){
                if(ast[i]<mid){ sm+=(mid-ast[i]); }
                else if(ast[i]>mid){ grt+=(ast[i]-mid); }
            }
            ans = min(ans, calc(sm,grt,m,a,r));
            //cout<<sm<<" "<<grt<<endl;
            if(sm>grt){ en=mid-1; }
            else{ st=mid+1; }
        }

        ll c2=0,c=0,k1,k2;
        for(int i=1;i<=n;i++){
            k1 = ((i-1)*(ast[i]))-c;
            k2 = (sum-c-ast[i])-((n-i)*ast[i]);
            ans =min(ans,k1*a+k2*r);
            //cout<<k1<<" "<<k2<<endl;
            c=c+ast[i];
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 998244353

ll calc(ll x,ll y,ll m,ll a,ll r){
    ll an=0;
    if(x>=y){ an = y*m+((x-y)*a);  }
    else{ an = x*m+ ((y-x)*r); }
    return an;
}

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //memset(prime,true,sizeof(prime));
    //cin>>t;
    while(t--){
        int n,a,r,m; cin>>n>>a>>r>>m;
        m = min(m,a+r);
        ll ast[n+1],sum=0; for(int i=1;i<=n;i++){  cin>>ast[i]; sum+=ast[i]; }
        sort(ast+1,ast+n+1);
        ll st=1,en=1e9,mid,sm,grt,tp,ans=1e18;
        while(st<=en){
            mid = (st+en)/2;
            sm=0,grt=0;
            for(int i=1;i<=n;i++){
                if(ast[i]<mid){ sm+=(mid-ast[i]); }
                else if(ast[i]>mid){ grt+=(ast[i]-mid); }
            }

            ans = min(ans, calc(sm,grt,m,a,r));
            //cout<<sm<<" "<<grt<<endl;
            if(sm>grt){ en=mid-1; }
            else{ st=mid+1; }
        }

        ll c2=0,c=0,k1,k2;
        for(int i=1;i<=n;i++){
            k1 = ((i-1)*(ast[i]))-c;
            k2 = (sum-c-ast[i])-((n-i)*ast[i]);
            ans =min(ans,k1*a+k2*r);
            //cout<<k1<<" "<<k2<<endl;
            c=c+ast[i];
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 998244353
#define maxn 100009
ll ast[maxn];
ll n,a,r,m;

ll calc(ll h){
    ll g1=0,sm=0,ans;
    for(int i=1;i<=n;i++){
        if(ast[i]>h){ g1+=(ast[i]-h); }
        else if(ast[i]<h){ sm+=(h-ast[i]); }
    }
    //cout<<g1<<" "<<sm<<" "<<h<<endl;
    if(g1>sm){ ans = sm*m + (g1-sm)*r; }
    else{ ans = g1*m + (sm-g1)*a; }
    return ans;
}

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //memset(prime,true,sizeof(prime));
    //cin>>t;
    while(t--){
        cin>>n>>a>>r>>m; m=min(m,a+r);
        m = min(m,a+r);
        ll sum=0; for(int i=1;i<=n;i++){  cin>>ast[i]; sum+=ast[i]; }
        sort(ast+1,ast+n+1);
        ll st=1,en=1e9,mid,f_ans=1e18;
        while((en-st)>0){
            mid = (st+en)/2;
            //cout<<calc(mid)<<" "<<calc(mid+1)<<" "<<mid<<endl;
            if(calc(mid)<=calc(mid+1)){ f_ans=min(f_ans,calc(mid)); en=mid-1; }
            else{  f_ans=min(f_ans,calc(mid+1)); st=mid+1; }
        }
        //cout<<st<<" "<<en<<endl;
        for(ll i=st;i<=en;i++){ f_ans=min(f_ans,calc(i)); }
        cout<<f_ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 998244353

ll calc(ll x,ll y,ll m,ll a,ll r){
    ll an=0;
    if(x>=y){ an = y*m+((x-y)*a);  }
    else{ an = x*m+ ((y-x)*r); }
    return an;
}

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //memset(prime,true,sizeof(prime));
    //cin>>t;
    while(t--){
        int n,a,r,m; cin>>n>>a>>r>>m;
        m = min(m,a+r);
        ll ast[n+1],sum=0; for(int i=1;i<=n;i++){  cin>>ast[i]; sum+=ast[i]; }
        sort(ast+1,ast+n+1);
        ll st=1,en=1e9,mid,sm,grt,tp,sm2,grt2,ans=1e18;
        while(st<=en){
            mid = (st+en)/2;
            sm=0,grt=0;
            for(int i=1;i<=n;i++){
                if(ast[i]<mid){ sm+=(mid-ast[i]); }
                else if(ast[i]>mid){ grt+=(ast[i]-mid); }
            }
            ans = min(ans, calc(sm,grt,m,a,r));
            mid = mid+1;

            for(int i=1;i<=n;i++){
                if(ast[i]<mid){ sm2+=(mid-ast[i]); }
                else if(ast[i]>mid){ grt2+=(ast[i]-mid); }
            }
            ans = min(ans, calc(sm2,grt2,m,a,r));
            if(sm>grt){ en=mid-1; }
            else{ st=mid+1; }
        }

        ll c2=0,c=0,k1,k2;
        for(int i=1;i<=n;i++){
            k1 = ((i-1)*(ast[i]))-c;
            k2 = (sum-c-ast[i])-((n-i)*ast[i]);
            ans =min(ans,k1*a+k2*r);
            //cout<<k1<<" "<<k2<<endl;
            c=c+ast[i];
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 998244353

ll calc(ll x,ll y,ll m,ll a,ll r){
    ll an=0;
    if(x>=y){ an = y*m+((x-y)*a);  }
    else{ an = x*m+ ((y-x)*r); }
    return an;
}

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //memset(prime,true,sizeof(prime));
    //cin>>t;
    while(t--){
        int n,a,r,m; cin>>n>>a>>r>>m;
        m = min(m,a+r);
        ll ast[n+1],sum=0; for(int i=1;i<=n;i++){  cin>>ast[i]; sum+=ast[i]; }
        sort(ast+1,ast+n+1);
        ll st=1,en=1e9,mid,sm,grt,tp,ans=1e16;
        while(st<=en){
            mid = (st+en)/2;
            sm=0,grt=0;
            for(int i=1;i<=n;i++){
                if(ast[i]<mid){ sm+=(mid-ast[i]); }
                else if(ast[i]>mid){ grt+=(ast[i]-mid); }
            }

            ans = min(ans, calc(sm,grt,m,a,r));
            //cout<<sm<<" "<<grt<<endl;
            if(sm>grt){ en=mid-1; }
            else{ st=mid+1; }
        }

        ll c2=0,c=0,k1,k2;
        for(int i=1;i<=n;i++){
            k1 = ((i-1)*(ast[i]))-c;
            k2 = (sum-c-ast[i])-((n-i)*ast[i]);
            ans =min(ans,k1*a+k2*r);
            //cout<<k1<<" "<<k2<<endl;
            c=c+ast[i];
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define F first
#define fr(i,n) for(ll i=1;i<=n;i++)
#define mm(a,k) memset(a,k,sizeof(a))
#define S second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 998244353

ll calc(ll x,ll y,ll m,ll a,ll r){
    ll an=0;
    if(x>=y){ an = y*m+((x-y)*a);  }
    else{ an = x*m+ ((y-x)*r); }
    return an;
}

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //memset(prime,true,sizeof(prime));
    //cin>>t;
    while(t--){
        int n,a,r,m; cin>>n>>a>>r>>m;
        m = min(m,a+r);
        ll ast[n+1],sum=0; for(int i=1;i<=n;i++){  cin>>ast[i]; sum+=ast[i]; }
        sort(ast+1,ast+n+1);
        ll st=1,en=1e9,mid,sm,grt,tp,sm2,grt2,ans=1e18;
        while(st<=en){
            mid = (st+en)/2;
            sm=0,grt=0;
            for(int i=1;i<=n;i++){
                if(ast[i]<mid){ sm+=(mid-ast[i]); }
                else if(ast[i]>mid){ grt+=(ast[i]-mid); }
            }
            ans = min(ans, calc(sm,grt,m,a,r));
            mid = mid+1;
            sm2=0,grt2=0;
            for(int i=1;i<=n;i++){
                if(ast[i]<mid){ sm2+=(mid-ast[i]); }
                else if(ast[i]>mid){ grt2+=(ast[i]-mid); }
            }
            ans = min(ans, calc(sm2,grt2,m,a,r));
            mid-=1;
            if(sm>grt){ en=mid-1; }
            else{ st=mid+1; }
        }

        ll c2=0,c=0,k1,k2;
        for(int i=1;i<=n;i++){
            k1 = ((i-1)*(ast[i]))-c;
            k2 = (sum-c-ast[i])-((n-i)*ast[i]);
            ans =min(ans,k1*a+k2*r);
            //cout<<k1<<" "<<k2<<endl;
            c=c+ast[i];
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(ll &h , vector<ll> &left , vector<ll> &right,ll a[],ll &A,ll &R,ll &M,ll &n)
{
    ll pos=lower_bound(a,a+n,h)-a;
    ll cost=min(M,A+R);
    ll l=left[pos],r=right[pos];
    ll ans=0,c=min(l,r);
    ans+=(c*cost);
    l-=c,r-=c;
    ans+=(l*A+r*R);
    return ans;

}
ll solve_avg(ll &avg,ll a[],ll &n,ll &A,ll &R,ll &M)
{
     ll pos=lower_bound(a,a+n,avg)-a;
     ll left=0,right=0;
     for(ll i=0;i<pos;i++)
        left+=(avg-a[i]);
     for(ll i=pos;i<n;i++)
        right+=(a[i]-avg);
     ll cost=min(A+R,M),c=min(left,right);
     ll ans=0;
     ans+=(cost*c);
     left-=c,right-=c;
     ans+=(left*A+right*R);
     return ans;
}
int main()
{
    ll n;
    cin>>n;
    ll A,R,M;
    cin>>A>>R>>M;
    ll a[n];
    for(ll i=0;i<n;++i) cin>>a[i];
       sort(a,a+n);
    vector<ll> left(n),right(n),pref(n);
    pref[0]=a[0];
    for(ll i=1;i<n;++i) pref[i]=a[i]+pref[i-1];
    for(ll i=1;i<n;++i) left[i]=(i*a[i])-pref[i-1];
    for(ll i=n-2;i>=0;i--) right[i]=pref[n-1]-pref[i]-(n-i-1)*a[i];
    ll cost=5e18;
    for(ll i=0;i<n;++i)
    cost=min(cost,solve(a[i],left,right,a,A,R,M,n));
    ll avg1=pref[n-1]/n,avg2=pref[n-1]/n+1;
    cost=min({cost,solve_avg(avg1,a,n,A,R,M),solve_avg(avg2,a,n,A,R,M)});
    cout<<cost<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(ll h , vector<ll> &left , vector<ll> &right,ll a[],ll &A,ll &R,ll &M,ll &n)
{
    ll pos=lower_bound(a,a+n,h)-a;
    ll cost=min(M,A+R);
    ll l=left[pos],r=right[pos];
    ll ans=0,c=min(l,r);
    ans+=c*cost;
    l-=c,r-=c;
    ans+=(l*A+r*R);
    return ans;

}
ll solve_avg(ll avg,ll a[],ll &n,ll &A,ll &R,ll &M)
{
     ll pos=lower_bound(a,a+n,avg)-a;
     ll left=0,right=0;
     for(ll i=0;i<pos;i++)
        left+=(avg-a[i]);
     for(ll i=pos;i<n;i++)
        right+=(a[i]-avg);
     ll cost=min(A+R,M),c=min(left,right);
     ll ans=0;
     ans+=(cost*c);
     left-=c,right-=c;
     ans+=(left*A+right*R);
     return ans;
}
int main()
{
    ll n;
    cin>>n;
    ll A,R,M;
    cin>>A>>R>>M;
    ll a[n];
    for(ll i=0;i<n;++i) cin>>a[i];
       sort(a,a+n);
    vector<ll> left(n),right(n),pref(n);
    pref[0]=a[0];
    for(ll i=1;i<n;++i) pref[i]=a[i]+pref[i-1];
    for(ll i=1;i<n;++i) left[i]=(i*a[i])-pref[i-1];
    for(ll i=n-2;i>=0;i--) right[i]=pref[n-1]-pref[i]-(n-i-1)*a[i];
    ll cost=5e18;
    for(ll i=0;i<n;++i)
    cost=min(cost,solve(a[i],left,right,a,A,R,M,n));
    ll avg1=pref[n-1]/n,avg2=pref[n-1]/(n+1);
    cost=min({cost,solve_avg(avg1,a,n,A,R,M),solve_avg(avg2,a,n,A,R,M)});
    cout<<cost<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(ll &h , vector<ll> &left , vector<ll> &right,ll a[],ll &A,ll &R,ll &M,ll &n)
{
    ll pos=lower_bound(a,a+n,h)-a;
    ll cost=min(M,A+R);
    ll l=left[pos],r=right[pos];
    ll ans=0,c=min(l,r);
    ans+=c*cost;
    l-=c,r-=c;
    ans+=(l*A+r*R);
    return ans;

}
int main()
{
    ll n;
    cin>>n;
    ll A,R,M;
    cin>>A>>R>>M;
    ll a[n];
    for(ll i=0;i<n;++i) cin>>a[i];
       sort(a,a+n);
    vector<ll> left(n),right(n),pref(n);
    pref[0]=a[0];
    for(ll i=1;i<n;++i) pref[i]=a[i]+pref[i-1];
    for(ll i=1;i<n;++i) left[i]=(i*a[i])-pref[i-1];
    for(ll i=n-2;i>=0;i--) right[i]=pref[n-1]-pref[i]-(n-i-1)*a[i];
    ll avg=pref[n-1]/n,cost=5e18;
    cost=min(cost,solve(avg,left,right,a,A,R,M,n));
    for(ll i=0;i<n;++i)
        cost=min(cost,solve(a[i],left,right,a,A,R,M,n));
    cout<<cost<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(ll h , vector<ll> &left , vector<ll> &right,ll a[],ll &A,ll &R,ll &M,ll &n)
{
    ll pos=lower_bound(a,a+n,h)-a;
    ll cost=min(M,A+R);
    ll l=left[pos],r=right[pos];
    ll ans=0,c=min(l,r);
    ans+=(c*cost);
    l-=c,r-=c;
    ans+=(l*A+r*R);
    return ans;

}
// ll solve_avg(ll avg,ll a[],ll &n,ll &A,ll &R,ll &M)
// {
//      ll pos=lower_bound(a,a+n,avg)-a;
//      ll left=0,right=0;
//      for(ll i=0;i<pos;i++)
//         left+=(avg-a[i]);
//      for(ll i=pos;i<n;i++)
//         right+=(a[i]-avg);
//      ll cost=min(A+R,M),c=min(left,right);
//      ll ans=0;
//      ans+=(cost*c);
//      left-=c,right-=c;
//      ans+=(left*A+right*R);
//      return ans;
//}
int main()
{
    ll n;
    cin>>n;
    ll A,R,M;
    cin>>A>>R>>M;
    ll a[n];
    for(ll i=0;i<n;++i) cin>>a[i];
       sort(a,a+n);
    vector<ll> left(n),right(n),pref(n);
    pref[0]=a[0];
    for(ll i=1;i<n;++i) pref[i]=a[i]+pref[i-1];
    for(ll i=1;i<n;++i) left[i]=(i*a[i])-pref[i-1];
    for(ll i=n-2;i>=0;i--) right[i]=pref[n-1]-pref[i]-(n-i-1)*a[i];
    ll cost=5e18;
    for(ll i=0;i<n;++i)
    cost=min(cost,solve(a[i],left,right,a,A,R,M,n));
    ll avg1=pref[n-1]/n,avg2=pref[n-1]/n+1;
    cost=min({cost,solve(avg1,left,right,a,A,R,M,n),solve(avg2,left,right,a,A,R,M,n)});
    cout<<cost<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(ll &h , vector<ll> &left , vector<ll> &right,ll a[],ll &A,ll &R,ll &M,ll &n)
{
    ll pos=lower_bound(a,a+n,h)-a;
    ll cost=min(M,A+R);
    ll l=left[pos],r=right[pos];
    ll ans=0,c=min(l,r);
    ans+=c*cost;
    l-=c,r-=c;
    ans+=(l*A+r*R);
    return ans;

}
ll solve_avg(ll &avg,ll a[],ll &n,ll &A,ll &R,ll &M)
{
     ll pos=lower_bound(a,a+n,avg)-a;
     ll left=0,right=0;
     for(ll i=0;i<pos;i++)
        left+=(avg-a[i]);
     for(ll i=pos;i<n;i++)
        right+=(a[i]-avg);
     ll cost=min(A+R,M),c=min(left,right);
     ll ans=0;
     ans+=(cost*c);
     left-=c,right-=c;
     ans+=(left*A+right*R);
     return ans;
}
int main()
{
    ll n;
    cin>>n;
    ll A,R,M;
    cin>>A>>R>>M;
    ll a[n];
    for(ll i=0;i<n;++i) cin>>a[i];
       sort(a,a+n);
    vector<ll> left(n),right(n),pref(n);
    pref[0]=a[0];
    for(ll i=1;i<n;++i) pref[i]=a[i]+pref[i-1];
    for(ll i=1;i<n;++i) left[i]=(i*a[i])-pref[i-1];
    for(ll i=n-2;i>=0;i--) right[i]=pref[n-1]-pref[i]-(n-i-1)*a[i];
    ll cost=5e18;
    for(ll i=0;i<n;++i)
    cost=min(cost,solve(a[i],left,right,a,A,R,M,n));
    ll avg1=pref[n-1]/n,avg2=pref[n-1]/(n+1);
    cost=min({cost,solve_avg(avg1,a,n,A,R,M),solve_avg(avg2,a,n,A,R,M)});
    cout<<cost<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(ll h , vector<ll> &left , vector<ll> &right,ll a[],ll &A,ll &R,ll &M,ll &n)
{
    ll pos=lower_bound(a,a+n,h)-a;
    ll cost=min(M,A+R);
    ll l=left[pos],r=right[pos];
    ll ans=0,c=min(l,r);
    ans+=(c*cost);
    l-=c,r-=c;
    ans+=(l*A+r*R);
    return ans;

}
ll solve_avg(ll avg,ll a[],ll &n,ll &A,ll &R,ll &M)
{
     ll pos=lower_bound(a,a+n,avg)-a;
     ll left=0,right=0;
     for(ll i=0;i<pos;i++)
        left+=(avg-a[i]);
     for(ll i=pos;i<n;i++)
        right+=(a[i]-avg);
     ll cost=min(A+R,M),c=min(left,right);
     ll ans=0;
     ans+=(cost*c);
     left-=c,right-=c;
     ans+=(left*A+right*R);
     return ans;
}
int main()
{
    ll n;
    cin>>n;
    ll A,R,M;
    cin>>A>>R>>M;
    ll a[n];
    for(ll i=0;i<n;++i) cin>>a[i];
       sort(a,a+n);
    vector<ll> left(n),right(n),pref(n);
    pref[0]=a[0];
    for(ll i=1;i<n;++i) pref[i]=a[i]+pref[i-1];
    for(ll i=1;i<n;++i) left[i]=(i*a[i])-pref[i-1];
    for(ll i=n-2;i>=0;i--) right[i]=pref[n-1]-pref[i]-(n-i-1)*a[i];
    ll cost=5e18;
    for(ll i=0;i<n;++i)
    cost=min(cost,solve(a[i],left,right,a,A,R,M,n));
    ll avg1=pref[n-1]/n,avg2=pref[n-1]/n+1;
    cost=min({cost,solve_avg(avg1,a,n,A,R,M),solve_avg(avg2,a,n,A,R,M)});
    cout<<cost<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
mt19937 rnd(time(0));
// begging you not to write cringe macro shits
const int MAXN = 200005;
const int INF = numeric_limits<int>::max() >> 3;
const int MOD = (int)998244353;

int n, a, r, m, h[MAXN];
int pl[MAXN], pr[MAXN];
signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> r >> m;
  if(m > a + r) m = a + r;
  for(int i = 1; i <= n; i ++) cin >> h[i];
  sort(h + 1, h + n + 1);
  for(int i = 1; i <= n; i ++) pl[i] = pl[i - 1] + h[i];
  for(int i = n; i >= 1; i --) pr[i] = pr[i + 1] + h[i];
  int ans = INF;
  for(int i = 1; i <= n; i ++){
    int x = i*h[i] - pl[i];
    int y = pr[i + 1] - (n - i)*h[i];
    int mv = min(x, y);
    x -= mv;
    y -= mv;
    if(x) ans = min(ans, mv*m + x*a);
    if(y) ans = min(ans, mv*m + y*r);
  }
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
mt19937 rnd(time(0));
// begging you not to write cringe macro shits
const int MAXN = 200005;
const int INF = numeric_limits<int>::max() >> 3;
const int MOD = (int)998244353;

int n, a, r, m, h[MAXN];
signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("FDT.txt","r",stdin);
  cin >> n >> a >> r >> m;
  if(m > a + r) m = a + r;
  for(int i = 1; i <= n; i ++) cin >> h[i];
  auto test = [&](int tar){
    int x = 0, y = 0;
    for(int i = 1; i <= n; i ++){
      if(h[i] < tar) x += (tar - h[i]);
      if(h[i] > tar) y += (h[i] - tar);
    }
    int move = min(x, y);
    int res = m*move;
    x -= move;
    y -= move;
    if(x) return res + x*a;
    else return res + y*r;
  };
  auto ter = [&](){
    int L = 0, R = (int)1e9;
    while(true){
      if(L + 10 > R){
        int res = INF;
        for(int i = L; i <= R; i ++) res = min(res, test(i));
        return res;
      }
      int M1 = L + (R - L)/3;
      int M2 = R - (R - L)/3;
      if(M1 > M2) L = M1;
      else R = M2;
    }
  };
  cout << ter();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
mt19937 rnd(time(0));
// begging you not to write cringe macro shits
const int MAXN = 200005;
const int INF = numeric_limits<int>::max() >> 3;
const int MOD = (int)998244353;

int n, a, r, m, h[MAXN];
signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("FDT.txt","r",stdin);
  cin >> n >> a >> r >> m;
  if(m > a + r) m = a + r;
  for(int i = 1; i <= n; i ++) cin >> h[i];
  auto test = [&](int tar){
    int x = 0, y = 0;
    for(int i = 1; i <= n; i ++){
      if(h[i] < tar) x += (tar - h[i]);
      if(h[i] > tar) y += (h[i] - tar);
    }
    int move = min(x, y);
    int res = m*move;
    x -= move;
    y -= move;
    if(x) return res + x*a;
    else return res + y*r;
  };
  auto ter = [&](){
    int L = 0, R = (int)1e9;
    while(true){
      if(L + 10 > R){
        int res = INF;
        for(int i = L; i <= R; i ++) res = min(res, test(i));
        return res;
      }
      int M1 = L + (R - L)/3 - rnd()%3;
      int M2 = R - (R - L)/3 + rnd()%3;
      if(test(M1) > test(M2)) L = M1;
      else R = M2;
    }
  };
  int iter = 20;
  int ans = INF;
  while(iter --) ans = min(ans, ter());
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
mt19937 rnd(time(0));
// begging you not to write cringe macro shits
const int MAXN = 200005;
const int INF = numeric_limits<int>::max() >> 3;
const int MOD = (int)998244353;

int n, a, r, m, h[MAXN];
signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> a >> r >> m;
  if(m > a + r) m = a + r;
  for(int i = 1; i <= n; i ++) cin >> h[i];
  auto test = [&](int tar){
    int x = 0, y = 0;
    for(int i = 1; i <= n; i ++){
      if(h[i] < tar) x += (tar - h[i]);
      if(h[i] > tar) y += (h[i] - tar);
    }
    int move = min(x, y);
    int res = m*move;
    x -= move;
    y -= move;
    if(x) return res + x*a;
    else return res + y*r;
  };
  auto ter = [&](){
    int L = 0, R = (int)1e9;
    while(true){
      if(L + 10 > R){
        int res = INF;
        for(int i = L; i <= R; i ++) res = min(res, test(i));
        return res;
      }
      int M1 = L + (R - L)/3 - rnd()%3;
      int M2 = R - (R - L)/3 + rnd()%3;
      if(M1 > M2) L = M1;
      else R = M2;
    }
  };
  int iter = 20;
  int ans = INF;
  while(iter --) ans = min(ans, ter());
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
mt19937 rnd(time(0));
// begging you not to write cringe macro shits
const int MAXN = 200005;
const int INF = numeric_limits<int>::max() >> 3;
const int MOD = (int)998244353;

int n, a, r, m, h[MAXN];
signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("FDT.txt","r",stdin);
  cin >> n >> a >> r >> m;
  if(m > a + r) m = a + r;
  for(int i = 1; i <= n; i ++) cin >> h[i];
  auto test = [&](int tar){
    int x = 0, y = 0;
    for(int i = 1; i <= n; i ++){
      if(h[i] < tar) x += (tar - h[i]);
      if(h[i] > tar) y += (h[i] - tar);
    }
    int move = min(x, y);
    int res = m*move;
    x -= move;
    y -= move;
    if(x) return res + x*a;
    else return res + y*r;
  };
  auto ter = [&](){
    int L = 0, R = (int)1e9;
    while(true){
      if(L + 10 > R){
        int res = INF;
        for(int i = L; i <= R; i ++) res = min(res, test(i));
        return res;
      }
      int M1 = L + (R - L)/3 - rnd()%3;
      int M2 = R - (R - L)/3 + rnd()%3;
      if(test(M1) > test(M2)) L = M1;
      else R = M2;
    }
  };
  int iter = 3;
  int ans = INF;
  while(iter --) ans = min(ans, ter());
  cout << ans;
  return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end())
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,n,d) for(ll i=0;i<n;i++)
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;
ll ct(ll a,ll r,ll m,v<ll> pref,v<ll> h,ll i){
            ll ans;
            ll n=h.size();
	      ans=ub(h,i);
	      ans--;
	      ll dum=0,less=0,more=0;
	      if(pref[n]<=n*i){
	            dum+=a*(n*i-pref[n]);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }
	      else{
	            dum+=r*(pref[n]-n*i);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }
	      return dum;
}
int main() {
	//your code goes here
	IOS;
	ll n,m;
	ll j,y,z,x,T,i;
	ll k,t;
	ll a,b,c,d,r;
	cin>>n>>a>>r>>m;
	v<ll> h(n);

	rep(i,n) {
	cin>>h[i];

	}
	sortv(h);
	v<ll> pref(n+1,0);
	rep(i,n){
	      pref[i+1]=pref[i]+h[i];
	}
	ll cost=1e18;

	m=min(m,a+r);
	ll l=h[0],R=h[n-1],m1,m2;
	while(l<=R){
	      m1=(2*l+R)/3; m2=(2*R+l)/3;
	      ll dum1=ct(a,r,m,pref,h,m1);
	      ll dum2=ct(a,r,m,pref,h,m2);

	      cost=min(cost,min(dum1,dum2));
	      if(dum1<dum2)
	      R=m2-1;
	      else
	      l=m1+1;
	}

	cout<<cost;

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end())
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,n,d) for(ll i=0;i<n;i++)
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;

int main() {
	//your code goes here
	IOS;
	ll n,m;
	ll j,y,z,x,T,i;
	ll k,t;
	ll a,b,c,d,r;
	cin>>n>>a>>r>>m;
	v<ll> h(n);

	rep(i,n) {
	cin>>h[i];

	}
	sortv(h);
	ll pref[n+1]={0};
	rep(i,n){
	      pref[i+1]=pref[i]+h[i];
	}
	ll cost=1e9;

	m=min(m,a+r);

	for(i=h[0];i<=h[n-1];i++){
	      ll ans;
	      ans=ub(h,i);
	      ans--;
	      ll dum=0,less=0,more=0;
	      if(pref[n]<=n*i){
	            dum+=a*(n*i-pref[n]);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }
	      else{
	            dum+=r*(pref[n]-n*i);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }

	      cost=min(cost,dum);
	}

	cout<<cost;

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end())
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,n,d) for(ll i=0;i<n;i++)
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;

int main() {
	//your code goes here
	IOS;
	ll n,m;
	ll j,y,z,x,T,i;
	ll k,t;
	ll a,b,c,d,r;
	cin>>n>>a>>r>>m;
	v<ll> h(n);

	rep(i,n) {
	cin>>h[i];

	}
	sortv(h);
	ll pref[n+1]={0};
	rep(i,n){
	      pref[i+1]=pref[i]+h[i];
	}
	ll cost=1e18;

	m=min(m,a+r);

	for(i=h[0];i<=h[n-1];i++){
	      ll ans;
	      ans=ub(h,i);
	      ans--;
	      ll dum=0,less=0,more=0;
	      if(pref[n]<=n*i){
	            dum+=a*(n*i-pref[n]);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }
	      else{
	            dum+=r*(pref[n]-n*i);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }

	      cost=min(cost,dum);
	}

	cout<<cost;

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end())
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,n,d) for(ll i=0;i<n;i++)
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;

int main() {
	//your code goes here
	IOS;
	ll n,m;
	ll j,y,z,x,T,i;
	ll k,t;
	ll a,b,c,d,r;
	cin>>n>>a>>r>>m;
	v<ll> h(n);

	rep(i,n) {
	cin>>h[i];

	}
	sortv(h);
	ll pref[n+1]={0};
	rep(i,n){
	      pref[i+1]=pref[i]+h[i];
	}
	ll cost=1e18;

	m=min(m,a+r);

	for(auto i:h){
	      ll ans;
	      ans=ub(h,i);
	      ans--;
	      ll dum=0,less=0,more=0;
	      if(pref[n]<=n*i){
	            dum+=a*(n*i-pref[n]);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }
	      else{
	            dum+=r*(pref[n]-n*i);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }

	      cost=min(cost,dum);
	}

	cout<<cost;

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end())
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,n,d) for(ll i=0;i<n;i++)
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;

int main() {
	//your code goes here
	IOS;
	ll n,m;
	ll j,y,z,x,T,i;
	ll k,t;
	ll a,b,c,d,r;
	cin>>n>>a>>r>>m;
	v<ll> h(n);

	rep(i,n) {
	cin>>h[i];

	}
	sortv(h);
	ll pref[n+1]={0};
	rep(i,n){
	      pref[i+1]=pref[i]+h[i];
	}
	v<ll> cost;

	m=min(m,a+r);

	for(i=h[0];i<=h[n-1];i++){
	      ll ans;
	      ans=ub(h,i);
	      ans--;
	      ll dum=0,less=0,more=0;
	      if(pref[n]<=n*i){
	            dum+=a*(n*i-pref[n]);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }
	      else{
	            dum+=r*(pref[n]-n*i);

	                  less=i*(ans+1)-pref[ans+1];
	                  more=pref[n]-pref[ans+1]-i*(n-1-ans);
	                  dum+=min(less,more)*m;

	      }

	      cost.pb(dum);
	}
	sortv(cost);
	cout<<cost[0];

	return 0;
}


/*
 * Author:  heyuhhh
 * Created Time:  2020/5/16 22:21:11
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A>
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

int n, A, R, M;
int h[N];

void run() {
    cin >> n >> A >> R >> M;
    M = min(M, A + R);
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    auto f = [&] (int x) {
        ll cnt_a = 0, cnt_b = 0;
        for (int i = 1; i <= n; i++) {
            if (h[i] < x) cnt_a += x - h[i];
            if (h[i] > x) cnt_b += h[i] - x;
        }
        ll cnt_c = min(cnt_a, cnt_b);
        cnt_a -= cnt_c;
        cnt_b -= cnt_c;
        return cnt_a * A + cnt_b * R + cnt_c * M;
    };
    int l = 0, r = INF, lmid, rmid;
    while (l < r) {
        lmid = l + ((r - l) / 3);
        rmid = r - ((r - l) / 3);
        if (f(lmid) < f(rmid)) {
            r = rmid - 1;
        } else {
            l = lmid + 1;
        }
    }
    cout << f(l) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}


/*
 * Author:  heyuhhh
 * Created Time:  2020/5/16 20:43:52
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A>
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

int n, a, r, m;
int h[N];
ll sum[N];

ll calc(int l, int r) {
    return sum[r] - sum[l - 1];
}

bool chk(int x, int i) {
    ll now = calc(i, n) - 1ll * (n - i + 1) * x;
    ll r = 1ll * x * (i - 1) - calc(1, i - 1);
    return now <= r;
}

void solve1() {
    ll ans = 1e18;
    int H = h[n];
    for (int i = n; i >= 2; i--) {
        int l = h[i - 1], r = h[i] + 1, mid;
        while (l < r) {
            mid = (l + r) >> 1;
            if (chk(mid, i)) r = mid;
            else l = mid + 1;
        }
        if (l > h[i]) break;
        H = l;
    }
    ll res = 1e18;

    int p = lower_bound(h + 1, h + n + 1, H) - h;
    ll now = calc(p, n) - 1ll * (n - p + 1) * H;
    ll R = 1ll * (p - 1) * H - calc(1, p - 1);
    if (now <= R) {
        res = 1ll * m * now + 1ll * (R - now) * a;
    }

    --H;
    p = lower_bound(h + 1, h + n + 1, H) - h;
    now = calc(p, n) - 1ll * (n - p + 1) * H;
    R = 1ll * (p - 1) * H - calc(1, p - 1);
    if (now >= R) {
        res = min(res, 1ll * m * now + 1ll * (now - R) * r);
    }

    res = min(res, (1ll * (n - 1) * h[n] - calc(1, n - 1)) * a);
    res = min(res, (calc(2, n) - 1ll * (n - 1) * h[1]) * r);
    ans = min(ans, res);
    cout << ans << '\n';
}

void solve2() {
    ll ans = 1e18;
    for (int i = n; i >= 1; i--) {
        ll res = 1ll * r * (calc(i + 1, n) - 1ll * (n - i) * h[i]) + (1ll * (i - 1) * h[i] - calc(1, i - 1)) * a;
        ans = min(ans, res);
    }
    cout << ans << '\n';
}

void run() {
    cin >> n >> a >> r >> m;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    sort(h + 1, h + n + 1);
    for (int i = 1; i <= n; i++) {
        sum[i] = sum[i - 1] + h[i];
    }
    if (m < a + r) {
        solve1();
    } else {
        solve2();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}