eolymp
bolt
Try our new interface for solving problems
Problems

Photoshoot

Photoshoot

Farmer John is arranging his $n$ cows numbered $1 ... n$ for a photoshoot. Initially, FJ planned for the $i$-th cow from the left to be the cow numbered $a_i$, and wrote down the permutation $a_1, a_2, ..., a_n$ on a sheet of paper. Unfortunately, that paper was recently stolen by Farmer Nhoj! Fortunately, there might still be a chance for FJ to recover the permutation that he originally wrote down. Before the sheet was stolen, Bessie recorded the sequence $b_1, b_2, ..., b_{n-1}$, which satisfies $b_i = a_i + a_{i+1}$ for each $i~(1 \le i < n)$. Based on Bessie's information, help FJ restore the "lexicographically minimum" permutation a that could have produced $b$. A permutation $x$ is lexicographically smaller than a permutation $y$ if for some $j$, $x_i = y_i$ for all $i < j$ and $x_j < y_j$ (in other words, the two permutations are identical up to a certain point, at which $x$ is smaller than $y$). It is guaranteed that at least one such a exists. \InputFile The first line contains a single integer $n~(2 \le n \le 10^3)$. The second line contains $n − 1$ integers $b_1, b_2, ..., b_{n-1}$. \OutputFile Print the lexicographically minimum permutation $a_1, a_2, ..., a_n$. \Note $a\:$ produces $b$ because $3 + 1 = 4$, $1 + 5 = 6$, $5 + 2 = 7$ and $2 + 4 = 6$.
Time limit 1 second
Memory limit 128 MiB
Input example #1
5
4 6 7 6
Output example #1
3 1 5 2 4
Source 2020 USACO January Bronze