Const
  n = 10;
Type Tname = record
  name,surname : string[20];
  phone        : string[8];
End;

Var
 ar1   : array [1..n] of Tname;
 tmp   : Tname;
 l,r,i : 1..n;
 f0    : string[20];
 k,j   : 1..n;
{--------==================---------------}
Procedure ReadStr(name_of_file:string);
Var
 s1  : array [1..n] of string;
 f1  : text;
 val : 1..3;
 h   : 1..n;
 l   : byte;
Begin
  assign(f1,name_of_file);
  reset(f1);
  for h := 1 to n do readln(f1,s1[h]);
  Close(f1);
  val := 1;
  for h := 1 to n do
    for l := 1 to length(s1[h]) do
      begin
       if s1[h,l] <> ' ' then
        case val of
         1: ar1[h].name := ar1[h].name+s1[h,l];
         2: ar1[h].surname := ar1[h].surname+s1[h,l];
         3: ar1[h].phone := ar1[h].phone+s1[h,l];
        end
       else inc(val);
       if l = length(s1[h]) then val := 1;
      end;
End;{ReadStr}
{-----------------------------}
Begin
  l := 1;
  r := n;
  ReadStr('num.txt');
  for k := 1 to n do
    for j := k+1 to n do
     if ar1[j].surname < ar1[k].surname then
       begin
         tmp.surname := ar1[k].surname;
         ar1[k].surname := ar1[j].surname;
         ar1[j].surname := tmp.surname;
         tmp.name := ar1[k].name;
         ar1[k].name := ar1[j].name;
         ar1[j].name := tmp.name;
         tmp.phone := ar1[k].phone;
         ar1[k].phone := ar1[j].phone;
         ar1[j].phone := tmp.phone;
       end;
  Write('Enter surname for search in base: ');
  Readln(f0);
  while l < r do
    if ar1[(l+r) div 2].surname >= f0 then r := (l+r) div 2
    else l := (l+r) div 2+1;
  if f0 = ar1[r].surname then WriteLn(ar1[r].name,' ',ar1[r].surname,' ',ar1[r].phone)
  else WriteLn('There are no records for that surname');
  ReadLn;
End.