#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = (a); i < int(b); ++i) #define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i) #define trav(it, v) for(typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it) #define all(v) (v).begin(), (v).end() typedef double fl; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; int a[500005]; int inv; int pos[500005]; int dx[500005][3]; vector<int> small; vector<int> asmall; struct Node{ Node *lc, *rc; int add; int best, bestInd; int L, R; Node(int _L, int _R){ lc=NULL; rc=NULL; add=0; best=0; L=_L; R=_R; bestInd=L; if(R-L > 1){ int mid=L+(R-L)/2; lc=new Node(L, mid); rc=new Node(mid, R); } } int query(int p){ if(R == L+1) return add; if(p < lc->R) return lc->query(p)+add; return rc->query(p)+add; } void update(int l, int r, int dv){ if(l < L) l=L; if(r > R) r=R; if(r <= l) return; if(r <= L || l >= R) return; if(R-L == 1){ add += dv; bestInd=l; best=add; return; } if(l == L && r == R) add += dv; else{ lc->update(l, r, dv); rc->update(l, r, dv); } if(lc->best >= rc->best){ bestInd=lc->bestInd; best=lc->best+add; } else{ bestInd=rc->bestInd; best=rc->best+add; } } }; Node *root; void update(int swL, int swR, int ind){ if(swL > swR) swap(swL, swR); int newdx; if(ind < swL || ind > swR){ newdx=0; } else if(swL == swR){ newdx=0; } else{ int Old=(a[ind] < a[swL])+(a[ind] > a[swR]); int New=(a[ind] < a[swR])+(a[ind] > a[swL]); newdx=Old-New; } } int main(){ int N; scanf("%d", &N); ++N; bool sorted=1; rep(i,1,N){ scanf("%d", a+i); pos[a[i]]=i; if(a[i] < a[i-1]) sorted=0; } if(sorted){ puts("Cool Array"); return 0; } a[N]=N; pos[N]=N; ++N; small.push_back(a[N-1]); rrep(i,N-1,0){ if(a[i] < a[small.back()]){ small.push_back(i); } } reverse(small.begin(), small.end()); rep(i,0,small.size()) asmall.push_back(a[small[i]]); root = new Node(0, small.size()+1); int restrictIndex=-1; //scanf("%d", &restrictIndex); rep(i,0,N){ if(i != restrictIndex && restrictIndex != -1) continue; int j=upper_bound(asmall.begin(), asmall.end(), a[i])-asmall.begin(); int k=upper_bound(small.begin(), small.end(), i)-small.begin(); dx[i][0] -= 2; root->update(max(j, k), small.size(), -2); //root->update(k, max(j, k), -2); } //root->update(0, small.size(), 3); int bestVal=-1000000000; pair<int, int> ans; int hi=0; /*rep(j,0,small.size()-1){ printf("Gain %d-%d: %d\n", 0, small[j], root->query(j)); }*/ rep(i,0,N){ if(a[i] > hi){ while(hi < a[i]){ ++hi; int I=pos[hi]; if(I < i){ continue; } if(I != restrictIndex && restrictIndex != -1){ continue; } int j=upper_bound(asmall.begin(), asmall.end(), a[I])-asmall.begin(); int k=upper_bound(small.begin(), small.end(), I)-small.begin(); dx[I][0] += 2; dx[I][1] += 2; root->update(max(j, k), small.size(), 2); root->update(k, max(j, k), 2); } if(i == restrictIndex || restrictIndex == -1){ int j=upper_bound(asmall.begin(), asmall.end(), a[i])-asmall.begin(); int k=upper_bound(small.begin(), small.end(), i)-small.begin(); dx[i][0] -= 1; dx[i][1] -= 1; root->update(k, small.size(), -1); } if(root->best > bestVal){ ans=make_pair(i, small[root->bestInd]); bestVal=root->best; } /*rep(j,0,small.size()-1){ printf("Gain %d-%d: %d\n", i, small[j], root->query(j)); }*/ if(i == restrictIndex || restrictIndex == -1){ int j=upper_bound(asmall.begin(), asmall.end(), a[i])-asmall.begin(); int k=upper_bound(small.begin(), small.end(), i)-small.begin(); dx[i][0] += 1; dx[i][1] += 1; root->update(k, small.size(), 1); } } if(i == restrictIndex || restrictIndex == -1){ int j=upper_bound(asmall.begin(), asmall.end(), a[i])-asmall.begin(); int k=upper_bound(small.begin(), small.end(), i)-small.begin(); root->update(max(j, k), small.size(), -dx[i][0]); root->update(k, max(j, k), -dx[i][1]); dx[i][0]=0; dx[i][1]=0; } } printf("%d %d\n", ans.first, ans.second); }