import java.util.*; class node{ int key; node left; node right; int height; int size; } class Solve{ int max(int a,int b){ return a>b?a:b; } int height(node N) { if (N == null) return 0; return N.height; } int size(node N) { if (N == null) return 0; return N.size; } node newNode(int key) { node nd =new node(); nd.key = key; nd.left = null; nd.right = null; nd.height = 1; // new node is initially added at leaf nd.size = 1; return nd; } node rightRotate(node y) { node x = y.left; node T2 = x.right; // Perform rotation x.right = y; y.left = T2; // Update heights y.height = max(height(y.left), height(y.right))+1; x.height = max(height(x.left), height(x.right))+1; // Update sizes y.size = size(y.left) + size(y.right) + 1; x.size = size(x.left) + size(x.right) + 1; // Return new root return x; } // A utility function to left rotate subtree rooted with x node leftRotate(node x) { node y = x.right; node T2 = y.left; // Perform rotation y.left = x; x.right = T2; // Update heights x.height = max(height(x.left), height(x.right))+1; y.height = max(height(y.left), height(y.right))+1; // Update sizes x.size = size(x.left) + size(x.right) + 1; y.size = size(y.left) + size(y.right) + 1; // Return new root return y; } // Get Balance factor of node N int getBalance(node N) { if (N == null) return 0; return height(N.left) - height(N.right); } node insert(node nd,int key,int count1[],int x)//*********count1 { /* 1. Perform the normal BST rotation */ if (nd == null) return newNode(key); if (key < nd.key) { nd.left = insert(nd.left, key,count1,x); // count1 = *count1 + size(node->right) + 1; } else { if(key > nd.key) { nd.right = insert(nd.right, key,count1,x); count1[x] = count1[x] + size(nd.left) + 1; } else nd.right = insert(nd.right, key,count1,x); } nd.height = max(height(nd.left), height(nd.right)) + 1; nd.size = size(nd.left) + size(nd.right) + 1; int balance = getBalance(nd); if (balance > 1 && key < nd.left.key) return rightRotate(nd); // Right Right Case if (balance < -1 && key > nd.right.key) return leftRotate(nd); // Left Right Case if (balance > 1 && key > nd.left.key) { nd.left = leftRotate(nd.left); return rightRotate(nd); } if (balance < -1 && key < nd.right.key) { nd.right = rightRotate(nd.right); return leftRotate(nd); } return nd; } node insert1(node nd,int key,int count[],int x)//************count { if (nd == null) return newNode(key); if (key < nd.key) { nd.left = insert1(nd.left, key, count,x); count[x] = count[x] + size(nd.right) + 1; } else { nd.right = insert1(nd.right, key,count,x); } nd.height = max(height(nd.left), height(nd.right)) + 1; nd.size = size(nd.left) + size(nd.right) + 1; int balance = getBalance(nd); if (balance > 1 && key < nd.left.key) return rightRotate(nd); // Right Right Case if (balance < -1 && key > nd.right.key) return leftRotate(nd); // Left Right Case if (balance > 1 && key > nd.left.key) { nd.left = leftRotate(nd.left); return rightRotate(nd); } if (balance < -1 && key < nd.right.key) { nd.right = rightRotate(nd.right); return leftRotate(nd); } return nd; } void constructLowerArray (int arr[],int arr1[] ,int countSmaller[],int countHigh[], int n) { int i, j; node root = null; node root1=null; for (i = 0; i < n; i++) { countSmaller[i] = 0; countHigh[i]=0; } for (i = 0; i <n; i++) { root = insert(root, arr[i],countSmaller,n-1-i); root1= insert1(root1,arr1[i],countHigh,i); } } void find_max(int low[],int high[],int n) { int i,j,k,l; int tempL[][]=new int[2][n],tempH[][]=new int[2][n]; int max=low[0],maxIdx=1; tempL[0][0]=max; tempL[1][0]=maxIdx; for(i=1;i<n;i++){ if(low[i]>max){ max=low[i]; maxIdx=i+1; } tempL[0][i]=max; tempL[1][i]=maxIdx; } max=high[n-1]; maxIdx=n; tempH[0][n-1]=max; tempH[1][n-1]=maxIdx; for(i=n-2;i>=0;i--){ if(high[i]>=max){ max=high[i]; maxIdx=i+1; } tempH[0][i]=max; tempH[1][i]=maxIdx; } max=tempL[0][0]+tempH[0][1]; k=tempL[1][0]; l=tempH[1][1]; for(i=1;i<n-1;i++){ if(max<tempL[0][i]+tempH[0][i+1]){ max=tempL[0][i]+tempH[0][i+1]; k=tempL[1][i]; l=tempH[1][i+1]; } } if(max==0) { System.out.println("Cool Array"); return; } else { System.out.println(k+" "+l); } } void reverse(int arr[],int arr1[],int n) { int low=0,i; for(i=n-1;i>=0;i--) { arr[low++]=arr1[i]; } } } public class Solution { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n,i; n=sc.nextInt(); int arr[]=new int[n]; int arr1[]=new int[n]; for(i=0;i<n;i++) arr1[i]=sc.nextInt(); Solve s=new Solve(); s.reverse(arr,arr1,n); int low[]=new int[n]; int high[]=new int[n]; s.constructLowerArray(arr,arr1 ,low,high ,n); s.find_max(low,high,n); } }