#include<bits/stdc++.h>
#define ll long long

using namespace std;
int n;
ll a[500010];
int binarno[500010][65];
bool neparno[65];
bool nepom[65];
ll stepen2[65];
ll maxc=62;

void rastavi(int i)
{
    ll tek=a[i];
    for(int j=0;j<maxc && tek!=0;j++)
        binarno[i][j]=tek%2, tek/=2;
}

ll najbolje(int i, int j)
{
    if(binarno[i][j]==1)
        return 0;
    ll uvecaj=stepen2[j]-(a[i]%stepen2[j]);
    if(stepen2[j]>a[i])
        return uvecaj;
    ll smanji=a[i]%stepen2[j]+1;
    return min(uvecaj,smanji);
}

ll resi(int j)
{
    ll ret=0;
    for(int i=0;i<n;i++)
        ret+=najbolje(i,j);
    return ret;
}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];

    stepen2[0]=1;
    for(int i=1;i<maxc;i++)
        stepen2[i]=stepen2[i-1]*2;

    for(int i=0;i<n;i++)
        rastavi(i);

    for(int j=0;j<64;j++)
    {
        int sum=0;
        for(int i=0;i<n;i++)
            sum+=binarno[i][j];
        if(sum%2==1)
            neparno[j]=true;
        else
            neparno[j]=false;
    }

    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<64;j++)
            cout<<binarno[i][j];
        cout<<endl;
    }*/

    ll sol=LONG_LONG_MAX;
    if(n%2==1)
    {
        for(int j=0;j<maxc;j++)
            sol=min(sol,resi(j));
        cout<<sol;
    }
    else
    {
        for(;;);
    }
}