def remove_010(S):
    """Count the minimum number of steps needed to remove the 010 pattern
    from a binary string, by replacing a 0 with 1 or 1 with 0
    """
    if len(S) < 3:
        return 0
    stack = S[:2]
    count = 0
    for s in S[2:]:
        if stack[-2:] + s == "010":
            s = "1"
            count += 1
        stack += s
    return count, stack