Function to find the sum of all the elements which are less than or equal to index
function sum_bitree ( BITree , index ) { let s = 0 ; while ( index > 0 ) { s += BITree [ index ] ; index -= ( index & ( - index ) ) ; } return s ; }