Algorithm


C. Unordered Subsequence
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subsequence which is not ordered.

A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements.

Input

The first line of the input contains one integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — the given sequence. All numbers in this sequence do not exceed 106 by absolute value.

Output

If the given sequence does not contain any unordered subsequences, output 0. Otherwise, output the length k of the shortest such subsequence. Then output k integers from the range [1..n] — indexes of the elements of this subsequence. If there are several solutions, output any of them.

Examples
input
Copy
5
67 499 600 42 23
output
Copy
3
1 3 5
input
Copy
3
1 2 3
output
Copy
0
input
Copy
3
2 3 1
output
Copy
3
1 2 3



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <cstdio>
#include <vector>

int main(){

    long n; scanf("%ld", &n);
    if(n <= 2){puts("0"); return 0;}

    std::vector<long long> a(n); for(long p = 0; p < n; p++){scanf("%lld", &a[p]);}
    long ind(-1);
    for(long p = 0; p + 1 < n; p++){
        if((a[p + 1] - a[p]) * (a[p] - a[0]) < 0){ind = p; break;}
    }


    if(ind < 0){puts("0");}
    else{printf("3\n1 %ld %ld\n", ind + 1, ind + 2);}

    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5
67 499 600 42 23

Output

x
+
cmd
3
1 3 5
Advertisements

Demonstration


Codeforces Solution-C. Unordered Subsequence-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+