시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 32 MB 5818 2019 1621 34.585%

문제

어느날, 미르코는 우연히 길거리에서 양수 N을 보았다. 미르코는 30이란 수를 존경하기 때문에, 그는 길거리에서 찾은 수에 포함된 숫자들을 섞어 30의 배수가 되는 가장 큰 수를 만들고 싶어한다.

미르코를 도와 그가 만들고 싶어하는 수를 계산하는 프로그램을 작성하라. (그 수가 존재한다면)

입력

N을 입력받는다. N는 최대 10^5개의 숫자로 구성되어 있다.

출력

미르코가 만들고 싶어하는 수가 존재한다면 그 수를 출력하라. 그 수가 존재하지 않는다면, -1을 출력하라.

예제 입력 1

30

예제 출력 1

30

예제 입력 2

102

예제 출력 2

210

예제 입력 3

2931

예제 출력 3

-1
W3sicHJvYmxlbV9pZCI6IjEwNjEwIiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiMzAiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YzViNFx1YjI5MFx1YjBhMCwgXHViYmY4XHViOTc0XHVjZjU0XHViMjk0IFx1YzZiMFx1YzVmMFx1ZDc4OCBcdWFlMzhcdWFjNzBcdWI5YWNcdWM1ZDBcdWMxMWMgXHVjNTkxXHVjMjE4IE5cdWM3NDQgXHViY2Y0XHVjNTU4XHViMmU0LiBcdWJiZjhcdWI5NzRcdWNmNTRcdWIyOTQgMzBcdWM3NzRcdWI3ODAgXHVjMjE4XHViOTdjIFx1Yzg3NFx1YWNiZFx1ZDU1OFx1YWUzMCBcdWI1NGNcdWJiMzhcdWM1ZDAsIFx1YWRmOFx1YjI5NCBcdWFlMzhcdWFjNzBcdWI5YWNcdWM1ZDBcdWMxMWMgXHVjYzNlXHVjNzQwIFx1YzIxOFx1YzVkMCBcdWQzZWNcdWQ1NjhcdWI0MWMgXHVjMjJiXHVjNzkwXHViNGU0XHVjNzQ0IFx1YzExZVx1YzViNCAzMFx1Yzc1OCBcdWJjMzBcdWMyMThcdWFjMDAgXHViNDE4XHViMjk0IFx1YWMwMFx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