Codeforces Round #312 (Div. 2) C.amr and chemistry

Source: Internet
Author: User

AMR loves chemistry, and specially doing experiments. He is preparing for a new interesting experiment.

AMR has n different types of chemicals. Each chemical i have an initial volume of a liters. For this experiment, the AMR have to mix all the chemicals together, but all the chemicals volumes must is equal first. So he task is the chemicals volumes equal.

To does this, the AMR can do different kind of operations.

    • Choose Some chemical i and double its current volume so the new volume would be 2ai
    • Choose Some chemical I and divide its volume by II (integer division) so the new volume would be

Suppose that each chemical are contained in a vessel of infinite volume. Now AMR wonders what's the minimum number of operations required to make all the chemicals volumes equal?

Input

The first line contains one number n (1≤ n ≤105), the number of chemicals.

The second line contains n space separated integers ai (1≤ a I ≤105), representing the initial volume of the I-th chemical in liters.

Output

Output One integer The minimum number of operations required to make all the chemicals volumes equal.

Sample Test (s) input
3
4 8 2
Output
2
Input
3
3 5 6
Output
5
Note

In the first sample test, the optimal solution are to divide the second chemical volume by both, and multiply the third chem ical volume by and volumes equal 4.

In the second sample test, the optimal solution are to divide the first chemical volume by both, and divide the second and T He third chemical volumes by and twice to make all the volumes equal 1.

The puzzle: By the value of the search handed up on the full ...

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn=100000+Ten, maxv=100000, inf=-1u>>1; One intVis[maxn],cnt[maxn],stp[maxn],n; AInlineintRead () { -     intx=0, sig=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} the      while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); -     returnx*=Sig; - } -InlinevoidWriteintx) { +     if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; -     intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; +      for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; A } at voidinit () { -n=read (); -queue<pair<int,int> >Q; -      for(intI=1; i<=n;i++){ -         intNum=read (); Q.push (num, Make_pair0)); -          while(!Q.empty ()) { in             intX=q.front (). first,y=Q.front (). Second; Q.pop (); -             if(x>maxv| | Vis[x]==i)Continue; tovis[x]=i;cnt[x]++;stp[x]+=y; +Q.push (Make_pair (x<<1, y+1)); -Q.push (Make_pair (x>>1, y+1)); the         } *     } $     intMi=inf;Panax Notoginseng      for(intI=0; i<=maxv;i++)if(CNT[I]==N&AMP;&AMP;STP[I]&LT;MI) mi=Stp[i]; - write (MI); the     return; + } A voidWork () { the     return; + } - voidprint () { $     return; $ } - intMain () {init (); work ();p rint ();return 0;}

Codeforces Round #312 (Div. 2) C.amr and chemistry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.