#USACO2277. 拍照

    ID: 756 Type: Default File IO: photo 1000ms 256MiB Tried: 7 Accepted: 2 Difficulty: 10 Uploaded By: Tags>USACO 2020 January Contest Bronze

拍照

Farmer John is lining up his NN cows (2N103)(2≤N≤10^3), numbered 1...N1...N, for a photoshoot. FJ initially planned for the ii-th cow from the left to be the cow numbered aia_i, and wrote down the permutation ai,a2...ana_i,a_2...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 b1,b2...bN1b_1,b_2...b_{N-1} that satisfies bi=ai+ai+1b_i=a_i+a_{i+1} for each 1i<N1≤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 y� if for some jj, xi=yjx_i=y_j for all i<ji<j and xi<yjx_i<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.

SCORING:

  • Test cases 2-4 satisfy N≤8.
  • Test cases 5-10 satisfy no additional constraints.

INPUT FORMAT (file photo.in):

The first line of input contains a single integer NN.The second line contains N1N-1space-separated integers b1,b2,bN1b_1,b_2,b_{N-1}.

OUTPUT FORMAT (file photo.out):

A single line with NN space-separated integers a1,a2,...aNa_1,a_2,...a_N.

SAMPLE INPUT:

5
4 6 7 6

SAMPLE OUTPUT:

3 1 5 2 4

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