#include <iostream>
using namespace std;
int binary(int a[],int l,int r,int k){
if(r>=l){
int m=l+(r-l)/2;
if (a[m]==k)
return m;
if (a[m]>k)
return binary(a,l,m-1,k);
return binary(a,m+1,r,k);
}
return -1;
}
int main(){
int n;
cout<<"Enter the no.of elements:";
cin>>n;
int a[n],t=-1;
cout<<"Enter the array elements:";
for(int i=0;i<n;i++){
cin>>a[i];
if(t==-1&&i>0&&a[i]<a[i-1])
t=i;
}
int k;
cout<<"Enter the search element:";
cin>>k;
if (a[0]<=k && k<=a[t-1]){
int p=binary(a,0,t-1,k);
if (p!= -1)
cout<<"Index is:"<<p;
else
cout<<"Not found";
}
if (a[t]<=k && k<=a[n-1]){
int p = binary(a,t,n-1,k);
if (p!= -1)
cout<<"Index is:"<<p;
else
cout<<"Not found";
}
return 0;
}