K-digit number High
Hard
Execution time limit is 1 second
Runtime memory usage limit is 8 megabytes
A number is considered K-digit if it contains no more than K distinct digits in its decimal representation (ignoring any leading zeros).
Given a number x, your task is to find the K-digit number that is closest to x.
Input
The input consists of a single line with two integers, K and x, both without leading zeros (1 ≤ K ≤ 10, 0 ≤ x ≤ 1010^6).
Output
Output a K-digit number y such that the absolute difference |y-x| is minimized. If there are multiple such numbers, you may output any one of them.
Examples
Input #1
Answer #1
Submissions 105
Acceptance rate 9%