시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 1024 MB 0 0 0 0.000%

문제

Today is the first day of work for Charles the Courier. He has been tasked with delivering N packages where each package has a (not necessarily unique) label number between 1 and N inclusive. At the end of each day, he is required to report a sequence A of N integers A1, . . . , AN where Ai is the label number of the ith delivered package.

A mathematician at heart, Charles decides to use delta encoding to save on memory space and records a sequence D of N − 1 integers D1, . . . , DN−1 instead, where Di = Ai+1 − Ai.

After delivering all the packages, Charles realises that he does not know how to recover A from D. Your task today is to help him, or state that it is not possible to uniquely recover A.

입력

Your program must read from standard input.

The first line contains a single integer N, the total number of packages.

The second line contains N − 1 space-separated integers, D1, . . . , DN−1. Di represents the difference between the label numbers of the (i + 1)th and ith delivered package.

출력

Your program must print to standard output.

If it is possible to uniquely recover A from D, your output should contain N space-separated integers, the sequence A.

Otherwise, your output should contain a single integer on a single line, the integer -1.

제한

  • 2 ≤ N ≤ 3 × 105
  • 1 ≤ Ai ≤ N
  • −N < Di < N

예제 입력 1

5
1 3 -2 1

예제 출력 1

1 2 5 3 4

We are able to uniquely recover A = [1, 2, 5, 3, 4].

This is consistent with D since:

  • A2 − A1 = 2 − 1 = 1 = D1
  • A3 − A2 = 5 − 2 = 3 = D2
  • A4 − A3 = 3 − 5 = −2 = D3
  • A5 − A4 = 4 − 3 = 1 = D4

예제 입력 2

5
2 2 -3 1

예제 출력 2

1 3 5 2 3

We are able to uniquely recover A = [1, 3, 5, 2, 3]. Note that label numbers can appear more than once.

예제 입력 3

2
0

예제 출력 3

-1

We are unable to uniquely recover A since we could have either A = [1, 1] or A = [2, 2].