// https://www.geeksforgeeks.org/minimum-length-unsorted-subarray-sorting-which-makes-the-complete-array-sorted/
#include <iostream>
using namespace std;
void algo (int a[], int n) {
int i,l,r;
for (l=0;l<n;l++)
if (a[l]>a[l+1])
break;
if (l==n-1) {
cout<< "Sorted Array";
return;
}
for (r=n-1;r>=0;r--)
if (a[r] < a[r-1])
break;
int min=a[l], max=a[l];
for (i=l+1;i<=r;i++) {
if (a[i] > max)
max=a[i];
if (a[i] < min)
min=a[i];
}
for (i=0;i<l;i++)
if (a[i] > min) {
l=i;
break;
}
for (i=n-1;i>r;i--)
if (a[i] < max) {
r=i;
break;
}
cout<< "Minimum Length unsorted subarray lies between " << l << " and " << r;
}
int main () {
int n,i;
cin>>n;
int a[n];
for (i=0;i<n;i++)
cin>>a[i];
algo(a,n);
}