The Expert

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

문제

We need you to draw seven red lines, all of them strictly perpendicular; some with green ink and some with transparent, and one in the form of a kitten.


Technical specification

You're asked to draw nn distinct lines on a plane that are parallel to the coordinate axes. Some pairs of the lines are required to be parallel, and some pairs are required to be perpendicular. All lines must be described by equations ax+by+c=0a \cdot x + b \cdot y + c = 0, where aa, bb and cc are integers. Let the ii-th line be described as a_ix+b_iy+c_i=0a\_i \cdot x + b\_i \cdot y + c\_i = 0. Your task is to minimize the size of set containing all numbers a_ia\_i, b_ib\_i and c_ic\_i. In other words, you need to minimize the number of different coefficients used in description of all lines.

Calculate the minimum number of different coefficients used to draw the lines, or report that it is impossible. If there is a solution, find any way to do it using the smallest number of different coefficients.

입력

First line contains two integers nn and mm, number of lines and number of requirements (1n,m1061 \le n, m \le 10^6).

Next mm lines describe requirements. The ii-th of these lines consists of three integers t_it\_i, p_ip\_i and q_iq\_i: if t_it\_i is equal to 00, then lines p_ip\_i and q_iq\_i must be parallel, otherwise, lines p_ip\_i and q_iq\_i must be perpendicular to each other (t_i0,1t\_i \in \\{0, 1\\}; 1p_i,q_in1 \le p\_i, q\_i \le n; p_iq_ip\_i \neq q\_i).

출력

If no solution exists, print 1-1

If solution exists, print the minimal number of different coefficient. Each of the next nn lines should consist of three integers, a_ia\_i, b_ib\_i and c_ic\_i --- the ii-th line coefficients. All coefficients mustn't exceed 10910^9 by their absolute value.

힌트

In the first example one of the ways to draw the lines:

  • 7x+0y+0=0-7 \cdot x + 0 \cdot y + 0 = 0
  • 0x7y7=00 \cdot x - 7 \cdot y - 7 = 0
  • 7x+0y7=0-7 \cdot x + 0 \cdot y - 7 = 0

In the second example lines 1 and 2 has to be perpendicular and parallel at the same time. No such lines exist.