Initialize array for Prefix sum
pre = [ 0 ] * N NEW_LINE pre [ 0 ] = check ( arr [ 0 ] ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT pre [ i ] = pre [ i - 1 ] + check ( arr [ i ] ) NEW_LINE DEDENT c = 0 NEW_LINE while ( Q > 0 ) : NEW_LINE INDENT l = queries [ 0 ] NEW_LINE r = queries [ 1 ] NEW_LINE c += 1 NEW_LINE print ( query ( l , r , pre ) , end = " ▁ " ) NEW_LINE Q -= 1 NEW_LINE DEDENT