CF214B Hometask

题目描述

给定 $n$ 个范围在 $[0,9]$ 的整数,求用这 $n$ 个数能拼出的被 $2,3,5$ 同时整除且没有前导 $0$ 的最大整数是多少?(可以不用完所有数字)

输入格式

第一行输入一个数 $n$。 第二行输入 $n$ 个数,代表你可以用的 $n$ 个数字。

输出格式

输出你拼出的满足题意的最大数字,如果不存在任何数满足题意,则输出 $-1$。

说明/提示

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.