LaLa and Divination Magic

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

LaLa\color{blue}{\text{LaLa}} specializes in divination magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}.

Let's say there are MM events E_0,,E_M1E\_0, \cdots, E\_{M-1} that LaLa\color{blue}{\text{LaLa}}'s interested in forecasting. Each event is associated with one of two outcomes: catastrophe or salvation.

With a single use of LaLa\color{blue}{\text{LaLa}}'s divination magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}, LaLa\color{blue}{\text{LaLa}} obtains the knowledge of one of the following four forms:

  1. Knowledge(i,j,1)\mathrm{Knowledge}(i,j,1): either E_iE\_i is catastrophe or E_jE\_j is catastrophe (possibly both).
  2. Knowledge(i,j,2)\mathrm{Knowledge}(i,j,2): either E_iE\_i is salvation or E_jE\_j is catastrophe (possibly both).
  3. Knowledge(i,j,3)\mathrm{Knowledge}(i,j,3): either E_iE\_i is catastrophe or E_jE\_j is salvation (possibly both).
  4. Knowledge(i,j,4)\mathrm{Knowledge}(i,j,4): either E_iE\_i is salvation or E_jE\_j is salvation (possibly both).

LaLa\color{blue}{\text{LaLa}} cast her magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}} several times, possibly 0, and wrote down all MM-tuples of the outcomes of events that are consistent with her knowledge: this is called the result of the forecasting. And then, LaLa\color{blue}{\text{LaLa}} fell asleep.

When LaLa\color{blue}{\text{LaLa}} woke up, she found out that her pet, Leo\color{brown}{\text{Leo}}, ruined all the predictions of her magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}}. Though LaLa\color{blue}{\text{LaLa}} was able to find the result of her forecasting, she is unsure if that data was ruined by Leo\color{brown}{\text{Leo}} as well.

Write a program that determines whether there exists a set of predictions of LaLa\color{blue}{\text{LaLa}}'s magic\color{red}{\text{m}} \color{brown}{\text{a}} \color{orange}{\text{g}} \color{blue}{\text{i}} \color{magenta} {\text{c}} whose result of the forecasting matches the one LaLa\color{blue}{\text{LaLa}} has, and finds a possible set of predictions if there is one.

입력

The input is given in the following format:

NN MM

S_0S\_0

S_1S\_1

\vdots

S_N1S\_{N-1}

where NN is the number of outcomes in the result, MM of events, and S_iS\_i is a binary string of length MM where jj-th character is '1' if and only if the ii-th result forecasts that jj-th event will be in salvation.

The input satisfies the following constraints:

  • NN and MM are integers.
  • 1N,M2,0001 \le N, M \le 2\\,000
  • S_iS_jS\_i \ne S\_j for all integers 0i<j<N0 \le i < j < N.

출력

If there is no such prediction, the output should be a single integer 1-1.

Otherwise, the output should be in the following format:

KK

I_0I\_0 J_0J\_0 t_0t\_0

I_1I\_1 J_1J\_1 t_1t\_1

\vdots

I_K1I\_{K-1} J_K1J\_{K-1} t_K1t\_{K-1}

where KK is the size of a possible set SS of predictions, and, for each 0i<K0 \le i < K, SS contains the prediction Knowledge(I_i,J_i,t_i)\mathrm{Knowledge}(I\_i,J\_i,t\_i).

The output should satisfy the following constraint:

  • 0K2M20 \le K \le 2\cdot M^2

It can be proved that if there is such a set of predictions, there also is one satisfying the constraint.