Hide

Problem D
Skeleton Array

A hint of disarray permeates the air in the department of Bioinformatics at Linköping University. Anatomy diagnostics reveal that the code skeleton, used in all of the department’s lab series, has lost its skeleton array implementation!

For an array $A$ of size $N$, define the skeleton array of $A$, $S(A)$, as the array of differences between subsequent elements of $A$. More formally, $S_ i(A) = A_{i} - A_{i+1}$ for $1 \leq i < N$.

Given an array $A$, you are tasked with finding an array $B$ such that $S(B) = A$ and the absolute value of the sum of $B$ is minimum. If there are multiple solutions $B$, output the one where $B_1$ is maximum.

Input

The first line of input consists of an integer $N$ ($1 \leq N \leq 10^5$), the size of the array $A$. The following line contains $N$ integers $A_1, A_2, ..., A_ N$ with $|A_ i| \leq 10^6$.

Output

Output a single line of $N+1$ space separated integers representing the array $B$.

Sample Input 1 Sample Output 1
2
1 6
3 2 -4
Sample Input 2 Sample Output 2
1
3
2 -1

Please log in to submit a solution to this problem

Log in