PROGRAM ComputeMeans
   IMPLICIT NONE

   REAL     :: Number, Sum, Product, InverseSum
   REAL     :: Arithmetic, Geometric, Harmonic
   INTEGER  :: Count, TotalNumber, TotalValid

   Sum        = 0.0
   Product    = 1.0
   InverseSum = 0.0
   TotalValid = 0

   READ(*,*) TotalNumber
   DO Count = 1, TotalNumber
      READ(*,*) Number
      IF ( Number < 0.0 ) THEN
         WRITE(*,*) ' Input <= 0. Ignored'
      ELSE
         TotalValid = TotalValid + 1
         Sum        = Sum + Number
         Product    = Product * Number
         InverseSum = InverseSum + ( 1.0 / Number )
      END IF
   END DO

   IF ( TotalValid > 0 ) THEN

      Arithmetic = Sum / TotalValid
      Geometric  = Product ** ( 1.0 / TotalValid )
      Harmonic   = TotalValid  / InverseSum

      WRITE(*,*) 'No. of valid items --> ', TotalValid
      WRITE(*,*) 'Averages: ', Arithmetic, Geometric, Harmonic

   ELSE
      WRITE(*,*) 'Error: none of the input were positive'
   END IF

END PROGRAM ComputeMeans
