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 <bits/stdc++.h>
using namespace std;

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N;
vec<int> A;

// 2分探索のテンプレ
void bin() {
		vec<int> M(N), D(N);
   auto check = [&](int mid) -> bool {
      // 判定処理を書く
      // 閉区間の方を >=, <= にする
			// 初期化
			rep (i, N) {
				M[i] = D[i] = 0;
			}

		// dbg(mid)
			/*
			D[0] += M[0] / 2;
			M[1] = A[0] - D[0];
			D[0] += M[1] / 2;
			*/
			M[0] = mid;
			for (int i = 0; i < N-1; i++) {
				D[i] += M[i] / 2;
				M[i+1] = (A[i] - D[i])*2;
				D[i] += M[i+1] / 2;
				// dbg2(D[i], M[i+1])
			}
			D[N-1] += M[0] / 2 + M[N-1] / 2;
			// M[N-1] += A[N-1] - D[N-1];
			int sum = 0;
			rep (i, N) {
				sum += A[i] - D[i];
			}
			
			// print1(all(M));
			// print1(all(D));
			// line()
			// return sum <= 0;
			return sum >= 0;
   };

   int l = -1; // 条件を満たさないと分かっている数を適当に
   int r = 1e10; // 条件を満たすと分かっている数を適当に

   // [l, r) か (l, r] か気をつける
   while (r - l > 1) { // 答えの整数範囲が1つになるまで繰り返し
      int mid = (l + r) / 2;
      if (check(mid)) {
         l = mid; // 場合によって異なる
      } else {
         r = mid; // 場合によって異なる
      }
   }

	rep (i, N-1) {
		cout << M[i] << " ";
	}
	cout << M.back() << endl;
  //  return r; // 場合によって異なる
}

void solve() {
		vec<int> M(N), D(N);
   auto check = [&](int mid) -> bool {
      // 判定処理を書く
      // 閉区間の方を >=, <= にする
			// 初期化
			rep (i, N) {
				M[i] = D[i] = 0;
			}

		// dbg(mid)
			/*
			D[0] += M[0] / 2;
			M[1] = A[0] - D[0];
			D[0] += M[1] / 2;
			*/
			M[0] = mid;
			for (int i = 0; i < N-1; i++) {
				D[i] += M[i] / 2;
				M[i+1] = (A[i] - D[i])*2;
				D[i] += M[i+1] / 2;
				// dbg2(D[i], M[i+1])
			}
			D[N-1] += M[0] / 2 + M[N-1] / 2;
			// M[N-1] += A[N-1] - D[N-1];
			int sum = 0;
			rep (i, N) {
				sum += A[i] - D[i];
				dbg2(A[i], D[i])
			}
			
			print1(all(M));
			print1(all(D));
			print1(all(A));
			return sum >= 0;
   };

	 for (int i = 0; i < 10; i++) {
		 dbg(check(i));
			line()
	 }
}

signed main() {
	cin >> N;
	rep (i, N) {
		int x; cin >> x;
		A.push_back(x);
	}

	// solve();
	bin();

	return 0;
}