CTAHKEB** ANDREW

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Cyclic shift of a sequence ss by kk (0k<s0 \leq k < |s|) positions is the following sequence s_ks_k+1s_s1s_0s_1s_k1s\_{k} s\_{k+1} \ldots s\_{|s|-1} s\_0 s\_1 \ldots s\_{k-1}. Note that 0-indexing is used. For example, cyclic shift by 0 positions is equal to the original sequence.                        

There is a permutation which is initially equal to the identity permutation (0,1,,n10, 1, \ldots, n-1).

Process a number of the following queries. Replace a subarray of the permutation by its cyclic shift by some number of positions. Formally you are given l,r,kl, r, k, such that 0l<rn,1k<rl0\leq l < r \leq n, 1 \leq k < r - l and replace the subarray between indices ll and rr (a half-interval, ll-th element is included, rr-th is not) by its cyclic shift by kk positions. For example, applying this operation to the permutation \[1,0,3,4,2]\[1, 0, 3, 4, 2] with parameters l=1,r=4,k=1l = 1, r = 4, k = 1 results in a permutation \[1,3,4,0,2]\[1, 3, 4, 0, 2].

After each query find the cyclic shift of the permutation which contains the minimal number of inversions.

The changes of the permutation persist and are not reverted between queries.

입력

The first line contains two integers nn and qq (2n105,1q1052 \leq n \leq 10^5,1 \leq q \leq 10^5), length of the permutation and the number of queries, respectively.

qq lines follow. ii-th of them contains three integers l_i,r_i,k_il\_i, r\_i, k\_i (0l_i<r_in,1k_i<r_il_i0 \leq l\_i < r\_i \leq n, 1 \leq k\_i < r\_i - l\_i), parameters of the ii-th query.

출력

Print qq lines. ii-th of them should contain an integer kk (0k<n0 \leq k < n), such that after the first ii queries cyclic shift of the permutation by kk positions contains the minimal number of inversions among cyclic shifts. If there are multiple possible kk print the smallest one.

힌트

In the first example after the modification the permutation is \[0,4,5,6,1,2,3,7]\[0, 4, 5, 6, 1, 2, 3, 7]. Its cyclic shift with the minimal number of inversions is \[1,2,3,7,0,4,5,6]\[1, 2, 3, 7, 0, 4, 5, 6].