#P1332G. No Monotone Triples

No Monotone Triples

No submission language available for this problem.

Description

Given a sequence of integers aa of length nn, a tuple (i,j,k)(i,j,k) is called monotone triples if

  • 1i<j<kn1 \le i<j<k\le n;
  • aiajaka_i \le a_j \le a_k or aiajaka_i \ge a_j \ge a_k is satisfied.

For example, a=[5,3,4,5]a=[5,3,4,5], then (2,3,4)(2,3,4) is monotone triples for sequence aa while (1,3,4)(1,3,4) is not.

Bob is given a sequence of integers aa of length nn in a math exam. The exams itself contains questions of form L,RL, R, for each of them he is asked to find any subsequence bb with size greater than 22 (i.e. b3|b| \ge 3) of sequence aL,aL+1,,aRa_L, a_{L+1},\ldots, a_{R}.

Recall that an sequence bb is a subsequence of sequence aa if bb can be obtained by deletion of several (possibly zero, or all) elements.

However, he hates monotone stuff, and he wants to find a subsequence free from monotone triples. Besides, he wants to find one subsequence with the largest length among all subsequences free from monotone triples for every query.

Please help Bob find out subsequences meeting the above constraints.

The first line contains two integers nn, qq (3n21053 \le n \le 2 \cdot 10^5, 1q21051 \le q \le 2 \cdot 10^5) — the length of sequence aa and the number of queries.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots, a_n (1ai1091 \le a_i \le 10^{9}), representing the sequence aa.

Then each of the following qq lines contains two integers LL, RR (1L,Rn1 \le L,R \le n, RL2R-L\ge 2).

For each query, output 00 if there is no subsequence bb satisfying the constraints mentioned in the legend. You can print the empty line after but that's not mandatory.

Otherwise, output one integer kk (k>2k > 2) denoting the length of sequence bb, then output kk integers i1,i2,,iki_1, i_2, \ldots, i_k (Li1<i2<<ikRL \le i_1 < i_2<\ldots<i_k\le R) satisfying that bj=aijb_j = a_{i_j} for 1jk1 \le j \le k.

If there are multiple answers with the maximum length, print any of them.

Input

The first line contains two integers nn, qq (3n21053 \le n \le 2 \cdot 10^5, 1q21051 \le q \le 2 \cdot 10^5) — the length of sequence aa and the number of queries.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots, a_n (1ai1091 \le a_i \le 10^{9}), representing the sequence aa.

Then each of the following qq lines contains two integers LL, RR (1L,Rn1 \le L,R \le n, RL2R-L\ge 2).

Output

For each query, output 00 if there is no subsequence bb satisfying the constraints mentioned in the legend. You can print the empty line after but that's not mandatory.

Otherwise, output one integer kk (k>2k > 2) denoting the length of sequence bb, then output kk integers i1,i2,,iki_1, i_2, \ldots, i_k (Li1<i2<<ikRL \le i_1 < i_2<\ldots<i_k\le R) satisfying that bj=aijb_j = a_{i_j} for 1jk1 \le j \le k.

If there are multiple answers with the maximum length, print any of them.

Samples

Sample Input 1

6 2
3 1 4 1 5 9
1 3
4 6

Sample Output 1

3
1 2 3 
0

Note

For the first query, the given sequence itself is monotone triples free.

For the second query, it can be shown that there is no subsequence bb with length greater than 22 such that bb is monotone triples free.