CF352A.Jeff and Digits

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Jeff's got n 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.

杰夫有 nn 张卡片,每张卡片上写着数字 0 或 5。杰夫可以选择若干张卡片,并将它们排成一行,从而构成一个数。他能用手中卡片组成的、能被 90 整除的最大可能数是多少?

杰夫构成的数不能有前导零;但特别地,我们认为数字 0 本身不包含前导零。杰夫不必使用全部卡片。

输入格式

The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers _a_1, _a_2, ..., a__n (a__i = 0 or a__i = 5). Number a__i represents the digit that is written on the i-th card.

第一行包含一个整数 nn(1 ≤ n ≤ 1031 ≤ n ≤ 10^3)。下一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(每个 ai=0a_i = 0 或 ai=5a_i = 5)。数字 aia_i 表示写在第 ii 张卡片上的数字。

输出格式

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.

在一行中输出问题的答案——能被 90 整除的最大数。如果无法用这些卡片构造出任何能被 90 整除的数,则输出 -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 — 0.

In the second test you can make number 5555555550, it is a multiple of 90.

在第一个测试中,你只能构造一个 90 的倍数——0。

在第二个测试中,你可以构造数字 5555555550,它是 90 的倍数。

输入解题思路,AI测评打分。不知道怎么写?

首页