G. Grandpa Frost and the Dreadful Eight
Easy
Execution time limit is 1 second
Runtime memory usage limit is 256 megabytes
Grandpa Frost has chosen a positive integer .
Your task is to determine if it's possible to rearrange the digits of this number to form a multiple of . The rearranged number must not have leading zeros, meaning no zeros should appear before the first non-zero digit.
Input
The input consists of a single line containing the integer ().
Output
If it's impossible to rearrange the digits of to form a multiple of , output the integer .
If it is possible, output any number that is a multiple of and can be formed by rearranging the digits of . If there are multiple valid solutions, you may output any one of them.
Examples
Input #1
Answer #1
Input #2
Answer #2
Submissions 584
Acceptance rate 13%