8 Divisible

Time limit: 1000 ms
Memory limit: 256 MB

You are given a large number NN. Can you permute its digits such that the new number is divisible by 88?

If the solution is not unique, print the smallest one. Leading 00s are not allowed.

Standard input

The first line contains a single large number NN.

Standard output

If there is no solution output 1-1.

Otherwise, print the answer on the first line.

Constraints and notes

  • The number of digits of NN is between 11 and 10001\,000
  • 1N1 \leq N

InputOutputExplanation
625
256

256256 is the only number divisible by 88 we can obtain

173
-1

There is no permutation of digits that creates a number divisible by 88.

2048
2048

02480248 is smaller, but leading 00s are not allowed.

Authenticate to use the workspace

Log In
Sign Up
Forgot Password?
or connect with