program together
  implicit none
  integer :: n, i, m, summ
  integer,allocatable :: a(:)
  real :: ave
  read(*,*) n
  allocate(a(n))
  read(*,*) a

  ave = real(sum(a),4)/real(size(a),4)

  if ( ave - int(ave) >= 0.5 ) then
     m = int(ave) + 1
  else
     m = int(ave)
  end if
  
  summ = 0
  do i = 1, n
     summ = summ + (a(i)-m)*(a(i)-m)
  end do
  write(*,*) summ
  deallocate(a)
  stop
end program together
