'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import QFT
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    qc.barrier()
    qc.compose(o, inplace=True)
    qc.barrier()
    qc.append(QFT(n), range(n))
    qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import HGate, CXGate

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
def qft(n):
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.append(HGate(), [i])
        for j in range(i+1, n):
            qc.append(CXGate(), [i, j])
    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(range(n))
    qc.barrier()
    qc.compose(o, inplace=True)
    qc.barrier()
    qc.compose(qft(n), inplace=True)
    qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import HGate, CPiGate

def qft(n):
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.append(HGate(), [i])
        for j in range(i+1, n):
            qc.append(CPiGate(2**(j-i)), [i, j])
    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(range(n))
    qc.barrier()
    qc.compose(o, inplace=True)
    qc.barrier()
    qc.compose(qft(n), inplace=True)
    qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import HGate, CPiGate
import math

def qft(n):
    qc = QuantumCircuit(n)  # Define the qc variable here
    for i in reversed(range(n)):
        qc.h(i)
        for j in reversed(range(i)):
            qc.cp(math.pi / 2 ** (i - j), j, i)

    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(range(n))
    qc.barrier()
    qc.compose(o, inplace=True)
    qc.barrier()
    qc.compose(qft(n), inplace=True)
    qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    # Step 1: Prepare uniform superposition
    for qubit in range(n):
        qc.h(qubit)  # Apply Hadamard to each qubit

    # Step 2: Apply the oracle
    qc.compose(o, inplace=True)

    # Step 3: Apply the diffusion operator
    # Apply Hadamard to all qubits
    for qubit in range(n):
        qc.h(qubit)

    # Apply X gates to all qubits
    for qubit in range(n):
        qc.x(qubit)

    # Apply controlled-Z (CZ) gate
    qc.h(n-1)  # Apply Hadamard to the last qubit
    qc.mct(list(range(n-1)), n-1)  # Multi-controlled Toffoli (n-1 controls)
    qc.h(n-1)  # Apply Hadamard to the last qubit again

    # Apply X gates to all qubits again
    for qubit in range(n):
        qc.x(qubit)

    # Apply Hadamard to all qubits again
    for qubit in range(n):
        qc.h(qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    # Apply Hadamard gates to all qubits
    for qubit in range(n):
        qc.h(qubit)

    # Apply the oracle
    qc.compose(o, inplace=True)

    # Apply Hadamard gates again to all qubits
    for qubit in range(n):
        qc.h(qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    qc.h(range(n))
    qc.compose(o, inplace=True)

    qc.h(range(n))
    qc.x(range(n))
    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)
    qc.h(n-1)
    qc.x(range(n))
    qc.h(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    num_iterations = int(np.floor(np.pi / 4 * np.sqrt(2**n)))

    for _ in range(num_iterations):
        qc.compose(o, inplace=True)
        qc.h(range(n))
        qc.x(range(n))
        qc.h(range(n))

        for qubit in range(n):
            qc.cz(0, qubit)

        qc.h(range(n))
        qc.x(range(n))
        qc.h(range(n))

        for qubit in range(n):
            if (target >> qubit) & 1:
                qc.x(qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate, GlobalPhaseGate
import numpy as np
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def refl(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    qc.append(GlobalPhaseGate(math.pi))
    qc.h(range(n))
    qc.x(range(n))

    mcz = ZGate().control(n-1)
    qc.append(mcz, list(range(n)))

    qc.x(range(n))
    qc.h(range(n))

    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    qc.h(range(n))
    qc.compose(o, inplace=True)
    qc.compose(refl(n), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for j in range(5):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.h(n-1)
        array = list(range(n -1))
        qc.mcx(array, n-1)
        qc.h(n-1)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for j in range(10):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.h(n-1)
        array = list(range(n -1))
        qc.mcx(array, n-1)
        qc.h(n-1)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for j in range(20):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.h(n-1)
        array = list(range(n -1))
        qc.mcx(array, n-1)
        qc.h(n-1)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for j in range(100):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.h(n-1)
        array = list(range(n -1))
        qc.mcx(array, n-1)
        qc.h(n-1)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for j in range(10000):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.h(n-1)
        array = list(range(n -1))
        qc.mcx(array, n-1)
        qc.h(n-1)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    qc.compose(o, inplace=True)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.mcp(math.pi,list(range(n-1)),n-1)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    qc.compose(o, inplace=True)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.mcp(math.pi,list(range(n-1)),n-1)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate, HGate

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
	qc = QuantumCircuit(n)
	qc.h(range(n))
	qc.compose(o, inplace=True)
	qc.h(range(n))
	qc.x(range(n))
	qc.h(n - 1)
	qc.mcx(list(range(n - 1)), n - 1)
	qc.h(n - 1)
	qc.x(range(n))
	qc.h(range(n))
	return qc
'''


'''python
from math import (
    pi,
    # degrees,
    # radians,
    # asin,
    # acos,
    # atan2,
    # sqrt,
    # sin,
    # cos,
    # tan
)
import numpy as np
from qiskit import QuantumCircuit, QuantumRegister

# from qiskit.circuit.library.standard_gates import (
#     C3XGate,
#     C3SXGate,
#     C4XGate,
#     CCXGate,
#     DCXGate,
#     CHGate,
#     CPhaseGate,
#     CRXGate,
#     CRYGate,
#     CRZGate,
#     CSwapGate,
#     CSXGate,
#     CUGate,
#     CU1Gate,
#     CU3Gate,
#     CXGate,
#     CYGate,
#     CZGate,
#     CCZGate,
#     HGate,
#     IGate,
#     MCPhaseGate,
#     PhaseGate,
#     RCCXGate,
#     RC3XGate,
#     RXGate,
#     RXXGate,
#     RYGate,
#     RYYGate,
#     RZGate,
#     RZZGate,
#     RZXGate,
#     XXMinusYYGate,
#     XXPlusYYGate,
#     ECRGate,
#     SGate,
#     SdgGate,
#     CSGate,
#     CSdgGate,
#     SwapGate,
#     iSwapGate,
#     SXGate,
#     SXdgGate,
#     TGate,
#     TdgGate,
#     UGate,
#     U1Gate,
#     U2Gate,
#     U3Gate,
#     XGate,
#     YGate,
#     ZGate,
# )

def preparation(targets: list[int]) -> QuantumCircuit:
    qc = QuantumCircuit(len(targets))
    qc.h(targets)
    return qc

def reflection(qc, targets: list[int]):
    o = preparation(targets)

    qc.compose(o.inverse(), inplace=True)
    qc.x(targets)
    qc.mcp(pi, targets[:-1], targets[-1])
    qc.x(targets)
    qc.compose(o, inplace=True)

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    prep = preparation(list(range(n)))
    oracle = o

    qc = QuantumCircuit(n)
    qc.compose(prep, inplace=True)
    qc.compose(oracle, inplace=True)
    qc.compose(prep, inplace=True)

    return qc
'''


'''python
from math import (
    pi,
    # degrees,
    # radians,
    # asin,
    # acos,
    # atan2,
    # sqrt,
    # sin,
    # cos,
    # tan
)
import numpy as np
from qiskit import QuantumCircuit, QuantumRegister

# from qiskit.circuit.library.standard_gates import (
#     C3XGate,
#     C3SXGate,
#     C4XGate,
#     CCXGate,
#     DCXGate,
#     CHGate,
#     CPhaseGate,
#     CRXGate,
#     CRYGate,
#     CRZGate,
#     CSwapGate,
#     CSXGate,
#     CUGate,
#     CU1Gate,
#     CU3Gate,
#     CXGate,
#     CYGate,
#     CZGate,
#     CCZGate,
#     HGate,
#     IGate,
#     MCPhaseGate,
#     PhaseGate,
#     RCCXGate,
#     RC3XGate,
#     RXGate,
#     RXXGate,
#     RYGate,
#     RYYGate,
#     RZGate,
#     RZZGate,
#     RZXGate,
#     XXMinusYYGate,
#     XXPlusYYGate,
#     ECRGate,
#     SGate,
#     SdgGate,
#     CSGate,
#     CSdgGate,
#     SwapGate,
#     iSwapGate,
#     SXGate,
#     SXdgGate,
#     TGate,
#     TdgGate,
#     UGate,
#     U1Gate,
#     U2Gate,
#     U3Gate,
#     XGate,
#     YGate,
#     ZGate,
# )

def preparation(targets: list[int]) -> QuantumCircuit:
    qc = QuantumCircuit(len(targets))
    qc.h(targets)
    return qc

def reflection(qc, targets: list[int]):
    o = preparation(targets)

    qc.compose(o.inverse(), inplace=True)
    qc.x(targets)
    qc.mcp(pi, targets[:-1], targets[-1])
    qc.x(targets)
    qc.compose(o, inplace=True)

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    prep = preparation(list(range(n)))
    oracle = o

    qc = QuantumCircuit(n)
    qc.compose(prep, inplace=True)

    qc.compose(oracle, inplace=True)
    reflection(qc, list(range(n)))

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def diffusion_oracle(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)
        qc.x(i)
    qc.append(ZGate().control(n - 1), range(n))
    for i in range(n):
        qc.x(i)
        qc.h(i)
    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    for _ in range(3):
        qc.compose(o, inplace=True)
        qc.compose(diffusion_oracle(), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def diffusion_oracle(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)
        qc.x(i)
    qc.append(ZGate().control(n - 1), range(n))
    for i in range(n):
        qc.x(i)
        qc.h(i)
    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    for _ in range(3):
        qc.compose(o, inplace=True)
        qc.compose(diffusion_oracle(n), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def diffusion_oracle(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)
        qc.x(i)
    qc.append(ZGate().control(n - 1), range(n))
    for i in range(n):
        qc.x(i)
        qc.h(i)
    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    for _ in range(10):
        qc.compose(o, inplace=True)
        qc.compose(diffusion_oracle(n), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)

    qc.compose(o, inplace=True)

    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    if n == 1:
        qc.z(0)
    elif n == 2:
        qc.h(n - 1)
        qc.cx(0, 1)
        qc.h(n - 1)
    else:
        qc.h(n - 1)
        qc.mcx(list(range(n - 1)), n - 1)
        qc.h(n - 1)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from math import pi, acos, sqrt
from qiskit.circuit.library import ZGate

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve1(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)

    qc.append(ZGate().control(n-1), range(n))

    for i in range(n):
        qc.x(i)

    return qc

def solve2(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)

    qc.compose(solve1(n), inplace=True)

    for i in range(n):
        qc.h(i)

    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    qc.compose(o, inplace=True)
    qc.compose(solve2(n), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def diffuser(n):
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)

    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)
    qc.h(n-1)

    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    niter = math.floor(math.pi/4  * math.sqrt(2**n))
    diff = diffuser(n)
    for i in range(n):
        qc.h(i)
    for i in range(niter):
        qc.compose(o, inplace=True)
        qc.compose(diff, inplace=True)
    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)
    qc.compose(o, inplace=True)
    for i in range(n):
        qc.h(i)
        qc.x(i)
    qc.compose(o,inplace=True)
    for i in range(n):
        qc.x(i)
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)
    qc.compose(o, inplace=True)
    for i in range(n):
        qc.h(i)
        qc.x(i)
    qc.compose(o,inplace=True)
    for i in range(n):
        qc.x(i)
        qc.h(i)
    qc.compose(o,inplace=True)
    for i in range(n):
        qc.x(i)
        qc.h(i)
    qc.compose(o,inplace=True)
    for i in range(n):
        qc.x(i)
        qc.h(i)
    qc.compose(o,inplace=True)
    for i in range(n):
        qc.x(i)
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    for _ in range(math.floor(math.pi/4*math.sqrt(2**n))):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
            qc.x(i)
        qc.compose(o,inplace=True)
        for i in range(n):
            qc.x(i)
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    for _ in range(9):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
            qc.x(i)
        qc.compose(o,inplace=True)
        for i in range(n):
            qc.x(i)
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit  # type: ignore
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    for _ in range(math.floor(math.pi/4*math.sqrt(2**n))):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit  # type: ignore
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    qc.compose(o, inplace=True)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.compose(o, inplace=True)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit  # type: ignore
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    for _ in range(5):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit  # type: ignore
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    for _ in range(25):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit  # type: ignore
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    # Grover's algorithm
    for _ in range(math.floor(math.pi/4*math.sqrt(2**n/2))):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit  # type: ignore
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    # Grover's algorithm
    for _ in range(6):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit  # type: ignore
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    # Grover's algorithm
    for _ in range(math.floor(math.pi/4*math.sqrt(n))):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit  # type: ignore
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init H
    for i in range(n):
        qc.h(i)
    # Grover's algorithm
    for _ in range(2):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    # Step 1: Apply Hadamard gate to all qubits to create superposition
    for i in range(n):
        qc.h(i)

    # Step 2: Apply Grover's algorithm with the necessary number of iterations
    iterations = math.floor(math.pi / 4 * math.sqrt(2 ** n))
    for _ in range(iterations):
        # Apply the oracle
        qc.compose(o, inplace=True)

        # Diffusion operator
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)

        # Apply a multi-controlled Z gate
        qc.h(0)
        qc.mcx(list(range(1, n)), 0)  # Apply controlled-Z
        qc.h(0)

        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n))
    for i in range(n):
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n))
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
def diffusion(n):
    theta = np.pi
    controls = list(range(n-1))
    target = n-1

    qc.h(range(n))

    for i in range(n):
        qc.x(i)

    qc.mcp(theta, controls, target)

    for i in range(n):
        qc.x(i)

    qc.h(range(n))

    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    rounds = np.round(np.pi/(4*(np.arcsin(np.sqrt(1/2**(n - 1)))))-1/2, 4)
    rounds_int = int(np.round(rounds))

    qc.h(range(n))

    for _ in range(rounds_int):
        qc.compose(o, inplace=True)
        qc.compose(diffusion(n), inplace = True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
def diffusion(n):
    theta = np.pi
    controls = list(range(n-1))
    target = n-1

    qc.h(range(n))

    for i in range(n):
        qc.x(i)

    qc.mcp(theta, controls, target)

    for i in range(n):
        qc.x(i)

    qc.h(range(n))

    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    rounds = np.round(np.pi/(4*(np.arcsin(np.sqrt(1/2**(n - 1)))))-1/2, 4)
    rounds_int = int(np.round(rounds))

    qc.h(range(n))

    for _ in range(rounds_int):
        qc.compose(o, inplace=True)
        qc.compose(diffusion(n), inplace = True)

    qc.measure_all()

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
def diffusion:
    theta = np.pi
    controls = list(range(n-1))
    target = n-1

    qc.h(range(n))

    for i in range(n):
        qc.x(i)

    qc.mcp(theta, controls, target)

    for i in range(n):
        qc.x(i)

    qc.h(range(n))

    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    rounds = np.round(np.pi/(4*(np.arcsin(np.sqrt(1/2**(n - 1)))))-1/2, 4)
    rounds_int = int(np.round(rounds))

    qc.h(range(n))

    for _ in range(rounds_int):
        qc.compose(o, inplace=True)
        qc.compose(diffusion, inplace = True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
def diffusion(n):
    theta = np.pi
    controls = list(range(n-1))
    target = n-1

    qc.h(range(n))

    for i in range(n):
        qc.x(i)

    qc.mcp(theta, controls, target)

    for i in range(n):
        qc.x(i)

    qc.h(range(n))

    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n = n
    rounds = np.round(np.pi/(4*(np.arcsin(np.sqrt(1/2**(n - 1)))))-1/2, 4)
    rounds_int = int(np.round(rounds))

    qc.h(range(n))

    for _ in range(rounds_int):
        qc.compose(o, inplace=True)
        qc.compose(diffusion(n), inplace = True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
def diffusion(n):
    theta = np.pi
    controls = list(range(n-1))
    target = n-1

    qc.h(range(n))

    for i in range(n):
        qc.x(i)

    qc.mcp(theta, controls, target)

    for i in range(n):
        qc.x(i)

    qc.h(range(n))

    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n = n
    rounds = np.round(np.pi/(4*(np.arcsin(np.sqrt(1/2**(n - 1)))))-1/2, 4)
    rounds_int = int(np.round(rounds))

    qc.h(range(n))

    for _ in range(rounds_int):
        qc.compose(o, inplace=True)
        qc.compose(diffusion(n), inplace = True)

    qc.measure_all()

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""
def diffusion(n):
    qc = QuantumCircuit(n)
    theta = np.pi
    controls = list(range(n-1))
    target = n-1

    qc.h(range(n))

    for i in range(n):
        qc.x(i)

    qc.mcp(theta, controls, target)

    for i in range(n):
        qc.x(i)

    qc.h(range(n))

    return qc

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n = n
    rounds = np.round(np.pi/(4*(np.arcsin(np.sqrt(1/2**(n - 1)))))-1/2, 4)
    rounds_int = int(np.round(rounds))

    qc.h(range(n))

    for _ in range(rounds_int):
        qc.compose(o, inplace=True)
        qc.compose(diffusion(n), inplace = True)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def diffuser(n):
    qc.h(range(n))
    qc.rz(2*np.pi, n-1)
    qc.x(list(range(n)))
    qc.mcp(np.pi, list(range(n-1)), n-1)
    qc.x(list(range(n)))
    qc.h(range(n))

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    for i in range(int(0.8 * n)):
        qc.compose(o, inplace=True)
        qc.diffuser()
    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def diffuser(n):
    qc.h(range(n))
    qc.rz(2*np.pi, n-1)
    qc.x(list(range(n)))
    qc.mcp(np.pi, list(range(n-1)), n-1)
    qc.x(list(range(n)))
    qc.h(range(n))

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    for i in range(int(0.8 * n)):
        qc.compose(o, inplace=True)
        qc.diffuser()
    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    for i in range(int(0.8 * n)):
        qc.compose(o, inplace=True)
        qc.h(range(n))
        qc.rz(2*np.pi, n-1)
        qc.x(list(range(n)))
        qc.mcp(np.pi, list(range(n-1)), n-1)
        qc.x(list(range(n)))
        qc.h(range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    # Step 1: Create uniform superposition
    for i in range(n):
        qc.h(i)

    # Step 2: Apply Grover iterations
    # For the required probability 4/2^n, we need approximately 1-2 iterations
    num_iterations = max(1, int(3.14159 / 4 * (2**n)**0.5 * 0.5))

    for _ in range(num_iterations):
        # Apply oracle
        qc.compose(o, inplace=True)

        # Apply diffusion operator (amplitude amplification about uniform superposition)
        # This is 2|s><s| - I where |s> is uniform superposition

        # Transform back to computational basis
        for i in range(n):
            qc.h(i)

        # Flip phase of |0> state
        qc.x(range(n))  # NOT all qubits
        if n == 1:
            qc.z(0)
        else:
            # Multi-controlled Z gate
            qc.h(n-1)
            qc.mcx(list(range(n-1)), n-1)
            qc.h(n-1)
        qc.x(range(n))  # NOT all qubits back

        # Transform back to superposition basis
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))

    for _ in range(2):
        qc.compose(o, inplace=True)

        qc.h(range(n))
        qc.x(range(n))

        qc.h(n - 1)
        qc.mcx(list(range(n - 1)), n - 1)
        qc.h(n - 1)

        qc.x(range(n))
        qc.h(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    #Gloverのアルゴリズム

    #重ね合わせ合わせ状態にする
    for i in range(n):
        qc.h(qubit)

    #反復回数計算
    itr = int(2 ** (n / 2))

    #反復開始！撃てぇええええ！
    for _ in range(itr):
        #欲しい状態だけ反転させる
        qc.compose(o, inplace=True)

        #アダマールゲートを作用させる
        for i in range(n):
            qc.h(i)

        #X gate装填！ビットフリップ！
        for i in range(n):
            qc.x(i)

        #おりゃあ増幅反転じゃい！
        qc.h(n - 1)
        qc.mcx(list(range(n - 1)), n - 1)
        qc.h(n - 1)

        #Xゲート反転じゃい！
        for qubit in range(n):
            qc.x(qubit)

        #重ね合わせ解除！
        for qubit in range(n):
            qc.h(qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    #Gloverのアルゴリズム

    #重ね合わせ合わせ状態にする
    for i in range(n):
        qc.h(qubit)

    #反復回数計算
    itr = int(2 ** (n / 2))

    #反復開始！撃てぇええええ！
    for k in range(itr):
        #欲しい状態だけ反転させる
        qc.compose(o, inplace=True)

        #アダマールゲートを作用させる
        for i in range(n):
            qc.h(i)

        #X gate装填！ビットフリップ！
        for i in range(n):
            qc.x(i)

        #おりゃあ増幅反転じゃい！
        qc.h(n - 1)
        qc.mcx(list(range(n - 1)), n - 1)
        qc.h(n - 1)

        #Xゲート反転じゃい！
        for i in range(n):
            qc.x(i)

        #重ね合わせ解除！
        for qubit in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    #Gloverのアルゴリズム

    #重ね合わせ合わせ状態にする
    for i in range(n):
        qc.h(qubit)

    #反復回数計算
    itr = int(2 ** (n / 2))

    #反復開始！撃てぇええええ！
    for k in range(itr):
        #欲しい状態だけ反転させる
        qc.compose(o, inplace=True)

        #アダマールゲートを作用させる
        for i in range(n):
            qc.h(i)

        #X gate装填！ビットフリップ！
        for i in range(n):
            qc.x(i)

        #おりゃあ増幅反転じゃい！
        qc.h(n - 1)
        qc.mcx(list(range(n - 1)), n - 1)
        qc.h(n - 1)

        #Xゲート反転じゃい！
        for i in range(n):
            qc.x(i)

        #重ね合わせ解除！
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    #Gloverのアルゴリズム

    #重ね合わせ合わせ状態にする
    for i in range(n):
        qc.h(i)

    #反復回数計算
    itr = int(2 ** (n / 2))

    #反復開始！撃てぇええええ！
    for k in range(itr):
        #欲しい状態だけ反転させる
        qc.compose(o, inplace=True)

        #アダマールゲートを作用させる
        for i in range(n):
            qc.h(i)

        #X gate装填！ビットフリップ！
        for i in range(n):
            qc.x(i)

        #おりゃあ増幅反転じゃい！
        qc.h(n - 1)
        qc.mcx(list(range(n - 1)), n - 1)
        qc.h(n - 1)

        #Xゲート反転じゃい！
        for i in range(n):
            qc.x(i)

        #重ね合わせ解除！
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # Paso 1: Aplicar puertas Hadamard a todos los qubits para crear la superposición uniforme
    qc.h(range(n))

    # Paso 2: Aplicar el oráculo O
    qc.compose(o, inplace=True)

    # Paso 3: Aplicar el operador de difusión
    # 3a: Aplicar puertas Hadamard a todos los qubits
    qc.h(range(n))

    # 3b: Aplicar puertas X a todos los qubits
    qc.x(range(n))

    # 3c: Aplicar una puerta Z multi-controlada
    # Para implementar una puerta Z multi-controlada:
    # - Aplicar una puerta Hadamard al último qubit
    qc.h(n-1)

    # - Aplicar una puerta MCX (multi-controlled X) con los n-1 primeros qubits como controles y el último como objetivo
    controls = list(range(n-1))
    target = n-1
    qc.mcx(controls, target)

    # - Aplicar nuevamente una puerta Hadamard al último qubit
    qc.h(n-1)

    # 3d: Aplicar puertas X a todos los qubits
    qc.x(range(n))

    # 3e: Aplicar puertas Hadamard a todos los qubits nuevamente
    qc.h(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import HGate, XGate, MCXGate

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    for qubit in range(n):
        qc.h(qubit)

    qc.compose(o, inplace=True)

    for qubit in range(n):
        qc.h(qubit)

    for qubit in range(n):
        qc.x(qubit)

    qc.mcx(list(range(n)), n-1)

    for qubit in range(n):
        qc.x(qubit)

    for qubit in range(n):
        qc.h(qubit)

    iterations = int(np.pi / 4 * np.sqrt(2**n))
    for _ in range(iterations):
        qc.compose(o, inplace=True)
        for qubit in range(n):
            qc.h(qubit)
        for qubit in range(n):
            qc.x(qubit)
        qc.mcx(list(range(n)), n-1)
        for qubit in range(n):
            qc.x(qubit)
        for qubit in range(n):
            qc.h(qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # how to do the Grover rotations lol
    for i in range(n):
        qc.h(i)

    for _ in range(4):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.h(0)
        qc.mcx(control_qubits=list(range(1,n)), target_qubit=0)
        qc.h(0)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # how to do the Grover rotations lol
    for i in range(n):
        qc.h(i)

    for _ in range(5):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.h(0)
        qc.mcx(control_qubits=list(range(1,n)), target_qubit=0)
        qc.h(0)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # how to do the Grover rotations lol
    for i in range(n):
        qc.h(i)

    for _ in range(6):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.h(0)
        qc.mcx(control_qubits=list(range(1,n)), target_qubit=0)
        qc.h(0)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # how to do the Grover rotations lol
    for i in range(n):
        qc.h(i)

    for _ in range(10):
        qc.compose(o, inplace=True)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.h(0)
        qc.mcx(control_qubits=list(range(1,n)), target_qubit=0)
        qc.h(0)
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
import numpy as np
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    for i in range(n):
        qc.h(i)

    for _ in range(int(np.sqrt(n))):
        qc.compose(o, inplace=True)

        for i in range(n):
            qc.h(i)
            qc.x(i)
        qc.mcp(np.pi, list(range(n-1)), n-1)
        for i in range(n):
            qc.x(i)
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import pi

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qubits = list(range(n))

    qc.h(qubits)

    qc.compose(o, inplace=True)

    qc.h(qubits)
    qc.x(qubits)
    qc.mcp(pi, qubits[1:], 0)
    qc.x(qubits)
    qc.h(qubits)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def b4(qc: QuantumCircuit) -> None:
    n = qc.num_qubits
    for i in range(n):
        qc.x(i)
    mcz = ZGate().control(n - 1)
    qc.append(mcz, range(n))

    for i in range(n):
        qc.x(i)

def b5(qc: QuantumCircuit) -> None:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    b4(qc)
    for i in range(n):
        qc.h(i)

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.compose(o, inplace=True)
    b5(qc)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def b4(qc: QuantumCircuit) -> None:
    n = qc.num_qubits
    for i in range(n):
        qc.x(i)
    mcz = ZGate().control(n - 1)
    qc.append(mcz, range(n))

    for i in range(n):
        qc.x(i)

def b5(qc: QuantumCircuit) -> None:
    n = qc.num_qubits
    # Write your code here:
    for i in range(n):
        qc.h(i)
    b4(qc)
    for i in range(n):
        qc.h(i)

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.compose(o, inplace=True)
    b5(qc)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def b4(qc: QuantumCircuit) -> None:
    n = qc.num_qubits
    for i in range(n):
        qc.x(i)
    mcz = ZGate().control(n - 1)
    qc.append(mcz, range(n))

    for i in range(n):
        qc.x(i)

def b5(qc: QuantumCircuit) -> None:
    n = qc.num_qubits
    # Write your code here:
    for i in range(n):
        qc.h(i)
    b4(qc)
    for i in range(n):
        qc.h(i)

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    qc.compose(o, inplace=True)
    b5(qc)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import PhaseGate
import math

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

#https://www.qcoder.jp/ja/contests/QPC002/submissions/f6eee4b0-4f58-4f8f-8af9-82d02ab32490
def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    L = 0

    for i in range(n):
        qc.h(i)

    qc.compose(o, inplace=True)

    L = 0

    for i in range(n):
        qc.h(i)

    for i in range(n):
        if not (L >> i) & 1:
            qc.x(i)

    if n == 1:
        qc.append(PhaseGate(math.pi), [0])
    else:
        qc.append(PhaseGate(math.pi).control(n - 1), range(n))

    for i in range(n):
        if not (L >> i) & 1:
            qc.x(i)

    for i in range(n):
        qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # 各量子ビットに対して角度T_iに基づく状態を作成
    for i in range(n):
        qc.ry(2 * T[i], i)  # 各ビットにRYゲートで角度を設定

    # 2 |ψ⟩⟨ψ| - I の拡散演算子の実装
    qc.h(range(n))  # すべてのビットにHadamardゲートを適用
    qc.x(range(n))  # すべてのビットにXゲートを適用

    # マルチ制御Zゲートを適用
    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)  # 最後のビットに対して制御Z
    qc.h(n-1)

    qc.x(range(n))  # 再びXゲートを適用
    qc.h(range(n))  # 再びHadamardゲートを適用

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    abc = [0] * n
    for i in range(n):
        abc[i]=i
    for i in range(n):
        qc.ry(T[i]*2,i)

    qc1 = QuantumCircuit(1)
    qc1.z(0)
    custom = qc1.to_gate().control(n-1)

    qc.ry(np.pi*2,n-1)
    qc.append(custom, abc)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.ry(T[i]*2,i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np
from qiskit.circuit.library.standard_gates import ZGate, HGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    abc = [0] * n
    for i in range(n):
        abc[i]=i
    for i in range(n):
        qc.ry(T[i]*2,i)

    qc1 = QuantumCircuit(1)
    qc1.z(0)
    custom = qc1.to_gate().control(n-1)

    qc.ry(np.pi*2,n-1)
    qc.append(custom, abc)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.ry(T[i]*2,i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np
from qiskit.circuit.library.standard_gates import ZGate, HGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    abc = [0] * n
    for i in range(n):
        abc[i]=i
    for i in range(n):
        qc.ry(T[i]*2,i)
    for i in range(n):
        qc.x(i)

    qc1 = QuantumCircuit(1)
    qc1.z(0)
    custom = qc1.to_gate().control(n-1)

    qc.ry(np.pi*2,n-1)
    qc.append(custom, abc)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.ry(T[i]*2,i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np
from qiskit.circuit.library.standard_gates import ZGate, HGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    abc = [0] * n
    for i in range(n):
        abc[i]=i
    for i in range(n):
        qc.ry(T[i]*2,i)
    for i in range(n):
        qc.x(i)

    qc1 = QuantumCircuit(1)
    qc1.z(0)
    custom = qc1.to_gate().control(n-1)

    qc.ry(np.pi*2,n-1)
    qc.append(custom, abc)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.ry(-T[i]*2,i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np
from qiskit.circuit.library.standard_gates import ZGate, HGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    abc = [0] * n
    for i in range(n):
        abc[i]=i
    for i in range(n):
        qc.ry(-T[i]*2,i)
    for i in range(n):
        qc.x(i)

    qc1 = QuantumCircuit(1)
    qc1.z(0)
    custom = qc1.to_gate().control(n-1)

    qc.ry(np.pi*2,n-1)
    qc.append(custom, abc)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.ry(T[i]*2,i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from math import pi, acos, sqrt
from qiskit.circuit.library import ZGate

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve1(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)

    qc.append(ZGate().control(n-1), range(n))

    for i in range(n):
        qc.x(i)

    return qc

def solve2(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)

    qc.compose(solve1(n), inplace=True)

    for i in range(n):
        qc.h(i)

    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(-2 * T[i], i)

    qc.compose(solve1(n), inplace=True)

    for i in range(n):
        qc.ry(2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def psi(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    for i in range(n):
        qc.ry(T[i] * 2, i)
    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.compose(psi(n, T), inplace=True)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n - 1), range(n))
    for i in range(n):
        qc.x(i)
    qc.compose(psi(n, T).inverse(), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def psi(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    for i in range(n):
        qc.ry(T[i] * 2, i)
    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.compose(psi(n, T).inverse(), inplace=True)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n - 1), range(n))
    for i in range(n):
        qc.x(i)
    qc.compose(psi(n, T), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def reflect(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    qc.x(range(n))
    qc.append(ZGate().control(n - 1), range(n))
    qc.x(range(n))

    return qc

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    qc.h(range(n))
    qc.compose(reflect(n), inplace=True)
    qc.h(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def reflect(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    qc.x(range(n))
    qc.append(ZGate().control(n - 1), range(n))
    qc.x(range(n))

    return qc

def rotate(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    for i in range(n):
        qc.ry(T[i] * 2, i)

    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    qc.compose(rotate(n, T).inverse(), inplace=True)
    qc.compose(reflect(n), inplace=True)
    qc.compose(rotate(n, T), inplace=True)

    return qc
'''


'''python
from math import (
    pi,
    # degrees,
    # radians,
    # asin,
    # acos,
    # atan2,
    # sqrt,
    # sin,
    # cos,
    # tan
)
import numpy as np
from qiskit import QuantumCircuit, QuantumRegister

# from qiskit.circuit.library.standard_gates import (
#     C3XGate,
#     C3SXGate,
#     C4XGate,
#     CCXGate,
#     DCXGate,
#     CHGate,
#     CPhaseGate,
#     CRXGate,
#     CRYGate,
#     CRZGate,
#     CSwapGate,
#     CSXGate,
#     CUGate,
#     CU1Gate,
#     CU3Gate,
#     CXGate,
#     CYGate,
#     CZGate,
#     CCZGate,
#     HGate,
#     IGate,
#     MCPhaseGate,
#     PhaseGate,
#     RCCXGate,
#     RC3XGate,
#     RXGate,
#     RXXGate,
#     RYGate,
#     RYYGate,
#     RZGate,
#     RZZGate,
#     RZXGate,
#     XXMinusYYGate,
#     XXPlusYYGate,
#     ECRGate,
#     SGate,
#     SdgGate,
#     CSGate,
#     CSdgGate,
#     SwapGate,
#     iSwapGate,
#     SXGate,
#     SXdgGate,
#     TGate,
#     TdgGate,
#     UGate,
#     U1Gate,
#     U2Gate,
#     U3Gate,
#     XGate,
#     YGate,
#     ZGate,
# )

def preparation(targets: list[int], thetas: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(len(targets))
    for i in range(len(targets)):
        qc.ry(thetas[i] * 2, targets[i])
    return qc

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    targets = list(range(n))
    o = preparation(targets, T)

    qc.compose(o.inverse(), inplace=True)
    qc.x(targets)
    qc.mcp(pi, targets[:-1], targets[-1])
    qc.x(targets)
    qc.compose(o, inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    # Step 1: Prepare the state |psi>
    for i in range(n):
        theta = T[i]
        # Apply Ry rotation to prepare the state |psi>
        qc.ry(2 * theta, i)  # R_y(2 * theta) prepares cos(theta)|0> + sin(theta)|1>

    # Step 2: Apply the reflection operation
    # We need to apply a controlled operation that reflects across |psi>
    # This can be done by applying a series of gates that create the reflection
    # We will use the fact that |psi> is already prepared in the circuit

    # To reflect across |psi>, we can use the following:
    # 1. Apply a Hadamard to all qubits
    qc.h(range(n))

    # 2. Apply the controlled rotation to flip the state
    for i in range(n):
        qc.ry(-2 * T[i], i)  # This is the inverse operation to reflect

    # 3. Apply Hadamard again to all qubits
    qc.h(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
import math

#https://www.qcoder.jp/ja/contests/QPC002/submissions/f6eee4b0-4f58-4f8f-8af9-82d02ab32490
def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    L = 0

    for i in range(n):
        qc.ry(2 * T[i], i)

    for i in range(n):
        if not (L >> i) & 1:
            qc.x(i)

    if n == 1:
        qc.append(ZGate(), [0])
    else:
        qc.append(ZGate().control(n - 1), range(n))

    for i in range(n):
        if not (L >> i) & 1:
            qc.x(i)

    for i in range(n):
        qc.ry((-2) * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
import math

#https://www.qcoder.jp/ja/contests/QPC002/submissions/f6eee4b0-4f58-4f8f-8af9-82d02ab32490
def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    L = 0

    for i in range(n):
        qc.ry((-2) * T[i], i)

    for i in range(n):
        if not (L >> i) & 1:
            qc.x(i)

    if n == 1:
        qc.append(ZGate(), [0])
    else:
        qc.append(ZGate().control(n - 1), range(n))

    for i in range(n):
        if not (L >> i) & 1:
            qc.x(i)

    for i in range(n):
        qc.ry(2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    U = QuantumCircuit(n)
    for i in range(n):
        U.ry(2 * T[i], i)
    qc.compose(U.inverse(), inplace=True)

    for i in range(n):
        qc.x(i)
    qc.h(n - 1)
    if n == 2:
        qc.cx(0, 1)
    else:
        qc.mcx(list(range(n - 1)), n - 1)
    qc.h(n - 1)
    for i in range(n):
        qc.x(i)

    qc.compose(U, inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(T[i] * 2, i)
    qc.rz(2*np.pi, n-1)
    qc.x(list(range(n)))
    qc.mcp(np.pi, list(range(n-1)), n-1)
    qc.x(list(range(n)))
    for i in range(n):
        qc.ry(T[i] * 2, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(T[i] * 2, i)
    qc.rz(2*np.pi, n-1)
    qc.x(list(range(n)))
    qc.mcp(np.pi, list(range(n-1)), n-1)
    qc.x(list(range(n)))
    for i in range(n):
        qc.ry(T[i] * 2, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(T[i] * 2, i)
    qc.rz(2*np.pi, n-1)
    qc.x(list(range(n)))
    qc.mcp(np.pi, list(range(n-1)), n-1)
    qc.x(list(range(n)))
    for i in range(n):
        qc.ry(T[i] * -2, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(T[i] * -2, i)
    qc.rz(2*np.pi, n-1)
    qc.x(list(range(n)))
    qc.mcp(np.pi, list(range(n-1)), n-1)
    qc.x(list(range(n)))
    for i in range(n):
        qc.ry(T[i] * 2, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate, GlobalPhaseGate
import numpy as np
import math

def zero_to_psi(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    for idx in range(0, n):
        qc.ry(2*T[idx], idx)

    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    qc.compose(zero_to_psi(n, T).inverse(), inplace=True)

    qc.append(GlobalPhaseGate(math.pi))
    qc.h(range(n))
    qc.x(range(n))

    mcz = ZGate().control(n-1)
    qc.append(mcz, list(range(n)))

    qc.x(range(n))
    qc.h(range(n))

    qc.compose(zero_to_psi(n, T), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate, GlobalPhaseGate
import numpy as np
import math

def zero_to_psi(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    for idx in range(0, n):
        qc.ry(2*T[idx], idx)

    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    qc.compose(zero_to_psi(n, T), inplace=True)

    qc.append(GlobalPhaseGate(math.pi))
    qc.h(range(n))
    qc.x(range(n))

    mcz = ZGate().control(n-1)
    qc.append(mcz, list(range(n)))

    qc.x(range(n))
    qc.h(range(n))

    qc.compose(zero_to_psi(n, T).inverse(), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate, GlobalPhaseGate
import numpy as np
import math

def zero_to_psi(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    for idx in range(0, n):
        qc.ry(2*T[idx], idx)

    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    qc.compose(zero_to_psi(n, T), inplace=True)

    qc.append(GlobalPhaseGate(math.pi))
    qc.x(range(n))

    mcz = ZGate().control(n-1)
    qc.append(mcz, list(range(n)))

    qc.x(range(n))

    qc.compose(zero_to_psi(n, T).inverse(), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate, GlobalPhaseGate
import numpy as np
import math

def zero_to_psi(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    for idx in range(0, n):
        qc.ry(2*T[idx], idx)

    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    qc.compose(zero_to_psi(n, T).inverse(), inplace=True)

    qc.append(GlobalPhaseGate(math.pi))
    qc.x(range(n))

    mcz = ZGate().control(n-1)
    qc.append(mcz, list(range(n)))

    qc.x(range(n))

    qc.compose(zero_to_psi(n, T), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import pi, acos

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qubits = list(range(n))

    for i, t in enumerate(T):
        qc.ry(-2 * t, i)

    qc.x(qubits)
    qc.mcp(pi, qubits[1:], 0)
    qc.x(qubits)

    for i, t in enumerate(T):
        qc.ry(2 * t, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def b4(qc: QuantumCircuit) -> None:
    n = qc.num_qubits
    for i in range(n):
        qc.x(i)
    mcz = ZGate().control(n - 1)
    qc.append(mcz, range(n))

    for i in range(n):
        qc.x(i)

def b5(qc: QuantumCircuit) -> None:
    n = qc.num_qubits
    # Write your code here:
    for i in range(n):
        qc.h(i)
    b4(qc)
    for i in range(n):
        qc.h(i)

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(2 * T[i], i)
    b5(qc)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def b4(qc: QuantumCircuit) -> None:
    n = qc.num_qubits
    for i in range(n):
        qc.x(i)
    mcz = ZGate().control(n - 1)
    qc.append(mcz, range(n))

    for i in range(n):
        qc.x(i)

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(2 * T[i], i)
    b4(qc)
    for i in range(n):
        qc.ry(2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate

def rotate(n: int, T: list[float]) -> QuantumCircuit:
    # Write your code here:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.ry(2 * T[i], i)
    return qc

def b4(qc: QuantumCircuit) -> None:
    n = qc.num_qubits
    for i in range(n):
        qc.x(i)
    mcz = ZGate().control(n - 1)
    qc.append(mcz, range(n))

    for i in range(n):
        qc.x(i)

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.compose(rotate(n, T).inverse(), inplace=True)
    b4(qc)
    qc.compose(rotate(n, T), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(len(T)):
        qc.ry(-T[i]*2,i)

    for i in range(n):
        if not (1 << i) & 0:
            qc.x(i)

    qc.mcp(math.pi, list(range(n - 1)), n - 1)

    for i in range(n):
        if not (1 << i) & 0:
            qc.x(i)

    for i in range(len(T)):
        qc.ry(T[i]*2,i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    mc_z_gate = MCPhaseGate(pi, num_ctrl_qubits=n - 1)
    for i in range(n):
        qc.ry(2 * T[i], i)
        qc.x(i)
    qc.append(mc_z_gate, [i for i in range(n)])
    for i in range(n):
        qc.x(i)
        qc.ry(2 * T[i], i)
    return qc
'''


'''python
from math import pi

from qiskit import QuantumCircuit
from qiskit.circuit.library import MCPhaseGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    mc_z_gate = MCPhaseGate(pi, num_ctrl_qubits=n - 1)
    for i in range(n):
        qc.ry(2 * T[i], i)
        qc.x(i)
    qc.append(mc_z_gate, [i for i in range(n)])
    for i in range(n):
        qc.x(i)
        qc.ry(2 * T[i], i)
    return qc
'''


'''python
from math import pi

from qiskit import QuantumCircuit
from qiskit.circuit.library import MCPhaseGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    mc_z_gate = MCPhaseGate(pi, num_ctrl_qubits=n - 1)
    for i in range(n):
        qc.ry(2 * T[i], i)
        qc.x(i)
    qc.append(mc_z_gate, [i for i in range(n)])
    for i in range(n):
        qc.x(i)
        qc.ry(-2 * T[i], i)
    return qc
'''


'''python
from math import pi

from qiskit import QuantumCircuit
from qiskit.circuit.library import MCPhaseGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    mc_z_gate = MCPhaseGate(pi, num_ctrl_qubits=n - 1)
    for i in range(n):
        qc.ry(-2 * T[i], i)
        qc.x(i)
    qc.append(mc_z_gate, [i for i in range(n)])
    for i in range(n):
        qc.x(i)
        qc.ry(2 * T[i], i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for qubit,t in enumerate(T):
        qc.ry(2*t, qubit)
        qc.x(qubit)

    qc.mcp(np.pi, list(range(n-1)), n-1)

    for qubit,t in enumerate(T):
        qc.ry(-2*t, qubit)
        qc.x(qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for qubit,t in enumerate(T):
        qc.ry(2*t, qubit)
        qc.x(qubit)

    qc.mcp(np.pi, list(range(n-1)), n-1)

    for qubit,t in enumerate(T):
        qc.x(qubit)
        qc.ry(-2*t, qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for qubit,t in enumerate(T):
        qc.ry(2*t, qubit)
        qc.x(qubit)

    qc.mcp(np.pi, list(range(n-1)), n-1)

    for qubit,t in enumerate(T):
        qc.x(qubit)
        qc.ry(-2*t, qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as n

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for qubit,t in enumerate(T):
        qc.ry(-2*t, qubit)

        qc.x(qubit)

    qc.mcp(np.pi, list(range(n-1)), n-1)

    for qubit,t in enumerate(T):
        qc.x(qubit)
        qc.ry(2*t, qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for qubit,t in enumerate(T):
        qc.ry(-2*t, qubit)

        qc.x(qubit)

    qc.mcp(np.pi, list(range(n-1)), n-1)

    for qubit,t in enumerate(T):
        qc.x(qubit)
        qc.ry(2*t, qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(2*T[i],i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.ry(-2*T[i],i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(-2*T[i],i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.ry(2*T[i],i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    sub_qc = QuantumCircuit(n)
    for i, t in enumerate(T):
        sub_qc.ry(2 * t, i)

    qc.compose(sub_qc.inverse(), inplace=True)

    qc.x(range(n))
    qc.h(n - 1)
    qc.mcx(list(range(n - 1)), n - 1)
    qc.h(n - 1)
    qc.x(range(n))

    qc.compose(sub_qc, inplace=True)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import GlobalPhaseGate
import math
# from qiskit.quantum_info import Statevector

def b3(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.ry(2*T[i], i)
    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init = [0]*(2**n)
    # init[2] = 1
    # qc.initialize(init)

    # Write your code here:
    qc.compose(b3(n, T).inverse(), inplace=True)

    for i in range(n):
        qc.x(i)
    qc.h(0)
    qc.mcx(list(range(1, n)), 0)
    qc.h(0)
    for i in range(n):
        qc.x(i)
    qc.append(GlobalPhaseGate(math.pi))

    qc.compose(b3(n, T), inplace=True)

    return qc

# if __name__ == "__main__":
#     qc = solve(3, [0]*3)
#     print(Statevector(qc))
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
from math import pi

def solve(n: int, T) -> QuantumCircuit:
	qc = QuantumCircuit(n)
	for i in range(n):
		qc.ry(2 * T[i], i)
	qc.x(range(n))
	qc.h(n - 1)
	qc.mcx(list(range(n - 1)), n - 1)
	qc.h(n - 1)
	qc.x(range(n))
	for i in range(n):
		qc.ry(-2 * T[i], i)
	return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
from math import pi

def solve(n: int, T) -> QuantumCircuit:
	qc = QuantumCircuit(n)
	for i in range(n):
		qc.ry(2 * T[i], i)
	qc.x(range(n))
	qc.h(n - 1)
	qc.mcx(list(range(n - 1)), n - 1)
	qc.h(n - 1)
	qc.x(range(n))
	for i in range(n):
		qc.ry(2 * T[i], i)
	return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    for i in range(n):
        # Aplicar una rotación Ry de 2*T[i] al qubit i
        qc.ry(2 * T[i], i)
        # Aplicar la compuerta Z al qubit i
        qc.z(i)
        # Aplicar una rotación Ry de -2*T[i] al qubit i
        qc.ry(-2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # Paso 1: Preparar el estado |ψ⟩ aplicando RY(2T_i) a cada qubit
    for i in range(n):
        qc.ry(2 * T[i], i)

    # Paso 2: Implementar la reflexión 2|0⟩⟨0|^{⊗n} - I
    # Aplicar Hadamard al último qubit
    qc.h(n-1)

    # Aplicar puerta multi-controlada (MCX) con los primeros n-1 qubits como controles
    controls = list(range(n-1))
    target = n-1
    if n == 2:
        # Para n=2, no se necesitan ancillas
        qc.ccx(controls[0], controls[1], target)
    else:
        # Para n > 2, usar la puerta MCX estándar que maneja ancillas internamente
        qc.mcx(controls, target)

    # Aplicar nuevamente Hadamard al último qubit
    qc.h(n-1)

    # Paso 3: Deshacer la preparación del estado |ψ⟩ aplicando RY(-2T_i) a cada qubit
    for i in range(n):
        qc.ry(-2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import MCXGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # Paso 1: Preparar el estado |ψ⟩ aplicando RY(2T_i) a cada qubit
    for i in range(n):
        qc.ry(2 * T[i], i)

    # Paso 2: Implementar la reflexión 2|0⟩⟨0|^{⊗n} - I
    # Aplicar Hadamard al último qubit
    qc.h(n-1)

    # Aplicar puerta multi-controlada (MCX) con los primeros n-1 qubits como controles
    controls = list(range(n-1))
    target = n-1
    if n == 2:
        # Para n=2, no se necesitan ancillas
        qc.ccx(controls[0], controls[1], target)
    else:
        # Para n > 2, usar la puerta MCX estándar que maneja ancillas internamente
        qc.mcx(controls, target)

    # Aplicar nuevamente Hadamard al último qubit
    qc.h(n-1)

    # Paso 3: Deshacer la preparación del estado |ψ⟩ aplicando RY(-2T_i) a cada qubit
    for i in range(n):
        qc.ry(-2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import MCXGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # Paso 1: Preparar el estado |ψ⟩ aplicando RY(2T_i) a cada qubit
    for i in range(n):
        qc.ry(2 * T[i], i)

    # Paso 2: Implementar la reflexión 2|0⟩⟨0|^{⊗n} - I
    # Esto se logra reflejando sobre |0⟩^{⊗n}:
    # 1. Aplicar X a todos los qubits para convertir |0⟩^{⊗n} en |1⟩^{⊗n}
    qc.x(range(n))

    if n == 2:
        # Para n=2, usar una puerta CZ directamente
        qc.cz(0, 1)
    else:
        # Para n > 2, implementar una reflexión multi-controlada
        # Aplicar Hadamard al último qubit
        qc.h(n-1)

        # Aplicar la puerta MCX con los primeros n-1 qubits como controles y el último como objetivo
        qc.mcx(list(range(n-1)), n-1)

        # Aplicar nuevamente Hadamard al último qubit
        qc.h(n-1)

    # 2. Aplicar X a todos los qubits para revertir la inversión
    qc.x(range(n))

    # Paso 3: Deshacer la preparación del estado |ψ⟩ aplicando RY(-2T_i) a cada qubit
    for i in range(n):
        qc.ry(-2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import MCXGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # Paso 1: Preparar el estado |psi> aplicando RY(2T_i) a cada qubit
    for i in range(n):
        qc.ry(2 * T[i], i)

    # Paso 2: Implementar la reflexión 2|psi><psi| - I
    # Esto se logra reflejando sobre |0>^{⊗n}:
    # 1. Aplicar X a todos los qubits para convertir |0>^{⊗n} en |1>^{⊗n}
    qc.x(range(n))

    # 2. Aplicar la reflexión sobre |1>^{⊗n}
    if n == 1:
        qc.z(0)
    elif n == 2:
        qc.cz(0, 1)
    else:
        # Para n > 2, implementar una puerta multi-controlada Z
        qc.h(n-1)
        qc.mcx(list(range(n-1)), n-1)
        qc.h(n-1)

    # 3. Aplicar X a todos los qubits para revertir la inversión
    qc.x(range(n))

    # Paso 3: Deshacer la preparación del estado |psi> aplicando RY(-2T_i) a cada qubit
    for i in range(n):
        qc.ry(-2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import MCXGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # Paso 1: Preparar el estado |ψ⟩ aplicando RY(2T_i) a cada qubit
    for i in range(n):
        qc.ry(2 * T[i], i)

    # Paso 2: Implementar la reflexión 2|0⟩⟨0|^{⊗n} - I
    # 2.1 Aplicar X a todos los qubits para convertir |0⟩^{⊗n} en |1⟩^{⊗n}
    qc.x(range(n))

    # 2.2 Aplicar una puerta multi-controlada Z
    if n == 1:
        qc.z(0)
    elif n == 2:
        qc.cz(0, 1)
    else:
        # Para n > 2, implementar una puerta multi-controlada Z usando puertas Hadamard y MCX
        qc.h(n-1)
        qc.mcx(list(range(n-1)), n-1)
        qc.h(n-1)

    # 2.3 Aplicar X a todos los qubits para revertir la inversión
    qc.x(range(n))

    # 2.4 Aplicar una fase global de -1 para corregir la inversión en el estado |0⟩^{⊗n}
    qc.z(range(n))

    # Paso 3: Deshacer la preparación del estado |ψ⟩ aplicando RY(-2T_i) a cada qubit
    for i in range(n):
        qc.ry(-2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import MCXGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # Definir el subcircuito que prepara el estado |\psi⟩
    def prepare_psi():
        sub_qc = QuantumCircuit(n)
        for i in range(n):
            sub_qc.ry(2 * T[i], i)
        return sub_qc

    # Paso 1: Aplicar U para preparar |\psi⟩
    U = prepare_psi()
    qc.compose(U, inplace=True)

    # Paso 2: Implementar la reflexión sobre |0⟩^{⊗n}
    qc.x(range(n))
    if n == 1:
        qc.z(0)
    elif n == 2:
        qc.cz(0, 1)
    else:
        qc.h(n-1)
        qc.mcx(list(range(n-1)), n-1)
        qc.h(n-1)
    qc.x(range(n))

    # Paso 3: Aplicar U† para deshacer la preparación de |\psi⟩
    qc.compose(U.inverse(), inplace=True)  # Usando el hint proporcionado

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import MCXGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # Definir el subcircuito que prepara el estado |\psi⟩
    def prepare_psi():
        sub_qc = QuantumCircuit(n)
        for i in range(n):
            sub_qc.ry(2 * T[i], i)
        return sub_qc

    # Paso 1: Aplicar U para preparar |\psi⟩
    U = prepare_psi()
    #qc.compose(U, inplace=True)

    # Paso 2: Implementar la reflexión sobre |0⟩^{⊗n}
    qc.x(range(n))
    if n == 1:
        qc.z(0)
    elif n == 2:
        qc.cz(0, 1)
    else:
        qc.h(n-1)
        qc.mcx(list(range(n-1)), n-1)
        qc.h(n-1)
    qc.x(range(n))

    # Paso 3: Aplicar U† para deshacer la preparación de |\psi⟩
    qc.compose(U.inverse(), inplace=True)  # Usando el hint proporcionado

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import MCXGate

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    # Define the subcircuit that prepares |\psi⟩
    def prepare_psi():
        sub_qc = QuantumCircuit(n)
        for i in range(n):
            sub_qc.ry(2 * T[i], i)
        return sub_qc

    # Step 1: Apply U† to unprepare |\psi⟩
    qc.compose(prepare_psi().inverse(), inplace=True)

    # Step 2: Implement the reflection R = 2|0^n⟩⟨0^n| - I
    if n == 1:
        qc.z(0)
    elif n == 2:
        qc.cz(0, 1)
    else:
        # Apply a multi-controlled Z gate without X gates
        qc.h(n - 1)  # Apply Hadamard to the target qubit
        qc.mcx(list(range(n - 1)), n - 1)  # Multi-controlled X gate
        qc.h(n - 1)  # Apply Hadamard again to the target qubit

    # Step 3: Apply U to prepare |\psi⟩
    qc.compose(prepare_psi(), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    def prepare_psi(n: int, T: list[float]) -> QuantumCircuit:
        qc = QuantumCircuit(n)
        for i in range(n):
            qc.ry(2 * T[i], i)
        return qc

    # Paso 1: Preparar el estado |psi>
    psi_circuit = prepare_psi(n, T)
    qc.compose(psi_circuit, inplace=True)

    # Paso 2: Aplicar la operación de Grover
    # Aplicar reflexión sobre el estado |0> -> Hadamard en todos los qubits
    qc.h(range(n))
    # Aplicar X en todos los qubits
    qc.x(range(n))
    # Aplicar la puerta de múltiples control Z (una Z en el último qubit con todos los demás como control)
    qc.h(n - 1)
    qc.mcx(list(range(n - 1)), n - 1)  # mcx con n-1 controles
    qc.h(n - 1)
    # Aplicar X de nuevo
    qc.x(range(n))
    # Aplicar Hadamard de nuevo en todos los qubits
    qc.h(range(n))

    # Paso 3: Aplicar la reflexión sobre el estado |psi>
    qc.compose(psi_circuit.inverse(), inplace=True)
    qc.compose(psi_circuit, inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    def prepare_psi(n: int, T: list[float]) -> QuantumCircuit:
        qc = QuantumCircuit(n)
        for i in range(n):
            qc.ry(2 * T[i], i)
        return qc

    # Paso 1: Preparar el estado |psi>
    psi_circuit = prepare_psi(n, T)
    qc.compose(psi_circuit, inplace=True)

    # Paso 2: Aplicar la operación de Grover
    # Aplicar reflexión sobre el estado |0> -> Hadamard en todos los qubits
    qc.h(range(n))
    # Aplicar X en todos los qubits
    qc.x(range(n))
    # Aplicar la puerta de múltiples control Z (una Z en el último qubit con todos los demás como control)
    qc.h(n - 1)
    qc.mcx(list(range(n - 1)), n - 1)  # mcx con n-1 controles
    qc.h(n - 1)
    # Aplicar X de nuevo
    qc.x(range(n))
    # Aplicar Hadamard de nuevo en todos los qubits
    qc.h(range(n))

    # Paso 3: Aplicar la reflexión sobre el estado |psi>
    qc.compose(psi_circuit.inverse(), inplace=True)
    "qc.compose(psi_circuit, inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    def prepare_psi(n: int, T: list[float]) -> QuantumCircuit:
        qc = QuantumCircuit(n)
        for i in range(n):
            qc.ry(2 * T[i], i)
        return qc

    # Paso 1: Preparar el estado |psi>
    psi_circuit = prepare_psi(n, T)
    qc.compose(psi_circuit, inplace=True)

    # Paso 2: Aplicar la operación de Grover
    # Aplicar reflexión sobre el estado |0> -> Hadamard en todos los qubits
    qc.h(range(n))
    # Aplicar X en todos los qubits
    qc.x(range(n))
    # Aplicar la puerta de múltiples control Z (una Z en el último qubit con todos los demás como control)
    qc.h(n - 1)
    qc.mcx(list(range(n - 1)), n - 1)  # mcx con n-1 controles
    qc.h(n - 1)
    # Aplicar X de nuevo
    qc.x(range(n))
    # Aplicar Hadamard de nuevo en todos los qubits
    qc.h(range(n))

    # Paso 3: Aplicar la reflexión sobre el estado |psi>
    qc.compose(psi_circuit.inverse(), inplace=True)
    #qc.compose(psi_circuit, inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    # Paso 1: Definir el circuito U que prepara |psi>
    U = QuantumCircuit(n)
    for i in range(n):
        U.ry(2 * T[i], i)

    # Aplicar U al circuito principal
    qc.compose(U, inplace=True)

    # Paso 2: Aplicar la reflexión 2|0><0| - I
    # Aplicar X a todos los qubits
    qc.x(range(n))

    # Aplicar una puerta Z controlada multi-qubit
    # Implementamos una puerta Z multi-controlada utilizando una puerta MCX con Hadamard
    qc.h(n-1)  # Aplicar Hadamard al último qubit
    qc.mcx(list(range(n-1)), n-1)  # Puerta MCX con los primeros n-1 qubits como controles
    qc.h(n-1)  # Aplicar Hadamard nuevamente al último qubit

    # Aplicar X nuevamente a todos los qubits
    qc.x(range(n))

    # Paso 3: Aplicar U† (inversa de U)
    qc.compose(U.inverse(), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate, GlobalPhaseGate
import numpy as np
import math

def zero_to_psi(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    for idx in range(0, n):
        qc.ry(2*T[idx], idx)

    return qc

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

    qc.compose(zero_to_psi(n, T).inverse(), inplace=True)

    qc.append(GlobalPhaseGate(math.pi))
    qc.x(range(n))

    mcz = ZGate().control(n-1)
    qc.append(mcz, list(range(n)))

    qc.x(range(n))

    qc.compose(zero_to_psi(n, T), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    #Ry gateによる位相変換を実行
    for i in range(n):
        qc.ry(2 * T[i], i)

    #数学的な確証はないがこうすればうまくいくはず
    for i in range(n):
        qc.ry(-2 * T[i], i)

    #これは確定でいるので書いておく
    qc.h(n - 1)
    qc.mcx(list(range(n - 1)), n - 1)
    qc.h(n - 1)

    #再度反転！確証はない！
    for i in range(n):
        qc.ry(2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    #Ry gateによる位相変換を実行
    for i in range(n):
        qc.ry(2 * T[i], i)

    #数学的な確証はないがこうすればうまくいくはず
    for i in range(n):
        qc.ry(-2 * T[i], i)

    #これは確定でいるので書いておく
    qc.h(n - 1)
    qc.mcx(list(range(n - 1)), n - 1)
    qc.h(n - 1)

    #再度反転！確証はない！
    for i in range(n):
        qc.ry(2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    for i in range(n):
        qc.ry(2 * T[i], i)

    for i in range(n):
        qc.ry(-2 * T[i], i)

    qc.h(n - 1)
    qc.mcx(list(range(n - 1)), n - 1)
    qc.h(n - 1)

    for i in range(n):
        qc.ry(2 * T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:
    k = 5
    for i in range(n):
        qc.h(i)
    for _ in range(k):
        qc.append(o,qargs = range(n))
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:
    k = 5
    for i in range(n):
        qc.h(i)
    for _ in range(k):
        qc.append(o,qargs = range(n))
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n))
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n+1))
    qc.z(n)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    k = 5
    for _ in range(k);
        qc.append(o,qargs = range(n+1))
        qc.z(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    k = 5
    for j in range(k);
        qc.append(o,qargs = range(n+1))
        qc.z(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n+1))
    qc.z(n)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n+1))
    qc.z(n)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n+1))
    qc.z(n)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n+1))
    qc.z(n)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n+1))
    qc.z(n)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    qc.append(o,qargs = range(n+1))
    qc.z(n)
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    for _ in range(5):
        qc.append(o,qargs = range(n+1))
        qc.z(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    for _ in range(10):
        qc.append(o,qargs = range(n+1))
        qc.z(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    for _ in range(45):
        qc.append(o,qargs = range(n+1))
        qc.z(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    for _ in range(35):
        qc.append(o,qargs = range(n+1))
        qc.z(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    for _ in range(10):
        qc.x(n)
        qc.h(n)
        qc.append(o,qargs = range(n+1))
        qc.h(n)
        qc.x(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    for _ in range(15):
        qc.x(n)
        qc.h(n)
        qc.append(o,qargs = range(n+1))
        qc.h(n)
        qc.x(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    for _ in range(25):
        qc.x(n)
        qc.h(n)
        qc.append(o,qargs = range(n+1))
        qc.h(n)
        qc.x(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
import math
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    k = int(math.pi*n**0.5/4)
    for _ in range(k):
        qc.x(n)
        qc.h(n)
        qc.append(o,qargs = range(n+1))
        qc.h(n)
        qc.x(n)
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate
import math
"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:-
    for i in range(n):
        qc.h(i)
    k = int((math.pi*n**0.5)/4)
    for _ in range(k):
        qc.append(o,qargs = range(n+1))
        qc.z(n)
        qc.append(o,qargs = range(n+1))
        for i in range(n):
            qc.h(i)
        for i in range(n):
            qc.x(i)
        qc.append(ZGate().control(n-1),qargs = range(n))
        for i in range(n):
            qc.x(i)
        for i in range(n):
            qc.h(i)
    return qc
'''