code: def insert_into_range(self,
                            operations: ops.OP_TREE,
                            start: int,
                            end: int) -> int:
          
          if not 0 <= start <= end <= len(self):
              raise IndexError('Bad insert indices: [{}, {})'.format(
                  start, end))
  
          operations = list(ops.flatten_op_tree(operations))
          for op in operations:
              self._device.validate_operation(op)
  
          i = start
          op_index = 0
          while op_index < len(operations):
              op = operations[op_index]
              while i < end and not self._device.can_add_operation_into_moment(
                      op, self._moments[i]):
                  i += 1
              if i >= end:
                  break
              self._moments[i] = self._moments[i].with_operation(op)
              op_index += 1
  
          if op_index >= len(operations):
              return end
  
          return self.insert(end, operations[op_index:])
docs: Writes operations inline into an area of the circuit.
  
          Args:
              start: The start of the range (inclusive) to write the
                  given operations into.
              end: The end of the range (exclusive) to write the given
                  operations into. If there are still operations remaining,
                  new moments are created to fit them.
              operations: An operation or tree of operations to insert.
  
          Returns:
              An insertion index that will place operations after the operations
              that were inserted by this method.
  
          Raises:
              IndexError: Bad inline_start and/or inline_end.