eolymp
bolt
Try our new interface for solving problems
Problems

Digit Sum

Digit Sum

When Grace was in third grade, her elementary school teacher assigned her the following problem: \textit{What is the smallest possible sum of two numbers that together use the numerals }\textit{\textbf{1}}\textit{, }\textit{\textbf{2}}\textit{, }\textit{\textbf{7}}\textit{, }\textit{\textbf{8}}\textit{, and }\textit{\textbf{9}}\textit{?} Grace figured out that the answer to this problem is \textbf{207} (for example, as \textbf{78 + 129}), but when the teacher assigned four pages of similar problems as homework, Grace got bored. It turns out that Grace was a rather advanced third grader, so she decided that it would be more fun to write a computer program to solve such problems. Surely you can do the same! \InputFile Each problem is described on a single line. The line begins with an integer \textbf{N}, such that \textbf{2} ≤ \textbf{N} ≤ \textbf{14}, designating the number of numerals included in the problem. Following that are those \textbf{N} numerals. There will always be at least \textbf{2 }numerals that are nonzero. The end of the input is designated by a line containing only the value \textbf{0}. \OutputFile For each case, output a line with the minimum sum S that can be achieved. Please keep in mind that by standard convention, the numeral \textbf{0} cannot appear as the first digit of either summand.
Time limit 1 second
Memory limit 64 MiB
Input example #1
5 1 2 7 8 9
6 3 4 2 2 2 2
9 0 1 2 3 4 0 1 2 3
0
Output example #1
207
447
11257
Source ACM Mid-Central Regional Programming Contest 2013