#CCC21S5. Math Homework

Math Homework

Your math teacher has given you an assignment involving coming up with a sequence of N integers A1_1,…,AN_N, such that 1≤Ai_i≤1000000000 for each i.

The sequence A must also satisfy M requirements, with the ith^{th} one stating that the GCD (Greatest Common Divisor) of the contiguous subsequence AXi_{Xi},…,AYi_{Yi} (1≤Xi_i≤Yi_i ≤N) must be equal to Zi_i. Note that the GCD of a sequence of integers is the largest integer d such that all the numbers in the sequence are divisible by d.

Find any valid sequence A consistent with all of these requirements, or determine that no such sequence exists.

Input Specification

The first line contains two space-separated integers, N and M. The next M lines each contain three space-separated integers, Xi_i, Yi_i, and Zi_i (1≤i≤M).

The following table shows how the available 15 marks are distributed.

Subtask N M Zi
3 marks 1≤N≤2000 1≤M≤2000 1≤Zi≤2 for each i
4 marks 1≤Zi≤16 for each i
8 marks 1≤N≤150000 1≤M≤150000

Output Specification

If no such sequence exists, output the string Impossible on one line. Otherwise, on one line, output N space-separated integers, forming the sequence A1_1,…,AN_N. If there are multiple possible valid sequences, any valid sequence will be accepted.

Sample Input 1

2 2
1 2 2
2 2 6

Output for Sample Input 1

4 6

Explanation of Output for Sample Input 1

If A1_1=4 and A2_2=6, the GCD of [A1_1,A2_2] is 2 and the GCD of [A2_2] is 6, as required. Please note that other outputs would also be accepted.

Sample Input 2

2 2
1 2 2
2 2 5

Output for Sample Input 2

Impossible

Explanation of Output for Sample Input 2

There exists no sequence [A1_1,A2_2] such that the GCD of [A1_1,A2_2] is 2 and the GCD of [A2_2] is 5.