## COCI '14 Contest 4 #1 Cesta

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

One morning, completely by chance, Mirko found a positive integer in the middle of the street. Since Mirko adores the number 30, he wants to know the maximum multiple of the number 30 that can be obtained by shuffling the digits of the number he found in the street. Help our hero and write a programme that calculates that number (if it exists).

#### Input

The first and only line of input contains the integer , consisting of at most digits.

#### Output

The first and only line of output must contain the required number from the task, if it exists. If it doesn't exist, output -1.

#### Sample Input 1

30

#### Sample Output 1

30

#### Sample Input 2

102

#### Sample Output 2

210

#### Sample Input 3

2931

#### Sample Output 3

-1

• commented on May 29, 2020, 12:48 a.m.

This problem should also be tagged as greedy algorithms.

• commented on May 18, 2015, 9:54 p.m. edited

Why does this problem have partial points? There aren't really any corner cases or increase in difficulty.

• commented on June 20, 2015, 1:25 a.m.

Maybe that some solutions TLE?

• commented on June 20, 2015, 10:28 a.m.