Uukjeo
InterviewTime limit1sMemory limit512 MB
Given N word lengths, build binary words of those lengths where no word is a prefix of another, or report -1 if it is impossible.
Problem
Uukjeo is the language that Uk-je uses, and it uses only the characters 0 and 1. Uukjeo has words, and the length of each word is . Uukjeo speakers often understand each other without saying a word to the end, because no word is a prefix of another word.
Jun-o, a Dongtan resident who wanted to learn Uukjeo, secretly obtained information about it. He got only the word lengths, not the words themselves. Given the N word lengths , determine whether words can be made so that no word is a prefix of another word.
Input
The first line contains the number of words (). The second line contains . The sum of the word lengths is a natural number at most 1,000.
Output
If it is possible to make Uukjeo words, print 1 on the first line. From the second line on, print the Uukjeo words, one per line. The words must follow the input order: a word of length , a word of length , ..., and a word of length .
If it is impossible to make Uukjeo words, print -1.