codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

352A.md (1276B)


      1 Source: https://codeforces.com/problemset/problem/352/A
      2 
      3 A. Jeff and Digits
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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?
     22 
     23 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.
     24 
     25 Input
     26 
     27 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.
     28 
     29 Output
     30 
     31 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.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 4  
     39 5 0 5 0
     40 ```
     41 
     42 Output
     43 
     44 ```
     45 0
     46 ```
     47 
     48 Input
     49 
     50 ```
     51 11  
     52 5 5 5 5 5 5 5 5 0 5 5
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 5555555550
     59 ```
     60 
     61 Note
     62 
     63 In the first test you can make only one number that is a multiple of 90 — 0.
     64 
     65 In the second test you can make number 5555555550, it is a multiple of 90.