if (
                        N + start - end - i - i == 1
                        and (N - end + start + 1) % 2 == 0
                    ):
                        if end == gate.controls[0]: