CESTA
시간 제한: 1000ms메모리 제한: 256MB출처: COCI 2014-2015BOJ 10610
문제
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).
입력
The first and only line of input contains the integer N, consisting of at most 105 digits.
출력
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.
예제
예제 1
입력
30
출력
30
예제 2
입력
102
출력
210
예제 3
입력
2931
출력
-1
예제 4
입력
80875542
출력
88755420
코드를 제출하려면 로그인하세요.