code: def merge_to_free(merge_result, free_list):
      merge_result_buf, mr_buf = [], []
  
      if not free_list:
          return merge_result
  
      free_list_buf = merge_result[-len(free_list) :]
      merge_result = merge_result[: -len(free_list)]
  
      for idx, r in enumerate(merge_result):
          if idx == len(merge_result) - 1:
              mr_buf.append(r)
              merge_result_buf.append(mr_buf)
              mr_buf = []
              continue
  
          if (mr_buf == []) or (mr_buf[-1][0] < r[0]):
              mr_buf.append(r)
          else:
              merge_result_buf.append(mr_buf)
              mr_buf = []
              mr_buf.append(r)
  
      for free_pos in free_list_buf:
          y_pos = len(merge_result_buf)
          x_pos = len(merge_result_buf[y_pos - 1])
          for i, result_pos in enumerate(merge_result_buf[1:]):
              if free_pos[0][0][1] < result_pos[0][0][0][1]:
                  y_pos = i
                  break
  
          for i, result_pos in enumerate(merge_result_buf[y_pos]):
              if free_pos[0][0][0] < result_pos[0][0][0]:
                  x_pos = i
                  break
  
          merge_result_buf[y_pos].insert(x_pos, free_pos)
  
      merge_result = []
      [merge_result.extend(r) for r in merge_result_buf]
      return merge_result
  
imports: from __future__ import print_function
  import torch
  import pickle
  import numpy
  import math
  import cv2
  from PIL import Image, JpegImagePlugin
  from scipy import ndimage
  import hashlib
  import sys, os
  from zipfile import ZipFile
  from .imgproc import loadImage
label_desc: Use image node_id 8 for calling a global function with example usage: merge_to_free(merge_result, free_list) and returns: merge_result, merge_result