CONST
 NScores = 5;
 NPupils = 8;
type 
 TScores = array [1..NScores] of 1..5;
 TPupil = record
  Name  : string[30];
  Marks : TScores;
  Score : Word;
 end;

var
 Pupils      : array [1..NPupils] of TPupil;
 Temp        : TPupil;
 Last        : array [1..NPupils] of Byte;
 i,j         : byte;
begin
  Assign(Input,'2.txt');
  {$I-}
    Reset(Input);
  {$I+}
  If IOResult <> 0 then
   begin
    WriteLn('Error opening input file!');
    Halt(200);
   end;

  FillChar(Last,0,NPupils);

  for i := 1 to NPupils do
  with Pupils[i] do
   begin
     Read(Name);
     Score := 0;
     For j := 1 to NScores do 
     begin
      Read(Marks[j]);
      Inc(Score,Marks[j]);
      if Marks[j] <= 2 then Inc(Last[i]);
     end;
     ReadLn;
   end;
  close(Input);

  for i := 1 to NPupils-1 do
   for j:= i+1 to NPupils do
     if Pupils[j].Score > Pupils[i].Score then
      begin
       Temp := Pupils[j];
       Pupils[j] := Pupils[i];
       Pupils[i] := Temp;
      end;
  Assign(Output,'Sorted.txt');
  Rewrite(output);
  WriteLn('                 Результаты экзаменов ');
  WriteLn(' студенты отсортированы в порядке убывания успеваемости');
  for i := 1 to NPupils do
   begin
     Write(Pupils[i].Name);
     For j := 1 to NScores do 
      Write(Pupils[i].Marks[j],' ');
     WriteLn;
   end;
  close(Output);
  Assign(OutPut,'exclude.txt');
  Rewrite(OutPut);
  WriteLn('               Список студентов, представленных на отчисление: ');
  for i := 1 to NPupils do
   if Last[i] > 1 then 
     WriteLn(Pupils[i].Name);
  Close(OutPut);
end.