def three_stack(R: ArrayStack, S: ArrayStack, T: ArrayStack): R_len = len(R) while not S.is_empty(): R.push(S.pop()) while not T.is_empty(): R.push(T.pop()) while len(R) > R_len: S.push(R.pop())
def stack_clear(s: ArrayStack) -> None: if s.is_empty(): return s.pop() return stack_clear(s)
def transfer(S: ArrayStack, T: ArrayStack) -> None: while not S.is_empty(): T.push(S.pop())