PivotOJ

Photoshoot

시간 제한: 2000ms메모리 제한: 512MB출처: USACO 2020 January Contest, BronzeBOJ 18323

문제

Farmer John is lining up his NN cows (2N1032\le N\le 10^3), numbered 1N1\ldots N, for a photoshoot. FJ initially planned for the ii-th cow from the left to be the cow numbered ai,a_i, and wrote down the permutation a1,a2,,aNa_1,a_2,\ldots,a_N on a sheet of paper. Unfortunately, that paper was recently stolen by Farmer Nhoj!

Luckily, it might still possible for FJ to recover the permutation that he originally wrote down. Before the sheet was stolen, Bessie recorded the sequence b1,b2,,bN1b_1,b_2,\ldots,b_{N-1} that satisfies bi=ai+ai+1b_i=a_i+a_{i+1} for each 1i<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, xi=yix_i=y_i for all i<ji<j and xj<yjx_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.

입력

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

The second line contains N1N-1 space-separated integers b1,b2,,bN1.b_1,b_2,\ldots,b_{N-1}.

출력

A single line with NN space-separated integers a1,a2,,aN.a_1,a_2,\ldots,a_{N}.

힌트

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.

예제

예제 1

입력
5
4 6 7 6
출력
3 1 5 2 4
코드를 제출하려면 로그인하세요.