#P7174. [COCI 2014/2015 #4] CESTA

[COCI 2014/2015 #4] CESTA

Description

Mirko found a positive integer nn. Since Mirko likes the number 3030, he wants to know the largest multiple of 3030 among the numbers that can be formed using each digit of nn.

Write a program to compute this number (if it does not exist, output -1).

Input Format

One number nn.

Output Format

Only one line: the required number.

30
30
102
210
2931
-1

Hint

Constraints

For 100%100\% of the testdata, the number of digits of nn does not exceed 10510^5.

Notes

This problem is translated from COCI2014-2015 CONTEST #4 T1 CESTA.

Translated by ChatGPT 5