Problem:
Score : 400 points

Problem Statement

There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number.

Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i and i+1 (Mountain N+1 is Mountain 1).

When Mountain i (1 \leq i \leq N) receives 2x liters of rain, Dam i-1 and Dam i each accumulates x liters of water (Dam 0 is Dam N).

One day, each of the mountains received a non-negative even number of liters of rain.

As a result, Dam i (1 \leq i \leq N) accumulated a total of A_i liters of water.

Find the amount of rain each of the mountains received. We can prove that the solution is unique under the constraints of this problem.

Constraints

All values in input are integers.

3 \leq N \leq 10^5-1

N is an odd number.

0 \leq A_i \leq 10^9

The situation represented by input can occur when each of the mountains receives a non-negative even number of liters of rain.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print N integers representing the number of liters of rain Mountain 1, Mountain 2, ..., Mountain N received, in this order.

Sample Input 1

3
2 2 4

Sample Output 1

4 0 4

If we assume Mountain 1, 2, and 3 received 4, 0, and 4 liters of rain, respectively, it is consistent with this input, as follows:

Dam 1 should have accumulated \frac{4}{2} + \frac{0}{2} = 2 liters of water.

Dam 2 should have accumulated \frac{0}{2} + \frac{4}{2} = 2 liters of water.

Dam 3 should have accumulated \frac{4}{2} + \frac{4}{2} = 4 liters of water.

Sample Input 2

5
3 8 7 5 5

Sample Output 2

2 4 12 2 8

Sample Input 3

3
1000000000 1000000000 0

Sample Output 3

0 2000000000 0

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()
#include <numeric>
#include <tuple>

#define rep(i, n) for(int i=0; i<(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) cout << "debug (" #a "):" << endl << (a) << endl;

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;

template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);

lint n, k;
lint h, w;

int main(){
//////////////////////////////////////////////////////

    cin >> n;
    vector<lint> a(n);
    //fpair<lint,lint> p = make_pair(1,2);
    //tuple<lint,lint,lint> t  = make_tuple(1,2,3);

    lint min = 1000000000;
    lint minno = 0;
    rep(i,n)
    {
        cin >> a[i];
        if(a[i] < min){
            min = a[i];
            minno = i;
        }
    }

    //     rep(i,n)
    // {
    //     cin >> a[i];
    //     if(a[i]-tonari < min){
    //         min = a[i]-tonari;
    //         minno = i;
    //     }
    //     tonari = a[i];
    // }

    // min = a[minno];

    // debug(minno);


    lint d;
    // for(d = a[0]; d >= 0; d--)
    // {
    //     lint k = d;
    //     rep(i,n-1)
    //     {
    //         k = a[i] - k;
    //         if(k<0)break;
    //     }

    //     if(k == a[n-1]-d)
    //     {
    //         //cout << "GGGGG" << d << endl;
    //         break;
    //     }
    // }


    

    lint ansd = -1;
    lint start = minno;
    lint goal = minno - 1;
    if(goal < 0)goal += n;


    //debug(start);
    //debug(goal);
    
    for (lint d = min ; d >= 0 ; d --)
    {
        //debug(d);
        lint k = d;
        lint p = start;
        while( p != goal )
        {
            //debug(k);
            k = a[p] - k;
            p++;
            if(p >= n)p = 0;
            if(k<0)break;
        }
        //cout << "out" << endl;
        if(k == a[goal]-d){
            //cout <<"GGGGG"<< d <<endl; 
            ansd = d;//cout <<"GGGGG"<< k <<endl; 
            break;

        }
        
    }

    k = ansd;
    //debug(k);
    rep(i,n)
    {
        cout << k * 2;
        k = a[i] - k;
        if(i==n-1)cout << endl;
        else cout << " ";
    }

    // cout << endl;
    
    

    //昇順ソート3

    //sort(all(a));

   

    // sort(input.begin() , input.end());

    // uint64_t max = numeric_limits<uint64_t>::max();


    //////////////////////////////////////////////////////
    // DP

//     // 無限大の値
//     const uint64_t INF = (uint64_t)1 << 60;
//     //const int64_t NINF = -1 * ((int64_t)1 << 60 );
 
//     // DP テーブル
//     uint64_t dp[100010];

//     //DPテーブル初期化（最小化用）
//     for (int i = 0; i < 100010; ++i)
//     {
//         //dp[i] = INF;
//         dp[i] = 0;
//     } 

//     // 初期条件
//     dp[0] = 0;

//     // ループ
//     for (int i = 1; i <= n; ++i) {
//         //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] ));
//         //if (i < 2)continue;
//         //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] ));



//         // chmax ( dp [i] , dp[i - 1]);
//         // chmax ( dp [i] , dp[i - 1] + input[i]);
//         // cout << "dp[" << i <<"] = " << dp[i] << endl;

//     }



// //////////////////////////////////////////////////////

//     cout << dp[n] << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


//最小化用関数
template<class T> inline bool chmin(T& a, T b)
{
    if (a > b) 
    {
        a = b;
        return true;
    }
    return false;
}

//最大化関数
template<class T> inline bool chmax(T& a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}


// vectorprint用
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

// //合計
// template<class T> lint sum(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0);
// }


// //平均
// template<class T> double ave(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0.0) / a.size();
// }