You are asked to find a number with N digits. Let's denote by di the i-th digit of the number. You are given an array A of N−1 integers:
If the solution is not unique, you should find the largest number that respects the restrictions.
The first line contains a single integer N.
The second line contains N−1 integers representing the elements of A.
If there is no solution output −1.
Otherwise, print the largest valid number.
Input | Output |
---|---|
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 |