LaLa specializes in divination magic.
Let's say there are M events E_0,⋯,E_M−1 that LaLa's interested in forecasting. Each event is associated with one of two outcomes: catastrophe or salvation.
With a single use of LaLa's divination magic, LaLa obtains the knowledge of one of the following four forms:
LaLa cast her magic several times, possibly 0, and wrote down all M-tuples of the outcomes of events that are consistent with her knowledge: this is called the result of the forecasting. And then, LaLa fell asleep.
When LaLa woke up, she found out that her pet, Leo, ruined all the predictions of her magic. Though LaLa was able to find the result of her forecasting, she is unsure if that data was ruined by Leo as well.
Write a program that determines whether there exists a set of predictions of LaLa's magic whose result of the forecasting matches the one LaLa has, and finds a possible set of predictions if there is one.
The input is given in the following format:
N M
S_0
S_1
⋮
S_N−1
where N is the number of outcomes in the result, M of events, and S_i is a binary string of length M where j-th character is '1' if and only if the i-th result forecasts that j-th event will be in salvation.
The input satisfies the following constraints:
If there is no such prediction, the output should be a single integer −1.
Otherwise, the output should be in the following format:
K
I_0 J_0 t_0
I_1 J_1 t_1
⋮
I_K−1 J_K−1 t_K−1
where K is the size of a possible set S of predictions, and, for each 0≤i<K, S contains the prediction Knowledge(I_i,J_i,t_i).
The output should satisfy the following constraint:
It can be proved that if there is such a set of predictions, there also is one satisfying the constraint.