Function to generate the sum of indices
function sumOfIndices ( s ) { let N = s . length ; let x = ( Math . ceil ( Math . log ( N ) / Math . log ( 2 ) ) ) ; let seg_size = 2 * Math . pow ( 2 , x ) - 1 ; let segment = new Array ( seg_size ) ; segment . fill ( 0 ) ; let count = 41 ;