Codeforces Round 1023 (Div. 2)
A
LRC and VIP
Codeforces
800
原题
←B →
翻译中…

You have an array $a$ of size $n$ — $a_1, a_2, \ldots a_n$.

翻译中…

You need to divide the $n$ elements into $2$ sequences $B$ and $C$, satisfying the following conditions:

翻译中…
  • Each element belongs to exactly one sequence.
  • Both sequences $B$ and $C$ contain at least one element.
  • $\gcd$ $(B_1, B_2, \ldots, B_{|B|}) \ne \gcd(C_1, C_2, \ldots, C_{|C|})$ $^{\text{∗}}$
翻译中…

$^{\text{∗}}$$\gcd(x, y)$ denotes the greatest common divisor (GCD) of integers $x$ and $y$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

翻译中…

The first line of each test case contains an integer $n$ ($2 \le n \le 100$).

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 10^4$).

翻译中…

Output

翻译中…

For each test case, first output $\texttt{Yes}$ if a solution exists or $\texttt{No}$ if no solution exists. You may print each character in either case, for example $\texttt{YES}$ and $\texttt{yEs}$ will also be accepted.

翻译中…

Only when there is a solution, output $n$ integers on the second line. The $i$-th number should be either $1$ or $2$. $1$ represents that the element belongs to sequence $B$ and $2$ represents that the element belongs to sequence $C$.

翻译中…

You should guarantee that $1$ and $2$ both appear at least once.

翻译中…

Note

翻译中…

In the first test case, $B = [51, 9]$ and $C = [1, 20]$. You can verify $\gcd(B_1, B_2) = 3 \ne 1 = \gcd(C_1, C_2)$.

翻译中…

In the second test case, it is impossible to find a solution. For example, suppose you distributed the first $3$ elements to array $B$ and then the last element to array $C$. You have $B = [5, 5, 5]$ and $C = [5]$, but $\gcd(B_1, B_2, B_3) = 5 = \gcd(C_1)$. Hence it is invalid.

翻译中…

样例

Input #1
3
4
1 20 51 9
4
5 5 5 5
3
1 2 2
Output #1
Yes
2 2 1 1
No
Yes
1 2 2
InputCopy OutputCopy
题目信息
题号
2107A
时间限制
1 s
内存限制
256 MB
标签
贪心
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。