A utility function for merging two nodes
def MergeUtil ( l : node , r : node ) -> node : NEW_LINE INDENT x = node ( ) NEW_LINE x . l0 = l . l0 if ( l . l0 != - 1 ) else r . l0 NEW_LINE x . r0 = r . r0 if ( r . r0 != - 1 ) else l . r0 NEW_LINE x . l1 = l . l1 if ( l . l1 != - 1 ) else r . l1 NEW_LINE x . r1 = r . r1 if ( r . r1 != - 1 ) else l . r1 NEW_LINE x . min0 = min ( l . min0 , r . min0 ) NEW_LINE if ( l . r0 != - 1 and r . l0 != - 1 ) : NEW_LINE INDENT x . min0 = min ( x . min0 , r . l0 - l . r0 ) NEW_LINE DEDENT x . min1 = min ( l . min1 , r . min1 ) NEW_LINE if ( l . r1 != - 1 and r . l1 != - 1 ) : NEW_LINE INDENT x . min1 = min ( x . min1 , r . l1 - l . r1 ) NEW_LINE DEDENT x . max0 = max ( l . max0 , r . max0 ) NEW_LINE if ( l . l0 != - 1 and r . r0 != - 1 ) : NEW_LINE INDENT x . max0 = max ( x . max0 , r . r0 - l . l0 ) NEW_LINE DEDENT x . max1 = max ( l . max1 , r . max1 ) NEW_LINE if ( l . l1 != - 1 and r . r1 != - 1 ) : NEW_LINE INDENT x . max1 = max ( x . max1 , r . r1 - l . l1 ) NEW_LINE DEDENT return x NEW_LINE DEDENT