#include <stdio.h>
#include <stdlib.h>
int binary_search(int a[],int n,int x){
int lef=0;
int rig=n-1;
while(lef<=rig){
int mid=(lef+rig)/2;
if(a[mid]==x){ return mid; }
else if(x<a[mid]){ rig=mid-1; }
else if(x>a[mid]){ lef=mid+1; }
}
return -1;
}
int main(void) {
int n,x,i;
int *a;
int ans = -1;
a
= (int*)malloc(sizeof(int)*n
); if(a==NULL){
return -1;
}
for(i=0;i<n;i++){
}
ans = binary_search(a,n,x);
if(ans
!= -1) printf("a[%d] = %d\n",ans
,a
[ans
]); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KIAppbnQgYmluYXJ5X3NlYXJjaChpbnQgYVtdLGludCBuLGludCB4KXsKCWludCBsZWY9MDsKCWludCByaWc9bi0xOwoJd2hpbGUobGVmPD1yaWcpewoJCWludCBtaWQ9KGxlZityaWcpLzI7CgkJaWYoYVttaWRdPT14KXsgcmV0dXJuIG1pZDsgfQoJCWVsc2UgaWYoeDxhW21pZF0peyByaWc9bWlkLTE7IH0gCgkJZWxzZSBpZih4PmFbbWlkXSl7IGxlZj1taWQrMTsgfQoJCX0KCXJldHVybiAtMTsKCX0KCmludCBtYWluKHZvaWQpIHsKCWludCBuLHgsaTsKCWludCAqYTsKCWludCBhbnMgPSAtMTsKCXNjYW5mKCIlZCAlZCIsJm4sJngpOwoJYSA9IChpbnQqKW1hbGxvYyhzaXplb2YoaW50KSpuKTsKCWlmKGE9PU5VTEwpewoJCXByaW50ZigiRVJST1JcbiIpOwoJCXJldHVybiAtMTsKCX0KCWZvcihpPTA7aTxuO2krKyl7CgkJc2NhbmYoIiVkIiwmYVtpXSk7Cgl9CglhbnMgPSBiaW5hcnlfc2VhcmNoKGEsbix4KTsKCWlmKGFucyAhPSAtMSkgcHJpbnRmKCJhWyVkXSA9ICVkXG4iLGFucyxhW2Fuc10pOwoJZWxzZSBwcmludGYoIm5vdCBmb3VuZFxuIik7CglmcmVlKGEpOwoJcmV0dXJuIDA7Cn0KIA==