In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Let be a decimal digit different from . We say that an arithmetic expression is a -representation of the integer if a value of this expression is and if it contains only numbers composed of a digit . (All the numbers are of course decimal). The following arithmetical operations are allowed in the expression: addition, subtraction, multiplication and division. Round brackets are allowed too. Division may appear only when a dividend is a multiple of a divisor.
Each of the following expressions is the 5-representation of the number 12:
The length of the -representation is the number of occurrences of digit in the expression. In the example above the first two representations have the length 6, the third - 5, and the forth - 4.
Write a program which:
The first line of the standard input contains digit , is en element of . The second line contains number , . In the following lines there is the series of natural numbers , (for ), one number in each line.
The standard output composes of lines. The -th line should contain:
For the input data:
5 2 12 31168
the correct result is:
4 NIE
Task author: Krzysztof Lorys.