# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo;
int n;

ll bat(ll k){
    int ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll get_it(int k){
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=20; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        for (int i=2; i<=n; i++) {
            y=a[i];
            if (b[i]<x) y<<=(x-b[i]); else y>>=(b[i]-x);
            if (T!=y) {
                cnt=oo;
                break;
            }
            cnt+=abs(x-b[i]);
        }
        z=min(z,cnt);
    }

    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%I64d",&a[i]);
        b[i]=bat(a[i]);
    }
    swap(a[1],a[2]);
    swap(b[1],b[2]);
    for (int i=1; i<=30; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo;
int n;

ll bat(ll k){
    int ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll get_it(int k){
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=30; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        for (int i=2; i<=n; i++) {
            y=a[i];
            if (b[i]<x) y<<=(x-b[i]); else y>>=(b[i]-x);
            if (T!=y) {
                cnt=oo;
                break;
            }
            cnt+=abs(x-b[i]);
        }
        z=min(z,cnt);
    }

    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%I64d",&a[i]);
        b[i]=bat(a[i]);
    }
    for (int i=1; i<=30; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo,N;
//map <ll,int> M;
int n;

ll bat(ll k){
    ll ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll bbt(ll x,ll y){
	//cout<<x<<" "<<y<<endl;
	ll t=0;
	while (x && x!=y && (x&1)==0) {
		t++;
		x>>=1;
		y>>=1;
	}
	if (x==y) return 2*t; else return oo;
}

ll get_it(int k){
	//if ((a[1]>>(N-k)&1)==0) return oo;
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=15; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        if (T<0) return z;
        for (int j=2; j<=n; j++) {
            y=a[j];
            if (b[j]<x) y<<=(x-b[j]); else y>>=(b[j]-x);
            if (T!=y) {
                ll p=bbt(T,y);
                if (p>=oo) return oo;
                cnt+=p;
                if (b[j]<x) {
                	cnt-=abs(x-b[j]);
                	continue;
				}
            }
            cnt+=abs(x-b[j]);
        }
        z=min(z,cnt);
        //if (z==90) cout<<k<<" "<<i<<endl;
    }
    //cout<<k<<endl;
    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) scanf("%I64d",&a[i]);
    sort(a+1,a+n+1);
    for (int i=1; i<=n; i++) b[i]=bat(a[i]);
    N=bat(a[1]);
    get_it(2);
    for (int i=1; i<=N; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

int n,a[200005],b[200005],ans=oo;

int bat(int k){
    int ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

int get_it(int k){
    int t=a[1],x=b[1],y;
    if (x<k) t<<=(k-x); else t>>=(x-k);
    int cnt=abs(k-x);
    for (int i=2; i<=n; i++) {
        y=a[i];
        if (b[i]<k) y<<=(k-b[i]); else y>>=(b[i]-k);
        if (t!=y) return oo;
        cnt+=abs(k-b[i]);
    }
    return cnt;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%d",&a[i]);
        b[i]=bat(a[i]);
    }
    for (int i=1; i<=40; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo;
int n;

ll bat(ll k){
    ll ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll bbt(ll x,ll y){
	//cout<<x<<" "<<y<<endl;
	ll t=0;
	while (x && x!=y && (x&1)==0) {
		t++;
		x>>=1;
		y>>=1;
	}
	if (x==y) return 2*t; else return oo;
}

ll get_it(int k){
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=20; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        if (T<0) return z;
        for (int j=2; j<=n; j++) {
            y=a[j];
            if (b[j]<x) y<<=(x-b[j]); else y>>=(b[j]-x);
            if (T!=y) {
                ll p=bbt(T,y);
                if (p>=oo) return oo;
                cnt+=p;
                if (b[j]<x) {
                	cnt-=abs(x-b[j]);
                	continue;
				}
            }
            cnt+=abs(x-b[j]);
        }
        z=min(z,cnt);
        //if (z==90) cout<<k<<" "<<i<<endl;
    }
    //cout<<k<<endl;
    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%I64d",&a[i]);
        b[i]=bat(a[i]);
    }
    //get_it(8);
    for (int i=1; i<=30; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo;
int n;

ll bat(ll k){
    int ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll get_it(int k){
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=20; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        for (int i=2; i<=n; i++) {
            y=a[i];
            if (b[i]<x) y<<=(x-b[i]); else y>>=(b[i]-x);
            if (T!=y) {
                cnt=oo;
                break;
            }
            cnt+=abs(x-b[i]);
        }
        z=min(z,cnt);
    }

    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%I64d",&a[i]);
        b[i]=bat(a[i]);
    }
    for (int i=1; i<=30; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo,N;
//map <ll,int> M;
int n;

ll bat(ll k){
    ll ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll bbt(ll x,ll y){
	//cout<<x<<" "<<y<<endl;
	ll t=0;
	while (x && x!=y && (x&1)==0) {
		t++;
		x>>=1;
		y>>=1;
	}
	if (x==y) return 2*t; else return oo;
}

ll get_it(int k){
	//if ((a[1]>>(N-k)&1)==0) return oo;
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=20; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        if (T<0) return z;
        for (int j=2; j<=n; j++) {
            y=a[j];
            if (b[j]<x) y<<=(x-b[j]); else y>>=(b[j]-x);
            if (T!=y) {
                ll p=bbt(T,y);
                if (p>=oo) return oo;
                cnt+=p;
                if (b[j]<x) {
                	cnt-=abs(x-b[j]);
                	continue;
				}
            }
            cnt+=abs(x-b[j]);
        }
        z=min(z,cnt);
        //if (z==90) cout<<k<<" "<<i<<endl;
    }
    //cout<<k<<endl;
    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) scanf("%I64d",&a[i]);
    sort(a+1,a+n+1);
    for (int i=1; i<=n; i++) b[i]=bat(a[i]);
    N=bat(a[1]);
    get_it(2);
    for (int i=1; i<=N+5; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo;
int n;

ll bat(ll k){
    ll ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll bbt(ll x,ll y){
	//cout<<x<<" "<<y<<endl;
	ll t=0;
	while (x && x!=y && (x&1)==0) {
		t++;
		x>>=1;
		y>>=1;
	}
	if (x==y) return 2*t; else return oo;
}

ll get_it(int k){
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=15; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        if (T<0) return z;
        for (int j=2; j<=n; j++) {
            y=a[j];
            if (b[j]<x) y<<=(x-b[j]); else y>>=(b[j]-x);
            if (T!=y) {
                ll p=bbt(T,y);
                if (p>=oo) return oo;
                cnt+=p;
                if (b[j]<x) {
                	cnt-=abs(x-b[j]);
                	continue;
				}
            }
            cnt+=abs(x-b[j]);
        }
        z=min(z,cnt);
        //if (z==90) cout<<k<<" "<<i<<endl;
    }
    //cout<<k<<endl;
    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%I64d",&a[i]);
        b[i]=bat(a[i]);
    }
    //get_it(8);
    for (int i=1; i<=17; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005];
int n,ans=oo;

int bat(ll k){
    int ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

int get_it(int k){
    ll t=a[1],x=b[1],y;
    if (x<k) t<<=(k-x); else t>>=(x-k);
    int cnt=abs(k-x);
    for (int i=2; i<=n; i++) {
        y=a[i];
        if (b[i]<k) y<<=(k-b[i]); else y>>=(b[i]-k);
        if (t!=y) return oo;
        cnt+=abs(k-b[i]);
    }
    return cnt;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%I64d",&a[i]);
        b[i]=bat(a[i]);
    }
    for (int i=1; i<=40; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo;
int n;

ll bat(ll k){
    ll ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll bbt(ll x,ll y){
	//cout<<x<<" "<<y<<endl;
	ll t=0;
	while (x && x!=y && (x&1)==0) {
		t++;
		x>>=1;
		y>>=1;
	}
	if (x==y) return 2*t; else return oo;
}

ll get_it(int k){
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=30; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        if (T<0) return z;
        for (int j=2; j<=n; j++) {
            y=a[j];
            if (b[j]<x) y<<=(x-b[j]); else y>>=(b[j]-x);
            if (T!=y) {
                ll p=bbt(T,y);
                if (p>=oo) return oo;
                cnt+=p;
                if (b[j]<x) {
                	cnt-=abs(x-b[j]);
                	continue;
				}
            }
            cnt+=abs(x-b[j]);
        }
        z=min(z,cnt);
        //if (z==90) cout<<k<<" "<<i<<endl;
    }
    //cout<<k<<endl;
    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%I64d",&a[i]);
        b[i]=bat(a[i]);
    }
    get_it(8);
    for (int i=1; i<=30; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo;
int n;

ll bat(ll k){
    ll ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll bbt(ll x,ll y){
	//cout<<x<<" "<<y<<endl;
	ll t=0;
	while (x && x!=y && (x&1)==0) {
		t++;
		x>>=1;
		y>>=1;
	}
	if (x==y) return 2*t; else return oo;
}

ll get_it(int k){
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=20; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        if (T<0) return z;
        for (int j=2; j<=n; j++) {
            y=a[j];
            if (b[j]<x) y<<=(x-b[j]); else y>>=(b[j]-x);
            if (T!=y) {
                ll p=bbt(T,y);
                if (p>=oo) return oo;
                cnt+=p;
                if (b[j]<x) {
                	cnt-=abs(x-b[j]);
                	continue;
				}
            }
            cnt+=abs(x-b[j]);
        }
        z=min(z,cnt);
        //if (z==90) cout<<k<<" "<<i<<endl;
    }
    //cout<<k<<endl;
    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%I64d",&a[i]);
        b[i]=bat(a[i]);
    }
    //get_it(8);
    for (int i=1; i<=17; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[200005],b[200005],ans=oo;
int n;

ll bat(ll k){
    int ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll get_it(int k){
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=10; i++){
        cnt=cnt0+i;
        x=x0+i;
        T=(t<<i);
        for (int i=2; i<=n; i++) {
            y=a[i];
            if (b[i]<x) y<<=(x-b[i]); else y>>=(b[i]-x);
            if (T!=y) {
                cnt=oo;
                break;
            }
            cnt+=abs(x-b[i]);
        }
        z=min(z,cnt);
    }

    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
        scanf("%I64d",&a[i]);
        b[i]=bat(a[i]);
    }
    for (int i=1; i<=30; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
//const int _p = 1007;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

ll a[100005],b[100005],ans=oo,N,P;
//map <ll,int> M;
int n;

ll bat(ll k){
    ll ans=0;
    while (k){
        ans++;
        k>>=1;
    }
    return ans;
}

ll bbt(ll x,ll y){
	//cout<<x<<" "<<y<<endl;
	ll t=0;
	while (x && x!=y && (x&1)==0) {
		t++;
		x>>=1;
		y>>=1;
	}
	if (x==y) return 2*t; else return oo;
}

ll get_it(int k){
	//if ((a[1]>>(N-k)&1)==0) return oo;
    ll t=a[1],x0=b[1],y,z=oo;
    if (x0<k) t<<=(k-x0); else t>>=(x0-k);
    ll cnt0=abs(k-x0),cnt,x,T;
    x0=k;
    for (int i=0; i<=20; i++){
        cnt=cnt0+i;
        x=x0+i;
        if (x>P) break;
        T=(t<<i);
        if (T<0) return z;
        for (int j=2; j<=n; j++) {
            y=a[j];
            if (b[j]<x) y<<=(x-b[j]); else y>>=(b[j]-x);
            if (T!=y) {
                ll p=bbt(T,y);
                if (p>=oo) return oo;
                cnt+=p;
                if (b[j]<x) {
                	cnt-=abs(x-b[j]);
                	continue;
				}
            }
            cnt+=abs(x-b[j]);
        }
        z=min(z,cnt);
        //if (z==90) cout<<k<<" "<<i<<endl;
    }
    //cout<<k<<endl;
    return z;
}

int main() {
    //file_put();

    scanf("%d",&n);
    for (int i=1; i<=n; i++) scanf("%I64d",&a[i]);
    sort(a+1,a+n+1);
    for (int i=1; i<=n; i++) b[i]=bat(a[i]);
    N=bat(a[1]);
    P=bat(a[n]);
    for (int i=1; i<=N; i++) ans=min(ans,get_it(i));
    cout<<ans<<endl;

    return 0;
}


#include <stdio.h>
#include <queue>
#include <utility>

#define MAX 100010

int n, cnt[MAX], steps[MAX], used[MAX];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x);

		std::queue<std::pair<int, int> > q;
		q.push(std::make_pair(x, 0));
		while (!q.empty())
		{
			std::pair<int, int> c = q.front();
			q.pop();

			if (c.first >= MAX || used[c.first] == i)
			{
				continue;
			}

			used[c.first] = i;
			cnt[c.first]++;
			steps[c.first] += c.second;

			q.push(std::make_pair(c.first / 2, c.second + 1));
			q.push(std::make_pair(c.first * 2, c.second + 1));
		}
	}

	int res = 1e9;
	for (int i = 0; i <= 100000; i++)
	{
		if (cnt[i] == n && steps[i] < res)
		{
			res = steps[i];
		}
	}

	printf("%d", res);
	return 0;
}


#include <stdio.h>
#include <queue>
#include <utility>

#define MAX 100010

int n, cnt[MAX], steps[MAX], used[MAX];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	for (int i = 0; i < MAX; i++)
	{
		used[i] = -1;
	}

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);

		std::queue<std::pair<int, int> > q;
		q.push(std::make_pair(x, 0));
		while (!q.empty())
		{
			std::pair<int, int> c = q.front();
			q.pop();

			if (c.first > MAX || used[c.first] == i)
			{
				continue;
			}

			used[c.first] = i;
			cnt[c.first]++;
			steps[c.first] += c.second;

			q.push(std::make_pair(c.first / 2, c.second + 1));
			q.push(std::make_pair(c.first * 2, c.second + 1));
		}
	}

	int res = 1e9;
	for (int i = 0; i < MAX; i++)
	{
		if (cnt[i] == n && steps[i] < res)
		{
			res = steps[i];
		}
	}

	printf("%d", res);
	return 0;
}


#include <stdio.h>

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

#define MAX 100010

int n, a[MAX], g = -1, l = -1;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		g = g == -1 ? a[i] : gcd(g, a[i]);
		l = l == -1 ? a[i] : lcm(l, a[i]);
	}

	if (n == 1)
	{
		printf("0");
		return 0;
	}

	l /= g;

	int res1 = 0;
	int res2 = 0;
	for (int i = 0; i < n; i++)
	{
		int x = a[i];
		while (((a[i] < l && x < l) || (a[i] > l && x > l)) && x > 0)
		{
			if (x > l) { x /= 2; }
			else { x *= 2; }
			res1++;
		}
		if (x != l) { res1 += 1000; }
		x = a[i];
		while (x > 1)
		{
			x /= 2;
			res2++;
		}
	}

	printf("%d", res1 > res2 ? res2 : res1);

	return 0;
}


#include <stdio.h>
#include <queue>
#include <utility>

#define MAX 100010

int n, cnt[MAX], steps[MAX], used[MAX];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	for (int i = 0; i < MAX; i++)
	{
		used[i] = -1;
	}

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);

		std::queue<std::pair<int, int>> q;
		q.push(std::make_pair(x, 0));
		while (!q.empty())
		{
			std::pair<int, int> c = q.front();
			q.pop();

			if (c.first > MAX || used[c.first] == i)
			{
				continue;
			}

			used[c.first] = i;
			cnt[c.first]++;
			steps[c.first] += c.second;

			q.push(std::make_pair(c.first / 2, c.second + 1));
			q.push(std::make_pair(c.first * 2, c.second + 1));
		}
	}

	int res = 1e9;
	for (int i = 0; i < MAX; i++)
	{
		if (cnt[i] == n && steps[i] < res)
		{
			res = steps[i];
		}
	}

	printf("%d", res);
	return 0;
}


#include <stdio.h>

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

#define MAX 100010

int n, a[MAX], g = -1, l = -1;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		g = g == -1 ? a[i] : gcd(g, a[i]);
		l = l == -1 ? a[i] : lcm(l, a[i]);
	}

	if (n == 1)
	{
		printf("0");
		return 0;
	}

	int res1 = 0;
	int res2 = 0;
	for (int i = 0; i < n; i++)
	{
		int x = a[i];
		while (((a[i] < l && x < l) || (a[i] > l && x > l)) && x > 0)
		{
			if (x > l) { x /= 2; }
			else { x *= 2; }
			res1++;
		}
		if (x != l) { res1 += 1000; }
		x = a[i];
		while (x > 1)
		{
			x /= 2;
			res2++;
		}
	}

	printf("%d", res1 > res2 ? res2 : res1);

	return 0;
}


#include <stdio.h>

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

#define MAX 100010

int n, a[MAX], g = -1, l = -1;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		g = g == -1 ? a[i] : gcd(g, a[i]);
		l = l == -1 ? a[i] : lcm(l, a[i]);
	}

	l /= g;

	int res1 = 0;
	int res2 = 0;
	for (int i = 0; i < n; i++)
	{
		int x = a[i];
		while (((a[i] < l && x < l) || (a[i] > l && x > l)) && x > 0)
		{
			if (x > l) { x /= 2; }
			else { x *= 2; }
			res1++;
		}
		if (x != l) { res1 += 1000; }
		x = a[i];
		while (x > 1)
		{
			x /= 2;
			res2++;
		}
	}

	printf("%d", res1 > res2 ? res2 : res1);

	return 0;
}


#include <stdio.h>

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

#define MAX 100010

int n, a[MAX], g = -1, l = -1;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		g = g == -1 ? a[i] : gcd(g, a[i]);
		l = l == -1 ? a[i] : lcm(l, a[i]);
	}

	if (n == 1)
	{
		printf("0");
		return;
	}

	l /= g;

	int res1 = 0;
	int res2 = 0;
	for (int i = 0; i < n; i++)
	{
		int x = a[i];
		while (((a[i] < l && x < l) || (a[i] > l && x > l)) && x > 0)
		{
			if (x > l) { x /= 2; }
			else { x *= 2; }
			res1++;
		}
		if (x != l) { res1 += 1000; }
		x = a[i];
		while (x > 1)
		{
			x /= 2;
			res2++;
		}
	}

	printf("%d", res1 > res2 ? res2 : res1);

	return 0;
}


#include <stdio.h>
#include <queue>
#include <utility>

#define MAX 100010

int n, cnt[MAX], steps[MAX], used[MAX];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x);

		std::queue<std::pair<int, int> > q;
		q.push(std::make_pair(x, 0));
		while (!q.empty())
		{
			std::pair<int, int> c = q.front();
			q.pop();

			if (c.first > MAX || used[c.first] == i)
			{
				continue;
			}

			used[c.first] = i;
			cnt[c.first]++;
			steps[c.first] += c.second;

			q.push(std::make_pair(c.first / 2, c.second + 1));
			q.push(std::make_pair(c.first * 2, c.second + 1));
		}
	}

	int res = 1e9;
	for (int i = 0; i <= 100000; i++)
	{
		if (cnt[i] == n && steps[i] < res)
		{
			res = steps[i];
		}
	}

	printf("%d", res);
	return 0;
}


#include <stdio.h>
#include <queue>
#include <utility>

#define MAX 100010

int n, cnt[MAX], steps[MAX], used[MAX];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x);

		std::queue<std::pair<int, int> > q;
		q.push(std::make_pair(x, 0));
		while (!q.empty())
		{
			std::pair<int, int> c = q.front();
			q.pop();

			if (c.first > MAX || used[c.first] == i)
			{
				continue;
			}

			used[c.first] = i;
			cnt[c.first]++;
			steps[c.first] += c.second;

			q.push(std::make_pair(c.first / 2, c.second + 1));
			q.push(std::make_pair(c.first * 2, c.second + 1));
		}
	}

	int res = 1e9;
	for (int i = 0; i < MAX; i++)
	{
		if (cnt[i] == n && steps[i] < res)
		{
			res = steps[i];
		}
	}

	printf("%d", res);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int a[100050];
int num[100010];
int v[1000060];
int maxx;
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(v,0,sizeof(v));
        maxx = -1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            v[a[i]]++;
            if(maxx<a[i])
            {
                maxx = a[i];
            }
        }
        for(int i=0; i<n; i++)
        {
            int t = a[i];
            int cnt = 0;
            while(t<maxx)
            {
                t = t<<1;
                cnt++;
                v[t]++;
                num[t] += cnt;
            }
            cnt = 0;
            int pp;
            t = a[i];
            while(t>0)
            {
                int flag = 0;
                if(t%2 == 1 && t!=1)
                {
                    flag = 1;
                }
                t = t>>1;
                cnt++;
                v[t]++;
                num[t] += cnt;
                if(flag == 1)
                {
                    pp = t<<1;
                    v[pp]++;
                    num[pp] += cnt+1;
                }
            }
        }
        int minn = 9999999;
        for(int i=0; i<=maxx; i++)
        {
            if(v[i] == n && minn > num[i])
            {
                minn = num[i];
            }
        }
        printf("%d\n",minn);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int a[1000050];
int num[1000010];
int v[10000060];
int maxx;
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(v,0,sizeof(v));
        maxx = -1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            v[a[i]]++;
            if(maxx<a[i])
            {
                maxx = a[i];
            }
        }
        for(int i=0; i<n; i++)
        {
            int t = a[i];
            int cnt = 0;
            while(t<maxx)
            {
                t = t<<1;
                cnt++;
                v[t]++;
                num[t] += cnt;
            }
            cnt = 0;
            int pp;
            t = a[i];
            while(t>0)
            {
                int flag = 0;
                if(t%2 == 1 && t!=1)
                {
                    flag = 1;
                }
                t = t>>1;
                cnt++;
                v[t]++;
                num[t] += cnt;
                if(flag == 1)
                {
                    pp = t<<1;
                    v[pp]++;
                    num[pp] += cnt+1;
                }
            }
        }
        int minn = 9999999;
        for(int i=0; i<=maxx; i++)
        {
            if(v[i] == n && minn > num[i])
            {
                minn = num[i];
            }
        }
        printf("%d\n",minn);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int a[1000050];
int num[1000010];
int v[10000060];
int maxx;
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(v,0,sizeof(v));
        maxx = -1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            v[a[i]]++;
            if(maxx<a[i])
            {
                maxx = a[i];
            }
        }
        for(int i=0; i<n; i++)
        {
            int t = a[i];
            int cnt = 0;
            while(t<maxx)
            {
                t = t<<1;
                cnt++;
                v[t]++;
                num[t] += cnt;
            }
            cnt = 0;
            int pp;
            t = a[i];
            while(t>0)
            {
                int flag = 0;
                if(t%2 == 1 && t!=1)
                {
                    flag = 1;
                }
                t = t>>1;
                cnt++;
                v[t]++;
                num[t] += cnt;
                if(flag == 1)
                {
                    pp = t;
                    int pcnt = cnt;
                    while(pp<maxx)
                    {
                        pp = pp<<1;
                        pcnt++;
                        v[pp]++;
                        num[pp] += pcnt;
                    }

                }
            }
        }
        int minn = 9999999;
        for(int i=0; i<=maxx; i++)
        {

            if(v[i] == n && minn > num[i])
            {
                minn = num[i];
            }
        }
        printf("%d\n",minn);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int a[300050];
int num[300010];
int v[3000060];
int maxx;
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(v,0,sizeof(v));
        maxx = -1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            v[a[i]]++;
            if(maxx<a[i])
            {
                maxx = a[i];
            }
        }
        for(int i=0; i<n; i++)
        {
            int t = a[i];
            int cnt = 0;
            while(t<maxx)
            {
                t = t<<1;
                cnt++;
                v[t]++;
                num[t] += cnt;
            }
            cnt = 0;
            int pp;
            t = a[i];
            while(t>1)
            {
                int flag = 0;
                if(t%2 == 1 && t!=1)
                {
                    flag = 1;
                }
                t = t>>1;
                cnt++;
                v[t]++;
                num[t] += cnt;
                if(flag == 1)
                {
                    pp = t<<1;
                    v[pp]++;
                    num[pp] += cnt+1;
                }
            }
        }
        int minn = 9999999;
        for(int i=0; i<=maxx; i++)
        {
            if(v[i] == n && minn > num[i])
            {
                minn = num[i];
            }
        }
        printf("%d\n",minn);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int a[100050];
int num[100010];
int v[1000060];
int maxx;
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(v,0,sizeof(v));
        maxx = -1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            v[a[i]]++;
            if(maxx<a[i])
            {
                maxx = a[i];
            }
        }
        for(int i=0; i<n; i++)
        {
            int t = a[i];
            int cnt = 0;
            while(t<maxx)
            {
                t = t<<1;
                cnt++;
                v[t]++;
                num[t] += cnt;
            }
            cnt = 0;
            int pp;
            t = a[i];
            while(t>1)
            {
                int flag = 0;
                if(t%2 == 1 && t!=1)
                {
                    flag = 1;
                }
                t = t>>1;
                cnt++;
                v[t]++;
                num[t] += cnt;
                if(flag == 1)
                {
                    pp = t<<1;
                    v[pp]++;
                    num[pp] += cnt+1;
                }
            }
        }
        int minn = 9999999;
        for(int i=0; i<=maxx; i++)
        {
            if(v[i] == n && minn > num[i])
            {
                minn = num[i];
            }
        }
        printf("%d\n",minn);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int a[100050];
int num[100010];
int v[1000060];
int maxx;
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(v,0,sizeof(v));
        maxx = -1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            v[a[i]]++;
            if(maxx<a[i])
            {
                maxx = a[i];
            }
        }
        for(int i=0; i<n; i++)
        {
            int t = a[i];
            int cnt = 0;
            while(t<maxx)
            {
                t = t<<1;
                cnt++;
                v[t]++;
                num[t] += cnt;
            }
            cnt = 0;
            int pp;
            t = a[i];
            while(t>0)
            {
                int flag = 0;
                if(t%2 == 1)
                {
                    flag = 1;
                }
                t = t>>1;
                cnt++;
                v[t]++;
                num[t] += cnt;
                if(flag == 1)
                {
                    pp = t<<1;
                    v[pp]++;
                    num[pp] += cnt+1;
                }
            }
        }
        int minn = 9999999;
        for(int i=1; i<=maxx; i++)
        {
            if(v[i] == n && minn > num[i])
            {
                minn = num[i];
            }
        }
        printf("%d\n",minn);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int a[100050];
int num[100010];
int v[1000060];
int maxx;
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(v,0,sizeof(v));
        maxx = -1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            v[a[i]]++;
            if(maxx<a[i])
            {
                maxx = a[i];
            }
        }
        for(int i=0; i<n; i++)
        {
            int t = a[i];
            int cnt = 0;
            while(t<=maxx)
            {
                t = t<<1;
                cnt++;
                v[t]++;
                num[t] += cnt;
            }
            cnt = 0;
            int pp;
            t = a[i];
            while(t>0)
            {
                int flag = 0;
                if(t%2 == 1)
                {
                    flag = 1;
                }
                t = t>>1;
                cnt++;
                v[t]++;
                num[t] += cnt;
                if(flag == 1)
                {
                    pp = t<<1;
                    v[pp]++;
                    num[pp] += cnt+1;
                }
            }
        }
        int minn = 9999999;
        for(int i=0; i<=maxx; i++)
        {
            if(v[i] == n && minn > num[i])
            {
                minn = num[i];
            }
        }
        printf("%d\n",minn);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int a[1000050];
int num[1000010];
int v[10000060];
int maxx;
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(v,0,sizeof(v));
        maxx = -1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            v[a[i]]++;
            if(maxx<a[i])
            {
                maxx = a[i];
            }
        }
        for(int i=0; i<n; i++)
        {
            int t = a[i];
            int cnt = 0;
            while(t<maxx)
            {
                t = t<<1;
                cnt++;
                v[t]++;
                num[t] += cnt;
            }
            cnt = 0;
            int pp;
            t = a[i];
            while(t>1)
            {
                int flag = 0;
                if(t%2 == 1 && t!=1)
                {
                    flag = 1;
                }
                t = t>>1;
                cnt++;
                v[t]++;
                num[t] += cnt;
                if(flag == 1)
                {
                    pp = t<<1;
                    v[pp]++;
                    num[pp] += cnt+1;
                }
            }
        }
        int minn = 9999999;
        for(int i=0; i<=maxx; i++)
        {
            if(v[i] == n && minn > num[i])
            {
                minn = num[i];
            }
        }
        printf("%d\n",minn);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int a[100050];
int num[100010];
int v[1000060];
int maxx;
int n;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        memset(num,0,sizeof(num));
        memset(v,0,sizeof(v));
        maxx = -1;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            v[a[i]]++;
            if(maxx<a[i])
            {
                maxx = a[i];
            }
        }
        for(int i=0; i<n; i++)
        {
            int t = a[i];
            int cnt = 0;
            while(t<=maxx)
            {
                t = t<<1;
                cnt++;
                v[t]++;
                num[t] += cnt;
            }
            cnt = 0;
            int pp;
            t = a[i];
            while(t>0)
            {
                int flag = 0;
                if(t%2 == 1)
                {
                    flag = 1;
                }
                t = t>>1;
                cnt++;
                v[t]++;
                num[t] += cnt;
                if(flag == 1)
                {
                    pp = t<<1;
                    v[pp]++;
                    num[pp] += cnt+1;
                }
            }
        }
        int minn = 9999999;
        for(int i=1; i<=maxx; i++)
        {
            if(v[i] == n && minn > num[i])
            {
                minn = num[i];
            }
        }
        printf("%d\n",minn);
    }
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const int MN=100*100*10*2;

int n,a[MN],c[MN],bu[MN],p[MN],pp[MN],mm=MN,lg;

int main(){
	for (int i=MN;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		pp[i]=p[i];
		bu[i]=c[i];
		mm=min(mm,c[i]);
	}
	ll ans=MN;
	for (mm=0;mm<MN;mm++){
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;bu[i]>mm;bu[i]/=2){
				t++;
			}
			if (t)
				t+=p[i],p[i]=0;
			if (bu[i]!=mm){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++)
				bu[i]=c[i],p[i]=pp[i];
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=max(i-p[j],p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++)
			bu[i]=c[i],p[i]=pp[i];
	}
	cout<<ans;
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const ll MNx=100*100*10*2,MN=MNx*MNx;

int n,a[MNx],c[MNx],bu[MNx],p[MNx],pp[MNx],mm=MN,lg,p2[MNx];

int main(){
	for (int i=1;i<MNx;i*=2)
		p2[i]=1;
	for (int i=MNx;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		pp[i]=p[i];
		bu[i]=a[i];
		mm=min(mm,c[i]);
	}
	ll ans=MN;
	for (;mm;mm/=2){
		if (mm%2==0)
			continue;
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;bu[i]%mm!=0 || !p2[bu[i]/mm];bu[i]/=2){
				if (bu[i]<mm)
					break;
				t++;
			}
			ll tttt=bu[i];
			p[i]=0;
			for (;bu[i]%2==0;bu[i]/=2,p[i]++);
			bu[i]=tttt;
			/**/
			if (bu[i]%mm!=0 || !p2[bu[i]/mm]){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++){
				bu[i]=a[i],p[i]=pp[i];
			}
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=abs(p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++){
			bu[i]=a[i],p[i]=pp[i];
		}
	}
	cout<<ans;
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const int MN=100*100*10*2;

int n,a[MN],c[MN],bu[MN],p[MN],pp[MN],mm=MN,lg,p2[MN];

int main(){
	for (int i=1;i<MN;i*=2)
		p2[i]=1;
	for (int i=MN;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		pp[i]=p[i];
		bu[i]=c[i];
		mm=min(mm,c[i]);
	}
	ll ans=MN;
	for (;mm;mm/=2){
		if (mm%2==0)
			continue;
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;(bu[i]%mm!=0 || !p2[bu[i]/mm]) && bu[i]>mm;bu[i]/=2){
				t++;
			}
			if (t){
				t+=p[i],p[i]=0;
			}
			/**/
			ll tttt=bu[i];
			if (!p[i])
				for (;bu[i]%2==0;bu[i]/=2,p[i]++);
			bu[i]=tttt;
			/**/
			if (bu[i]%mm!=0 || !p2[bu[i]/mm]){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++){
				bu[i]=c[i],p[i]=pp[i];
			}
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=abs(p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++){
			bu[i]=c[i],p[i]=pp[i];
		}
	}
	cout<<ans;
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const int MN=100*100*10*2;

int n,a[MN],c[MN],bu[MN],p[MN],pp[MN],mm=MN,lg;

int main(){
	for (int i=MN;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		pp[i]=p[i];
		bu[i]=c[i];
		mm=min(mm,c[i]);
	}
	ll ans=MN;
	ll mmm=mm;
	for (mm=1;mm<MN;mm+=2){
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;bu[i]>mm;bu[i]/=2){
				t++;
			}
			if (t)
				t+=p[i],p[i]=0;
			if (bu[i]!=mm){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++)
				bu[i]=c[i],p[i]=pp[i];
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=max(i-p[j],p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++)
			bu[i]=c[i],p[i]=pp[i];
	}
	cout<<ans;
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const int MN=100*100*10*2;

int n,a[MN],c[MN],bu[MN],p[MN],mm=MN,lg;

int main(){
	for (int i=MN;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		bu[i]=c[i];
		mm=min(mm,c[i]);
	}
	ll ans=MN;
	for (;mm;mm/=2){
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;bu[i]>mm;bu[i]/=2){
				t++;
			}
			if (bu[i]!=mm){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++)
				bu[i]=c[i];
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=max(i-p[j],p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++)
			bu[i]=c[i];
	}
	cout<<ans;
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const int MN=100*100*10*2;

int n,a[MN],c[MN],bu[MN],p[MN],pp[MN],mm=MN,lg;

int main(){
	for (int i=MN;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		pp[i]=p[i];
		bu[i]=c[i];
		mm=min(mm,c[i]);
	}
	ll ans=MN;
	for (;mm;mm/=2){
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;bu[i]>mm;bu[i]/=2){
				t++;
			}
			if (t)
				t+=p[i],p[i]=0;
			if (bu[i]!=mm){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++)
				bu[i]=c[i],p[i]=pp[i];
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=max(i-p[j],p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++)
			bu[i]=c[i],p[i]=pp[i];
	}
	cout<<ans;
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const int MN=100*100*10*2;

int n,a[MN],c[MN],bu[MN],p[MN],pp[MN],mm=MN,lg;

int main(){
	for (int i=MN;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		pp[i]=p[i];
		bu[i]=c[i];
		mm=min(mm,c[i]);
	}
	ll ans=MN;
	for (;mm;mm/=2){
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;bu[i]>mm;bu[i]/=2){
				t++;
			}
			if (t)
				t+=p[i],p[i]=0;
			if (bu[i]!=mm){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++)
				bu[i]=c[i];
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=max(i-p[j],p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++)
			bu[i]=c[i],p[i]=pp[i];
	}
	cout<<ans;
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const int MN=100*100*10*2;

int n,a[MN],c[MN],bu[MN],p[MN],pp[MN],mm=MN,lg;

int main(){
	for (int i=MN;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		pp[i]=p[i];
		bu[i]=c[i];
		mm=min(mm,c[i]);
	}
	ll ans=MN;
	for (;mm;mm/=2){
		if (mm%2==0)
			continue;
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;bu[i]>mm;bu[i]/=2){
				t++;
			}
			if (t)
				t+=p[i],p[i]=0;
			if (bu[i]!=mm){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++)
				bu[i]=c[i],p[i]=pp[i];
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=max(i-p[j],p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++)
			bu[i]=c[i],p[i]=pp[i];
	}
	cout<<ans;
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const int MN=100*100*10*2;

int n,a[MN],c[MN],bu[MN],p[MN],pp[MN],mm=MN,lg,p2[MN];

int main(){
	for (int i=1;i<MN;i*=2)
		p2[i]=1;
	for (int i=MN;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		pp[i]=p[i];
		bu[i]=a[i];
		mm=min(mm,c[i]);
	}
	ll ans=MN;
	for (;mm;mm/=2){
		if (mm%2==0)
			continue;
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;bu[i]%mm!=0 || !p2[bu[i]/mm];bu[i]/=2){
				if (bu[i]<mm)
					break;
				t++;
			}
			ll tttt=bu[i];
			p[i]=0;
			for (;bu[i]%2==0;bu[i]/=2,p[i]++);
			bu[i]=tttt;
			/**/
			if (bu[i]%mm!=0 || !p2[bu[i]/mm]){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++){
				bu[i]=a[i],p[i]=pp[i];
			}
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=abs(p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++){
			bu[i]=a[i],p[i]=pp[i];
		}
	}
	cout<<ans;
    return 0;
}


//In the name of god
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second

const int MN=100*100*10*2;

int n,a[MN],c[MN],bu[MN],p[MN],mm=MN,lg;

int main(){
	for (int i=MN;i;i/=2,lg++);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		c[i]=bu[i]=a[i];
		for (;c[i]%2==0;c[i]/=2,p[i]++);
		bu[i]=c[i];
		mm=min(mm,a[i]);
	}
	ll ans=MN;
	for (;mm;mm/=2){
		ll t=0,tmp,flag=0;
		for (int i=0;i<n;i++){
			for (;bu[i]>mm;bu[i]/=2){
				t++;
			}
			if (bu[i]!=mm){
				flag=1;
				break;
			}
		}
		if (flag){
			for (int i=0;i<n;i++)
				bu[i]=c[i];
			continue;
		}
		tmp=t;
		for (int i=0;i<lg;i++){
			for (int j=0;j<n;j++){
				t+=max(i-p[j],p[j]-i);
			}
			ans=min(ans,t);
			t=tmp;
		}
		for (int i=0;i<n;i++)
			bu[i]=c[i];
	}
	cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,i;
unsigned long long a[200010],b,x;
int main()
{
    cin>>n;
    cin>>x;
    b=x;
    a[1]=0;
    a[n]=b;
    for(i=2;i<=n/2;i++)
    {
        cin>>x;
        if(x<=b)
            b=x;
        a[n-i+1]=b;
        a[i]=x-b;
    }
    for(i=1;i<=n;i++)
        cout<<a[i]<<' ';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,i;
long long a[200010],b,x;
int main()
{
    cin>>n;
    cin>>x;
    b=x;
    a[1]=0;
    a[n]=b;
    for(i=2;i<=n/2;i++)
    {
        cin>>x;
        if(x<=b)
            b=x;
        a[n-i+1]=b;
        a[i]=x-b;
    }
    for(i=1;i<=n;i++)
        cout<<a[i]<<' ';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[200005];

int main()
{
    ll x, n;

    cin>>n;
    ll mn = 3223372036854775808,id;

    for(int i = 1; i <= n/2; i++)
    {
        scanf("%lld", &x);
        arr[i] = 0;
        arr[n - i + 1] = x;
        if(mn > x)
        {
            mn = x;
        }
    }

    for(int i = n; i >= 1; i--)
        if(mn == arr[i])
        {
            id = i;
            break;
        }
    for(int i = id; i >= 1; i--)
    {
        if(arr[i]>mn){
        ll extra = arr[i] - mn;
        arr[n - i + 1] = extra;
        arr[i] = mn;
        }
    }
    for(int i = 1; i <= n; i++)
        cout<<arr[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll arr[200005];

int main()
{
    ll x, n;

    cin>>n;
    ll mx = 0,id;

    for(int i = 1; i <= n/2; i++)
    {
        scanf("%lld", &x);
        int lf = i;
        int rt = n - i + 1;
        if(i == 1)
        {
            arr[lf] = 0;
            arr[rt] = x;
        }
        else
        {
            if(x < arr[rt + 1])
            {
                arr[rt] = x - mx;
                arr[lf] = mx;
            }
            else
            {
                arr[rt] = arr[rt + 1];
                arr[lf] = x - arr[rt];

                mx = max(mx,arr[lf]);
            }
        }

    }

    for(int i = 1; i <= n; i++)
        cout<<arr[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[200005];

int main()
{
    ll x, n;

    cin>>n;
    ll mn = 3223372036854775808,id;

    for(int i = 1; i <= n/2; i++)
    {
        scanf("%lld", &x);
        int lf = i;
        int rt = n - i + 1;
        if(i == 1)
        {
            arr[lf] = 0;
            arr[rt] = x;
        }
        else
        {
            if(x < arr[rt + 1])
            {
                arr[rt] = x;
                arr[lf] = 0;
            }
            else
            {
                arr[rt] = arr[rt + 1];
                arr[lf] = x - arr[rt];
            }
        }

    }

    for(int i = 1; i <= n; i++)
        cout<<arr[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[200005];

int main()
{
    ll x, n;

    cin>>n;
    ll mn = 3223372036854775808,id;

    for(int i = 1; i <= n/2; i++)
    {
        scanf("%lld", &x);
        int lf = i;
        int rt = n - i + 1;
        if(i == 1)
        {
            arr[lf] = 0;
            arr[rt] = x;
        }
        else
        {
            if(x <= arr[rt + 1])
            {
                arr[rt] = x;
                arr[lf] = 0;
            }
            else
            {
                arr[rt] = arr[rt + 1];
                arr[lf] = x - arr[rt];
            }
        }

    }

    for(int i = 1; i <= n; i++)
        cout<<arr[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll arr[200005];

int main()
{
    ll x, n;

    cin>>n;
    ll mx = 0,id;

    for(int i = 1; i <= n/2; i++)
    {
        scanf("%lld", &x);
        int lf = i;
        int rt = n - i + 1;
        if(i == 1)
        {
            arr[lf] = 0;
            arr[rt] = x;
        }
        else
        {

            ll l = x - arr[rt + 1];

             if(l < mx)
             {
                 l = mx;
             }

               arr[lf] = l;
               arr[rt] = x - l;
            }

    }

    for(int i = 1; i <= n; i++)
        cout<<arr[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[200005];

int main()
{
    ll x, n;

    cin>>n;
    ll mn = 3223372036854775808,id;

    for(int i = 1; i <= n/2; i++)
    {
        scanf("%lld", &x);
        int lf = i;
        int rt = n - i + 1;
        if(i == 1)
        {
            arr[lf] = 0;
            arr[rt] = x;
        }
        else
        {
            if(x < arr[rt + 1])
            {
                arr[rt] = x;
                arr[lf] = 0;
            }
            else
            {
                arr[rt] = arr[rt + 1];
                arr[lf] = x - arr[rt];
            }
        }

    }

    if(arr[n/2] > arr[n - n/2 + 1]) swap(arr[n/2],arr[n - n/2 + 1]);

    for(int i = 1; i <= n; i++)
        cout<<arr[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll arr[200005];

int main()
{
    ll x, n;

    cin>>n;
    ll mx = 0,id;

    for(int i = 1; i <= n/2; i++)
    {
        scanf("%lld", &x);
        int lf = i;
        int rt = n - i + 1;
        if(i == 1)
        {
            arr[lf] = 0;
            arr[rt] = x;
        }
        else
        {
            if(x <= arr[rt + 1])
            {
                arr[rt] = x - mx;
                arr[lf] = mx;
            }
            else
            {
                ll l = x - arr[rt + 1];

             if(l < mx)
             {
                 l = mx;
             }

               arr[lf] = l;
               arr[rt] = x - l;
            }
        }

    }

    for(int i = 1; i <= n; i++)
        cout<<arr[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll arr[200005];

int main()
{
    ll x, n;

    cin>>n;
    ll mx = 0,id;

    for(int i = 1; i <= n/2; i++)
    {
        scanf("%lld", &x);
        int lf = i;
        int rt = n - i + 1;
        if(i == 1)
        {
            arr[lf] = 0;
            arr[rt] = x;
        }
        else
        {
            if(x <= arr[rt + 1])
            {
                arr[rt] = x - mx;
                arr[lf] = mx;
            }
            else
            {
                ll l = x - arr[rt + 1];

             if(l < mx)
             {
                 l = mx;
             }

               arr[lf] = l;
               arr[rt] = x - l;
               mx = max(mx,l);
            }
        }

    }

    for(int i = 1; i <= n; i++)
        cout<<arr[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll arr[200005];

int main()
{
    ll x, n;

    cin>>n;
    ll mx = 0,id;

    for(int i = 1; i <= n/2; i++)
    {
        scanf("%lld", &x);
        int lf = i;
        int rt = n - i + 1;
        if(i == 1)
        {
            arr[lf] = 0;
            arr[rt] = x;
        }
        else
        {
            if(x <= arr[rt + 1])
            {
                arr[rt] = x - mx;
                arr[lf] = mx;
            }
            else
            {
                arr[rt] = arr[rt + 1];
                arr[lf] = x - arr[rt];

                mx = max(mx,arr[lf]);
            }
        }

    }

    for(int i = 1; i <= n; i++)
        cout<<arr[i]<<" ";
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>b[i];
    reverse(b,b+n/2);
    rrrep(i,n/2-2,0){
        if(b[i]>b[i+1]){
            tmp=b[i]-b[i+1];
            a[i]=tmp;
            b[i]-=tmp;
        }
    }
    reverse(a,a+n/2);

    rep(i,n/2)cout<<a[i]<<" ";
    rep(i,n/2){
        if(i==n/2-1)cout<<b[i]<<"\n";
        else cout<<b[i]<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>b[i];
    //reverse(b,b+n/2);
    rrrep(i,n-1,n/2){
        if(i==n-1)a[i]=b[n-i-1],a[n-i-1]=0;
        else{
            if(a[i+1]<b[n-i-1]){
                tmp=b[n-i-1]-a[i+1];
                a[i]=a[i+1];
                a[n-i-1]=tmp;
            }
            else{
                a[i]=b[n-i-1];
                a[n-i-1]=0;
            }
        }
        //rep(i,n)cout<<a[i]<<" ";
        //cout<<"\n";
    }
    rep(i,n){
        if(i==n-1){
            Cout(a[i]);
        }
        else{
        cout<<a[i]<<" ";
        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>b[i];
    reverse(b,b+n/2);
    rrrep(i,n/2-2,0){
        if(b[i]>b[i+1]){
            tmp=b[i]-b[i+1];
            a[n/2-i-1]=tmp;
            b[i]-=tmp;
        }
    }
    //reverse(a,a+n/2);
    rep(i,n/2)cout<<a[i]<<" ";
    rep(i,n/2){
        if(i==n/2-1)cout<<b[i]<<"\n";
        else cout<<b[i]<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>b[i];
    reverse(b,b+n/2);
    rrrep(i,n/2-2,0){
        if(b[i]>b[i+1]){
            tmp=b[i]-b[i+1];
            a[n/2-i-1]=tmp;
            b[i]-=tmp;
        }
    }
    //reverse(a,a+n/2);
    rep(i,n/2-1){
        if(a[i]>a[i+1]){
            tmp=a[i]-a[i+1];
            a[i+1]=a[i];
            b[n/2-i-2]-=tmp;
        }
    }
     rep(i,n/2)cout<<a[i]<<" ";
    rep(i,n/2){
        if(i==n/2-1)cout<<b[i]<<"\n";
        else cout<<b[i]<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>b[i];
    //reverse(b,b+n/2);
    rrrep(i,n-1,n/2){
        if(i==n-1)a[i]=b[n-i-1],a[n-i-1]=0;
        else{
            if(a[i+1]<b[n-i-1]){
                tmp=b[n-i-1]-a[i+1];
                a[i]=a[i+1];
                a[n-i-1]=tmp;
            }
            else{
                a[i]=b[n-i-1];
                a[n-i-1]=0;
            }
        }
        //rep(i,n)cout<<a[i]<<" ";
        //cout<<"\n";
    }
    rep(i,n/2){
        if(a[i]+a[n-i-1]!=b[i]){
            tmp=b[i]-a[i]-a[n-i-1];
            a[n-i-1]+=tmp;
        }
    }
    rep(i,n){
        if(i==n-1){
            Cout(a[i]);
        }
        else{
        cout<<a[i]<<" ";
        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>b[i];
    //reverse(b,b+n/2);
    rrrep(i,n-1,n/2){
        if(i==n-1)a[i]=b[n-i-1],a[n-i-1]=0;
        else{
            if(a[i+1]<b[n-i-1]){
                tmp=b[n-i-1]-a[i+1];
                a[i]=a[i+1];
                a[n-i-1]=tmp;
            }
            else{
                a[i]=b[n-i-1];
                a[n-i-1]=0;
            }
        }
        //rep(i,n)cout<<a[i]<<" ";
        //cout<<"\n";
    }
    rep(i,n/2-1){
        if(a[i]>a[i+1]){
            tmp=a[i]-a[i+1];
            tmp*=-1;
            a[n-i-1]+=tmp;
            a[i+1]=a[i];
        }
    }
    rep(i,n/2){
        if(a[i]+a[n-i-1]!=b[i]){
            tmp=b[i]-a[i]-a[n-i-1];
            a[n-i-1]+=tmp;
        }
    }
    rep(i,n){
        if(i==n-1){
            Cout(a[i]);
        }
        else{
        cout<<a[i]<<" ";
        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>b[i];
    //reverse(b,b+n/2);
    rrrep(i,n-1,n/2){
        if(i==n-1)a[i]=b[n-i-1],a[n-i-1]=0;
        else{
            if(a[i+1]<b[n-i-1]){
                tmp=b[n-i-1]-a[i+1];
                a[i]=a[i+1];
                a[n-i-1]=tmp;
            }
            else{
                a[i]=b[n-i-1];
                a[n-i-1]=0;
            }
        }
        //rep(i,n)cout<<a[i]<<" ";
        //cout<<"\n";
    }
    rep(i,n/2-1){
        if(a[i]>a[i+1]){
            tmp=a[i]-a[i+1];
            tmp*=-1;
            a[n-i-1]+=tmp;
            a[i+1]=a[i];
        }
    }
    rep(i,n/2){
        if(a[i]+a[n-i-1]!=b[i]){
            tmp=b[i]-a[i]-a[n-i-1];
            a[n-i-1]+=tmp;
        }
    }
    rep(i,n/2){
        if(a[i]<0){
            tmp=a[i];
            tmp*=-1;
            a[i]=0;
            a[n-i-1]+=tmp;
        }
        else if(a[n-i-1]<0){
            tmp=a[n-i-1];
            tmp*=-1;
            a[n-i-1]=0;
            a[i]+=tmp;
        }
    }
    rep(i,n){
        if(i==n-1){
            Cout(a[i]);
        }
        else{
        cout<<a[i]<<" ";
        }
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>a[i];
    rrrep(i,n/2-1,0){
        ll pai,to,mae,ato;
        to=a[i];
        pai=n-i-1;
        mae=to/2;
        ato=mae;
        if(to%2==1)ato++;
        if(i==n/2-1){
            b[i]=mae;
            b[pai]=ato;
        }
        else{
            //if(i==0)cout<<mae<<" "<<b[i+1]<<" "<<ato<<" "<<b[pai-1]<<"\n";
            if(mae>b[i+1]){
                tmp=mae-b[i+1];
                mae=b[i+1];
                ato+=tmp;
            }
            if(ato<b[pai-1]){
                tmp=ato-b[pai-1];
                ato=b[pai-1];
                mae+=tmp;
            }
            b[i]=mae;
            b[pai]=ato;
        }
    }
    rep(i,n){
        if(i==n-1)Cout(b[i]);
        else cout<<b[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>a[i];
    rrrep(i,n/2-1,0){
        ll pai,to,mae,ato;
        to=a[i];
        pai=n-i-1;
        mae=to/2;
        ato=mae;
        if(to%2==1)ato++;
        if(i==n/2-1){
            b[i]=mae;
            b[pai]=ato;
        }
        else{
            if(mae>b[i+1]){
                tmp=mae-b[i+1];
                mae=b[i+1];
                ato+=tmp;
            }
            else if(ato>b[pai-1]){
                tmp=ato-b[pai-1];
                ato=b[pai-1];
                mae+=tmp;
            }
            b[i]=mae;
            b[pai]=ato;
        }
    }
    rep(i,n){
        if(i==n-1)Cout(b[i]);
        else cout<<b[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>b[i];
    reverse(b,b+n/2);
    rep(i,n/2-1){
        if(b[i]>b[i+1]){
            tmp=b[i]-b[i+1];
            a[i]=tmp;
            b[i]-=tmp;
        }
    }
    reverse(a,a+n/2);
    rep(i,n/2)cout<<a[i]<<" ";
    rep(i,n/2){
        if(i==n/2-1)cout<<b[i]<<"\n";
        else cout<<b[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
    rep(i,n/2)cin>>b[i];
    reverse(b,b+n/2);
    rep(i,n/2)cout<<0<<" ";
    rep(i,n/2){
        if(i==n/2-1)cout<<b[i]<<"\n";
        else cout<<b[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<deque>
using namespace std;

int main() {

		int n;
		cin >> n;
		int p = n / 2;
		int x;
		vector<int>b;
		while (p>0) {
			cin >> x;
			b.push_back(x);
			p--;
		}
		vector<int>front;
		deque<int>back;
		front.push_back(0);
		back.push_front(b[0]);
		for (int i = 1;i < n/2;i++) {
			int a1 = 0;
			int a2 = b[i];
			while (a1 < *(front.end() - 1)) {
				a1++;
				a2--;
			}
			while (a2 > * back.begin()) {
				a1++;
				a2--;
			}
			front.push_back(a1);
			back.push_front(a2);
		}
		for (auto e : front) {
			cout << e;
		}
		for (auto e : back) {
			cout << e;
		}
		cout <<endl;

	return 0;
}


#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<deque>
using namespace std;

int main() {

		int n;
		cin >> n;
		int p = n / 2;
		long long x;
		vector<long long>b;
		while (p>0) {
			cin >> x;
			b.push_back(x);
			p--;
		}
		vector<long long>front;
		deque<long long>back;
		front.push_back(0);
		back.push_front(b[0]);
		for (int i = 1;i < n/2;i++) {
			int a1 = 0;
			int a2 = b[i];
			if (a1 < *(front.end() - 1)) {
				a1 = *(front.end() - 1);
				a2=b[i]-a1;
			}
			if (a2 > *back.begin()) {
				a2=*back.begin();
				a1=b[i]-a2;
			}
			front.push_back(a1);
			back.push_front(a2);
		}
		for (auto e : front) {
			cout << e<<" ";
		}
		for (auto e : back) {
			cout << e<<" ";
		}
		cout <<endl;

	return 0;
}


#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<deque>
using namespace std;

int main() {

		int n;
		cin >> n;
		int p = n / 2;
		long long x;
		vector<long long>b;
		while (p>0) {
			cin >> x;
			b.push_back(x);
			p--;
		}
		vector<long long>front;
		deque<long long>back;
		front.push_back(0);
		back.push_front(b[0]);
		for (int i = 1;i < n/2;i++) {
			long long a1 = 0;
			long long a2 = b[i];
			if (a1 < *(front.end() - 1)) {
				a1 = *(front.end() - 1);
				a2=b[i]-a1;
			}
			if (a2 > *back.begin()) {
				a2=*back.begin();
				a1=b[i]-a2;
			}
			front.push_back(a1);
			back.push_front(a2);
		}
		for (auto e : front) {
			cout << e<<" ";
		}
		for (auto e : back) {
			cout << e<<" ";
		}
		cout <<endl;

	return 0;
}


#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<deque>
using namespace std;

int main() {

		int n;
		cin >> n;
		int p = n / 2;
		int x;
		vector<long long>b;
		while (p>0) {
			cin >> x;
			b.push_back(x);
			p--;
		}
		vector<long long>front;
		deque<long long>back;
		front.push_back(0);
		back.push_front(b[0]);
		for (int i = 1;i < n/2;i++) {
			int a1 = 0;
			int a2 = b[i];
			while (a1 < *(front.end() - 1)) {
				a1++;
				a2--;
			}
			while (a2 > *back.begin()) {
				a1++;
				a2--;
			}
			front.push_back(a1);
			back.push_front(a2);
		}
		for (auto e : front) {
			cout << e<<" ";
		}
		for (auto e : back) {
			cout << e<<" ";
		}
		cout <<endl;

	return 0;
}


#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<deque>
using namespace std;

int main() {

		int n;
		cin >> n;
		int p = n / 2;
		long long x;
		vector<long long>b;
		while (p>0) {
			cin >> x;
			b.push_back(x);
			p--;
		}
		vector<long long>front;
		deque<long long>back;
		front.push_back(0);
		back.push_front(b[0]);
		for (int i = 1;i < n/2;i++) {
			long long a1 = 0;
			long long a2 = b[i];
			while (a1 < *(front.end() - 1)) {
				a1++;
				a2--;
			}
			while (a2 > *back.begin()) {
				a1++;
				a2--;
			}
			front.push_back(a1);
			back.push_front(a2);
		}
		for (auto e : front) {
			cout << e<<" ";
		}
		for (auto e : back) {
			cout << e<<" ";
		}
		cout <<endl;

	return 0;
}


#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<deque>
using namespace std;

int main() {

		int n;
		cin >> n;
		int p = n / 2;
		int x;
		vector<int>b;
		while (p>0) {
			cin >> x;
			b.push_back(x);
			p--;
		}
		vector<int>front;
		deque<int>back;
		front.push_back(0);
		back.push_front(b[0]);
		for (int i = 1;i < n/2;i++) {
			int a1 = 0;
			int a2 = b[i];
			while (a1 < *(front.end() - 1)) {
				a1++;
				a2--;
			}
			while (a2 > * back.begin()) {
				a1++;
				a2--;
			}
			front.push_back(a1);
			back.push_front(a2);
		}
		for (auto e : front) {
			cout << e<<" ";
		}
		for (auto e : back) {
			cout << e<<" ";
		}
		cout <<endl;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
using namespace std;

 void prinvector(std::vector<int> v){for(int i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}
void prinarray(int a[],int n){for(int i = 0;i < n;++i){cout<<a[i]<<" ";}cout<<" "<<endl;}
 int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
 int n;
 cin>>n;
 long long b[n/2];
 cin>>b[0];
 long long a[n];
 a[n-1]=b[0];
 a[0]=0;
 for (int i = 1; i < n/2; ++i)
 {
 	cin>>b[i];
 	a[i]=a[i-1];
 	a[n-i-1]=a[n-i];
 	for (int ii = 0; ; ++ii)
 	{
 		//int j=0;
 		//cout<<(a[n-i-1]+a[i])<<"jhk"<<b[i]<<endl;
 		if((a[n-i-1]+a[i])==b[i]){
 			//a[i]++;
 			break;
 		}else{
 			if((a[n-i-1]+a[i])<b[i]){
 				a[i]=a[i]+b[i]-(a[n-i-1]+a[i]);
 			}else{a[n-i-1]=a[n-i-1]-((a[n-i-1]+a[i])-b[i]);}

 		}
 		//if(j==1){break;}
 		/* code */
 	}
//if(b){}

 	/* code */
 }
 for (int i = 0; i < n; ++i)
 {
 	cout<<a[i]<<" ";
 	/* code */
 }
 cout<<endl;

 //std::vector<int> v;
 //int x=5;
 //while(x--)
 //v.push_back(x);

//for (int i = 0; i < v.size(); ++i)
//{
//	cout<<v[i]<<endl;
//}

      return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
using namespace std;

 void prinvector(std::vector<int> v){for(int i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}
void prinarray(int a[],int n){for(int i = 0;i < n;++i){cout<<a[i]<<" ";}cout<<" "<<endl;}
 int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
 int n;
 cin>>n;
 long long b[n/2];
 cin>>b[0];
 long long a[n];
 a[n-1]=b[0];
 a[0]=0;
 for (int i = 1; i < n/2; ++i)
 {
 	cin>>b[i];
 	a[i]=a[i-1];
 	a[n-i-1]=a[n-i];
 	for (int ii = 0;ii ; ++ii)
 	{
 		//int j=0;
 		//cout<<(a[n-i-1]+a[i])<<"jhk"<<b[i]<<endl;
 		if((a[n-i-1]+a[i])==b[i]){
 			//a[i]++;
 			break;
 		}else{
 			if((a[n-i-1]+a[i])<b[i]){
 				a[i]++;
 			}else{a[n-i-1]--;}

 		}
 		//if(j==1){break;}
 		/* code */
 	}
//if(b){}

 	/* code */
 }
 for (int i = 0; i < n; ++i)
 {
 	cout<<a[i];
 	/* code */
 }
 cout<<endl;

 //std::vector<int> v;
 //int x=5;
 //while(x--)
 //v.push_back(x);

//for (int i = 0; i < v.size(); ++i)
//{
//	cout<<v[i]<<endl;
//}

      return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
using namespace std;

 void prinvector(std::vector<int> v){for(int i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}
void prinarray(int a[],int n){for(int i = 0;i < n;++i){cout<<a[i]<<" ";}cout<<" "<<endl;}
 int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
 int n;
 cin>>n;
 long long b[n/2];
 cin>>b[0];
 long long a[n];
 a[n-1]=b[0];
 a[0]=0;
 for (int i = 1; i < n/2; ++i)
 {
 	cin>>b[i];
 	a[i]=a[i-1];
 	a[n-i-1]=a[n-1];
 	for (int ii = 0;ii<100000 ; ++ii)
 	{
 		//int j=0;
 		//cout<<(a[n-i-1]+a[i])<<"jhk"<<b[i]<<endl;
 		if((a[n-i-1]+a[i])==b[i]){
 			//a[i]++;
 			break;
 		}else{
 			if((a[n-i-1]+a[i])<b[i]){
 				a[i]++;
 			}else{a[n-i-1]--;}

 		}
 		//if(j==1){break;}
 		/* code */
 	}
//if(b){}

 	/* code */
 }
 for (int i = 0; i < n; ++i)
 {
 	cout<<a[i];
 	/* code */
 }
 cout<<endl;

 //std::vector<int> v;
 //int x=5;
 //while(x--)
 //v.push_back(x);

//for (int i = 0; i < v.size(); ++i)
//{
//	cout<<v[i]<<endl;
//}

      return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
using namespace std;

 void prinvector(std::vector<int> v){for(int i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}
void prinarray(int a[],int n){for(int i = 0;i < n;++i){cout<<a[i]<<" ";}cout<<" "<<endl;}
 int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
 int n;
 cin>>n;
 long long b[n/2];
 cin>>b[0];
 long long a[n];
 a[n-1]=b[0];
 a[0]=0;
 for (int i = 1; i < n/2; ++i)
 {
 	cin>>b[i];
 	a[i]=a[i-1];
 	a[n-i-1]=a[n-i];
 	for (int ii = 0; ; ++ii)
 	{
 		//int j=0;
 		//cout<<(a[n-i-1]+a[i])<<"jhk"<<b[i]<<endl;
 		if((a[n-i-1]+a[i])==b[i]){
 			//a[i]++;
 			break;
 		}else{
 			if((a[n-i-1]+a[i])<b[i]){
 				a[i]++;
 			}else{a[n-i-1]--;}

 		}
 		//if(j==1){break;}
 		/* code */
 	}
//if(b){}

 	/* code */
 }
 for (int i = 0; i < n; ++i)
 {
 	cout<<a[i];
 	/* code */
 }
 cout<<endl;

 //std::vector<int> v;
 //int x=5;
 //while(x--)
 //v.push_back(x);

//for (int i = 0; i < v.size(); ++i)
//{
//	cout<<v[i]<<endl;
//}

      return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
using namespace std;

 void prinvector(std::vector<int> v){for(int i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}
void prinarray(int a[],int n){for(int i = 0;i < n;++i){cout<<a[i]<<" ";}cout<<" "<<endl;}
 int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
 int n;
 cin>>n;
 long long b[n/2];
 cin>>b[0];
 long long a[n];
 a[n-1]=b[0];
 a[0]=0;
 for (int i = 1; i < n/2; ++i)
 {
 	cin>>b[i];
 	a[i]=a[i-1];
 	a[n-i-1]=a[n-i];
 	for (int ii = 0; ; ++ii)
 	{
 		//int j=0;
 		//cout<<(a[n-i-1]+a[i])<<"jhk"<<b[i]<<endl;
 		if((a[n-i-1]+a[i])==b[i]){
 			//a[i]++;
 			break;
 		}else{
 			if((a[n-i-1]+a[i])<b[i]){
 				a[i]++;
 			}else{a[n-i-1]--;}

 		}
 		//if(j==1){break;}
 		/* code */
 	}
//if(b){}

 	/* code */
 }
 for (int i = 0; i < n; ++i)
 {
 	cout<<a[i]<<" ";
 	/* code */
 }
 cout<<endl;

 //std::vector<int> v;
 //int x=5;
 //while(x--)
 //v.push_back(x);

//for (int i = 0; i < v.size(); ++i)
//{
//	cout<<v[i]<<endl;
//}

      return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
using namespace std;

 void prinvector(std::vector<int> v){for(int i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}
void prinarray(int a[],int n){for(int i = 0;i < n;++i){cout<<a[i]<<" ";}cout<<" "<<endl;}
 int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
 int n;
 cin>>n;
 long long b[n/2];
 cin>>b[0];
 long long a[n];
 a[n-1]=b[0];
 a[0]=0;
 for (int i = 1; i < n/2; ++i)
 {
 	cin>>b[i];
if(b[i]>a[n-i]){
	//cout<<b[i]<<n-i-1<<endl;
	a[n-i-1]=a[n-i];a[i]=b[i]-a[n-i-1];}else{a[n-i-1]=b[i];a[i]=b[i]-a[n-i-1];}
 	/* code */
 }
 for (int i = 0; i < n; ++i)
 {
 	cout<<a[i];
 	/* code */
 }
 cout<<endl;

 //std::vector<int> v;
 //int x=5;
 //while(x--)
 //v.push_back(x);

//for (int i = 0; i < v.size(); ++i)
//{
//	cout<<v[i]<<endl;
//}

      return 0;
}


#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<math.h>
#include <iomanip>
#include <algorithm>
#include<bits/stdc++.h>
#include <iterator>
using namespace std;

 void prinvector(std::vector<int> v){for(int i = 0;i<v.size();++i){cout<<v[i]<<" ";}cout<<" "<<endl;}
void prinarray(int a[],int n){for(int i = 0;i < n;++i){cout<<a[i]<<" ";}cout<<" "<<endl;}
 int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
 int n;
 cin>>n;
 long long b[n/2];
 cin>>b[0];
 long long a[n];
 a[n-1]=b[0];
 a[0]=0;
 for (int i = 1; i < n/2; ++i)
 {
 	cin>>b[i];
 	a[i]=a[i-1];
 	a[n-i-1]=a[n-1];
 	for (int ii = 0; ; ++ii)
 	{
 		//int j=0;
 		//cout<<(a[n-i-1]+a[i])<<"jhk"<<b[i]<<endl;
 		if((a[n-i-1]+a[i])==b[i]){
 			//a[i]++;
 			break;
 		}else{
 			if((a[n-i-1]+a[i])<b[i]){
 				a[i]++;
 			}else{a[n-i-1]--;}

 		}
 		//if(j==1){break;}
 		/* code */
 	}
//if(b){}

 	/* code */
 }
 for (int i = 0; i < n; ++i)
 {
 	cout<<a[i];
 	/* code */
 }
 cout<<endl;

 //std::vector<int> v;
 //int x=5;
 //while(x--)
 //v.push_back(x);

//for (int i = 0; i < v.size(); ++i)
//{
//	cout<<v[i]<<endl;
//}

      return 0;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll b[(n/2)+1];
    for(ll i=1;i<n/2+1;i++)
        cin>>b[i];
    ll a[n+1];
    ll count=0;
    ll prev=1e18+5;
    int start=1;
    int end=n;
    for(ll i=1;i<=n/2;i++)
    {
        if(b[i]<=prev)
        {
            a[start]=count;
            a[end]=b[start]-count;
        }
        else
        {
            a[start]=a[end+1];
            a[start]=b[start]-a[end];
            count=a[i];
        }
        start++;
        end--;
        prev=b[i];
    }
    for(ll i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll b[(n/2)+1];
    for(ll i=1;i<n/2+1;i++)
        cin>>b[i];
    ll a[n+1];
    ll count=0;
    ll prev=1e18+5;
    int start=1;
    int end=n;
    for(ll i=1;i<=n/2;i++)
    {
        if(b[i]<prev)
        {
            a[start]=count;
            a[end]=b[start]-count;
        }
        else
        {
            a[end]=a[end+1];
            a[start]=b[start]-a[end];
            count=a[start];
        }
        prev=b[i];
        start++;
        end--;
    }
    for(ll i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll b[(n/2)+1];
    for(ll i=1;i<n/2+1;i++)
        cin>>b[i];
    ll a[n+1];
    ll count=0;
    ll prev=1e18+5;
    int start=1;
    int end=n;
    for(ll i=1;i<=n/2;i++)
    {
        if(b[i]<prev)
        {
            a[start]=count;
            a[end]=b[start]-count;
        }
        else
        {
            a[start]=a[end+1];
            a[start]=b[start]-a[end];
            count=a[i];
        }
        start++;
        end--;
        prev=b[i];
    }
    for(ll i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll b[(n/2)+1];
    for(ll i=1;i<n/2+1;i++)
        cin>>b[i];
    ll a[n+1];
    ll count=0;
    ll prev=1e18+5;
    int start=1;
    int end=n;
    for(ll i=1;i<=n/2;i++)
    {
        if(i==1)
        {
            a[start]=count;
            a[end]=b[start]-count;
        }
        else if(b[i]<prev)
        {
            a[start]=count;
            a[end]=b[start]-count;
        }
        else
        {
            a[end]=a[end+1];
            a[start]=b[start]-a[end];
            count=a[start];
        }
        prev=b[i];
        start++;
        end--;
    }
    for(ll i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll b[(n/2)+1];
    for(ll i=1;i<n/2+1;i++)
        cin>>b[i];
    ll a[n+1];
    ll count=0;
    ll prev=1e18+5;
    int start=1;
    int end=n;
    for(ll i=1;i<=n/2;i++)
    {
        if(b[i]<prev)
        {
            a[start]=count;
            a[end]=b[start]-count;
        }
        else
        {
            a[start]=a[end+1];
            a[start]=b[start]-a[end];
            count=a[i];
        }
        start++;
        end--;
        prev=b[i];
    }
    for(ll i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}
1


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll b[(n/2)+1];
    for(ll i=1;i<n/2+1;i++)
        cin>>b[i];
    ll a[n+1];
    ll count=0;
    ll prev=1e18+5;
    for(ll i=1;i<=n/2;i++)
    {
        if(b[i]<prev)
        {
            a[i]=count;
            a[n-i+1]=b[i]-count;
        }
        else
        {
            a[n-i+1]=a[n-i+1+1];
            a[i]=b[i]-a[n-i+1];
            count=a[i];
        }
        prev=b[i];
    }
    for(ll i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll b[(n/2)+1];
    for(ll i=1;i<n/2+1;i++)
        cin>>b[i];
    ll a[n+1];
    ll count=0;
    ll prev=1e18;
    for(ll i=1;i<=n/2;i++)
    {
        if(b[i]<prev)
        {
            a[i]=count;
            a[n-i+1]=b[i]-count;
        }
        else
        {
            a[n-i+1]=a[n-i+1+1];
            a[i]=b[i]-a[n-i+1];
            count=a[i];
        }
        prev=b[i];
    }
    for(ll i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}


#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef long long ll;
using namespace std;
int main()
{
    int n;
    cin>>n;
    int b[(n/2)+1];
    for(int i=1;i<n/2+1;i++)
        cin>>b[i];
    int a[n+1];
    int count=0;
    int prev=INT_MAX;
    for(int i=1;i<=n/2;i++)
    {
        if(b[i]<prev)
        {
            a[i]=count;
            a[n-i+1]=b[i]-count;
        }
        else
        {
            a[n-i+1]=a[n-i+1+1];
            a[i]=b[i]-a[n-i+1];
            count=a[i];
        }
        prev=b[i];
    }
    for(int i=1;i<=n;i++)
        cout<<a[i]<<' ';
    cout<<endl;
}