const
maxn=100000000000000000;
var
i,j:longint;
n,k,c,max,min:int64;
a,f:Array[0..100000]of int64;
procedure sort(l,r:longint);
var
i,j,x,y:longint;
begin
x:=a[(l+r) div 2];
i:=l;
j:=r;
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if i<=j then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
dec(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
begin
assign(input,'dividea.in'); reset(input);
assign(output,'dividea.out'); rewrite(output);
readln(n,k,c);
for i:=1 to n do read(a[i]);
sort(1,n);
f[1]:=c;
for i:=2 to n do
begin
f[i]:=maxn;
for j:=i-k+1 downto 1 do
begin
if f[j-1]+c+sqr(a[i]-a[j])<f[i] then f[i]:=f[j-1]+c+sqr(a[i]-a[j]);
end;
end;
writeln(f[n]);
close(input);
close(output);
end.