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

#GD0000165. Bảng nhị phân cân bằng (Grid-00100)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bảng nhị phân cân bằng (Grid-00100)

Grid-00100

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Construct an n×nn\times n binary grid with exactly kk ones. Let RiR_i and CjC_j be its row and column sums. Minimize f(A)=(max⁡R−min⁡R)2+(max⁡C−min⁡C)2f(A)=(\max R-\min R)^2+(\max C-\min C)^2. Print the minimum score and any grid attaining it.

Input

One line contains integers n,kn,k.

Output

Print the minimum possible f(A)f(A), followed by nn rows of exactly nn characters 0 or 1, without spaces.

Subtasks

  • Subtask 1 (20 points): 1≤n≤51\le n\le 5; 0≤k≤n20\le k\le n^2.
  • Subtask 2 (30 points): 1≤n≤401\le n\le 40; 0≤k≤n20\le k\le n^2.
  • Subtask 3 (50 points): 1≤n≤3001\le n\le 300; 0≤k≤n20\le k\le n^2.

Examples

Input

2 2

Output

0
10
01

Explanation

Place the two ones at (1,1)(1,1) and (2,2)(2,2). Both row sums and both column sums are 11, giving f(A)=0f(A)=0. A sum of squares cannot be negative, so the score is optimal.