Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
256M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
One morning, ~Jack~ happened to see a positive integer ~ N ~ on the way from home to school. Since ~Jack~ really likes the number ~30~, he wants to transform ~N~ into a number ~ M~ which is the largest possible number and a multiple of ~30~ by rearranging the digits of ~ N ~ that ~Jack~ saw.
Help ~Jack~ by writing a program to find the number ~ M ~ (if it exists).
Input
- A single line containing the integer ~ N ~ (~N ~ has up to ~ 10^5 ~ digits).
Output
- Print the number ~M ~ found. If ~ M ~ does not exist, print ~-1~.
Sample Input
102
Sample Output
210
Bình luận