#d21002. 最小整数
最小整数
Smallest Integer
Problem Description
You are given the frequency of each digit : digit appears times. Using all the given digits, form an integer that satisfies the following conditions and is as small as possible:
- All given digits must be used.
- The leading digit cannot be , unless the result is the single digit .
- No two adjacent digits may be the same.
Find the smallest integer that can be formed.
Input Format
Input integers (), the frequencies of each digit. It is guaranteed that .
Output Format
Output one line containing an integer: the smallest integer that can be formed; if no such integer exists, output -1.
Sample Input
2 0 1 0 0 1 0 2 0 0
Sample Output
205707