static int BinarySearch(int[] A, int n, int x)
{
int left_bound = 0, right_bound = n, q;
while(left_bound != right_bound)
{
q = (left_bound + right_bound) >> 1;
if(A[q] == x)
return q;
else if(A[q] > x)
right_bound = q;
else
left_bound = q;
}
return -1;
}