Under construction

Still being built. Things may change

Schedule

Time limit2sMemory limit1024 MB

Summary
Schedule one member per team each week so every pair of people from different teams meets, minimizing the longest gap between their meetings.
Level

Hard9 of 10

Topics
Combinatorics, Bit manipulation, Math
Solved
No attempts yet

Problem

The Institute for Creative Product Combinations (ICPC) searches for unusual, innovative ways to join products or technologies that seem unrelated. These combinations open new markets and create jobs. For example, its latest success was the 'hairbachi', a hair dryer with a hibachi grill top attachment for cooking hot meals on the go.

The company employs nn teams of two people each. Each team first researches its own products. Then members of different teams meet to explore ways to combine products.

During the pandemic, ICPC management scheduled everyone so that never more than nn people were in the office at the same time. Things ran smoothly, so they kept the process after normal operations resumed. The scheme works as follows. Label the teams 11 through nn and the two people on team ii as (i,1)(i,1) and (i,2)(i,2). Each week, exactly one person from each team comes into the office, while the other stays away. The members (i,1)(i,1) and (i,2)(i,2) know each other well and collaborate productively while isolated, so they do not need to meet in the office. However, isolation between members of different teams is still a concern.

Each pair of teams ii and jj with i≠ji \ne j has to collaborate occasionally. For a given number ww of weeks and fixed team members (i,a)(i,a) and (j,b)(j,b), let w1<w2<⋯<wkw_1 < w_2 < \dots < w_k be the weeks in which these two people meet in the office. The isolation of those two people is the maximum of {w1,w2−w1,…,wk−wk−1,w+1−wk}\{w_1, w_2 - w_1, \dots, w_k - w_{k-1}, w+1 - w_k\}, or infinity if they never meet. The isolation of the whole company is the maximum isolation across all choices of ii, jj, aa, and bb.

Find a weekly schedule that minimizes the isolation of the whole company over ww weeks.

Input

A single line with two integers nn (2≤n≤1042 \le n \le 10^4) and ww (1≤w≤521 \le w \le 52), where nn is the number of teams and ww is the number of weeks to schedule.

Output

Print one line with the minimum isolation achievable for nn teams, or the word infinity if no schedule guarantees that every pair of people from different teams meets. If the isolation is finite, print ww more lines giving a schedule that achieves it. The jjth line is a string of length nn using only the symbols 1 and 2, where the iith symbol shows which member of team ii comes into the office in week jj.

Examples2

  1. Example 1

    Input
    2 6
    
    Expected output
    4
    11
    12
    21
    22
    11
    12
    
  2. Example 2

    Input
    2 1
    
    Expected output
    infinity