P28286 [洛谷] HXY Plays with Cards
普及-
题目描述

Problem Description

HXY has received some cards, each marked with the digit $0$ or $5$. She can choose some of these cards to form a sequence such that the number formed by the sequence is the largest possible and divisible by $90$. This number must be a valid non-negative integer, meaning it cannot have leading zeros, except for the number $0$ itself, which is considered valid. If no such number can be formed, output -1.

Input Format

The first line contains the number of cards, $n$.

The second line contains $n$ digits, each being either $5$ or $0$.

Output Format

Output a single line containing the number that can be formed, or -1 if no valid number can be formed.

Sample Input and Output

Sample Input #1

4
5 0 5 0

Sample Output #1

0

Sample Input #2

11
5 5 5 5 5 5 5 5 0 5 5

Sample Output #2

5555555550

Sample Input #3

2
5 5

Sample Output #3

-1

Notes

Data Range:

  • For $30\%$ of the data, $n \le 10$.
  • For $20\%$ of the data, only the digit $5$ is present.
  • For $100\%$ of the data, $n \le 1000$.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 5 0 5 0
样例输出
0