### PROBLEM LINK:

**Author:** Abdullah768

**Tester:** Adiprogrammer

**Editorialist:** Abdullah768

### DIFFICULTY:

EASY

### PREREQUISITES:

Simple Math

### PROBLEM:

The problem can be reduced to finding the largest permutation of **X** which gives a remainder 3 when divided by 6.

### EXPLANATION:

The problem asks us to find the largest permutation of **X** which can be represented as: 6t+3

Where t can be any whole number.

It’s obvious that the above expression is divisible by 3, but not by 6.

For this to happen, the number should be an odd multiple of 3, i.e divisible by 3 but not by 2.

Since we want it to be divisible by 3, sum of digits should be divisible by 3.

Since we don’t want it to be divisible by 2, there should be at least one odd digit which can be placed at the unit’s digit.

If both of the above conditions are not met, it is impossible to have a solution.

Now, to generate the maximum value which satisfies the conditions, we need to place the **smallest** odd number at the unit’s place (so that the greater one’s can be used at the more significant positions). There are no constraints on the remaining digits and hence they can be arranged in descending order to attain the maximum value.

### AUTHOR’S SOLUTION:

Author’s solution