def switch_sides(d_u, dfs_data):
<EOL>m = dfs_data['<STR_LIT>']['<STR_LIT:m>']<EOL>u_m = u(m, dfs_data)<EOL>if d_u <= u_m:<EOL><INDENT>l_w = lw(dfs_data)<EOL>u_m1 = u(m-<NUM_LIT:1>, dfs_data)<EOL>while u_m1 > l_w:<EOL><INDENT>merge_Fm(dfs_data)<EOL>m = dfs_data['<STR_LIT>']['<STR_LIT:m>']<EOL>u_m1 = u(m-<NUM_LIT:1>, dfs_data)<EOL><DEDENT>dfs_data['<STR_LIT>']['<STR_LIT:l>'] = dfs_data['<STR_LIT>']['<STR_LIT:r>']<EOL>x_m = fn_x(m, dfs_data)<EOL>r = len(dfs_data['<STR_LIT>']) - <NUM_LIT:1><EOL>g_r = dfs_data['<STR_LIT>'][r][<NUM_LIT:0>]<EOL>while g_r >= x_m:<EOL><INDENT>r -= <NUM_LIT:1><EOL>if r < <NUM_LIT:0>:<EOL><INDENT>r = <NUM_LIT:0><EOL>break<EOL><DEDENT>g_r = dfs_data['<STR_LIT>'][r][<NUM_LIT:0>]<EOL><DEDENT>dfs_data['<STR_LIT>']['<STR_LIT:r>'] = r<EOL><DEDENT>else:<EOL><INDENT>r_w = rw(dfs_data)<EOL>x_m1 = fn_x(m-<NUM_LIT:1>, dfs_data)<EOL>while x_m1 > r_w:<EOL><INDENT>merge_Fm(dfs_data)<EOL>m = dfs_data['<STR_LIT>']['<STR_LIT:m>']<EOL>x_m1 = fn_x(m-<NUM_LIT:1>, dfs_data)<EOL><DEDENT>dfs_data['<STR_LIT>']['<STR_LIT:r>'] = dfs_data['<STR_LIT>']['<STR_LIT:l>']<EOL>u_m = u(m, dfs_data)<EOL>l = len(dfs_data['<STR_LIT>']) - <NUM_LIT:1><EOL>f_l = dfs_data['<STR_LIT>'][l][<NUM_LIT:0>]<EOL>while f_l >= u_m:<EOL><INDENT>l -= <NUM_LIT:1><EOL>f_l = dfs_data['<STR_LIT>'][l][<NUM_LIT:0>]<EOL><DEDENT>dfs_data['<STR_LIT>']['<STR_LIT:l>'] = l<EOL><DEDENT>m = dfs_data['<STR_LIT>']['<STR_LIT:m>']<EOL>LF = dfs_data['<STR_LIT>']<EOL>RF = dfs_data['<STR_LIT>']<EOL>u_m = u(m, dfs_data)<EOL>v_m = v(m, dfs_data)<EOL>x_m = fn_x(m, dfs_data)<EOL>y_m = y(m, dfs_data)<EOL>first_left_index = <NUM_LIT:1><EOL>last_left_index = len(LF) - <NUM_LIT:1><EOL>first_right_index = <NUM_LIT:1><EOL>last_right_index = len(RF) - <NUM_LIT:1><EOL>while first_left_index < last_left_index:<EOL><INDENT>frond = LF[first_left_index]<EOL>if u_m >= frond[<NUM_LIT:0>]:<EOL><INDENT>first_left_index -= <NUM_LIT:1><EOL>break<EOL><DEDENT>else:<EOL><INDENT>first_left_index += <NUM_LIT:1><EOL><DEDENT><DEDENT>while first_left_index < last_left_index:<EOL><INDENT>frond = LF[last_left_index]<EOL>if v_m < frond[<NUM_LIT:1>]:<EOL><INDENT>last_left_index -= <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>last_left_index += <NUM_LIT:1><EOL>break<EOL><DEDENT><DEDENT>while first_right_index < last_right_index:<EOL><INDENT>frond = RF[first_right_index]<EOL>if x_m >= frond[<NUM_LIT:0>]:<EOL><INDENT>first_right_index -= <NUM_LIT:1><EOL>break<EOL><DEDENT>else:<EOL><INDENT>first_right_index += <NUM_LIT:1><EOL><DEDENT><DEDENT>while first_right_index < last_right_index:<EOL><INDENT>frond = RF[last_right_index]<EOL>if y_m < frond[<NUM_LIT:1>]:<EOL><INDENT>last_right_index -= <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>last_right_index += <NUM_LIT:1><EOL>break<EOL><DEDENT><DEDENT>LF_slice = LF[first_left_index:last_left_index+<NUM_LIT:1>]<EOL>RF_slice = RF[first_right_index:last_right_index+<NUM_LIT:1>]<EOL>del LF[first_left_index:last_left_index+<NUM_LIT:1>]<EOL>del RF[first_right_index:last_right_index+<NUM_LIT:1>]<EOL>i = first_left_index<EOL>for x in RF_slice:<EOL><INDENT>LF.insert(i, x)<EOL>i += <NUM_LIT:1><EOL><DEDENT>i = first_right_index<EOL>for x in LF_slice:<EOL><INDENT>RF.insert(i, x)<EOL>i += <NUM_LIT:1><EOL><DEDENT>old_rm = dfs_data['<STR_LIT>'][m][<NUM_LIT:1>]<EOL>old_lm = dfs_data['<STR_LIT>'][m][<NUM_LIT:0>]<EOL>converted_rm = __convert_RF_dict_to_LF(old_rm)<EOL>converted_lm = __convert_LF_dict_to_RF(old_lm)<EOL>dfs_data['<STR_LIT>'][m][<NUM_LIT:1>] = converted_lm<EOL>dfs_data['<STR_LIT>'][m][<NUM_LIT:0>] = converted_rm<EOL>merge_Fm(dfs_data)<EOL>
Switches Lm and Rm, as defined on page 20 of the paper.