Under construction

Still being built. Things may change

Graph Measurement

Time limit30sMemory limit512 MB

Summary
Given k random black/white colorings of an unknown graph's edges, recover the graph from the per-vertex counts of black edges.
Level

Hard8 of 10

Topics
Probability, Math
Solved
No attempts yet

Statement

Andrew has a simple undirected graph on nn vertices (1≤n≤201 \le n \le 20). The graph has no self-loops and no multiple edges. He repeats the following measurement kk times. For each edge, he colors it black or white independently, with probability 50% for each color. Then he counts the number of black edges adjacent to each vertex and tells you these nn numbers.

Your goal is to restore the original graph from the given k⋅nk \cdot n numbers.

Input

The first line contains two integers nn and kk (in all cases except the sample, k=800⋅n2k = 800 \cdot n^2). The next kk lines each contain nn integers. Line ii gives, for measurement ii, the number of black edges adjacent to each vertex, in vertex order.

Output

In the first line, print an integer mm, the number of edges in the graph. In the next mm lines, describe each edge by the two vertices it connects. Vertices are numbered from 1 to nn. There must be no self-loops, and at most one edge may connect any pair of vertices. The order of the edges and the order of the two vertices within each edge do not matter.

In the sample case, any valid graph is accepted, even if it is inconsistent with the input (for example, a graph with 0 edges). In all other cases, only the graph that actually generated the input is accepted.

Hints

Note that all cases except the sample have many measurements, specifically k=800⋅n2k = 800 \cdot n^2. There are 33 non-sample test cases.

Examples1

  1. Example 1

    Input
    3 2
    1 2 1
    1 1 0
    
    Expected output
    2
    1 2
    2 3