{分班 NOIP模拟2010-11-18
水题
Author: yangbohua
Time: 2010-11-18}
program groupa;
var
a:array[0..5000] of longint;
n,i,sum,l,r,max1,max2:longint;
begin
assign(input,'groupa.in');
reset(input);
assign(output,'groupa.out');
rewrite(output);
readln(n);
sum:=0;
for i:=1 to n do
begin
read(a[i]);
sum:=sum+a[i];
end;
readln(l,r);
if (sum/n>=l) and (sum/n<=r) then
begin
max1:=0;
max2:=0;
for i:=1 to n do
begin
if a[i]>r then max1:=max1+a[i]-r;
if a[i]<l then max2:=max2+l-a[i];
end;
if max1>max2
then writeln(max1)
else writeln(max2);
end
else
writeln(-1);
close(input);
close(output);
end.