class DeletableSet:
__slots__ = ['_parent']
def __init__(self, size):
self._parent = list(range(size))
def get_greater_or_equal(self, x):
if (par := self._parent[x]) == x:
return x
while (gpar := self._parent[par]) != par:
self._parent[x] = gpar
x, par = par, gpar
return par
def delete(self, x):
if (root_x := self.get_greater_or_equal(x)) == (
root_y := self.get_greater_or_equal(x + 1)
):
raise ValueError
self._parent[root_x] = root_y