#469
Silver IV
Photoshoot
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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 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,\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.

SCORING:

Test cases 2-4 satisfy N8.N\le 8.Test cases 5-10 satisfy no additional constraints.

입력

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}.

예제 입력 1

5
4 6 7 6

예제 출력 1

3 1 5 2 4
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Silver IV1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.