#include <cstdlib>
#include <cstdio>
#define gr 500010
#define ll long long
ll a[gr];
ll r[60];
inline ll manje(ll aaa,ll bbb){if(aaa<bbb)return aaa;return bbb;}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i)scanf("%d",a+i);
    r[0]=0;
    for(int i=0;i<n;++i)if((a[i]&1)==0)++r[0];
    ll b=2;
    for(int s=1;s<60;++s)
    {
        r[s]=0;
        for(int i=0;i<n;++i)
        {
            if((a[i]&b)==0)
            {
                ll opaaa;
                ll xxx=b-(a[i]&(b-1));
                ll yyy=b+1-xxx;
                if((a[i]&(b-1))==a[i])opaaa=xxx;
                else opaaa=manje(xxx,yyy);
                r[s]+=opaaa;
                if(r[s]>1000000)break;
            }
        }
        b<<=1;
    }
    int smin=0;
    int rmin=r[0];
    for(int i=1;i<60;++i)
    {
        if(r[i]<=rmin)
        {
            rmin=r[i];
            smin=i;
        }
    }
    if(smin==0)
    {
        bool sven=true;
        for(int i=0;i<n;++i)if((a[i]>1)&&((a[i]&1)==0)){sven=false;break;}
        if(sven)
        {
            printf("%d\n",r[0]+2*((n+1)&1));
            return 0;
        }
        printf("%d\n",r[0]);
        return 0;
    }
    b=1<<smin;
    ll xr=0;
    for(int i=0;i<n;++i)
    {
        if((a[i]&b)==0)
        {
            ll xxx=b-(a[i]&(b-1));
            ll yyy=b+1-xxx;
            if((a[i]&(b-1))==a[i])xr^=b;
            if(xxx<yyy)xr^=a[i]+xxx;
            else xr^=a[i]-yyy;
        }
        else xr^=a[i];
    }
    ll res=rmin;
    if(xr==0)++res;
    printf("%lld\n",res);
    return 0;
}