#P2192. HXY玩卡片

HXY玩卡片

Description

HXY has some cards, each labeled with the digit 00 or 55.

She can choose some of these cards and arrange them in a row to form the largest possible number that is divisible by 9090.

This number must be a valid non-negative integer, meaning it cannot have a leading 00; that is, 00 cannot be the first digit of the sequence.

Exceptionally, the integer 00 is allowed.

If no such number can be formed, output 1-1.

Input Format

The first line contains the number of cards nn.

The second line contains the nn digits (each is either 55 or 00).

Output Format

Output a single line: if it is possible, print the number; otherwise, print 1-1.

4
5 0 5 0
0

11
5 5 5 5 5 5 5 5 0 5 5
5555555550
2
5 5
-1

Hint

Constraints:

For 30%30\% of the testdata, n10n \le 10.

For 20%20\% of the testdata, all given digits are 55.

For 100%100\% of the testdata, n1000n \le 1000.

Translated by ChatGPT 5