If there are at least two elements in between i and indexGreater find the Number of ways to select two points out of these
if ( numberOfElements >= 2 ) { ways += ( numberOfElements * ( numberOfElements - 1 ) / 2 ) ; } } return ways ; } function upper_bound ( a , low , high , element ) { while ( low < high ) { let middle = low + parseInt ( ( high - low ) / 2 , 10 ) ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; }