<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _remove_advices(target, advices, ctx):
 """Remove advices from input target. :param advices: advices to remove. If None, remove all advices. """

    # if ctx is not None
    if ctx is not None:  # check if intercepted ctx is ctx
        _, intercepted_ctx = get_intercepted(target)
        if intercepted_ctx is None or intercepted_ctx is not ctx:
            return

    interception_fn = _get_function(target)

    target_advices = getattr(interception_fn, _ADVICES, None)

    if target_advices is not None:

        if advices is None:
            target_advices = []
        else:
            target_advices = [
                advice for advice in target_advices if advice not in advices
            ]

        if target_advices:  # update target advices
            setattr(interception_fn, _ADVICES, target_advices)

        else:  # free target advices if necessary
            delattr(interception_fn, _ADVICES)
            _unapply_interception(target, ctx=ctx)