#include <cstdio> #include <cmath> #include <cstring> #include <string> #include <sstream> #include <algorithm> #include <iostream> #include <iomanip> #include <map> #include <set> #include <list> #include <queue> #include <stack> #include <vector> #include <cassert> using namespace std; #define pb push_back #define mp make_pair #define REP(i, n) for (int i = 0; i < (int)(n); ++i) typedef long long LL; typedef pair<int, int> PII; struct Node { int val = 0; Node *left = NULL, *right = NULL; Node(int x) : val(x) {} Node() {} }; Node nodes[11111111]; int nodeCount = 1; Node* st[500001]; const int off = 1 << 19; int updatePos; Node* stUpdate(Node *v, int L, int R) { Node *ret = nodes + nodeCount++; if (v == NULL) ret->val = 1; else { ret->val = v->val + 1; ret->left = v->left; ret->right = v->right; } if (L == R) return ret; int mid = (L + R) >> 1; if (updatePos <= mid) ret->left = stUpdate(v ? v->left : NULL, L, mid); else ret->right = stUpdate(v ? v->right : NULL, mid + 1, R); return ret; } int stFrom, stTo, stRes; void stGet(Node *v, int L, int R) { if (!v) return; if (L >= stFrom && R <= stTo) { stRes += v->val; return; } int mid = (L + R) >> 1; if (stFrom <= mid) stGet(v->left, L, mid); if (stTo > mid) stGet(v->right, mid + 1, R); } int n; int a[500000], rev[500000]; int nx[500000]; int main() { //freopen("input.txt", "r", stdin); scanf("%d", &n); REP(i, n) scanf("%d", a + i), --a[i]; REP(i, n) rev[a[i]] = i; st[0] = nodes; REP(i, n) { updatePos = rev[i]; st[i + 1] = stUpdate(st[i], 0, off - 1); } nx[n - 1] = n; int mn = n - 1; for (int i = n - 2; i >= 0; --i) { nx[i] = mn; if (a[i] < a[mn]) mn = i; } int best = -1, bestL = -1, bestR = -1; for (int i = n - 1; i >= 0; --i) { int pos = rev[i]; int ans = -1, curR = -1; for (int pre = pos, end = nx[pos]; end < n && a[end] < i; pre = end, end = nx[end]) { stFrom = pos + 1, stTo = end - 1, stRes = 0; stGet(st[i + 1], 0, off - 1); int cur = stRes; stRes = 0; stGet(st[a[end] + 1], 0, off - 1); cur -= stRes; if (cur > ans) { ans = cur; curR = end; } else { nx[pre] = nx[end]; } } if (curR > -1) if (ans > best || (ans == best && pos < bestL)) { best = ans; bestL = pos; bestR = curR; } } if (best == -1) { printf("Cool Array\n"); return 0; } printf("%d %d\n", bestL + 1, bestR + 1); return 0; }