Codeforces Round 131 (Div. 2)
B
Hometask
Codeforces
1600
原题
← AC →
翻译中…

Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?

翻译中…

You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by $2$, $3$, $5$ without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.

翻译中…

Each digit is allowed to occur in the number the same number of times it occurs in the set.

翻译中…

Input

翻译中…

A single line contains a single integer $*n*$ $(1 ≤ *n* ≤ 100000)$ — the number of digits in the set. The second line contains $*n*$ digits, the digits are separated by a single space.

翻译中…

Output

翻译中…

On a single line print the answer to the problem. If such number does not exist, then you should print -1.

翻译中…

Note

翻译中…

In the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.

翻译中…

样例

Input #1
1
0
Output #1
0
InputCopy OutputCopy
Input #2
11
3 4 5 4 5 3 5 3 4 4 0
Output #2
5554443330
InputCopy OutputCopy
Input #3
8
3 2 5 1 5 2 2 3
Output #3
-1
InputCopy OutputCopy
题目信息
题号
214B
时间限制
2 s
内存限制
256 MB
标签
暴力
构造
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。