int gmax(register int a,register int b){return a>b?a:b;}
int gmin(register int a,register int b){return a<b?a:b;}
int binary_search(unsigned *a,int n,register unsigned x)
{
int p=1ll*n*x/a[n-1],lim=16;
if(x<=a[p])
{
for(;a[gmax(p-lim,0)]>x;lim<<=1);
register int l=gmax(p-lim,0),r=p;
do
{
register int mid=(l+r)>>1;
(a[mid]<x)?(l=mid+1):(r=mid);
}
while(l!=r);
return l;
}
else
{
for(;x>a[gmin(p+lim,n-1)];lim<<=1);
register int l=p,r=gmin(p+lim,n-1);
do
{
register int mid=(l+r)>>1;
(a[mid]<x)?(l=mid+1):(r=mid);
}
while(l!=r);
return l;
}
}