#SGM0000069. Số nhỏ thứ k (K-th Number)

Số nhỏ thứ k (K-th Number)

K-th Number

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem

For every query Q(i,j,k)Q(i,j,k), return the kk-th smallest value of the distinct integers in subarray ai..aja_i..a_j.

Input

The first line contains n,mn,m, followed by the array and then mm lines i,j,ki,j,k.

Output

Print one answer per query.

Subtasks

Subtask 1 (20%)

  • n≤30n\le 30, number of queries ≤30\le 30.
  • All other conditions are the same as Subtask 3.

Subtask 2 (30%)

  • n≤3000n\le 3000, number of queries ≤1000\le 1000.
  • All other conditions are the same as Subtask 3.

Subtask 3 (50%)

  • 1≤n≤1051\le n\le10^5
  • 1≤m≤50001\le m\le5000
  • ∣ai∣≤109|a_i|\le10^9 and all values are distinct
  • 1≤i≤j≤n1\le i\le j\le n
  • 1≤k≤j−i+11\le k\le j-i+1

Example

Input

7 3
1 5 2 6 3 7 4
2 5 3
4 4 1
1 7 3

Output

5
6
3

Explanation

Sorting [5,2,6,3] gives [2,3,5,6]; the third value is 55.