#P1188. PASTE

PASTE

Description

We use a text processor to handle a special text file with NN lines. Each line contains exactly one natural number: the first line is 11, the second line is 22, and so on, up to line NN which is the natural number NN.

A single "cut and paste" operation is defined as follows: first choose a consecutive block of lines. The "cut" operation removes the selected lines from the file, and the "paste" operation inserts the removed block into another position in the file.

Write a program to determine the contents of the first ten lines of the text file after performing several "cut and paste" operations in sequence.

Input Format

The first line contains two natural numbers NN and KK, where NN is the total number of lines in the file (10N100,000)(10 \le N \le 100{,}000), and KK is the total number of "cut and paste" operations (1K1000)(1 \le K \le 1000).

Each of the next KK lines describes one "cut and paste" operation with three space-separated natural numbers A,B,CA, B, C, where 1ABN1 \le A \le B \le N, 0CN(BA+1)0 \le C \le N - (B - A + 1). AA and BB are the first and last line numbers of the selected block. CC is the line number immediately preceding the insertion position of the cut block; if C=0C = 0, the block is inserted at the beginning of the file.

Output Format

Output ten lines, which are the numbers contained in the first ten lines of the text file after all operations have been completed.

13 3
6 12 1
2 9 0
10 13 8

6
7
8
9
10
11
12
2
3
4

Hint

Translated by ChatGPT 5