begin
if tar=0 then exit
else
begin
if a[tar]=ned then dg(tar-1,ned1)
else
begin
if (a[tar]>ned) then begin inc(ans);dg(tar-1,ned1-(a[tar]-ned)); end
else if (a[tar]<ned) then
begin
inc(ans);
dg(tar-1,ned1+(ned-a[tar]));
end;
end;