Function to find lower_bound
static int LowerBound ( int [ ] a , int k , int x ) { int l = - 1 ; int r = k ; while ( l + 1 < r ) { int m = ( l + r ) >> 1 ; if ( a [ m ] >= x ) { r = m ; } else { l = m ; } } return r ; }