Under construction

Still being built. Things may change

Photoshoot

Interview

Time limit2sMemory limit512 MB

Summary
Given adjacent sums b_i = a_i + a_{i+1} of a hidden permutation of 1..N, reconstruct the lexicographically smallest permutation a.
Level

Medium4 of 10

Topics
Brute force, Implementation, Array, Math
Solved
No attempts yet

Problem

Farmer John is lining up his NN cows (2≤N≤1032\le N\le 10^3), numbered 1…N1\ldots N, for a photoshoot. FJ initially planned for the ii-th cow from the left to be the cow numbered a_i,a\_i, and wrote down the permutation a_1,a_2,…,a_Na\_1,a\_2,\ldots,a\_N on a sheet of paper. Unfortunately, that paper was recently stolen by Farmer Nhoj!

Luckily, it might still be possible 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−1b\_1,b\_2,\ldots,b\_{N-1} that satisfies b_i=a_i+a_i+1b\_i=a\_i+a\_{i+1} for each 1≤i<N.1\le i<N.

Based on Bessie's information, help FJ restore the lexicographically minimum permutation aa that could have produced bb. A permutation xx is lexicographically smaller than a permutation yy if for some jj, x_i=y_ix\_i=y\_i for all i<ji<j and x_j<y_jx\_j<y\_j (in other words, the two permutations are identical up to a certain point, at which xx is smaller than yy). It is guaranteed that at least one such aa exists.

Input

The first line of input contains a single integer N.N.

The second line contains N−1N-1 space-separated integers b_1,b_2,…,b_N−1.b\_1,b\_2,\ldots,b\_{N-1}.

Output

A single line with NN space-separated integers a_1,a_2,…,a_N.a\_1,a\_2,\ldots,a\_N.

Hints

aa produces bb because 3+1=43+1=4, 1+5=61+5=6, 5+2=75+2=7, and 2+4=6.2+4=6.

Examples1

  1. Example 1

    Input
    5
    4 6 7 6
    
    Expected output
    3 1 5 2 4