Problem list
Log in
#coci00329 · COCI 2014/2015 Contest 4

Cesta

Silver IV 1.0 s 32 MB

One morning, completely by chance, Mirko found a positive integer $N$ 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 $N$, consisting of at most $10^{5}$ 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 TEST DATA input input input 30 102 2931 output output output 30 210 -1

Example 1

Input
30
Output
30

Example 2

Input
102
Output
210

Example 3

Input
2931
Output
-1
Source
COCI 2014/2015 Contest 4
Appears in
Not part of a ladder, contest or set yet.
Accepted 1 Submissions 1 Acceptance 100% Solvers 1

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code