This page is still under construction.

Parts of this page are still being built. What you see may change.

Rotating the basket order

Interview

Time limit1sMemory limit256 MB

Summary
Perform M given segment rotations on baskets numbered 1 to N and print the final left-to-right order.
Level

Easy2 of 10

Topics
Simulation, Array
Solved
No attempts yet

Problem

Dohyun has NN baskets, and the baskets are numbered 1 through NN in order. The baskets stand in one row. The leftmost basket is at position 1, the next one at position 2, and so on up to position NN at the right end.

Dohyun rotates the basket order MM times. For each rotation he picks the range to rotate, then picks one basket inside that range as the pivot. If the ends of the chosen range are beginbegin and endend and the pivot sits at position midmid, then the baskets that stood in the order begin,begin+1,…,mid−1,mid,mid+1,…,end−1,endbegin, begin+1, \dots, mid-1, mid, mid+1, \dots, end-1, end end up in the order mid,mid+1,…,end−1,end,begin,begin+1,…,mid−1mid, mid+1, \dots, end-1, end, begin, begin+1, \dots, mid-1.

Given the rotations, write a program that performs all MM of them and prints the number written on each basket, starting from the leftmost one.

Input

The first line contains NN (1≤N≤1001 \le N \le 100) and MM (1≤M≤1001 \le M \le 100).

Each of the next MM lines contains one rotation as three integers ii, jj, kk. It means the order of the baskets from position ii to position jj counted from the left is rotated, and the pivot is the basket at position kk. (1≤i≤k≤j≤N1 \le i \le k \le j \le N)

Dohyun applies the rotations in the order they are given.

Output

After all rotations, print the number written on each basket from the leftmost one, on one line, separated by single spaces.

Examples3

  1. Example 1

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

    Input
    1 1
    1 1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    2 1
    1 2 2
    
    Expected output
    2 1