Festival Lights
Kevin has set up lamps for a festival lasting
days. Each lamp may change colour once during the festival. Every colour is represented by an integer from
to
.
For each lamp :
- On days
, its colour is
.
- On days
, its colour is
.
If , the lamp has colour
for the entire festival. The two colours
and
may be equal, in which case the lamp does not visibly change colour.
For each day of the festival, determine the number of distinct colours displayed by the lamps.
Input
The first line contains two integers and
(
): the number of lamps and the number of days in the festival.
Each of the next lines contains three integers
,
, and
(
,
), describing the colours and change day of lamp
.
Output
Output lines. On line
, output the number of distinct colours displayed on day
.
Example 1
Input 1
6 7
1 3 2
2 6 5
5 5 1
3 3 5
4 1 6
6 3 6
Output 1
5
5
3
3
4
4
4
The lamps display the following colours each day:
| Day | Colours of lamps 1–6 | Different colours |
|---|---|---|
| 1 | 1, 2, 5, 3, 6, 6 | 5 |
| 2 | 1, 2, 5, 3, 6, 6 | 5 |
| 3 | 2, 2, 5, 5, 6, 6 | 3 |
| 4 | 2, 2, 5, 5, 6, 6 | 3 |
| 5 | 2, 2, 1, 5, 6, 6 | 4 |
| 6 | 2, 5, 1, 5, 6, 6 | 4 |
| 7 | 2, 5, 1, 5, 6, 6 | 4 |
Comments