Some positive integers can be shown to have a property called Chain divisibility. For a number to be chain-divisible by n, it must fulfil three requirements:
Each digit divides the number formed by the n digits that follow it.
For example, the number 7143 is chain-divisible by 2 because 7 divides 14 and 1 divides 43. It is not chain-divisible by 3 because 7 does not divide 143.
Each subsequence taken into account for divisibility must not have leading zeros.
For instance, the number 14208 is not chain-divisible by 2 because 08 has a leading zero. It is, however, chain-divisible by 3, because 208 does not have a leading zero.
All digits in the number must be unique.
For instance, the number 14280 is chain-divisible by 2, 3 and 4. If my explanation of chain divisibility is unclear please ask questions in the comments.
The input to the program consists of a single integer
n, followed by a space, then a number that has had certain digits replaced by underscores. For example, the following is a possible input:
n will be greater than 1. The number will never be entirely underscores. You are not guaranteed that the first digit is not an underscore. The first digit will never be 0. n will never be greater or equal to the number of digits in the number.
Output the number, with the digits replaced by integers such that the resulting number is chain-divisible by n. If more than one way of completing the chain-divisible number exists, any may be used as output. If there is no numbers that can complete it, output
no answer. For instance, the output of the example input could be:
This is code golf, so the shortest code wins.