uses sysutils;
const
f_input: string = 'list.txt';    { ,
       ,
       ,
                   }
foutput: string = 'task.html';  { ,
          
           }
fanswer: string = 'answer.txt'; { ,
          
               ;}
nu=9;                   { 
           }
abc: string='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var w: array[0..10000] of word;      c: char;
    u: array[0..nu]    of byte;   t,t1,t2: string;
    s: array[0..nu+1]  of ansistring;
  off,a,i,o,it: textfile;    ja,j,k,l,m,n,p: word;
{$I-}
procedure rep(s: string); var o:textfile;BEGIN
assign (o,'ReadMe.txt');  rewrite(o);
writeln(o,s);   close(o);    halt(0)       END;
                                         BEGIN
if not fileexists(f_input)
 then rep(' '+f_input+' !');
if not fileexists(foutput)
 then rep(' '+foutput+' !');
assign(i,f_input); reset(i);
assign(o,foutput); reset(o);  readln(o,t);  readln(o,t1);  readln(o,t2);
 close(o);       rewrite(o); writeln(o,t); writeln(o,t1); writeln(o,t2);
assign(a,fanswer); rewrite(a);
ja:=0;       {ja -   }
j:=0;  randomize;
repeat inc(j);
  read(i,k);    {k -    }
  if (ioresult<>0) then rep(' '+
      '   '+inttostr(j));
  readln(i,t);     {t -   }
  while t[1]=' ' do delete(t,1,1);
  if fileexists(t) and (k>0) then         BEGIN
    assign(it,t);
    reset (it);
    n:=0;
    repeat readln(it,c);
           if c<>' ' then inc(n)
     until eof(it);
    close(it);
    n:=(n div 2)-1;        {n -  
                                t}
    if n<k then rep('   '+t);

        {    
                          1..n
                            w[n-k+1..n]}
    for j:=1 to n do w[j]:=j;
    for j:=1 to k do                     begin
        l:=1+random(n-j+1);
        w[0]:=w[l];
              w[l]:=w[n-j+1];
                    w[n-j+1]:=w[0]         end;

    k:=n-k+1; {w[k..n]-  }

                 {  w[k..n]}
    for j:=n downto k+1 do               begin
    m:=k;
    for l:=k+1 to j do  if w[l]>w[m] then m:=l;
    w[0]:=w[m];  w[m]:=w[j];  w[j]:=w[0]   end;

    reset(it);
    j:=0;     {˳ ,  
                  " "}
    assign(off,'off.txt'); rewrite(off);{!!!}
    repeat
      readln(it,s[0]);
      writeln(off,s[0]);{!!!}
     if s[0][1]<>' ' then inc(j);
     if (j+1) div 2 =w[k]  then          begin
       inc(ja);
       write(a,ja);
                     {   ja}
       writeln(o,s[0]);
       l:=0;   {˳  }
       repeat inc(l);  readln(it,s[l]);
        until s[l][1]<>' ';
       dec(l);
       if l>0 then                       begin
          {   
               1..l   u[1..l]}
         for m:=1 to l do u[m]:=m;
         for m:=1 to l do                begin
           p:=1+random(l-m+1);
           u[0]:=u[p];
                 u[p]:=u[l-m+1];
                       u[l-m+1]:=u[0]      end;

                 {  }
         for m:=1 to l do writeln(o,s[u[m]]);

         {  
             ja}
         for m:=1 to l do for p:=1 to l do
         if u[p]=m then write(a,' ',abc[p])     end;
         writeln(o,s[l+1]);
         inc(k);  inc(j);
       writeln(a); close(off)            end;
    until (n<k);
    close(it)                              END
  else if (k>0) then rep(' '+t+' !');
until eof(i);
writeln(o,'</body></HTML>');
  close(a);   close(i);   close(o)         END.
