Driver code
let n = 5 , q = 2 ; let a = [ 0 , 7 , 3 , 4 , 5 ] ; let b = [ 0 , 3 , 1 , 2 , 3 ] ; let lr = new Array ( q * 2 ) ; lr [ 0 ] = 1 ; lr [ 1 ] = 1 ; lr [ 2 ] = 1 ; lr [ 3 ] = 3 ; calc ( a , b , lr , q , n ) ;