PROGRAM ClassGrades (Input,Output);

CONST
   MaxStudents = 100;

TYPE
   GradesRange = 0..100;
   StudentsRange = 0..MaxStudents;
   GradesArray = ARRAY[StudentsRange] OF GradesRange;
   RangeArray = ARRAY[1..10] OF Integer;

VAR
   Grades : GradesArray;
   Ranges : RangeArray;
   NumStudents : StudentsRange;
   i : Integer;
   Mean, StandardDeviation : Real;



PROCEDURE GetGrades (VAR Grades : GradesArray;
                     VAR Length : StudentsRange);
Var
   Grade : Integer;
Begin
   Length := 0;
   WHILE NOT EOF DO
     Begin
       Readln(Grade);
       IF (Grade >= 0) AND (Grade <= 100) THEN
         Begin
           Length := Length + 1;
           Grades[Length] := Grade;
         End
       ELSE
          Writeln('Invalid grade value: ',Grade);
     End
End;



PROCEDURE GetStats (VAR Grades : GradesArray; Length : StudentsRange;
                    VAR Mean, StandardDev : Real;
                    VAR RAnges : RangeArray);
Var
   i, k, Sum : Integer;
   DiffSum : Real;
Begin
   Sum := 0;
   FOR i := 1 TO Length DO
     Begin
       Sum := Sum + Grades[i];
       k := Trunc(Grades[i] / 10) + 1;
       Ranges[k] := Ranges[k] + 1;
     End;

   Mean := Sum / Length;

   DiffSum := 0;
   FOR i := 1 TO Length DO
      DiffSum := DiffSum + Abs(Grades[i] - Mean);

   StandardDev := DiffSum / Length;
End;



PROCEDURE DisplayStats (Mean, StandardDev : Real;
                        VAR Ranges : RangeArray);
Var
   i, j : Integer;
Begin
   Writeln('Mean: ',Mean:5:2,'   Standard Deviation: ',StandardDev:5:2);
   FOR i := 1 TO 10 DO
     Begin
       Write(((i-1)*10):2,'-',((i*10)-1):2,': ');
       FOR j := 1 TO Ranges[i] DO
          Write('*');
       Writeln;
     End;
End;



BEGIN
   FOR i := 1 TO 10 DO
      Ranges[i] := 0;

   GetGrades(Grades,NumStudents);

   GetStats(Grades,NumStudents,Mean,StandardDeviation,Ranges);

   DisplayStats(Mean,StandardDeviation,Ranges);
END.
