program gls;
var
n,a,b,k,i,j,ans,sum:longint;
ss:array[1..1000000]of longint;
st:array[0..1000000]of int64;
f,g:text;
function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end;
begin
assign(f,'suma.in');
reset(f);
assign(g,'suma.out');
rewrite(g);
readln(f,n,a,b);
for k:=1 to n do
readln(f,ss[k]);
st[1]:=ss[1];
st[0]:=0;
for k:=2 to n do
st[k]:=st[k-1]+ss[k];
{ for k:=1 to n do
write(g,st[k],' ');
writeln(g); }
ans:=maxlongint;
for i:=1 to n-1 do
for j:=i to n do
begin sum:=0;
sum:=st[j]-st[i-1];
if sum mod b>=a then
ans:=min(ans,sum mod b);
end;
writeln(g,ans);
close(f);close(g);
end.