PROGRAM CompAvers
   IMPLICIT NONE

   INTEGER          :: NumSec, NumExam, NumStudent, NumStudentClass
   INTEGER          :: Sec, SecTot, ClassTot, Student, StudentTot
   INTEGER          :: Score, Sco
   REAL             :: StudentAve, SecAve, ClassAve
   CHARACTER(len=4) :: StudentID

   READ *, NumSec, NumExam
   WRITE(*,*) NumSec, ' sections and ' , NumExam , ' exams.'

   NumStudentClass = 0
   ClassTot = 0

   DO Sec = 1, NumSec
      READ(*,*) NumStudent
      WRITE(*,*) 'Section ', Sec , ' has ', NumStudent , ' students.'
      NumStudentClass = NumStudentClass + NumStudent
      SecTot = 0

      DO Student = 1, NumStudent
         READ(*,*) StudentID
         StudentTot = 0
         DO Sco = 1, NumExam 
            READ(*,*) Score
            StudentTot = StudentTot + Score
         END DO
         StudentAve = REAL(StudentTot) / REAL(NumExam)
         WRITE(*,*) 'Student ',StudentID,' average: ', StudentAve
         SecTot = SecTot + StudentAve
      END DO 
      SecAve = REAL(SecTot) / REAL(NumStudent)
      WRITE(*,*)
      WRITE(*,*) 'The average for section ',Sec,' is ', SecAve
      WRITE(*,*)
      ClassTot = ClassTot + SecTot
   END DO
   ClassAve = REAL(ClassTot) / REAL(NumStudentClass)
   WRITE(*,*) 'The average for the entire Class is: ', ClassAve

END PROGRAM CompAvers
