Consecutive Digits Signs

Time limit: 1000 ms
Memory limit: 128 MB

You are asked to find a number with NN digits. Let's denote by did_i the ii-th digit of the number. You are given an array AA of N1N-1 integers:

  • Ai=1A_i = -1 if di<di+1d_i < d_{i+1}
  • Ai=0A_i = 0 if di=di+1d_i = d_{i+1}
  • Ai=1A_i = 1 if di>di+1d_i > d_{i+1}

If the solution is not unique, you should find the largest number that respects the restrictions.

Standard input

The first line contains a single integer NN.

The second line contains N1N-1 integers representing the elements of AA.

Standard output

If there is no solution output 1-1.

Otherwise, print the largest valid number.

Constraints and notes

  • 2N1052 \leq N \leq 10^5

InputOutput
8
1 1 1 0 1 1 1
98766543
10
1 1 0 -1 -1 -1 0 1 1
9866789987
11
-1 -1 0 1 1 0 0 1 -1 -1
78998777689

Authenticate to use the workspace

Log In
Sign Up
Forgot Password?
or connect with