Making a Number
InterviewTime limit2sMemory limit128 MB
Given how many cards exist for each digit 0-9, build the largest possible number using some or all cards so that no two adjacent digits match and no leading zero appears.
Problem
Sejun has digit cards numbered from 0 through 9. Each card contains one digit, and he may choose some or all of the given cards to make one number.
The number must not start with 0, and no two adjacent digits may be the same. If only 0 can be made, the one-digit number 0 is allowed.
Given how many cards Sejun has for each digit, find the largest number that can be made while satisfying these rules.
Input
The first line contains 10 integers: the number of cards for digits 0 through 9, in order. The total number of cards is at least 1 and at most 50.
Output
Print the largest number that can be made while satisfying the rules.