const
 n=10000;
var
 carray : array[1..n] of real;
 i : integer;
 a : real;
 _in : text;
{----------------------------------------------------------------------}
procedure quick(low : integer; hi : integer);
  var
   barrier,aux : real;
   i,j : integer;
  begin
        if (hi>low) then
	   begin i:=low;
	     j:=hi;
	     barrier:=carray[random(hi-low)+low];
             while(i < j) do
              begin
               if (carray[i+1]<=barrier) then
                begin  carray[i]:=carray[i+1];
                   carray[i+1]:=barrier;
                   i:=i+1;
                end
                else
                begin  if (carray[j]<barrier) then
                   begin  aux:=carray[j];
                      carray[j]:=carray[i+1];
                      carray[i+1]:=aux;
                    end;
                   j:=j-1;
                end;
             end;
             quick(low,i-1);
             quick(i+1,hi);
           end;
end;
{--------------------------------------------------------------------------}
function afind(a : real;len : integer): integer;
 var
  pos,i : integer;
 begin
  pos:=Round(len/2);
  i:=Round(len/2);
  if a=carray[len] then begin afind:=len; exit; end;
  while (pos>=1) and (pos<len+1) do
   begin
    if a=carray[pos] then begin afind:=pos; exit; end;
    if a>carray[pos] then  pos:=Round(pos+i/2)
    else pos:=Trunc(pos-i/2);
    i:=Round(i/2);
   end;
  if pos>len then pos:=0;
  afind:=pos;
 end;
{--------------------------------------------------------------------------}
begin
 {Assign(_in,'data.dat');
 Reset(_in); }
 randomize;
 for i:=1 to n do
  {if not EOF(_in) then}
   carray[i]:=random(100);
  {else break;}
 quick(1,i);
 WriteLn('Что искать? :');
 ReadLn(a);
 WriteLn('Обьект найден в элементе с номером ',afind(a,i-5));
 ReadLn;
 Close(_in);
end.