#include <cstdio> #include <cstdlib> #include <algorithm> #include <queue> #include <cmath> #include <iostream> #include <set> #include <fstream> #include <string> #include <vector> using namespace std; #define FOR(i,s,e) for (int i=(s); i<(e); i++) #define FOE(i,s,e) for (int i=(s); i<=(e); i++) #define FOD(i,s,e) for (int i=(s); i>=(e); i--) #define LL long long #define eps 1e-9 #define pi acos(-1.0) #define fail {printf("Impossible\n"); return 0;} LL max(LL a,LL b){if (a>b){return a;} else {return b;}} LL min(LL a,LL b){if (a<b){return a;} else {return b;}} #define K 600001 #define M 12000001 int a[K], n, res, na, nb; int ans; int root[K], l[M], r[M], s[M], h = 0; void build(int u, int lb, int rb){ if (lb == rb){ if (lb == a[1]) s[u] = 1; else s[u] = 0; return; } build(l[u] = ++h, lb, (lb + rb) / 2); build(r[u] = ++h, (lb + rb) / 2 + 1, rb); s[u] = s[l[u]] + s[r[u]]; } void parse(int u, int pu, int lb, int rb, int z){ s[u] = s[pu] + 1; if (lb == rb){ s[u] = 1; return; } l[u] = l[pu]; r[u] = r[pu]; if ((lb + rb) / 2 >= z){ parse(l[u] = ++h, l[pu], lb, (lb + rb) / 2, z); } else { parse(r[u] = ++h, r[pu], (lb + rb) / 2 + 1, rb, z); } } vector<int> U, L; int reduced = 0; int SS(int u, int lb, int rb, int lq, int rq){ // printf("SS %d %d %d %d %d\n", u, lb, rb, lq, rq); if (lb >= lq && rb <= rq) return s[u]; int s1 = 0, s2 = 0; int mid = (lb + rb) / 2; if (lq <= mid) s1 = SS(l[u], lb, mid, lq, rq); if (rq > mid) s2 = SS(r[u], mid + 1, rb, lq, rq); return s1 + s2; } //from a to b, range c to d num? int query(int a, int b, int c, int d){ return SS(root[b], 1, n, c, d) - (a==1?0:SS(root[a - 1], 1, n, c, d)); } int calc(int w, int b){ if (w >= b) return -1000; if (a[b] > a[w]) return -1000; // printf("CALC %d %d\n", w, b); return query(w, b, a[b], a[w]); } int main(){ // freopen("out.txt", "r", stdin); scanf("%d", &n); FOE(i, 1, n) scanf("%d", &a[i]); int yes = 1; FOE(i, 1, n) if (a[i] != i) yes = 0; if (yes){ puts("Cool Array"); return 0; } build(root[1] = 0, 1, n); FOE(i, 2, n) parse(root[i] = ++h, root[i - 1], 1, n, a[i]); FOE(i, 1, n){ if (i == 1) U.push_back(1); else if (a[i] > a[U[U.size() - 1]]) U.push_back(i); } FOD(i, n, 1){ if (i == n) L.push_back(i); else if (a[i] < a[L[L.size() - 1]]) L.push_back(i); } int pos = L.size() - 1; // FOE(i, 0, L.size() - 1) printf("L[%d] = %d\n", i, L[i]); FOR(i, 0, U.size()){ // printf("JUDGE %d %d\n", U[i], L[pos]); while (pos != 0 && (U[i] < L[pos - 1]) && calc(U[i], L[pos]) <= calc(U[i], L[pos - 1])) { pos--;int z = calc(U[i], L[pos]); if (z > reduced){ reduced = z; na = U[i]; nb = L[pos]; } // printf("JUDGE %d %d\n", U[i], L[pos]); } int z = calc(U[i], L[pos]); if (z > reduced){ reduced = z; na = U[i]; nb = L[pos]; } } pos = 0; FOD(i, L.size() - 1, 0){ // printf("JUDGE %d %d\n", U[i], L[pos]); while (pos != U.size() - 1 && (U[pos] < L[i]) && calc(U[pos], L[i]) <= calc(U[pos + 1], L[i])) { pos++; int z = calc(U[pos], L[i]); if (z > reduced || (z == reduced && (U[pos] < na || (U[pos] == na && L[i] < nb)))){ reduced = z; na = U[pos]; nb = L[i]; } // printf("JUDGE %d %d\n", U[i], L[pos]); } int z = calc(U[pos], L[i]); if (z > reduced || (z == reduced && (U[pos] < na || (U[pos] == na && L[i] < nb)))){ reduced = z; na = U[pos]; nb = L[i]; } }FOR(i, 0, U.size()){ int z = calc(U[i], nb); if (z > reduced || (z == reduced && (U[i] < na || (U[i] == na && nb < nb)))){ reduced = z; na = U[i]; } } FOR(i, 0, L.size()){ int z = calc(na, L[i]); if (z > reduced || (z == reduced && (na < na || (na == na && L[i] < nb)))){ reduced = z; nb = L[i]; } } printf("%d %d\n", na, nb); return 0; }