#P2192. Maximum Number Divisible by 90
Maximum Number Divisible by 90
Maximum Number Divisible by 90
HXY has obtained a set of cards, each of which is marked with either the digit \(0\) or \(5\). She can choose some of the cards and arrange them in a row to form the largest possible number, under the condition that the number is divisible by \(90\). Additionally, the formed number must be a valid non-negative integer, which means it should not contain any leading zeros (except for the number \(0\) itself, which is valid). If such a number cannot be formed, output \(-1\).
Note: A valid number must not have leading zeros. For example, if no valid number can be formed by following the above rules, output -1
.
inputFormat
The first line contains a single integer \(n\) \( (1 \leq n \leq 10^3)\), representing the number of cards.
The second line contains \(n\) space-separated integers, each being either \(0\) or \(5\), which correspond to the digits on the cards.
outputFormat
Output a single string representing the maximum valid number that can be formed which is divisible by \(90\). If no such number can be formed, output -1
.
sample
1
0
0