'''python
import math
from qiskit import QuantumCircuit
from qiskit import QuantumCircuit, QuantumRegister

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)
    return qc

if __name__ == "__main__":
    qc = solve(3, [0.1, 0.2, 0.3])
    print(qc)
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    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)

    for i in range(n):
        theta = T[i] * 2.0
        qc.ry(theta, 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, r in enumerate(T):
        qc.ry(i*2, r)

    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)

    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:
    phi = 0
    lam = np.pi
    for i,t in enumarate(T):
        theta = 2*t
        qc.u(theta, phi, lam, 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:
    phi = 0
    lam = np.pi
    for i,t in enumerate(T):
        theta = 2*t
        qc.u(theta, phi, lam, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math
# from qiskit.quantum_info import Statevector

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)
    return qc

# if __name__ == "__main__":
#     qc = solve()
#     print(Statevector(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.u(2*T[i], pi/2, 0)
    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(n):
        mat = [[cos(T[i]), sin(T[i])],
               [0,0]]
        qc.UnitaryGate( mat , [i])
    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(n):
        #mat = [[cos(T[i]), sin(T[i])],
        #       [0,0]]
        #qc.UnitaryGate( mat , [i])
        qc.rx(2*T[i])
        qc.s(i)
    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(n):
        #mat = [[cos(T[i]), sin(T[i])],
        #       [0,0]]
        #qc.UnitaryGate( mat , [i])
        qc.rx(2*T[i], i)
        qc.s(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):
        qc.rx(-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):
        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):
        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):
        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):
        qc.ry(-T[i] * 2)
    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)
    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)
    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,
# )

"""
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:

    for i in range(n):
        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:
    for i in range(n):
        qc.ry(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):
        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 len(T)
        qc.Ry(T[i],i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    j=0
    # Write your code here:
    for i in T
        qc.Ry(i,j)
        j+=1
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    j=0
    # Write your code here:
    for i in T:
        qc.Ry(i,j)
        j+=1
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    j=0
    # Write your code here:
    for i in T:
        qc.ry(i,j)
        j+=1
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
      qc.r(2*T[i], math.pi/2, 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):
        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:
    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):
        qc.ry(2*T[i],n-1-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):
        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):
        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):
        qc.ry(T[i]*2, i)
    return qc
'''


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

"""
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:
    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):
        qc.u(2*T[i], 0, 0, 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):
        qc.ry(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):
        qc.ry(T[i], n - i - 1)
    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, n - i - 1)
    return qc
'''


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

def solve(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
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i,t in enumurate[T]:
        qc.p(T*2,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,t in enumurate[T]:
        qc.p(t*2,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,t in enumrate[T]:
        qc.p(t*2,i)e

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i,t in enumrate[T]:
        qc.p(t*2,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,t in enumrate[T]:
        qc.ry(t*2,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,t in enumerate[T]:
        qc.ry(t*2,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(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:
    for i in range(n):
        theta = T[i]

        qc.ry(2 * theta, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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(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 _ in range(n):
        qc.ry(T[_] * 2, _)
    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(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):
        qc.ry(i, T[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):
        qc.ry(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):
        qc.ry(-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, t in enumerate(T):
        qc.ry(2 * t, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.ry(2*T[a], a)
    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)
        qc.p(2*T[i],i)
        qc.h(i)
        qc.p(math.pi/2,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):
        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:
    for i in range(n):
        qc.h(i)
        qc.ry(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):
        # qc.h(i)
        circuit.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):
        qc.h(i)
        circuit.ry(2 * T[i], i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Apply RY gates to each qubit
    for i in range(n):
        qc.ry(T[i], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, T: list[float]) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        theta = T[i]
        qc.ry(2 * theta, i)  # Apply rotation around Y-axis
    return qc
'''


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

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

    anc = QuantumRegister(n)
    qc.add_register(anc)

    def ccx_chain(n):
        regx, anc = QuantumRegister(n), QuantumRegister(n)
        qc = QuantumCircuit(regx, anc)

        qc.x(regx)
        for idx in range(len(regx)):
            if idx == 0:
                qc.cx(regx[0], anc[0])
            else:
                qc.ccx(regx[idx], anc[idx-1], anc[idx])

        return qc

    qc.compose(ccx_chain(n), inplace=True)
    qc.z(anc[-1])
    qc.compose(ccx_chain(n).inverse(), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)
    qc.h(0)
    qc.mcx(control_qubits=list(range(1,n)), target_qubits=0)
    qc.h(0)
    for i in range(n):
        qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.mcx(control_qubits=range(n-1), target_qubit=n-1, ctrl_state=0)
    qc.x(n-1)
    qc.z(n-1)
    qc.x(n-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.mcx(control_qubits=list(range(n-1)), target_qubit=n-1, ctrl_state=0)
    qc.x(n-1)
    qc.z(n-1)
    qc.x(n-)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    qc.x(range(n))
    if n == 1:
        qc.z(0)
    else:
        qc.h(n - 1)
        qc.mct(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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    aux = QuantumRegister(1)
    qc.add_bits(aux)

    qc.x(aux)
    qc.h(aux)
    qc.mcx(control_qubits=list(range(n)), target_qubit=aux, ctrl_state=0)
    qc.h(aux)
    qc.x(aux)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(1)
    qc.z(0)

    return qc
'''


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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.mcz(range(n-1), n)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.mcz(range(n-1), n-1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        qc.x(i)

    qc.h(n-1)
    qc.mcx([range(n-1)], n-1)
    qc.h(n-1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(n-1)
    qc.mcx([range(n-1)], n-1)
    qc.h(n-1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.mcx([range(1,n)], 0)
    qc.h(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.mcx([range(n-1,0,-1)], 0)
    qc.h(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        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.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        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)
        qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        qc.x(i)
    qc.barrier()
    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)
    qc.h(n-1)
    qc.barrier()

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

    return qc.reverse_bits()
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)
    qc.h(0)
    lists = []
    for i in range(1,n):
        lists.append(i)
    qc.mcx(lists,0)
    qc.h(0)
    for i in range(n):
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)
    qc.h(0)
    lists = []
    for i in range(1,n):
        lists.append(i)
    qc.mcx(list,0)
    qc.h(0)
    for i in range(n):
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)
    qc.h(0)
    lists = []
    for i in range(1,n):
        lists.append(i)
    qc.mcx(lists,0)
    qc.h(0)
    for i in range(n):
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    for i in range(1, n):
        qc.cx(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(1, n):
        qc.cx(0, i)

    for i in range(1, n):
        qc.z(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(1, n):
        qc.cx(0, i)

    for i in range(1, n):
        qc.z(i)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(1, n):
        qc.z(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(range(n))
    qc.h(n - 1)
    qc.mct(list(range(n - 1)), n - 1)
    qc.h(n - 1)
    qc.x(range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(range(n))
    qc.h(n - 1)
    qc.cx(0, 1)
    qc.tdg(1)
    qc.cx(1, n - 1)
    qc.t(1)
    qc.cx(0, 1)
    qc.tdg(1)
    qc.cx(1, n - 1)
    qc.t(1)
    qc.h(n - 1)
    qc.x(range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    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)
    for i in range(n):
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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)
    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 solve(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
'''


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

def solve(n: int) -> QuantumCircuit:
    array = list(range(1, n))

    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        qc.x(i)
    qc.h(0)
    qc.mcx(array,0)
    qc.h(0)
    for i in range(n):
        qc.h(i)
        qc.x(i)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    array = list(range(1, n))

    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        # qc.x(i)
    # qc.h(0)
    qc.mcx(array,0)
    # qc.h(0)
    for i in range(n):
        qc.h(i)
        # qc.x(i)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    array = list(range(1, n))

    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        qc.x(i)
    qc.mcx(array,0)
    for i in range(n):
        qc.h(i)
        qc.x(i)

    return qc
'''


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

def diffuser_matrix(n):
    # Dimension of the matrix
    dim = 2 ** n

    # Create |00...0><00...0| which is all zeros except the (0, 0) element
    projector = np.zeros((dim, dim))
    projector[0, 0] = 1

    # Construct the diffuser matrix: A = 2 * projector - I
    diffuser = 2 * projector - np.eye(dim)

    return diffuser

def solve(n: int) -> QuantumCircuit:
    array = list(range(0,n))
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    qc.unitary(diffuser_matrix(n), array)
    for i in range(n):
        qc.h(i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    array = list(range(0,n))
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.x(i)
    # qc.unitary(diffuser_matrix(n), array)
    qc.h(0)
    qc.mcx(array,0)
    qc.h(0)
    for i in range(n):
        qc.x(i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    array = list(range(1,n))
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.x(i)
    # qc.unitary(diffuser_matrix(n), array)
    qc.h(0)
    qc.mcx(array,0)
    qc.h(0)
    for i in range(n):
        qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if not (1 << i) & 0:
            qc.x(i)

    qc.mcp(theta, list(range(n - 1)), n - 1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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)

    return qc
'''


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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(range(n))

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

    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np
from qiskit.circuit.library.standard_gates import XGate

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    control = [0] * n
    for i in range(n):
        control[i]=i
    for i in range(n):
        qc.x(i)
    custom = qc.ZGate().control(n-1)
    qc.ry(np.pi*2,n-1)
    qc.append(custom, control)
    for i in range(n):
    qc.x(i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    control = [0] * n
    for i in range(n):
        control[i]=i
    for i in range(n):
        qc.x(i)
    custom = qc.ZGate().control(n-1)
    qc.ry(np.pi*2,n-1)
    qc.append(custom, control)
    for i in range(n):
    qc.x(i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    abc = [0] * n
    for i in range(n):
        abc[i]=i
    for i in range(n):
        qc.x(i)
    custom = qc.ZGate().control(n-1)
    qc.ry(np.pi*2,n-1)
    qc.append(custom, abc)
    for i in range(n):
    qc.x(i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    abc = [0] * n
    for i in range(n):
        abc[i]=i
    for i in range(n):
        qc.x(i)
    custom = qc.ZGate().control(n-1)
    qc.ry(np.pi*2,n-1)
    qc.append(custom, abc)
    for i in range(n):
        qc.x(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) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    abc = [0] * n
    for i in range(n):
        abc[i]=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)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for qubit in range(n):
        qc.h(qubit)  # Llevar superposición
    qc.z(0) #Cambiar la fase de 0

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(n)
    for i in range(n):
        qc.cz(n, i)
    qc.measure(n, 0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(range(n))
    for i in range(n - 1):
        qc.cz(i,i + 1)
    qc.x(range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(range(n))
    for i in range(n):
        qc.cz(i,i + 1)
    qc.x(range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


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

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


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init = [0]*(2**n)
    # init[1] = 1
    # qc.initialize(init)
    # Write your code here:
    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))
    return qc

# if __name__ == "__main__":
#     qc = solve(3)
#     print(Statevector(qc))
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    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)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Paso 1: Aplicar puertas X a todos los qubits para convertir |00...0> en |11...1>
    qc.x(range(n))

    # Paso 2: Aplicar una puerta Z controlada por todos los qubits
    # Implementación de una puerta Z multi-controlada:
    # - Aplicar una puerta H al último qubit
    # - Aplicar una puerta MCX (Toffoli multi-controlada) con los n-1 primeros qubits como controles y el último como objetivo
    # - Aplicar una puerta H al último qubit nuevamente
    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)  # Multi-Controlled X gate
    qc.h(n-1)

    # Paso 3: Aplicar nuevamente puertas X a todos los qubits para restaurar los estados originales
    qc.x(range(n))

    return qc

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1,n):
        qc.z(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    aux = QuantumRegister(1)
    qc.add_bits(aux)

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

    qc.mcx(list(range(n)), aux[0])
    qc.z(aux[0])
    qc.mcx(list(range(n)), aux[0])

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

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    aux = QuantumRegister(1)
    qc.add_bits(aux)

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

    qc.mcx(list(range(n)), aux[0])
    qc.z(aux[0])
    qc.mcx(list(range(n)), aux[0])

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

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    aux = QuantumRegister(1)
    qc.add_bits(aux)

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

    qc.mcx(list(range(n)), n)
    qc.z(n)
    qc.mcx(list(range(n)), n)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

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

    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(range(n))
    qc.mcz([range(n-1)], n)
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.z(range(n))
    qc.mcz([range(n-1)], n)
    # qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(range(n))
    # qc.mcz([range(n-1)], n)
    # qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(range(n))
    # qc.mcz([range(n-1)], n)
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(range(n))
    qc.mcp(math.pi, [range(n-1)], n)
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(range(n))
    qc.mcp(math.pi/2, [range(n-1)], n)
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.x(range(n))
    qc.mcp(math.pi, [range(n-1)], n)
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.x(range(n))
    qc.mcp(math.pi/2, [range(n-1)], n)
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.x(range(n))
    qc.mcp(math.pi/2, [range(n-1)], n - 1)
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.x(range(n))
    qc.mcp(math.pi, [range(n-1)], n - 1)
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.z(range(n))
    qc.mcp(math.pi, [range(n-1)], n - 1)
    qc.z(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(range(n))
    qc.mcp(math.pi, [range(n-1)], n - 1)
    qc.h(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.z(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.extensions import UnitaryGate
import numpy as np

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

    # Step 1: Apply Hadamard gates to all qubits
    qc.h(range(n))

    # Step 2: Apply the phase flip to the |0⟩ state
    # This can be done by applying a multi-controlled Z gate
    # First, apply X gates to all qubits to flip |0⟩ to |1⟩
    qc.x(range(n))
    # Then apply a multi-controlled Z gate
    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)  # Multi-controlled X gate
    qc.h(n-1)
    # Finally, apply X gates again to flip back to |0⟩
    qc.x(range(n))

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Step 1: Apply Hadamard gates to all qubits to create superposition
    qc.h(range(n))

    # Step 2: Apply the phase flip to the |0⟩ state
    # This is equivalent to applying a multi-controlled Z gate
    # To implement this, we use X gates and a multi-controlled X gate
    # Flip all qubits to |1⟩ using X gates
    qc.x(range(n))
    # Apply a multi-controlled Z gate (using H gates and a multi-controlled X gate)
    qc.h(n-1)  # Apply H to the last qubit
    qc.mcx(list(range(n-1)), n-1)  # Multi-controlled X gate (Toffoli-like)
    qc.h(n-1)  # Apply H again to the last qubit
    # Flip all qubits back to |0⟩ using X gates
    qc.x(range(n))

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.extensions import UnitaryGate

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

    # Step 1: Apply Hadamard gates to all qubits
    qc.h(range(n))

    # Step 2: Apply the phase flip to the |0⟩ state
    # This can be done by applying a multi-controlled Z gate
    # First, apply X gates to all qubits to flip |0⟩ to |1⟩
    qc.x(range(n))
    # Then apply a multi-controlled Z gate
    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)  # Multi-controlled X gate
    qc.h(n-1)
    # Finally, apply X gates again to flip back to |0⟩
    qc.x(range(n))

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Apply the multi-qubit |0><0| projector scaled by 2 and subtract identity
    qc.h(range(n))  # Apply Hadamard gates to all qubits
    qc.append(oracle(n), range(n))  # Apply the custom oracle
    qc.h(range(n))  # Apply Hadamard gates to all qubits again

    return qc

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

    # Implement 2|0><0| - I
    qc.x(range(n))  # Flip all qubits
    qc.h(n - 1)  # Hadamard on last qubit
    qc.mcx(list(range(n - 1)), n - 1)  # Multi-control Toffoli
    qc.h(n - 1)  # Hadamard on last qubit
    qc.x(range(n))  # Flip all qubits back

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import MCXGate
import numpy as np

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

    # Apply the identity matrix (which does nothing)
    # We will implement 2|0><0| - I

    # Step 1: Apply an MCX (multi-controlled X) gate to flip the |0...0> state to |1...1>
    qc.append(MCXGate(n-1), list(range(n-1)) + [n-1])

    # Step 2: Apply a Z-gate (phase shift) on the |1...1> state
    qc.z(n-1)

    # Step 3: Apply the MCX gate again to revert the |0...0> state
    qc.append(MCXGate(n-1), list(range(n-1)) + [n-1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1, 2**n):
        qc.x(range(n))
        qc.z(range(n))
        qc.x(range(n))

    return qc
'''


'''python
import math
from qiskit import QuantumCircuit
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1, 2**n):
        bits: list[bool] = [bool(int(x)) for x in f"{i:0{n}b}"]
        for j, bit in enumerate(bits):
            if bit:
                qc.x(j)
        qc.h(range(n))
        qc.mcx(list(range(n-1)), n-1)
        qc.h(range(n))
        for j, bit in enumerate(bits):
            if bit:
                qc.x(j)
    return qc
'''


'''python
import math
from qiskit import QuantumCircuit
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(2**n - 1):
        bits: list[bool] = [bool(int(x)) for x in f"{i:0{n}b}"]
        for j, bit in enumerate(bits):
            if bit:
                qc.x(j)
        qc.h(range(n))
        qc.mcx(list(range(n-1)), n-1)
        qc.h(range(n))
        for j, bit in enumerate(bits):
            if bit:
                qc.x(j)
    return qc

if __name__ == "__main__":
    qc = solve(3)
    print(qc)
'''


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

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

    L = 0

    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)

    return qc
'''


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

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

    L = 0

    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)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    L = 0

    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)

    return qc
'''


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

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

    L = 0

    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)

    return qc
'''


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

def solve(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
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.ry(2*pi, 0)
    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)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.ry(2*pi, 0)
    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)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.mcx([0, 1, 2], 3)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
     I = (-1)*np.identity(2**n)
    # Write your code here:
    I[0][0] = 1
    ls = [i for i in range(n)]
    qc.UnitaryGate(I, ls)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
     I = (-1)*np.identity(2**n)
    # Write your code here:
    I[0][0] = 1
    ls = [i for i in range(n)]
    qc.unitary(I, ls)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    I = (-1)*np.identity(2**n)
    # Write your code here:
    I[0][0] = 1
    ls = [i for i in range(n)]
    qc.unitary(I, ls)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    I = (-1)*np.identity(2**n, dtype = int)
    # Write your code here:
    I[0][0] = 1
    ls = [i for i in range(n)]
    qc.unitary(I, ls)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1, n):
        qc.cz(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1, n):
        qc.z(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1, n):
        qc.z(i)
        qc.cz(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1, n):
        qc.cz(0, i)
    for i in range(n):
        qc.z(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.z(i)
    for i in range(1, n):
        qc.cz(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.z(i)
    for i in range(1, n):
        qc.cx(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.z(i)
    qc.h(0)
    for i in range(1, n):
        qc.cz(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        qc.x(i)
    qc.h(n-1)
    qc.mcx(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

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

    for i in range(n):
        qc.x(i)
    qc.h(n-1)
    qc.mcx(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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for qubit in range(n):
        qc.z(qubit)

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

    qc.append(MCXGate(n - 1), [i for i in range(n - 1)] + [n - 1])

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

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for qubit in range(n):
        qc.z(qubit)

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

    qc.append(MCXGate(n - 1), [i for i in range(n - 1)] + [n - 1])

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if i == 0:
            qc.z(i)
        else:
            qc.mcz(list(range(i)), i)
        qc.x(i)
    for i in range(n):
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if i == 0:
            qc.z(i)
        else:
            qc.mcp(math.pi, list(range(i)), i)
        qc.x(i)
    for i in range(n):
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)
    qc.ccz()
    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)
    qc.mcp(4*math.pi,list(range(n - 1)),n - 1)
    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    for i in range(n):
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)
    qc.mcp(math.pi,list(range(n - 1)),n - 1)
    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    for i in range(n):
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    def make_U_s(nqubits):
    U_s = QuantumCircuit(nqubits)

    ## 2|0><0| - I の実装
    U_s.add_gate(to_matrix_gate(RZ(nqubits-1, 2*np.pi))) ## まず、位相(-1)を全ての状態に付与する。ゲート行列はarrary([[-1,0],[0,-1]])
    U_s.add_gate( X(nqubits-1) )
    ## 全てのi-th qubitが0の場合だけZゲートを作用させる
    CnZ = to_matrix_gate(Z(nqubits-1))
    for i in range(nqubits-1):
        control_index = i
        control_with_value = 0
        CnZ.add_control_qubit(control_index, control_with_value)
    U_s.add_gate( CnZ )
    U_s.add_gate( X(nqubits-1) )

    return U_s

    qc.U_s

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    def make_U_s(nqubits):
    U_s = QuantumCircuit(nqubits)

    ## 2|0><0| - I の実装
    U_s.add_gate(to_matrix_gate(RZ(nqubits-1, 2*np.pi))) ## まず、位相(-1)を全ての状態に付与する。ゲート行列はarrary([[-1,0],[0,-1]])
    U_s.add_gate( X(nqubits-1) )
    ## 全てのi-th qubitが0の場合だけZゲートを作用させる
    CnZ = to_matrix_gate(Z(nqubits-1))
    for i in range(nqubits-1):
        control_index = i
        control_with_value = 0
        CnZ.add_control_qubit(control_index, control_with_value)
    U_s.add_gate( CnZ )
    U_s.add_gate( X(nqubits-1) )

    return U_s

    U_s(qc)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    def make_U_s(nqubits):
    U_s = QuantumCircuit(nqubits)

    ## 2|0><0| - I の実装
    U_s.add_gate(to_matrix_gate(RZ(nqubits-1, 2*np.pi))) ## まず、位相(-1)を全ての状態に付与する。ゲート行列はarrary([[-1,0],[0,-1]])
    U_s.add_gate( X(nqubits-1) )
    ## 全てのi-th qubitが0の場合だけZゲートを作用させる
    CnZ = to_matrix_gate(Z(nqubits-1))
    for i in range(nqubits-1):
        control_index = i
        control_with_value = 0
        CnZ.add_control_qubit(control_index, control_with_value)
    U_s.add_gate( CnZ )
    U_s.add_gate( X(nqubits-1) )

    return U_s

    U_s.update_quantum_state(qc)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    def make_U_s(nqubits):
    U_s = QuantumCircuit(nqubits)

    ## 2|0><0| - I の実装
    U_s.add_gate(to_matrix_gate(RZ(nqubits-1, 2*np.pi))) ## まず、位相(-1)を全ての状態に付与する。ゲート行列はarrary([[-1,0],[0,-1]])
    U_s.add_gate( X(nqubits-1) )
    ## 全てのi-th qubitが0の場合だけZゲートを作用させる
    CnZ = to_matrix_gate(Z(nqubits-1))
    for i in range(nqubits-1):
        control_index = i
        control_with_value = 0
        CnZ.add_control_qubit(control_index, control_with_value)
    U_s.add_gate( CnZ )
    U_s.add_gate( X(nqubits-1) )

    return U_s
    U_s = make_U_s(nqubits)
    U_s.update_quantum_state(qc)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.quantum_info.operators.operator import Operator
import numpy as np

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    uni = np.identity(n) * -1
    uni[0][0] = 1
    operator = Operator(uni)
    qc.append(operator, [_ for _ in range(n)])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.rz(2*np.pi, n-1)
    qc.x(list(range(n)))

    # multi-controlled Zゲート
    qc.mcp(np.pi, list(range(n-1)), n-1)

    qc.x(list(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,
# )

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    qc.cz(0, 1)
    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from math import pi

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

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


'''python
from qiskit import QuantumCircuit

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

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

    qc.x(0)
    qc.h(0)
    qc.x(0)

    qc.mcry(2 * 3.14159, [i for i in range(n)], n)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.cz(0, 1)
    if n > 2:
        for i in range(2, n):
            qc.cz(0, i)
    qc.h(range(n))

    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(range(n))

    qc.x(range(n))

    qc.h(0)
    qc.mcx([0] + list(range(1, n)), n-1)

    qc.x(range(n))

    qc.h(range(n))

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
      qc.x(i)
    qc.mcp(pi, list(range(1, n)), 0)
    for i in range(n):
      qc.x(i)
    phase = QuantumCircuit(n, global_phase=pi).to_gate()
    qc.compose(phase, inplace=True)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
      qc.x(i)
    qc.mcp(pi, list(range(1, n)), 0)
    for i in range(n):
      qc.x(i)
    qc.global_phase = pi
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i inrange(n-2):
        qc.x(i+1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i inrange(n-3):
        qc.x(i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n-2):
        qc.x(i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n-2):
        qc.x(n-i-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n-2):
        qc.z(i+1)
        qc.x(i+1)
        qc.z(i+1)
        qx.x(i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n-2):
        qc.z(i+1)
        qc.x(i+1)
        qc.z(i+1)
        qc.x(i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    for i in range(n-2):
        qc.z(i+1)
        qc.x(i+1)
        qc.z(i+1)
        qc.x(i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    for i in range(n-2):
        qc.z(i+1)
        qc.x(i+1)
        qc.z(i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    for i in range(n-2):
        qc.z(i)
        qc.x(i)
        qc.z(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    for i in range(n-2):
        qc.z(i)
        qc.x(i)
        qc.z(i)
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    for i in range(n-1):
        qc.z(i+1)
        qc.x(i+1)
        qc.z(i+1)
        qc.x(i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.z(0)

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

        qc.h(i)
        qc.mcx(list(range(i)), i, mode='noancilla')
        qc.h(i)

        qc.x(range(i))

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    theta = np.pi
    controls = list(range(n-1))
    target = n-1
    for i in range(n):
        qc.x(i)

    qc.mcp(theta, controls, target)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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


'''python
from qiskit import QuantumCircuit

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

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

    for i in range(n):
        qc.x(i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    for i in range(n):
        qc.x(i)
    qc.z(0)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    qc.append(MCXGate(n-1), list(range(n)))
    qc.h(range(n))
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    qc.mcx(list(range(1,n)), 0)
    for i in range(n):
        qc.h(i)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.append(MCXGate(n-1), list(range(n)))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.mcp(math.pi, list(range(n-1)), n-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)
    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)
    for i in range(n):
        qc.h(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(range(n))
    for i in range(n-1):
        qc.cx(i, i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n-1):
        qc.cx(i, i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(1, n):
        qc.cx(0, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    gate = []
    for i in range(2**n):
        if i == 0:
            gate.append([1]+[0]*(2**n-1))
        else:
            gate.append([0]*(i)+[-1]+[0]*(2**n-i-1))
    qc.unitary(gate, [i for i in range(n)])
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
      qc.x(i)
    qc.mp(math.pi, list(range(n-1)), n-1)
    for i in range(n):
      qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    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)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


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

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

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

    return qc
'''


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

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

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

    return qc
'''


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

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

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

    for i in range(x):
        qc.x{i}

    return qc
'''


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

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

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

    for j in range(x):
        qc.x{j}

    return qc
'''


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

def solve(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 j in range(n):
        qc.x{j}

    return qc
'''


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

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

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

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

    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(1, 1 << n):
        for j in range(n):
            if i >> j & 1:
                qc.x(j)
        qc.append(ZGate().control(n - 1), range(n))
        for j in range(n):
            if i >> j & 1:
                qc.x(j)
    qc.x(range(n))
    return qc
'''


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

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

    for i in range(1, 1 << n):
        for j in range(n):
            if i >> j & 1:
                qc.x(j)
        qc.append(ZGate().control(n - 1), range(n))
        for j in range(n):
            if i >> j & 1:
                qc.x(j)
    qc.x(range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Apply a Hadamard gate to all qubits to create superposition
    for qubit in range(n):
        qc.h(qubit)

    # Apply a phase shift of π to all qubits except the first one (|0> state)
    for qubit in range(1, n):
        qc.z(qubit)  # Z gate applies a phase of π to |1> state

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for l in range(1, 2^n + 1):
        for i in range(n):
            if not ((l >> i) & 1):
                qc.x(i)
        if n == 1:
            qc.z(0)
        else:
            qc.append(ZGate().control(n - 1), range(n))
        for i in range(n):
            if not ((l >> i) & 1):
                qc.x(i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.rx(math.pi,0)
    for i in range(n-1):
        qc.x(i)
    qc.append(ZGate().control(n-1),qargs = range(n))
    for i in range(n):
        qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
import math
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.rx(2*math.pi,0)
    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)
    return qc
'''


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

def solve(n: int, T) -> QuantumCircuit:
	qc = QuantumCircuit(n)
	for i in range(n):
		qc.x(i)
	qc.append(ZGate().control(n - 1), list(range(n)))
	for i in range(n):
		qc.x(i)
	return qc
'''


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

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


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

def b4(qc: QuantumCircuit) -> None:
    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) -> QuantumCircuit:
    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)

    return qc
'''


'''python
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) -> QuantumCircuit:
    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)

    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) -> QuantumCircuit:
    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)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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
'''


'''python
from qiskit import QuantumCircuit

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

    # Step 1: Apply Hadamard gates to create |ψ⟩
    for i in range(n):
        qc.h(i)

    # Step 2: Apply the Grover diffusion operator (2|ψ⟩⟨ψ| - I)

    # Apply Hadamard again
    for i in range(n):
        qc.h(i)

    # Apply X gates
    for i in range(n):
        qc.x(i)

    # Multi-controlled Z gate
    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)
    qc.h(n-1)

    # Apply X gates again
    for i in range(n):
        qc.x(i)

    # Apply Hadamard again
    for i in range(n):
        qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def reflect(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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)
    # Write your code here:
    qc.h(range(n))
    qc.composer(reflect(n), inplace = True)
    qc.h(range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit

def reflect(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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)
    # Write your code here:
    qc.h(range(n))
    qc.compose(reflect(n), inplace=True)
    qc.h(range(n))
    return qc
'''


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

def reflect(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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)
    # Write your code here:
    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 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
import numpy as np
from qiskit.circuit.library.standard_gates import ZGate, HGate

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    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.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.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, Aer, transpile, assemble, execute

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

    qc.h(range(n))

    qc.x(range(n))

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

    qc.x(range(n))

    return qc

if __name__ == "__main__":
    n = 2
    qc = solve(n)
    print(qc.draw())
'''


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

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

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

    qc.x(range(n))

    for qubit in range(n-1):
        qc.cx(qubit, n-1)

    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> 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 puertas X a todos los qubits
    qc.x(range(n))

    # Paso 3: Aplicar una puerta Z multi-controlada
    # Esto se logra mediante:
    # a. Aplicar una puerta Hadamard al último qubit
    qc.h(n-1)

    # b. 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)

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

    # Paso 4: Aplicar nuevamente puertas X a todos los qubits para revertir la transformación
    qc.x(range(n))

    # Paso 5: Aplicar puertas Hadamard a todos los qubits nuevamente para volver a la base computacional
    qc.h(range(n))

    return qc
'''


'''python
from math import pi

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

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


'''python
from math import pi

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

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


'''python
from math import pi

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

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


'''python
from qiskit import QuantumCircuit

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

    qc.z(0)

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

        qc.h(i)
        qc.mcx(list(range(i)), i, mode='noancilla')
        qc.h(i)

        qc.x(range(i))

    return qc

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

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

    return qc
'''


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

def solve(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
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # n量子ビットの回路を作成

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

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

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

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # n量子ビットの回路を作成

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

    return qc
'''


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

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

    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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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

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) -> QuantumCircuit:
    return diffusion_oracle(n)
'''


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

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) -> QuantumCircuit:
    return diffusion_oracle(n)
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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, QuantumRegister
from qiskit.circuit.library import PhaseGate, XGate, YGate, ZGate
from math import sqrt, acos, pi

def solve(n: int) -> QuantumCircuit:
	qc = QuantumCircuit(n)
	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

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

    # Step 1: Prepare the state |ψ⟩ = (1/sqrt(2^n)) * (|0⟩ + |1⟩ + ... + |(2^n-1)⟩)
    # This is done by applying Hadamard gates to all qubits
    for qubit in range(n):
        qc.h(qubit)

    # Step 2: Apply the operator A = 2 |ψ⟩⟨ψ| - I
    # We can implement |ψ⟩⟨ψ| using a series of controlled operations.

    # Create a controlled operation that flips the sign of the state |ψ⟩
    # This can be done by applying a series of CNOT gates based on the state |ψ⟩
    # The state |ψ⟩ is the equal superposition, so we can use the fact that
    # we want to apply a negative sign to the |ψ⟩ state.

    # The matrix A can be implemented as follows:
    # 1. Apply a Hadamard to create |ψ⟩
    # 2. Apply a series of CNOTs to create the effect of |ψ⟩⟨ψ| and then adjust for the identity.

    # The effect of 2|ψ⟩⟨ψ| can be achieved by applying a phase flip to the |ψ⟩ state.
    # We can use a multi-controlled Z gate to achieve this.

    # Apply a controlled-Z gate with all qubits as controls to flip the sign of |ψ⟩
    # This is equivalent to applying a phase of -1 to the |ψ⟩ state.
    qc.h(range(n))  # Apply Hadamard to all qubits to create |ψ⟩
    qc.z(range(n))  # Apply Z gate to all qubits to flip the sign of |ψ⟩
    qc.h(range(n))  # Apply Hadamard again to return to the computational basis

    # Step 3: The identity operation is already accounted for in the circuit.

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init = [0]*(2**n)
    # init[2] = 1
    # qc.initialize(init)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    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))
    for i in range(n):
        qc.h(i)
    return qc

# if __name__ == "__main__":
#     qc = solve(3)
#     print(Statevector(qc))
'''


'''python
from qiskit import QuantumCircuit

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

    #Gloverのゲートが出ることは対策済み

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

    for j in range(n):#反転じゃい
        qc.x(j)

    # 欲しい状態だけz gateで反転
    qc.h(n - 1)
    qc.mcx(list(range(n - 1)), n - 1)
    qc.h(n - 1)

    for k in range(n):#反転して戻しちゃえ
        qc.x(k)

    for l in range(n):#Hadamrd反転じゃい
        qc.h(l)

    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,
# )

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

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

    qc.h(range(n))

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

    qc.h(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    lists=[]
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    for i in range(n-1):
        lists.append(i)
    qc.mcz(lists,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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    lists=[]
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    for i in range(n-1):
        lists.append(i)
    qc.mct(lists,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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    lists=[]
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    for i in range(n-1):
        lists.append(i)
    qc.cz(0,1)
    for i in range(n):
        qc.x(i)
    for i in range(n):
        qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    lists=[]
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    for i in range(n-1):
        lists.append(i)
    for i in range (1,n):
        qc.cz(0,i)
    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
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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 math import pi

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

    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
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    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, 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 solve(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
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    for i in range(n):
        qc.x(i)
    qc.mcz(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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    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.standard_gates import GlobalPhaseGate
import math

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

def b5(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # init = [0]*(2**n)
    # init[2] = 1
    # qc.initialize(init)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    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))
    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(b5(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:
    qc.h(range(n))
    qc.barrier()
    qc.compose(o, inplace=True)
    qc.barrier()
    qc.append(QFT(n), range(n))
    qc.barrier()
    return qc
'''