Under construction

Still being built. Things may change

Grade Conversion 2

Interview

Time limit2sMemory limit1024 MB

Summary
Given the new grades b, recover old grades a that produce them under the averaging rule, or print -1 if no such sequence exists.
Level

Medium5 of 10

Topics
Prefix sum, Greedy
Solved
No attempts yet

Problem

Until the 2023 academic year, Daegu Science High School gave each student a semester grade, an integer from 11 to 10910^9, based on that semester's performance. A lower number meant a better grade, so 11 was the best and 10910^9 was the worst. This system did not reflect how much a student improved from the previous semester, so students focused on their rank relative to others instead of their own growth.

Starting in the 2024 academic year, the school changed the rule. If a student's grade was lower than the average of their earlier grades, the grade was reduced by 11. Specifically, let a_1,a_2,…,a_Na\_1, a\_2, …, a\_N be the grades for semesters 11 through NN under the old system, which was in use through the 2023 academic year. Then the grades b_1,b_2,…,b_Nb\_1, b\_2, …, b\_N are computed as follows.

  • b_1=a_1b\_1 = a\_1
  • For each 1≤i≤N−11 \leq i \leq N-1, if a_i+1<1i∑_j=1ia_ja\_{i+1}<\frac{1}{i}\sum\_{j=1}^{i}a\_j, then b_i+1=a_i+1−1b\_{i+1} = a\_{i+1} - 1. Otherwise, b_i+1=a_i+1b\_{i+1}= a\_{i+1}.

Under this definition, grades from the 2024 academic year onward are always integers from 00 to 10910^9.

Input

The first line contains NN, the number of semesters Eunseong attended.

The second line contains Eunseong's grades b_1,b_2,…,b_Nb\_1, b\_2, …, b\_N.

Output

Print the old-system grades a_1,a_2,…,a_Na\_1, a\_2, \ldots, a\_N separated by spaces. If several sequences satisfy the conditions, print any one of them. If no such sequence exists, print −1-1 instead.

Constraints

  • 1≤N≤500 0001 \le N \le 500\ 000
  • For each 1≤i≤N1\le i\le N, 0≤b_i≤1090 \le b\_i \le 10^9
  • All given numbers are integers.

Examples3

  1. Example 1

    Input
    5
    2 3 0 2 0
    
    Expected output
    2 3 1 2 1
    
  2. Example 2

    Input
    7
    0 32 16 7 3 1 0
    
    Expected output
    -1
    
  3. Example 3

    Input
    5
    1000000000 1000000000 1000000000 1000000000 1000000000
    
    Expected output
    1000000000 1000000000 1000000000 1000000000 1000000000