PROGRAM nearmo
  IMPLICIT NONE

  INTEGER :: a(3590), i,j
  DOUBLE PRECISION :: mo
  
  OPEN (25, file="ints", action="read", status="old")
  
  DO i=1,SIZE(a)
     READ (25,*) a(i)     
  END DO
  CLOSE (25)
  
  
  mo = SUM(a) / DBLE(SIZE(a))
  ! A' τρόπος υπολογισμού του j
  j = MINLOC(ABS(mo-a),1) 

  
  ! Β' τρόπος υπολογισμού του j
  j=1
  DO i = 2,SIZE(a)
     IF (ABS(mo - a(i)) < ABS(mo - a(j))) j = i
  END DO
  

  PRINT *, mo, a(j)
  
END PROGRAM nearmo
