The K-th Number

No attempts yetTime limit1sMemory limit256 MB

Problem

You want to build a function that sorts a range of an array and then returns the value at a given rank.

An array a[1n]a[1 \dots n] of size nn stores nn distinct integers. For this array, define the function Q(i,j,k)Q(i, j, k) as follows.

Q(i,j,k)Q(i, j, k): returns the kk-th smallest value when the subarray a[ij]a[i \dots j] is sorted in ascending order.

For example, suppose a=(1,5,2,6,3,7,4)a = (1, 5, 2, 6, 3, 7, 4) and consider Q(2,5,3)Q(2, 5, 3). The subarray a[25]a[2 \dots 5] is (5,2,6,3)(5, 2, 6, 3), which becomes (2,3,5,6)(2, 3, 5, 6) after sorting. The 3rd value in the sorted array is 5, so Q(2,5,3)=5Q(2, 5, 3) = 5.

Given the array aa and several queries Q(i,j,k)Q(i, j, k), write a program that prints the return value of each query.

Input

The first line contains the array size nn and the number of queries mm, separated by a space. (1n100,0001 \le n \le 100{,}000, 1m5,0001 \le m \le 5{,}000)

The second line contains the nn array elements in order. Each element is an integer whose absolute value does not exceed 10910^9, and all elements are distinct.

Each of the following mm lines contains the arguments ii, jj, kk of one query. (1ijn1 \le i \le j \le n, 1kji+11 \le k \le j - i + 1)

Output

For each query, print the return value of Q(i,j,k)Q(i, j, k), one per line.