Under construction

Still being built. Things may change

Balanced Job Assignment

Time limit4sMemory limit256 MB

Summary
Assign every matchable job to exactly one qualified worker so that the job counts per worker are as close as possible to M/N in Euclidean distance.
Level

Medium7 of 10

Topics
Graph, Shortest path
Solved
No attempts yet

Problem

There are NN workers and MM different jobs. You are given a matrix AA, where Ai,j=1A_{i,j}=1 if worker ii is qualified to complete job jj, and Ai,j=0A_{i,j}=0 otherwise. A worker can be assigned to a job only if they are qualified for it.

Assign workers to jobs so that the distribution of the number of jobs done by each worker is as close as possible to uniform, measured by Euclidean distance. That is, the NN-dimensional vector whose ii-th element is the number of jobs done by worker ii should be as close as possible to the NN-dimensional vector whose every element is the real number M/NM / N.

Each job that can be completed by at least one worker must be assigned to exactly one worker.

Input

The first line contains two integers NN and MM (1≤N,M≤3001 \le N, M \le 300). The next NN lines each contain MM characters, either '0' or '1'. These lines describe the matrix AA.

Output

Print NN lines. On line ii, first print kik_i, the number of jobs assigned to worker ii. Then print the numbers of those jobs. If several assignments give an optimal distribution, you may print any of them.

Hint

The Euclidean distance between two vectors (u1,u2,…,uN)(u_1, u_2, \ldots, u_N) and (v1,v2,…,vN)(v_1, v_2, \ldots, v_N) is (v1−u1)2+(v2−u2)2+…+(vN−uN)2\sqrt{(v_1 - u_1)^2 + (v_2 - u_2)^2 + \ldots + (v_N - u_N)^2}

Examples2

  1. Example 1

    Input
    3 3
    111
    111
    111
    
    Expected output
    1 1
    1 2
    1 3
    
  2. Example 2

    Input
    2 4
    0100
    1100
    
    Expected output
    1 2
    1 1