시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
5 초 512 MB 0 0 0 0.000%

## 문제

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 $n$ 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 $a \cdot x + b \cdot y + c = 0$, where $a$, $b$ and $c$ are integers. Let the $i$-th line be described as $a_i \cdot x + b_i \cdot y + c_i = 0$. Your task is to minimize the size of set containing all numbers $a_i$, $b_i$ and $c_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 $n$ and $m$, number of lines and number of requirements ($1 \le n, m \le 10^6$).

Next $m$ lines describe requirements. The $i$-th of these lines consists of three integers $t_i$, $p_i$ and $q_i$: if $t_i$ is equal to $0$, then lines $p_i$ and $q_i$ must be parallel, otherwise, lines $p_i$ and $q_i$ must be perpendicular to each other ($t_i \in \{0, 1\}$; $1 \le p_i, q_i \le n$; $p_i \neq q_i$).

## 출력

If no solution exists, print $-1$.

If solution exists, print the minimal number of different coefficient. Each of the next $n$ lines should consist of three integers, $a_i$, $b_i$ and $c_i$ --- the $i$-th line coefficients. All coefficients mustn't exceed $10^9$ by their absolute value.

## 서브태스크

번호 배점 제한
1 10

$n, m \le 15$

2 20

$n \le 5\,000$, all $t_i = 0$

3 20

$m = n - 1$, $p_i = 1$, $q_i = i + 1$

4 20

$n \le 5\,000$

5 15

$n \le 100\,000$

6 15

No additional constraint

## 예제 입력 1

3 3
1 3 2
0 1 3
1 1 2


## 예제 출력 1

2
-7 0 0
0 -7 -7
-7 0 -7


## 예제 입력 2

2 2
1 1 2
0 2 1


## 예제 출력 2

-1


## 힌트

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

• $-7 \cdot x + 0 \cdot y + 0 = 0$
• $0 \cdot x - 7 \cdot y - 7 = 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.

## 채점 및 기타 정보

• 예제는 채점하지 않는다.