시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 128 MB 181 54 39 34.211%

문제

몇 개의 숫자 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
W3sicHJvYmxlbV9pZCI6IjIyODciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJhYThcdWIxNzhcdWI1MTRcdWM5YzBcdWQxMzggXHVkNDVjXHVkNjA0IiwiZGVzY3JpcHRpb24iOiI8cD5cdWJhODcgXHVhYzFjXHVjNzU4IFx1YzIyYlx1Yzc5MCBLKEtcdWIyOTQgMSwgMiwgJmhlbGxpcDssIDlcdWM5MTEgXHVkNTU4XHViMDk4KVx1YzY0MCBcdWMwYWNcdWNlNTkgXHVjNWYwXHVjMGIwKFx1YjM2N1x1YzE0OCwgXHViZTg0XHVjMTQ4LCBcdWFjZjFcdWMxNDgsIFx1YjA5OFx1YjIxN1x1YzE0OClcdWI5Y2NcdWM3NDQgXHVjMGFjXHVjNmE5XHVkNTU4XHVjNWVjIFx1YzViNFx1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