Function return output of each query in O ( 1 )
def query ( BOP , BCP , s , e ) : NEW_LINE INDENT if ( BOP [ s - 1 ] == BOP [ s ] ) : NEW_LINE INDENT return ( BCP [ e ] - BOP [ s ] ) * 2 ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( BCP [ e ] - BOP [ s ] + 1 ) * 2 ; NEW_LINE DEDENT DEDENT