CF352A.Jeff and Digits

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Jeff's got nn cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?

Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.

输入格式

The first line contains integer nn (1<=n<=103)(1<=n<=10^{3}) . The next line contains nn integers a1a_{1} , a2a_{2} , ...... , ana_{n} ( ai=0a_{i}=0 or ai=5a_{i}=5 ). Number aia_{i} represents the digit that is written on the ii -th card.

输出格式

In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.

输入输出样例

  • 输入#1

    4
    5 0 5 0
    

    输出#1

    0
    
  • 输入#2

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

    输出#2

    5555555550
    

说明/提示

In the first test you can make only one number that is a multiple of 90 — 00 .

In the second test you can make number 55555555505555555550 , it is a multiple of 9090 .

首页