code: def range_merge(ranges, dist=0):
      
      if not ranges:
          return []
  
      ranges.sort()
  
      cur_range = list(ranges[0])
      merged_ranges = []
      for r in ranges[1:]:
          # open new range if start > cur_end or seqid != cur_seqid
          if r[1] - cur_range[2] > dist or r[0] != cur_range[0]:
              merged_ranges.append(tuple(cur_range))
              cur_range = list(r)
          else:
              cur_range[2] = max(cur_range[2], r[2])
      merged_ranges.append(tuple(cur_range))
  
      return merged_ranges
docs: Returns merged range. Similar to range_union, except this returns
      new ranges.
  
      >>> ranges = [("1", 30, 45), ("1", 40, 50), ("1", 10, 50)]
      >>> range_merge(ranges)
      [('1', 10, 50)]
      >>> ranges = [("1", 30, 40), ("1", 45, 50)]
      >>> range_merge(ranges)
      [('1', 30, 40), ('1', 45, 50)]
      >>> ranges = [("1", 30, 40), ("1", 45, 50)]
      >>> range_merge(ranges, dist=5)
      [('1', 30, 50)]