#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <set> #include <cstdio> #include <cstdlib> #include <stack> #include <cstring> #include <iomanip> #include <cctype> #include <map> #include <cassert> using namespace std; const int N = 500005; int currentSize = 0; struct stNode { int c; stNode *left,*right; stNode(int c,stNode* left,stNode* right):c(c),left(left),right(right) {} stNode* insert(int x,int y,int q); }; stNode* snull = new stNode(0,NULL,NULL); stNode* stRoot[N]; stNode* stNode::insert(int x,int y,int q) { if(q > y || q < x) return this; else if(x == y) return new stNode(this->c + 1,snull,snull); else return new stNode(this->c + 1,this->left->insert(x,(x + y)/2,q),this->right->insert((x + y)/2 + 1,y,q)); } void init() { stRoot[0] = snull; snull->left = snull; snull->right = snull; } int queryLess(stNode* a,stNode* b,int x,int y,int q) { if(x > q) return 0; else if(y <= q) return a->c - b->c; else { return queryLess(a->left,b->left,x,(x + y)/2,q) + queryLess(a->right,b->right,(x + y)/2 + 1,y,q); } } int queryLess(int l,int r,int x) { return queryLess(stRoot[r],stRoot[l - 1],1,N,x); } int queryGreater(int l,int r,int x) { return r - l + 1 - queryLess(l,r,x); } void insert(int x) { stRoot[currentSize + 1] = stRoot[currentSize]->insert(1,N,x); currentSize++; } long long invCount = 0; int a[N]; int n; void initInversionCount() { for(int i = 2;i <= n;i++) { invCount+=queryGreater(1,i - 1,a[i]); } } long long newCount(int x,int y) { return invCount + queryGreater(x + 1,y,a[x]) + queryLess(x,y - 1,a[y]) - queryLess(x + 1,y,a[x]) - queryGreater(x,y - 1,a[y]); } int pge[N],nle[N]; int pp[N],nn[N]; int ppc = 0,nnc = 0; int main() { init(); cin>>n; for(int i = 1;i <= n;i++) { scanf("%d",&a[i]); insert(a[i]); } stack<int> st; for(int i = n;i >= 1;i--) { while(!st.empty() && a[i] > a[st.top()]) { pge[st.top()] = i; st.pop(); } st.push(i); } while(!st.empty()) st.pop(); for(int i = 1;i <= n;i++) { while(!st.empty() && a[i] < a[st.top()]) { nle[st.top()] = i; st.pop(); } st.push(i); } for(int i = 1;i <= n;i++) { if(pge[i] == 0) pp[ppc++] = i; if(nle[i] == 0 && i > 1 && a[i] < a[i - 1]) nn[nnc++] = i; } initInversionCount(); int flag = 0; for(int i = 2;i <= n;i++) { if(a[i] < a[i - 1]) flag = 1; } if(!flag) { cout<<"Cool Array"<<endl; return 0; } long long bst = invCount; int x = 0,y = 0; for(int i = 0;i < ppc;i++) { for(int j = 0;j < nnc;j++) { if(pp[i] >= nn[j] || a[pp[i]] < a[nn[j]]) continue; long long can = newCount(pp[i],nn[j]); if(can < bst) { bst = can; x = pp[i]; y = nn[j]; } } } cout<<x<<' '<<y<<endl; }