시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB106041320832.653%

문제

몇 개의 숫자 K(K는 1, 2, …, 9중 하나)와 사칙 연산(덧셈, 뺄셈, 곱셈, 나눗셈)만을 사용하여 어떤 자연수 X를 수식으로 표현한 것을 X의 K-표현이라 부른다. 수식에는 괄호가 포함될 수 있으며, 나눗셈은 나눈 몫만을 취한다.

예를 들어 12의 5-표현을 몇 개 써 보면 5+5+(5/5)+(5/5), 55/5+5/5, (55+5)/5 등이 있다. K-표현의 길이를 사용한 K의 개수라 하면, 각각의 길이는 6, 5, 4가 된다.

K가 주어졌을 때, 어떤 자연수의 K-표현 중 가장 짧은 길이를 알아보려 한다.

입력

첫째 줄에 K가 주어진다. 다음 줄에는 표현 식을 찾을 수의 개수 n(1 ≤ n ≤ 1,000)이 주어진다. 다음 줄에는 K-표현 중 가장 짧은 길이를 알아보려 하는 자연수 a(1 ≤ a ≤ 32,000)가 주어진다.

출력

입력되는 순서대로 K-표현의 최소 길이를 n개의 줄에 출력한다. 만약 K-표현의 최소 길이가 8보다 크다면 “NO"를 출력한다.

예제 입력 1

5
2
12
31168

예제 출력 1

4
NO
W3sicHJvYmxlbV9pZCI6IjIyODciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJhYThcdWIxNzhcdWI1MTRcdWM5YzBcdWQxMzggXHVkNDVjXHVkNjA0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWJhODcgXHVhYzFjXHVjNzU4IFx1YzIyYlx1Yzc5MCBLKEtcdWIyOTQgMSwgMiwgJmhlbGxpcDssIDlcdWM5MTEgXHVkNTU4XHViMDk4KVx1YzY0MCBcdWMwYWNcdWNlNTkgXHVjNWYwXHVjMGIwKFx1YjM2N1x1YzE0OCwgXHViZTg0XHVjMTQ4LCBcdWFjZjFcdWMxNDgsIFx1YjA5OFx1YjIxN1x1YzE0OClcdWI5Y2NcdWM3NDQgXHVjMGFjXHVjNmE5XHVkNTU4XHVjNWVjIFx1YzVi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