Under construction

Still being built. Things may change

Comso Christmas

Interview

Time limit2sMemory limit1024 MB

Summary
Decide if N problems, each needing s_i wrong answers before its accepted verdict, can be submitted so that verdicts alternate, starting with Accepted.
Level

Medium5 of 10

Topics
Greedy, Sorting, Prefix sum
Solved
No attempts yet

Problem

The Department of Computer Science and Software has a tradition of decorating each Christmas's submission status like a Christmas tree. Specifically, when all submissions from a given day are collected, that day's submissions are said to be decorated like a Christmas tree if all of the following conditions hold.

  • Every submission's verdict is either "Accepted!!" or "Wrong Answer".
  • When the submissions are listed in time order, the first submission's verdict is "Accepted!!".
  • Every submission other than the first has a verdict different from the one right before it. For example, the second submission is "Wrong Answer", the third is "Accepted!!", and so on, ⋯\cdots

Input

On Christmas, Arami will solve all NN problems. The problems are numbered from 1 to NN. Arami always follows these rules while solving.

  • Arami submits only code whose verdict is "Accepted!!" or "Wrong Answer".
  • Arami does not resubmit a problem that has already been solved.

To keep the Comso tradition, Arami wants to decorate the day's submission status like a Christmas tree. All-knowing participants can tell exactly how many times Arami got "Wrong Answer" on each problem before solving it. Write a program that determines whether Arami can receive "Accepted!!" on all NN problems while the submissions are decorated like a Christmas tree. If it can, print the order in which the submissions should be made.

Output

The first line contains the number of problems NN that Arami will solve. (1≤N≤200 000)(1\leq N\leq 200\,000)

From the second line on, NN integers s1,s2,⋯ ,sNs_1, s_2, \cdots, s_N are given, one per line. sis_i means that Arami solves problem ii after getting "Wrong Answer" sis_i times. In other words, Arami can submit problem ii at most si+1s_i+1 times, gets "Accepted!!" on the (si+1)(s_i+1)-th submission, and gets "Wrong Answer" on the rest. (0≤si≤109)(0\le s_i\le 10^9)

Examples3

  1. Example 1

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

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

    Input
    5
    0
    0
    1
    2
    1
    
    Expected output
    2
    4
    1
    5
    5
    3
    3
    4
    4