Return the total count of pairs
return count ; } function lowerBound ( a , low , high , element ) { while ( low < high ) { let middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } function upperBound ( a , low , high , element ) { while ( low < high ) { let middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; }