PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000246. Tô màu đồ thị XOR nguyên tố (Prime XOR Coloring)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tô màu đồ thị XOR nguyên tố (Prime XOR Coloring)

Prime XOR Coloring

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Consider an undirected graph with vertices numbered 1,2,…,n1,2,\ldots,n. Two distinct vertices uu and vv are adjacent if and only if u⊕vu\oplus v is prime, where ⊕\oplus denotes bitwise XOR. A prime is an integer greater than 11 with exactly two positive divisors.

Color all vertices so that the endpoints of every edge have different colors, using the minimum possible number of colors. Any optimal coloring is accepted.

Input

The only line contains integer nn, the number of vertices. Edges are determined by the XOR rule; no edge list is provided.

Output

  • On the first line, print the minimum number kk of colors.
  • On the second line, print exactly nn integers c1,c2,…,cnc_1,c_2,\ldots,c_n with 1≤ci≤k1\le c_i\le k, where cic_i is the color of vertex ii.
  • For every edge (u,v)(u,v), cu≠cvc_u\ne c_v must hold. Any coloring achieving minimum kk is valid.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; vertices numbered from 11 to nn.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le2000; vertices numbered from 11 to nn.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le2\cdot10^5; vertices numbered from 11 to nn.

Examples

Input

6

Output

4
1 2 3 4 1 2

Explanation

Here n=6n=6, and the output assigns colors [1,2,3,4,1,2][1,2,3,4,1,2]. Vertices 11 and 55 share color 11 but 1⊕5=41\oplus5=4 is not prime. Likewise, 2⊕6=42\oplus6=4 is not prime, so the other repeated color is also legal. All other colors occur only once. The vertices 1,3,4,61,3,4,6 are pairwise adjacent: their six XOR values are 2,5,7,7,5,22,5,7,7,5,2, all prime. They therefore require at least four colors. The displayed coloring uses exactly four, so it is optimal.