Cut and Paste

Time limit1sMemory limit128 MB

Summary
Simulate K cut-and-paste block moves on an N-line document and report the first ten resulting line values.
Level

Medium5 of 10

Topics
Simulation, Array, Implementation
Solved
No attempts yet

Problem

A document produced by a text editor consists of NN lines. Initially the first line contains the number 11, the second line contains the number 22, and so on, so that the ii-th line contains the number ii (for 1≤i≤N1 \le i \le N).

Exactly KK "cut and paste" operations are then performed on the document. Each operation acts on a group of consecutive lines: the "cut" removes the selected lines from the document, and the "paste" reinserts the removed block at another position among the remaining lines.

Given the sequence of "cut and paste" operations, determine the contents of the first ten lines of the document after all operations have been performed.

Input

The first line contains two integers NN and KK separated by a space: the number of lines in the document (10≤N≤100,00010 \le N \le 100{,}000) and the number of "cut and paste" operations (1≤K≤1,0001 \le K \le 1{,}000).

Each of the next KK lines describes one operation, in the order in which they are executed, as three integers AA, BB, and CC separated by spaces, where 1≤A≤B≤N1 \le A \le B \le N and 0≤C≤N−(B−A+1)0 \le C \le N - (B - A + 1). Here AA and BB are the first and last lines of the block to be cut, numbered within the current document, and CC is the line, counted in the document after the block has been removed, after which the block must be inserted. If C=0C = 0, the block is inserted at the very beginning of the document.

Output

Print ten lines containing the numbers written on the first ten lines of the document after all operations have been performed.

Examples3

  1. Example 1

    Input
    15 1
    1 15 0
    
    Expected output
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    
  2. Example 2

    Input
    13 3
    6 12 1
    2 9 0
    10 13 8
    
    Expected output
    6
    7
    8
    9
    10
    11
    12
    2
    3
    4
    
  3. Example 3

    Input
    1000 6
    3 7 4
    1 100 57
    50 60 200
    63 70 500
    1 800 4
    7 77 98
    
    Expected output
    801
    802
    803
    804
    101
    102
    36
    37
    38
    39