Here is my code ā
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << ā>ā << #x << ā:ā << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);iā)
typedef long long ll;
int main()
{
int n , a[1000];
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
int key ;
cin>>key;
int t= 0 ;
int pos = 0 ;
int start = 0 ;
int end = n-1;
while(start<= end){
int mid = (start +end )/2 ;
if(a[mid] == key){
pos= mid;
t=1;
break;
}
else if ( key > a[mid])
start = mid+1 ;
else {
end = mid -1;
}
}
if(t==1)
cout<<pos<<endl;
else
cout<<"-1";
return 0;
}