## Editorial for An Animal Contest 3 P2 - Monkey Potato

Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Author: sjay05

Denote to be the set of all valid digits given in input.

For this subtask, notice that we can take the smallest digit in and output it times.

Time Complexity:

Consider cases:

• :

• No valid integer can be formed with the digit , so -1 should be outputted.
• :

Let the second smallest digit in be .

• The smallest palindrome consists of 's.
• A length palindrome can be constructed with the form: .
• :

• Let the smallest digit in be . The length palindrome is: .

Time Complexity: