#include
using namespace std;
int firstocc(int a[],int n,int key){
int s=0;
int e=n-1;
int mid=(s+e)/2;
int ans=-1;
while(s<=e){
if(a[mid]==key){
ans=mid;
e=mid-1;
}
else if(a[mid]>key){
e=mid-1;
}
else{
s=mid+1;
}
}
return ans;
}
int main(){
int a[]={1,1,2,2,2,2,4,5,6,6};
int n=10;
int key;
cout<<"ENTER THE ELEMENT WHOSE FIRST OCCURENCe YOU WANT TO FIND : ";
cin>>key;
int k=firstocc(a,n,key);
cout<<"FIRST OCCURENCE OF THE "<<key<<" IS "<<k<<endl;
return 0;
}