code: def _loc(self, pos, idx):
          
          if not pos:
              return idx
  
          _index = self._index
  
          if not len(_index):
              self._build_index()
  
          total = 0
  
          # Increment pos to point in the index to len(self._lists[pos]).
  
          pos += self._offset
  
          # Iterate until reaching the root of the index tree at pos = 0.
  
          while pos:
  
              # Right-child nodes are at odd indices. At such indices
              # account the total below the left child node.
  
              if not (pos & 1):
                  total += _index[pos - 1]
  
              # Advance pos to the parent node.
  
              pos = (pos - 1) >> 1
  
          return total + idx
docs: Convert an index pair (alpha, beta) into a single index that corresponds to
          the position of the value in the sorted list.
  
          Most queries require the index be built. Details of the index are
          described in self._build_index.
  
          Indexing requires traversing the tree from a leaf node to the root. The
          parent of each node is easily computable at (pos - 1) // 2.
  
          Left-child nodes are always at odd indices and right-child nodes are
          always at even indices.
  
          When traversing up from a right-child node, increment the total by the
          left-child node.
  
          The final index is the sum from traversal and the index in the sublist.
  
          For example, using the index from self._build_index:
  
          _index = 14 5 9 3 2 4 5
          _offset = 3
  
          Tree:
  
                   14
                5      9
              3   2  4   5
  
          Converting index pair (2, 3) into a single index involves iterating like
          so:
  
          1. Starting at the leaf node: offset + alpha = 3 + 2 = 5. We identify
             the node as a left-child node. At such nodes, we simply traverse to
             the parent.
  
          2. At node 9, position 2, we recognize the node as a right-child node
             and accumulate the left-child in our total. Total is now 5 and we
             traverse to the parent at position 0.
  
          3. Iteration ends at the root.
  
          Computing the index is the sum of the total and beta: 5 + 3 = 8.