PROGRAM minmaxcount
  IMPLICIT NONE

  DOUBLE PRECISION, ALLOCATABLE :: a(:)
  INTEGER :: n, j, k
  DOUBLE PRECISION, PARAMETER :: pi = 3.14159265358979323846d0
  DOUBLE PRECISION :: minv, maxv

  PRINT *, "Dwse to N"
  READ *, n

  ALLOCATE(a(n))

  DO j = 1, SIZE(a)
     a(j) = SIN(pi * j / N)
  END DO

  ! A' tropos, me DO
  
  minv = a(1)
  DO j=2,SIZE(a)
     IF (a(j) < minv) minv = a(j)
  ENDDO

  maxv = a(1)
  DO j=2,SIZE(a)
     IF (a(j) > maxv) maxv = a(j)
  ENDDO
 
  k = 0
  DO j=1,SIZE(a)
     IF (ABS(a(j)) > 0.4d0) k = k+1
  END DO

  PRINT *, "to elaxisto stoixeio einai (me DO): ", minv
  PRINT *, "to megisto stoixeio einai (me DO): ", maxv
  PRINT *, "to plithos twn stoixeiwn poy einai megalytera kat' apolyth timh apo 0.4 einai (me DO): ", k

  ! B' tropos
  
  minv = MINVAL(a)
  maxv = MAXVAL(a)
  k = COUNT(ABS(a)>0.4d0)

  PRINT *, " to elaxisto stoixeio einai (me minval): ", minv
  PRINT *, " to megisto stoixeio einai (me maxval): ", maxv
  PRINT *, "to plithos twn stoixeiwn poy einai megalytera kat' apolyth timh apo 0.4 einai (me count): ", k

END PROGRAM minmaxcount
