'''python
from qiskit import QuantumCircuit

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

    for i in range(n-2,-1,-1):
        qc.dcx(i,i+1)
        qc.cx(i,i+1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
# import matplotlib.pyplot

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

    return qc

# solve(3).draw("mpl")
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n - 2, -1):
        qc.cx(i + 1, i)
        qc.cx(i, 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, -1):
        qc.cx(i, i + 1)
        qc.cx(i + 1, 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 - 2, -1, -1):
        qc.cx(i, i + 1)
        qc.cx(i + 1, 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,2):
        qc.cx(i-1,i)
        qc.cx(i,i-1)
        qc.cx(i-1,i)
    for i in range(((n-1)//2)*2,1,-2):
        qc.cx(i-2,i)
        qc.cx(i,i-2)
        qc.cx(i-2,i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for q in range(n-1, 0, -1):
        qc.cx(q-1, q)
        qc.cx(q, q-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 - 1, 0, -1):
        qc.cx(i-1, i)
        qc.cx(i, i-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Apply the cyclic shift only if x_(n-1) = 0 (controlled on qubit n-1 being |0⟩)
    for i in range(n - 2, -1, -1):
        qc.ccx(n - 1, i, i + 1)  # Controlled shift using CCX
        qc.cx(i + 1, i)
        qc.ccx(n - 1, i, i + 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # For n=2 case, we need a CNOT gate to handle |10⟩ → |01⟩
    # For larger n, we need to shift all bits right cyclically

    # Since xₙ₋₁ = 0 is guaranteed, we can use this fact
    # We can propagate values using CNOTs

    # Propagate values from right to left using CNOTs
    for i in range(n-2, -1, -1):
        qc.cx(i, i+1)

    # The leftmost qubit will be 0 (given constraint)
    # so we don't need to handle that case

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Implement the cyclic shift logic
    # Condition: x_(n-1) = 0, meaning last qubit is 0
    for i in range(n - 1, 0, -1):
        qc.cx(i - 1, i)  # Perform CNOTs to shift

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # For cyclic shift when last qubit (xₙ₋₁) = 0
    # We can use CNOT gates to implement the shift

    # Apply CNOT gates in reverse order to shift the bits
    for i in range(n-1):
        qc.cx(i, i+1)

    # Apply CNOT gates in forward order to complete the transformation
    for i in range(n-2, -1, -1):
        qc.cx(i, i+1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Perform the cyclic shift
    for i in range(n-1, 0, -1):
        qc.cx(i-1, i)

    # Swap the first and last qubit states
    qc.cx(n-1, 0)

    return qc

# Example usage:
n = 2
qc = solve(n)
print(qc)
'''


'''python
from qiskit import QuantumCircuit

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

    # For n qubits, we need to perform a controlled cyclic shift
    # First, connect adjacent qubits with CNOT to propagate values
    for i in range(n-1):
        qc.cx(i, i+1)

    # The last qubit now holds the shifted value
    # We need to clear the intermediate states
    for i in range(n-2, -1, -1):
        qc.cx(i, i+1)

    # Finally, connect first and last qubit to complete the cycle
    qc.cx(n-1, 0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Perform the cyclic shift
    for i in range(n-1):
        qc.cx(i, i+1)  # CNOT from qubit i to qubit i+1

    # Handle the last qubit shifting to the first position
    qc.cx(n-1, 0)

    return qc

# Example usage:
n = 2
qc = solve(n)
print(qc)
'''


'''python
ffrom 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)

    # Perform the cyclic shift
    for i in range(n-1, 0, -1):
        qc.cx(i-1, i)

    # Move the last qubit to the first position
    qc.cx(n-1, 0)

    return qc

# Example usage:
# qc = solve(2)
# print(qc)
'''


'''python
from qiskit import QuantumCircuit

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

    # Perform the cyclic shift
    # Step 1: Move the last qubit to the first position
    for i in range(n-1, 0, -1):
        qc.cx(i-1, i)  # CNOT from qubit i-1 to qubit i

    # Step 2: Move the last qubit to the first position
    qc.cx(n-1, 0)  # CNOT from qubit n-1 to qubit 0

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # We only perform the cyclic shift when the last qubit (n-1) is 0
    # To achieve this, we'll first apply X gate to the last qubit
    qc.x(n-1)

    # Now we can use the last qubit as control for our cyclic shift
    # We need to move each bit to its new position when control is 1
    # This effectively performs the shift when original last bit was 0
    for i in range(n-1):
        qc.cx(i, (i+1)%n)

    # Apply CNOTs in reverse order to clean up intermediate states
    for i in range(n-2, -1, -1):
        qc.cx(i, (i+1)%n)

    # Finally, revert the X gate on the last qubit
    qc.x(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # We want to shift only when last qubit is 0
    # So we'll use its inverse (1) as control
    qc.x(n-1)

    # For each pair of qubits that need to be potentially swapped
    for i in range(n-1):
        next_i = (i + 1) % n

        # Controlled-CNOT (CNOT controlled by last qubit)
        qc.cx(n-1, i)
        qc.cx(i, next_i)
        qc.cx(n-1, i)

    # Restore the last qubit
    qc.x(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(n-1):
        qc.cx(i, n-1)
        qc.cx(n-1, i)
        qc.cx(i, 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(n-1, 0, -1):
        qc.cx(i, n-1)
        qc.cx(i-1, i)
        qc.cx(i, i-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.reset(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(n-2):
        qc.cx(0, i + 1)
        qc.cx(i+1, 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 - 1):
        qc.cx(0, i + 1)
        qc.cx(i + 1, 0)
        qc.cx(0, 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.cx(0, i + 1)
        qc.cx(i + 1, 0)
        qc.cx(0, i + 1)
    qc.cx(0, n)
    qc.cx(n-1, 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 - 2):
        qc.cx(0, i + 1)
        qc.cx(i + 1, 0)
        qc.cx(0, 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-1):
        qc.cx(n-1-i, n-2-i)
        qc.cx(n-2-i, n-1-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-1):
        qc.cx(n-2-i, n-1-i)
        qc.cx(n-1-i, n-2-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-1):
        qc.measure(n-1, 0)
        last = n - 1 - i
        qc.cx(last - 1, last)
        qc.cx(last, last - 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-1):
        qc.measure(n-1, 0)
        qc.reset(n-1)
        last = n - 1 - i
        qc.cx(last - 1, last)
        qc.cx(last, last - 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-1):
        qc.reset(n-1)
        last = n - 1 - i
        qc.cx(last - 1, last)
        qc.cx(last, last - 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-1):
        qc.reset(n-1)
        last = n - 1 - i
        qc.cx(last - 1, last)
        qc.cx(last, last - 1)
        qc.cx(last - 1, last)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n-2, 0, -1):
        qc.cx(i, i-1)
        qc.cx(i-1, i)
        qc.cx(i, 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-1, 0, -1):
        qc.cx(i, i-1)

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


'''python
from qiskit import QuantumCircuit

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

    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 )
    for i in range(n-2, -1, -1):
        qc.cx(i, i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    i = 0
    j = n - 1

    while i < j:
        qc.cx(i, j)
        qc.cx(j, i)
        qc.cx(i, j)

        i += 1

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    i = 0
    j = n - 1

    while i < j:
        qc.cx(i, j)
        qc.cx(j, 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)

    qc.cx(n-1, 0)

    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-1, 0, -1):
        qc.cz(i, i-1)

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

    return qc

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    for i in range(n-1, 0, -1):
        qc.cx(i, 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):
        if i == 0:
            qc.x(0)
        else:
            # Apply an (i)-controlled X gate with controls qubits [0, 1, ..., i-1] and target qubit i.
            qc.mcx(list(range(i)), i, mode='gray')

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # 1. すべてのビットを反転 (Xゲート)
    qc.x(range(n))

    # 2. +1 の加算回路 (Ripple-Carry Adder の簡易バージョン)
    carry = 1  # 最下位ビットからキャリーを伝播させる
    for i in range(n):
        qc.cx(i, carry)  # i番目のビットにキャリーを伝播
        carry = i  # 次のキャリー

    # 3. すべてのビットを再度反転
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Step 1. Invert every qubit.
    qc.x(range(n))

    # Step 2. Add 1 modulo 2^n.
    # To add a constant, it suffices to switch to the Fourier basis,
    # apply appropriate phase shifts, then transform back.
    #
    # (a) Apply the Quantum Fourier Transform.
    qc.append(QFT(n, do_swaps=True).to_gate(), range(n))

    # (b) In the Fourier basis, adding 1 is diagonal.
    # For a state |y⟩ we must apply the phase exp(-2πi·y/2^n).
    # Since y = Σ_{j=0}^{n-1} y_j 2^j, these phases can be applied
    # as single-qubit phase gates on each qubit.
    for j in range(n):
        angle = -2 * math.pi / (2 ** (j+1))
        qc.p(angle, j)

    # (c) Apply the inverse QFT.
    qc.append(QFT(n, do_swaps=True).inverse().to_gate(), range(n))

    # Step 3. Invert every qubit again.
    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(n-1)
    for i in reversed(range(2,n)):
        qc.cx(i-1,i-2)
        qc.cx(i,i-1)
    qc.cx(1,0)

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(n-1)
    for i in reversed(range(2,n)):
        qc.cx(i,i-1)
    qc.cx(1,0)

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    fg=False
    for i in reversed(range(n)):
        if qc(i):
            fg=True
        qc.x(i)
        if fg:
            break

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    for i in range(1,n):
        qc.mcx([0,i],0)
    qc.x(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)
    for i in reversed(range(1,n)):
        qc.mcx(list(range(i)),i)
    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:
    for i in range(n):
        qc.x(i)
    for i in reversed(range(2,n)):
        qc.mcx(list(range(i)),i)
    qc.cx(0,1)
    for i in range(2,n):
        qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # We will decrement the value in the little-endian format
    # We need to flip bits until we find a 0 to turn into a 1
    for i in range(n):
        # Flip the i-th qubit
        qc.x(i)  # Prepare the qubit to be flipped

        # Apply a series of CNOT gates to handle the carry
        if i < n - 1:
            qc.cx(i, i + 1)  # CNOT from i to i+1
        qc.x(i)  # Flip back the i-th qubit

    # The last qubit needs to be flipped to handle the wrap-around case
    qc.x(n - 1)  # Prepare the last qubit to be flipped
    for i in range(n - 1):
        qc.cx(i, n - 1)  # CNOT from i to the last qubit
    qc.x(n - 1)  # Flip back the last qubit

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from math import pi, acos, sqrt, asin
from qiskit.circuit.library import XGate, 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 - 1):
        qc.append(XGate().control(1, ctrl_state="0"), [i, i + 1])

    qc.x(0)

    return qc
'''


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

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

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

    for i in range(n, 1, -1):
        qc.append(XGate().control(i-1, ctrl_state="0" * (i-1)), range(i))
    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

        qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(1, n):
        qc.mcx(list(range(i)), i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n, 0, -1):
        qc.mcx(list(range(i)), i)

    qc.x(0)

    return qc.inverse()
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n-1, 0, -1):
        qc.mcx(list(range(i)), i)

    qc.x(0)

    return qc.inverse()
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # 初期状態に基づいて量子減算器を実装
    for i in range(n):
        qc.x(i)  # 全ての量子ビットを反転

    for i in range(n - 1, 0, -1):
        qc.cx(i, i - 1)  # キャリーを伝播

    qc.x(0)  # 最上位ビットを反転

    for i in range(1, n):
        qc.cx(i, i - 1)  # キャリーを戻す

    for i in range(n):
        qc.x(i)  # ビットを再び反転して元に戻す

    return qc
'''


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

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

    for idx in range(n):
        if idx == 0:
            qc.x(idx)
        else:
            qc.mcx(list(range(idx)), idx)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    for i in range(1,n):
        qc.mcx(range(i), i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    for i in range(1,n):
        qc.mcx(list(range(i)), i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in reversed(range(1, n)):
        qc.mcx(list(range(i)), i)

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)

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

    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.x(n-1)
    for i in range(n-1):
        qc.append(MCXGate(i+1), list(range(n-1, n-i-3, -1)))
    return qc
'''


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

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


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n) -> QuantumCircuit:
	qc = QuantumCircuit(n)
	carry = QuantumRegister(1)
	extra = QuantumRegister(n)
	qc.add_bits(carry)
	qc.add_bits(extra)

	c = carry[0]
	qc.x(c)
	for i in range(n):
		e = extra[i]
		qc.x(i)
		qc.ccx(i, c, e)
		qc.x(i)
		qc.cx(c, i)
		qc.swap(c, e)
	return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

	qc.x(0)
	for i in range(1, n):
		qc.mcx(list(range(i)), i)
	return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(n-1)
    qc.cx(n-1,n-2)

    for i in range(n-3,-1,-1):
        qc.ccx(i+2,i+1,i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(n-1)

    for i in range(n-2,-1,-1):
        qc.mcx(range(i+1,n),i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)

    controls = [0]

    for i in range(1,n):
        qc.mcx(controls, i)
        controls.append(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Using the inverse of the increment operation
    # To decrement by 1, we apply a series of CNOT and X gates

    # Step 1: Apply X to all qubits to flip the representation of (x-1)
    qc.x(n - 1)

    # Step 2: Construct the decrement using a ripple-carry method
    for i in range(n - 1):
        qc.cx(i, i + 1)  # Carry propagation

    # Step 3: Flip the LSB to complete subtraction
    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Apply X to all qubits to flip the representation for modular subtraction
    qc.x(n - 1)

    # Ripple borrow propagation for decrementing
    for i in range(n - 1):
        qc.cx(i, i + 1)

    # Final step to complete subtraction by flipping the LSB
    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply controlled-NOT gates in decreasing order
    for i in range(n-1, 0, -1):
        qc.cx(i-1, i)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

from qiskit import QuantumCircuit

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

    # Apply inverse of the +1 operation
    # This effectively implements the -1 operation
    for i in range(n-1, -1, -1):
        qc.x(i)
        for j in range(i+1, n):
            qc.cx(i, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # First apply X gates to all qubits
    for i in range(n):
        qc.x(i)

    # Then apply CNOT gates in the correct order
    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)
    # Write your code here:
    qc.x(0)
    for _ in range(1, n):
        qc.mcx(list(range(_)), _)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # 量子ビットをすべてXゲートで反転させます (NOTゲート)
    # これは、|x> から |~x> (ビット反転) へのマッピングを作成します。
    # |x> が 0 の場合、|1> になります。|x> が 2^n - 1 の場合、|0> になります。
    for i in range(n):
        qc.x(i)

    # nビットの加算器を実装することで、(x-1) mod 2^n を実現します。
    # これを行うには、量子フーリエ変換 (QFT) を使用して加算器を構築します。
    # まず、QFTの逆変換を適用します。
    # QFTの逆変換は、量子ビットの重ね合わせ状態を周波数領域に変換します。
    # この変換は、加算操作を位相シフトとして実行できるようにするために必要です。
    def qft_dagger(circuit, num_qubits):
        """n量子ビットのQFTの逆変換を適用します。"""
        for j in range(num_qubits // 2):
            circuit.swap(j, num_qubits - 1 - j)
        for j in range(num_qubits):
            for m in range(j):
                circuit.cp(-2 * qc.pi / (2**(j - m + 1)), m, j)
            circuit.h(j)

    # QFTを適用します。
    # QFTは、量子ビットの重ね合わせ状態を周波数領域に変換します。
    # これにより、加算操作を位相シフトとして実行できます。
    def qft(circuit, num_qubits):
        """n量子ビットのQFTを適用します。"""
        for j in range(num_qubits - 1, -1, -1):
            circuit.h(j)
            for m in range(j):
                circuit.cp(2 * qc.pi / (2**(j - m + 1)), m, j)
        for j in range(num_qubits // 2):
            circuit.swap(j, num_qubits - 1 - j)

    # QFTを適用します。
    qft(qc, n)

    # -1 を加算することに相当する位相シフトを適用します。
    # QFTの性質上、数値の加算は周波数領域での位相シフトに変換されます。
    # ここでは、各量子ビットに適切な位相シフトを適用して、-1 を加算する効果を実現します。
    for i in range(n):
        qc.p(-2 * qc.pi / (2**(n - i)), i)

    # QFTの逆変換を適用して、結果を元の基底に戻します。
    qft_dagger(qc, n)

    # 再びXゲートを適用して、元の状態に戻します。
    # これは、最初に適用したXゲートの効果を元に戻し、
    # 最終的な結果が (x-1) mod 2^n になるようにします。
    for i in range(n):
        qc.x(i)

    return qc
'''


'''python
from math import ceil,floor,acos,asin,atan,sqrt,pi,gcd,sin,cos,tan
from qiskit import QuantumCircuit,QuantumRegister

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

    for i in reversed(range(n)):
        qc.h(i)
        for j in reversed(range(i)):
            qc.cp(pi / 2 ** (i - j), j, i)

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

    return qc

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

    qc.compose(qft_n,qc,inplace=True)

    for i in range(n):
        theta = 2 * pi * 1 * 2**i / 2**n
        qc.p(theta, i)

    qc.compose(qft_n.inverse(),qc,inplace=True)
    return qc
'''


'''python
from math import ceil,floor,acos,asin,atan,sqrt,pi,gcd,sin,cos,tan
from qiskit import QuantumCircuit,QuantumRegister

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

    for i in reversed(range(n)):
        qc.h(i)
        for j in reversed(range(i)):
            qc.cp(pi / 2 ** (i - j), j, i)

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

    return qc

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

    qc.compose(qft_n,qc,inplace=True)

    for i in range(n):
        theta = 2 * pi * 1 * 2**i / 2**n
        qc.p(theta, i)

    qc.compose(qft_n.inverse(),qc,inplace=True)
    return qc
'''


'''python
from math import ceil,floor,acos,asin,atan,sqrt,pi,gcd,sin,cos,tan
from qiskit import QuantumCircuit,QuantumRegister

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

    for i in reversed(range(n)):
        qc.h(i)
        for j in reversed(range(i)):
            qc.cp(pi / 2 ** (i - j), j, i)

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

    return qc

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

    qc.compose(qft_n,qc,inplace=True)

    for i in range(n):
        theta = 2 * pi * 1 * 2**i / 2**n
        qc.p(theta, i)

    qc.compose(qft_n.inverse(),qc,inplace=True)
    return qc.inverse()
'''


'''python
from math import ceil,floor,acos,asin,atan,sqrt,pi,gcd,sin,cos,tan
from qiskit import QuantumCircuit,QuantumRegister

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

    for i in reversed(range(n)):
        qc.h(i)
        for j in reversed(range(i)):
            qc.cp(pi / 2 ** (i - j), j, i)

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

    return qc

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

    qc.compose(qft_n,qq,inplace=True)

    for i in range(n):
        theta = 2 * pi * 1 * 2**i / 2**n
        qc.p(theta, i)

    qc.compose(qft_n.inverse(),qq,inplace=True)
    return qc.inverse()
'''


'''python
from math import ceil,floor,acos,asin,atan,sqrt,pi,gcd,sin,cos,tan
from qiskit import QuantumCircuit,QuantumRegister

def solve(n: int) -> QuantumCircuit:
    qq=QuantumRegister(n)
    for i in range(n):
        qc.x(i)
        for j in range(i+1, n):
            qc.mcx(list(range(i, j)), j)
        qc.x(i)
    return qc.inverse()
'''


'''python
from math import ceil,floor,acos,asin,atan,sqrt,pi,gcd,sin,cos,tan
from qiskit import QuantumCircuit,QuantumRegister

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.x(i)
        for j in range(i+1, n):
            qc.mcx(list(range(i, j)), j)
        qc.x(i)
    return qc.inverse()
'''


'''python
from math import ceil,floor,acos,asin,atan,sqrt,pi,gcd,sin,cos,tan
from qiskit import QuantumCircuit,QuantumRegister

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


'''python
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n-1,0,-1):
        #qc.cx(i,i-1)
        qc.cx(i-1,i)
        #qc.cx(i,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-1,0,-1):
        #qc.cx(i,i-1)
        qc.cx(i-1,i)
        #qc.cx(i,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-1,0,-1):
        qc.cx(i,i-1)
        #qc.cx(i-1,i)
        #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,0,-1):
        qc.mcx(list(range(i)), i)

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n-1,0,-1):
        qc.mcx(list(range(i)), i)

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n-1,-1,-1):
        qc.mcx(list(range(i)), i)

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n-1,0,-1):
        qc.mcx(list(range(i)), i)

    qc.x(0)

    return qc.inverse()
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
    	print(i)
    	if i == 0:
    		qc.x(0)
    	else:
    		qc.cx(i,list(range(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)[::-1]:
    	print(i)
    	if i == 0:
    		qc.x(0)
    	else:
    		qc.mcx(list(range(0,i)),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):
    	print(i)
    	if i == 0:
    		qc.x(0)
    	else:
    		qc.mcx(list(range(0,i)),i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n-2, -1, -1):
        qc.cx(i, i+1)

    qc.x

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(n-1)

    for i in range(n-2, -1, -1):
        qc.cx(i, i+1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(n-1)

    for i in range(n-2, -1, -1):
        qc.cx(i+1, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    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-1):
        qc.cx(i, i+1)

    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-2, -1, -1):
        qc.cx(i, i+1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)

    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)
    # Write your code here:
    qc.x(n-1)
    for i in reversed(range(n-1)):
        qc.cx(i+1, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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:
    controls = []
    qc.x(0)
    for i in range(n-1):
        controls.append(i)
        mcx = MCXGate(len(controls))
        qc.append(mcx, controls + [i+1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.append(QFT(n), range(n))
    for i in range(n):
        qc.p(-2*np.pi/2**(i+1), i)
    qc.append(QFT(n).inverse(), range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for q in range(0, n-1):
        qc.cx(q, q+1)

    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for q in range(q-1, 0, -1):
        qc.cx(q, q-1)

    qc.x(n-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for q in range(n-1, 0, -1):
        qc.cx(q, q-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.x(n-1)
    # for q in range(n-1, 0, -1):
    #     qc.cx(q, q-1)

    for q in range(0, n-1):
        qc.cx(q+1, q)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    # for q in range(n-1, 0, -1):
    #     qc.cx(q, q-1)

    for q in range(0, n-1):
        qc.cx(q+1, q)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)

    for i in range(1, n):
        qc.mcx(list[range(i)], i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)

    for i in range(1, n):
        qc.mcx(list(range(i)), i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import XGate
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    for i in range(1,n):
        qc.append(XGate().control(i),qargs=range(i+1))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

        if i > 0:
            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, -1, -1):
        qc.cx(i, i)

        if i > 0:
            qc.cx(i, i-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(n-1)
    qc.cx(n-1, n-2)

    for i in range(n-2):
        x = QuantumRegister(1)
        qc.add_bits(x)
        qc.ccx(n - 2 - i, n - 1 +  i,  n - 3- i)
        if i < n - 3:
            qc.ccx(n - 2 - i, n- 1 + i, n + i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(n-1)
    qc.cx(n-1, n-2)

    for i in range(n-2):
        if i < n - 3:
            x = QuantumRegister(1)
            qc.add_bits(x)
        qc.ccx(n - 2 - i, n - 1 +  i,  n - 3- i)
        if i < n - 3:
            qc.ccx(n - 2 - i, n- 1 + i, n + i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qr = QuantumRegister(n)
    cr = ClassicalRegister(1)
    qc = QuantumCircuit(qr, cr)
    # Write your code here:
    qc.x(n-1)

    for i in range(n):
        qc.cx(n-1 - i, n-2 - i)
        qc.measure(qr[n - 2 - i], cr[0])

        with qc.if_test((cr[0], 0)) as else_:
            break

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    n=2
    qc = QuantumCircuit()
    # Write your code here:
    qc.x(n-1)
    qc.cx(n-1, n - 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    n=2
    qc = QuantumCircuit()
    # Write your code here:
    qc.x(n-1)
    qc.cx(n-1, n - 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    n=2
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(n-1)
    qc.cx(n-1, n - 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    n=3
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(n-1)
    qc.cx(n-1, n - 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    n=5
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(n-1)
    qc.cx(n-1, n - 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    n=5
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(n-1)
    qc.cx(n-1, n - 2)

    for i in range(n-2):
        if i < n - 3:
            x = QuantumRegister(1)
            qc.add_bits(x)
        qc.ccx(n - 2 - i, n - 1 +  i,  n - 3- i)
        if i < n - 3:
            qc.ccx(n - 2 - i, n- 1 + i, n + i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    n=6
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(n-1)
    qc.cx(n-1, n - 2)

    for i in range(n-2):
        if i < n - 3:
            x = QuantumRegister(1)
            qc.add_bits(x)
        qc.ccx(n - 2 - i, n - 1 +  i,  n - 3- i)
        if i < n - 3:
            qc.ccx(n - 2 - i, n- 1 + i, n + i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(n-1)
    qc.cx(n-1, n - 2)

    for i in range(n-2):
        if i < n - 3:
            x = QuantumRegister(1)
            qc.add_bits(x)
        qc.ccx(n - 2 - i, n - 1 +  i,  n - 3- i)
        if i < n - 3:
            qc.ccx(n - 2 - i, n- 1 + i, n + i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    qc.cx(0, 1)
    qc.ccx(0, 1, 2)

    x = QuantumRegister(1)
    qc.add_bits(x)

    for i in range(n-2):
        if i == 0:
            qc.ccx(0, 1, 10)
        else:
            x = QuantumRegister(1)
            qc.add_bits(x)
            qc.ccx(i + 1, n + i -1,  n + i)

        qc.ccx(n + i, i + 2, i + 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):
        if i == 0:
            qc.x(qreg[i])
        else:
            qc.cx(qreg[i-1], qreg[i])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n - 1, 0, -1):
        qc.append(MCXGate(num_ctrl_qubits=i, ctrl_state="0" * i),
                  qargs=list(range(i)) + [i])
    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import pi
from qiskit.circuit.library.standard_gates import MCPhaseGate

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

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

        qc.h(i)

        qc.append(MCPhaseGate(pi, num_qubits=i+1), qargs=list(range(i+1)))
        qc.h(i)

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

    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import pi
from qiskit.circuit.library.standard_gates import MCPhaseGate

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

        qc.h(i)
        qc.append(MCPhaseGate(pi, num_ctrl_qubits=i), qargs=list(range(i+1)))
        qc.h(i)

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

    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import pi
from qiskit.circuit.library.standard_gates import MCPhaseGate

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

        qc.h(i)
        qc.append(MCPhaseGate(pi, num_ctrl_qubits=i), qargs=list(range(i)) + [i])
        qc.h(i)
        for j in range(i):
            qc.x(j)

    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library.standard_gates import XGate, CXGate, CCXGate
import math

def add_one_in_log_depth(qc: QuantumCircuit, data: QuantumRegister, carry: QuantumRegister):
    n = len(data)

    for i in range(n):
        qc.cx(carry[i], data[i])

    for i in range(n):
        qc.ccx(data[i], carry[i], carry[i+1])

    log_n = math.ceil(math.log2(n))

    block_size = 1
    while block_size < n:
        for start in range(0, n, 2*block_size):
            mid = start + block_size
            if mid < n:
                qc.ccx(carry[start], data[mid], carry[mid])
                qc.cx(carry[start], data[mid])
                qc.ccx(carry[start], data[mid], carry[mid])
        block_size *= 2

    for i in range(n):
        qc.cx(carry[i], data[i])

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

    data = QuantumRegister(n, "data")
    carry = QuantumRegister(n+1, "carry")
    qc.add_register(carry)

    # Step 0: carry[0]を1に初期化 (Xゲート), 他は0のまま
    qc.x(carry[0])  # carry[0] = 1

    # Step 1: 全ビットを反転 (深さ1扱い: n個のXは並列実行可能)
    for i in range(n):
        qc.x(data[i])

    # Step 2: +1 (mod 2^n) の回路を挿入（深さ O(log n)）
    add_one_in_log_depth(qc, data, carry)

    # Step 3: 再度全ビットを反転 (深さ1)
    for i in range(n):
        qc.x(data[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library.standard_gates import XGate, CXGate, CCXGate
import math

def add_one_in_log_depth(qc: QuantumCircuit, data: QuantumRegister, carry: QuantumRegister):
    n = len(data)

    for i in range(n):
        qc.cx(carry[i], data[i])

    for i in range(n):
        qc.ccx(data[i], carry[i], carry[i+1])

    log_n = math.ceil(math.log2(n))

    block_size = 1
    while block_size < n:
        for start in range(0, n, 2*block_size):
            mid = start + block_size
            if mid < n:
                qc.ccx(carry[start], data[mid], carry[mid])
                qc.cx(carry[start], data[mid])
                qc.ccx(carry[start], data[mid], carry[mid])
        block_size *= 2

    for i in range(n):
        qc.cx(carry[i], data[i])

def solve(n: int) -> QuantumCircuit:
    data = QuantumRegister(n, "data")
    qc = QuantumCircuit(data)

    carry = QuantumRegister(n+1, "carry")
    qc.add_register(carry)

    # Step 0: carry[0]を1に初期化 (Xゲート), 他は0のまま
    qc.x(carry[0])  # carry[0] = 1

    # Step 1: 全ビットを反転 (深さ1扱い: n個のXは並列実行可能)
    for i in range(n):
        qc.x(data[i])

    # Step 2: +1 (mod 2^n) の回路を挿入（深さ O(log n)）
    add_one_in_log_depth(qc, data, carry)

    # Step 3: 再度全ビットを反転 (深さ1)
    for i in range(n):
        qc.x(data[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import MCPhaseGate
import math

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

    qc.x(0)
    for i in range(1, n):
        qc.h(i)
        qc.append(MCPhaseGate(math.pi, num_ctrl_qubits=i), list(range(i)) + [i])
        qc.h(i)

    return qc
'''


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

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

    qft = QFT(n, do_swaps=False, approximation_degree=0)

    qc.append(qft, list(range(n)))

    for j in range(n):
        qc.rz(-2*math.pi/2**(j+1), j)

    qc.append(qft.inverse(), list(range(n)))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def parallel_qft(n: int) -> QuantumCircuit:

    qc = QuantumCircuit(n)

    def _qft_recursive(qubits):
        m = len(qubits)
        if m == 1:
            qc.h(qubits[0])
        else:
            # qubit 列をおおよそ半分に分割
            mid = m // 2
            left = qubits[:mid]
            right = qubits[mid:]
            # 両ブロック上で並列に QFT を実施
            _qft_recursive(left)
            _qft_recursive(right)

            for i, qi in enumerate(left):
                for j, qj in enumerate(right):
                    angle = 2 * math.pi / (2 ** (i + j + 2))
                    qc.cp(angle, qj, qi)

    _qft_recursive(list(range(n)))
    return qc

def parallel_iqft(n: int) -> QuantumCircuit:
    return parallel_qft(n).inverse()

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

    qft_gate = parallel_qft(n).to_gate(label="parallel_QFT")
    qc.append(qft_gate, list(range(n)))

    for j in range(n):
        qc.rz(-2 * math.pi / (2 ** (j + 1)), j)

    iqft_gate = parallel_iqft(n).to_gate(label="parallel_iQFT")
    qc.append(iqft_gate, list(range(n)))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    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.x(i)

    qc.x(0)

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.mcx(list(range(i)), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    for i in range(n-1):
        qc.cx(i, i+1)
        qc.ccx(i, i+1, i)

    qc.x(n-1)

    for i in reversed(range(n-1)):
        qc.ccx(i, i+1, i)
        qc.cx(i, i+1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    for i in range(1, n):
        print(i)
        qc.mcx(list(range(i)),target_qubit=i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(0)
    for i in range(1, n):
        qc.mcx(list(range(0, i)), 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.cx(i, (i + 1)%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-1):
      qc.swap(i, i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    for i in range(n - 1):
        qc.mcx(list(range(0, i + 1)), 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):
        qc.x(i)
        if i < n - 1:
            qc.cx(i, i + 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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.x(0)

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

        if i == 1:
            qc.cx(0, 1)
        elif i == 2:
            qc.ccx(0, 1, 2)
        else:
            qc.mcx(list(range(i)), i)

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

    return qc
'''


'''python
# from qiskit import QuantumCircuit

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

#     qc.x(0)

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

#         if i == 1:
#             qc.cx(0, 1)
#         elif i == 2:
#             qc.ccx(0, 1, 2)
#         else:
#             qc.mcx(list(range(i)), i)

#         for j in range(i):
#             qc.x(j)

#     return qc

from qiskit import QuantumCircuit

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

    # +1演算の実装
    plus_one_qc = QuantumCircuit(n)
    plus_one_qc.x(0)

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

        if i == 1:
            plus_one_qc.cx(0, 1)
        elif i == 2:
            plus_one_qc.ccx(0, 1, 2)
        else:
            plus_one_qc.mcx(list(range(i)), i)

        for j in range(i):
            plus_one_qc.x(j)

    # +1演算の逆演算（-1演算）を実行
    qc = qc.compose(plus_one_qc.inverse())

    return qc
'''


'''python
# from qiskit import QuantumCircuit

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

#     qc.x(0)

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

#         if i == 1:
#             qc.cx(0, 1)
#         elif i == 2:
#             qc.ccx(0, 1, 2)
#         else:
#             qc.mcx(list(range(i)), i)

#         for j in range(i):
#             qc.x(j)

#     return qc

from qiskit import QuantumCircuit

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

    qc.x(0)

    for i in range(1, n):
        if i == 1:
            qc.cx(0, 1)
        else:
            qc.cx(i-1, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    for i in range(n - 2):
        qc.cx(0, i + 1)
    qc.cx(n - 2, n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import ZGate, XGate, HGate, SwapGate
import math

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

    for i in reversed(range(n)):
        if i == 0:
            qc.x(i)
        else:
            qc.append(XGate().control(i), range(i + 1))
    return qc.inverse()

# if __name__ == "__main__":
#     from qiskit.quantum_info import Statevector
#     import numpy as np

#     qc = solve(3)
#     print(qc)
#     sv = Statevector.from_label('001')
#     print(sv.evolve(qc))
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    for i in range(n-1):
        p=[j for j in range(i+1)]
        qc.mcx(p, i+1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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)
    # Write your code here:

    for i in range(n - 3):
        qc.cx(i, i+1)
        qc.x(i)
        qc.x(i+1)
qc.cx(n-2 n-1)
qc.x(n-2)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(n-2)
    qc.cx(n-2,n-1)

    for i in range(n - 3,0,-1):
        qc.x(i)
        qc.x(i+1)
        qc.cx(i, i+1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.compose(inc(n).inverse(), inplace=True)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.compose(inc(n).inverse(), inplace=True)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        if(i == 0):
            qc.x(0)
        else:
            qc.mcx(list(range(0,i,1)),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.mcx(list(range(i, n)), i - 1)
    qc.x(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, n):
      qc.mcx(list(range(0, n - i)), n - i)
    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(0,n): qc.x(i)
    qc.cx(1, 0)
    qc.cx(2, 1)
    qc.ccx(0, 1, 2)
    qc.cx(3, 2)
    qc.ccx(1, 2, 3)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.cx(1, 0)
    qc.cx(2, 1)
    qc.ccx(0, 1, 2)
    qc.cx(3, 2)
    qc.ccx(1, 2, 3)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(0,n): qc.x(i)
    for i in range(0, n-3):
        qc.cx(i+1, i)
        qc.cx(i+2, i+1)
        qc.ccx(i, i+1, i+2)
        qc.cx(i+3, i+2)
        qc.ccx(i+1, i+2, i+3)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc = QuantumCircuit(n)
    numbers=[0,1,2,3,4,5,6,7,8,9,10]
    qc.x(n-1)
    for i in range(n-2,-1,-1):
        qc.mcx(numbers[i+1:10],i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc = QuantumCircuit(n)
    numbers=[0,1,2,3,4,5,6,7,8,9,10]
    qc.x(n-1)
    for i in range(n-2,-1,-1):
        qc.mcx(numbers[i+1:n],i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc = QuantumCircuit(n)
    numbers=[0,1,2,3,4,5,6,7,8,9,10]
    qc.x(0)
    for i in range(1, n):

        qc.mcx(numbers[0:i],i)

    return qc

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    for i in range(n-1):
        qc.mcx([j for j in range(i+1)], 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-1):
        qc.mcx(list(range(1,n-i)), i, ctrl_state='0')
    qc.x(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(n-1):
        qc.mcx(list(range(i+1,n)), i, ctrl_state=0)
    qc.x(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(n-1):
        qc.mcx(list(range(n-i-1)), n-i-1, ctrl_state=0)
    qc.x(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):
        # CNOT ゲートで、減算操作を行うためにキャリーを伝播
        qc.cx(i, (i + 1) % n)
    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.x(qubit)
    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.cx(qubit, (qubit + 1) % n)
    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)

    for qubit in range(n):
        qc.x(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):
        qc.cx(i, (i + 1) % n)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    add_one_circuit = QuantumCircuit(n)

    add_one_circuit.h(range(n))

    for i in range(n):
        for j in range(i):
            add_one_circuit.cp(-2 * np.pi / (2 ** (i - j + 1)), j, i)

    add_one_circuit.h(range(n))

    minus_one_circuit = add_one_circuit.inverse()

    qc.compose(minus_one_circuit, inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:

    qc = QuantumCircuit(n)

    for i in range(n - 1):
        qc.mcx(control_qubits=list(range(i + 1)), target_qubit=i + 1, mode='noancilla')
    qc.x(0)
    qc = qc.inverse()

    return qc

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:

    qc = QuantumCircuit(n)

    qc.x(range(n))

    for i in range(n - 1):
        qc.mcx(control_qubits=list(range(i + 1)), target_qubit=i + 1, mode='noancilla')
    qc.x(0)

    qc.x(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    theta = 4 * math.atan(math.sqrt(6)/ (3 + math.sqrt(3)))

    qc.ry(theta, 0)
    qc.ch(0, 1)
    qc.cx(1, 0)
    qc.x(0)
    qc.cz(1,0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    import math
    theta = 4 * math.atan(math.sqrt(6)/ (3 + math.sqrt(3)))

    qc.ry(theta, 0)
    qc.ch(0, 1)
    qc.cx(1, 0)
    qc.x(0)
    qc.cz(1,0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    theta = 4 * math.atan(math.sqrt(6)/ (3 + math.sqrt(3)))

    qc.ry(theta, 0)
    qc.ch(0, 1)
    qc.cx(1, 0)
    qc.x(0)
    qc.cz(1,0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.ry(1.9106332362490188, 0)
    qc.ch(0, 1)
    qc.cx(1, 0)
    qc.x(0)
    qc.cz(1,0)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # 1/sqrt(3) の係数を得るための回転
    theta = 2 * np.arccos(1 / np.sqrt(3))
    qc.ry(theta, 0)  # q[0] に振幅を調整

    # q[1] にアダマールを適用し、重ね合わせを作る
    qc.h(1)

    # 位相調整
    qc.cp(-np.pi, 0, 1)  # CPhase(-π)

    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    qc.ry(1.9106332362490188, 1)
    qc.ch(1, 0)
    qc.cx(0, 1)
    qc.x(1)
    qc.cz(0,1)

    return qc
'''


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

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

    c = 1/np.sqrt(3)

    U = np.array([[c, c, c, 0], [c, c, 0, c], [0, c, c, c], [-c, 0, c, c]])

    qc.unitary(U, [0, 1])

    return qc
'''


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

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

    c = 1/np.sqrt(3)

    U = [[c, c, c, 0], [c, c, 0, c], [0, c, c, c], [-c, 0, c, c]]

    qc.unitary(U, [0, 1])

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    c = 1/math.sqrt(3)

    U = [[c, c, c, 0], [c, c, 0, c], [0, c, c, c], [-c, 0, c, c]]

    qc.unitary(U, [0, 1])

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.ry(2 * np.arccos(1/np.sqrt(3)), 1)
    qc.cx(1, 0)
    qc.x(1)
    qc.cz(1, 0)
    qc.x(1)

    # |10⟩
    qc.cx(0, 1)
    qc.ry(2 * np.arccos(1/np.sqrt(3)), 1)
    qc.cx(0, 1)

    qc.z(1)
    qc.cz(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.ry(2 * math.arccos(1/np.sqrt(3)), 1)
    qc.cx(1, 0)
    qc.x(1)
    qc.cz(1, 0)
    qc.x(1)

    # |10⟩
    qc.cx(0, 1)
    qc.ry(2 * math.arccos(1/np.sqrt(3)), 1)
    qc.cx(0, 1)

    #
    qc.z(1)
    qc.cz(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.ry(2 * math.arccos(1/math.sqrt(3)), 1)
    qc.cx(1, 0)
    qc.x(1)
    qc.cz(1, 0)
    qc.x(1)

    # |10⟩
    qc.cx(0, 1)
    qc.ry(2 * mat.arccos(1/math.sqrt(3)), 1)
    qc.cx(0, 1)

    #
    qc.z(1)
    qc.cz(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.ry(2 * math.arccos(1/math.sqrt(3)), 1)
    qc.cx(1, 0)
    qc.x(1)
    qc.cz(1, 0)
    qc.x(1)

    # |10⟩
    qc.cx(0, 1)
    qc.ry(2 * math.arccos(1/math.sqrt(3)), 1)
    qc.cx(0, 1)

    #
    qc.z(1)
    qc.cz(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.ry(2 * math.acos(1/math.sqrt(3)), 1)
    qc.cx(1, 0)
    qc.x(1)
    qc.cz(1, 0)
    qc.x(1)

    # |10⟩
    qc.cx(0, 1)
    qc.ry(2 * math.acos(1/math.sqrt(3)), 1)
    qc.cx(0, 1)

    #
    qc.z(1)
    qc.cz(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)

    theta = 2 * math.acos(1/math.sqrt(3))
    qc.cry(theta, 0, 1)

    qc.cz(0, 1)

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    # Create a quantum circuit with 2 qubits
    qc = QuantumCircuit(2)

    # First, apply a custom transformation to achieve the desired superpositions
    # We need specific rotation angles to get the 1/√3 amplitudes

    # For the first transition (|00⟩ transformation)
    theta1 = 2 * 0.6154797086703874  # arccos(1/√3)
    qc.ry(theta1, 0)
    qc.cx(0, 1)
    qc.rz(3.141592653589793, 1)  # π rotation for the minus sign
    qc.cx(0, 1)

    # For the second transition (|10⟩ transformation)
    theta2 = 2 * 0.6154797086703874  # same angle as it's also 1/√3
    qc.x(0)  # Flip first qubit to handle |10⟩ case
    qc.ry(theta2, 0)
    qc.cx(0, 1)
    qc.x(0)  # Restore first qubit

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # Apply Hadamard gate to the first qubit
    qc.h(0)

    # Apply CNOT gate with the first qubit as control and the second qubit as target
    qc.cx(0, 1)

    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # Define the transformation matrix
    U = np.array([
        [1/np.sqrt(3), 0, 1/np.sqrt(3), 0],
        [1/np.sqrt(3), 0, 0, 0],
        [0, 0, 1/np.sqrt(3), 0],
        [-1/np.sqrt(3), 0, 1/np.sqrt(3), 1]
    ])

    # Convert to a UnitaryGate
    gate = UnitaryGate(U)

    # Apply the unitary gate to the 2-qubit circuit
    qc.append(gate, [0, 1])

    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # Step 1: Apply a Y rotation on qubit 0 to create superposition
    qc.ry(2 * np.arccos(1 / np.sqrt(3)), 0)

    # Step 2: Use a CNOT to entangle qubit 0 and qubit 1
    qc.cx(0, 1)

    # Step 3: Apply phase shifts to introduce negative sign
    qc.rz(np.pi, 1)

    return qc
'''


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

def solve() -> QuantumCircuit:
    # Initialize a quantum circuit with 2 qubits
    qc = QuantumCircuit(2)

    # To achieve the desired transformations:
    # |00⟩ → (1/√3)(|00⟩ + |01⟩ - |11⟩)
    # |10⟩ → (1/√3)(|00⟩ + |10⟩ + |11⟩)

    # First, apply a rotation to create the proper superposition
    theta = 2 * np.arccos(1/np.sqrt(3))

    # Apply Ry rotation to first qubit
    qc.ry(theta, 0)

    # Apply controlled operations for state preparation
    qc.cx(0, 1)

    # Apply phase adjustment
    qc.rz(np.pi, 1)

    # Additional transformations for proper superposition
    qc.h(1)

    # Apply controlled-Z for phase alignment
    qc.cz(0, 1)

    # Final adjustments for amplitude matching
    qc.ry(-theta/2, 0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # Apply a Hadamard gate to the first qubit to create superposition
    qc.h(0)

    # Apply a CNOT gate with the first qubit as control and the second as target
    qc.cx(0, 1)

    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # Step 1: Transform |00⟩ → (|00⟩ + |01⟩ - |11⟩) / sqrt(3)
    # Apply a rotation gate to the first qubit to create the desired amplitudes
    theta = 2 * np.arccos(np.sqrt(2 / 3))  # Angle for the correct amplitudes
    qc.u(theta, np.pi, 0, 0)  # Apply a U3 gate to the first qubit

    # Step 2: Apply a Hadamard gate to the first qubit to create superposition
    qc.h(0)

    # Step 3: Use a CNOT gate to transform |01⟩ to |11⟩
    qc.cx(0, 1)

    # Step 4: Adjust phases for the |11⟩ state
    qc.z(1)  # Apply a Z gate to the second qubit to introduce a phase of -1

    # Step 5: Transform |10⟩ → (|00⟩ + |10⟩ + |11⟩) / sqrt(3)
    # Use controlled gates to ensure the transformation only applies when the first qubit is |1⟩
    qc.cu(theta, 0, 0, 0, 0, 1)  # Controlled-U gate

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # Step 1: Transform |00⟩ → (|00⟩ + |01⟩ - |11⟩) / sqrt(3)
    # Apply a Hadamard gate to the first qubit to create superposition
    qc.h(0)

    # Apply a controlled-Z gate to introduce the phase of -1 for |11⟩
    qc.cz(0, 1)

    # Step 2: Transform |10⟩ → (|00⟩ + |10⟩ + |11⟩) / sqrt(3)
    # Apply a controlled-Hadamard gate to the second qubit when the first qubit is |1⟩
    qc.ch(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import sqrt

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # Apply Hadamard gate to the first qubit
    qc.h(0)

    # Apply controlled gates to create the desired state
    qc.cx(0, 1)
    qc.ch(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # Step 1: Create a superposition on the first qubit
    qc.ry(2 * (1/3)**0.5, 0)  # Custom Ry to match 1/sqrt(3) coefficient

    # Step 2: Use CNOT to entangle second qubit with control on the first
    qc.cx(0, 1)

    # Step 3: Apply phase shift to adjust the sign of |11⟩
    qc.z(1)  # Apply Z on the second qubit to introduce the required negative sign

    return qc
'''


'''python
import math

from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    theta = 2 * math.atan(math.sqrt(2))

    qc.rx(theta, 1)
    qc.ch(1, 0)
    qc.x(0)
    qc.cx(0, 1)
    qc.x(0)
    qc.cz(1, 0)

    return qc
'''


'''python
import math

from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    theta = 2 * math.atan(math.sqrt(2))

    qc.rx(theta, 1)
    qc.z(1)
    qc.ch(1, 0)
    qc.x(0)
    qc.cx(0, 1)
    qc.x(0)
    qc.cz(1, 0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    phi = 2 * math.atan(math.sqrt(2))
    qc.ry(phi, 1)
    qc.ch(1, 0)
    qc.x(0)
    qc.cx(0, 1)
    qc.x(0)
    qc.cz(1, 0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)
    qc.ch(0,1)
    qc.cx(1,0)
    qc.x(1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)
    qc.ch(1,0)
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.x(0)
    qc.h(0)
    qc.ch(0,1)
    qc.cx(1,0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.x(0)
    qc.h(0)
    qc.ch(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.ry(2 * math.atan(math.sqrt(2)),1)
    qc.ch(1,0)
    qc.x(0)
    qc.cx(0,1)
    qc.x(0)
    qc.cz(1,0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    theta = 2 * math.atan(math.sqrt(2))

    qc.ry(theta, 1)
    qc.ch(1, 0)
    qc.x(0)
    qc.cx(0, 1)
    qc.x(0)
    qc.cz(1, 0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    theta = 2 * math.atan(math.sqrt(2))

    qc.ry(theta, 1)
    qc.ch(1, 0)
    qc.x(0)
    qc.cx(0, 1)
    qc.x(0)
    qc.cz(1, 0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    # Apply a Hadamard gate to the first qubit
    qc.h(0)

    # Apply a controlled phase rotation to create the necessary superpositions
    qc.cp(-2 * math.pi / 3, 0, 1)  # Apply a controlled phase shift from qubit 0 to qubit 1

    # Apply a Hadamard gate to the second qubit
    qc.h(1)

    # Apply a controlled NOT gate to entangle the qubits
    qc.cx(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from numpy import sqrt, acos

def solve() -> QuantumCircuit:
	qc = QuantumCircuit(2)
	qc.ry(2 * acos(1 / sqrt(3)), 0)
	qc.x(1)
	qc.ch(0, 1)
	return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from numpy import sqrt, acos

def solve() -> QuantumCircuit:
	qc = QuantumCircuit(2)
	qc.ry(2 * acos(1 / sqrt(3)), 0)
	qc.x(1)
	qc.ch(0, 1)
	qc.x(1)
	qc.cx(1, 0)
	qc.x(1)
	qc.swap(0, 1)
	return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from numpy import sqrt, acos

def solve() -> QuantumCircuit:
	qc = QuantumCircuit(2)
	qc.swap(0, 1)
	qc.ry(2 * acos(1 / sqrt(3)), 0)
	qc.x(1)
	qc.ch(0, 1)
	qc.x(1)
	qc.cx(1, 0)
	qc.x(1)
	return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.ry(2*math.atan(math.sqrt(2)),1)
    qc.ch(1,0)
    qc.x(0)
    qc.cx(0,1)
    qc.x(0)
    qc.cz(1,0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

import math

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.x(1)

    qc.ry(math.asin( sqrt(2)/sqrt(3) )*2, 0)
    qc.cry(-math.pi/2, 0,1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

import math

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

    qc.ry(math.asin( sqrt(2)/sqrt(3) )*2, 0)
    qc.cry(-math.pi/2, 0,1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

import math

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

    qc.ry(math.asin( sqrt(2)/sqrt(3) )*2, 0)
    qc.ch(0,1)

    qc.x(1)
    qc.cx(1,0)
    qc.x(1)

    qc.cz(0,1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

import math

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

    qc.ry(math.asin( sqrt(2)/sqrt(3) )*2, 1)
    qc.ch(1,0)

    qc.x(0)
    qc.cx(0,1)
    qc.x(0)

    qc.cz(0,1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

import math

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

    qc.ry(math.asin( math.sqrt(2)/math.sqrt(3) )*2, 0)
    qc.ch(0,1)

    qc.x(1)
    qc.cx(1,0)
    qc.x(1)

    qc.cz(0,1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

import math

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

    qc.ry(math.asin( math.sqrt(2)/math.sqrt(3) )*2, 1)
    qc.ch(1,0)

    qc.x(0)
    qc.cx(0,1)
    qc.x(0)

    qc.cz(0,1)

    return qc
'''


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

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

    U = np.array([[1/np.sqrt(3), 1/np.sqrt(3), 1, 1],[0, 1/np.sqrt(3), 0, 0],[1/np.sqrt(3), 0, 0, 0],[-1/np.sqrt(3), 1/np.sqrt(3), 0, 0]])
    qc.unitary(U, [0,1])
    # theta1 = 2 * math.atan(math.sqrt(2))
    # theta2 = 2 * math.atan(1)

    # #00
    # qc.x(0)
    # qc.cry(theta1, 0, 1)
    # qc.cry(theta2, 1, 0)
    # qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    qc.h(0)
    qc.u1(sqrt(3)/2, 1)
    qc.cx(0, 1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)

    qc.h(0)
    qc.u1((3)^(1/2)/2, 1)
    qc.cx(0, 1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)
    qc.cx(0, 1)
    qc.x(0)
    qc.cz(0, 1)
    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)
    theta = 2 * np.arccos(np.sqrt(2/3))
    qc.cry(theta, 0, 1)

    qc.cz(0, 1)

    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)
    theta = 2 * np.arccos(np.sqrt(2/3))
    qc.cry(theta, 0, 1)

    qc.cz(0, 1)

    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)

    qc.cx(0, 1)
    qc.x(0)
    qc.cp(-np.pi/2, 0, 1)  # Controlled phase gate
    qc.x(0)

    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)

    # Apply controlled gates to create the desired states
    qc.cx(0, 1)
    qc.h(1)
    qc.cp(-np.pi, 0, 1)  # Controlled phase gate for the -|11> term
    qc.h(1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)

    qc.cx(0, 1)

    qc.cp(np.pi, 0, 1)

    qc.h(1)
    return qc
'''


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

def solve():
    l, r = QuantumRegister(1), QuantumRegister(1)
    qc = QuantumCircuit(l, r)

    qc.ry(math.acos(math.sqrt(1 / 3)) * 2, r)
    qc.ch(r, l)

    qc.x(r)
    qc.cx(l, r)
    qc.cz(l, r)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.ry(1.230, 0)
    qc.rz(-0.785, 0)
    qc.cx(0, 1)
    qc.ry(0.628, 0)
    qc.rz(2.111, 1)
    qc.cx(0, 1)
    qc.ry(-1.570, 0)
    qc.rz(0.349, 0)
    qc.cx(0, 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(1/np.sqrt(3))
    qc.ry(2*angle, 1)
    qc.cx(1, 0)
    qc.ch(1, 0)
    qc.x(0)
    qc.cx(0,1)
    qc.x(0)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(1/np.sqrt(3))
    qc.ry(2*angle, 1)
    qc.cx(1, 0)
    qc.ch(1, 0)
    qc.x(0)
    qc.cx(0, 1)
    qc.x(0)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(1/np.sqrt(3))
    qc.ry(2*angle, 0)
    qc.cx(0, 1)
    qc.ch(10, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(1/np.sqrt(3))
    qc.ry(2*angle, 0)
    qc.cx(0, 1)
    qc.ch(0, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(1/2)
    qc.ry(2*angle, 0)
    qc.cx(0, 1)
    qc.ch(0, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(np.sqrt(2)/np.sqrt{3})
    qc.ry(2*angle, 0)
    qc.cx(0, 1)
    qc.ch(0, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(np.sqrt(2)/np.sqrt(3))
    qc.ry(2*angle, 0)
    qc.cx(0, 1)
    qc.ch(0, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(np.sqrt(2)/np.sqrt(3))
    qc.ry(-2*angle, 0)
    qc.cx(0, 1)
    qc.ch(0, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(np.sqrt(2)/np.sqrt(3))
    qc.ry(2*angle, 1)
    qc.cx(1, 0)
    qc.ch(1, 0)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(np.sqrt(2)/np.sqrt(3))
    qc.ry(2*angle, 1)
    qc.cx(1, 0)
    qc.ch(1, 0)
    qc.x(0)
    qc.cx(0, 1)
    qc.x(0)
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(np.sqrt(2)/np.sqrt(3))
    qc.ry(2*angle, 0)
    qc.cx(0, 1)
    qc.ch(0, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    angle=np.arcsin(np.sqrt(2)/np.sqrt(3))
    qc.ry(2*angle, 1)
    qc.cx(1, 0)
    qc.ch(1, 0)
    qc.x(0)
    qc.cx(0, 1)
    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # 定義するユニタリ行列 U (計算基底順序: |00>, |01>, |10>, |11>)
    U = (1/np.sqrt(3)) * np.array([
        [ 1,  1,  1,  0],
        [ 1, -1,  0,  1],
        [ 0, -1,  1, -1],
        [-1,  0,  1,  1]
    ], dtype=complex)

    # 2量子ビット全体に対して U を実装
    qc.unitary(U, [0, 1], label="U")

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.x(1)
    qc.cx(1, 0)
    qc.ch(0, 1)
    qc.cx(1, 0)
    qc.h(1)
    qc.cx(1, 0)
    qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.swap(0, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    qc.cx(1, 0)
    qc.ch(0, 1)
    qc.cx(1, 0)
    qc.h(1)
    qc.cx(1, 0)
    qc.h(0)

    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.swap(0, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    qc.cry(2*np.arccos(2/3), 0, 1)
    qc.cry(2*np.arccos(-1/np.sqrt(10)), 1, 0)
    qc.ry(2*np.arccos(1/np.sqrt(3)), 1)
    qc.cx(1, 0)
    qc.ch(1, 0)
    qc.cz(1, 0)
    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.swap(0, 1)
    qc.x(1)
    qc.cx(1, 0)
    qc.x(1)
    qc.cry(np.arccos(2/3), 0, 1)
    qc.cry(np.arccos(-1/np.sqrt(10)), 1, 0)
    qc.ry(np.arccos(1/np.sqrt(3)), 1)
    qc.cx(1, 0)
    qc.ch(1, 0)
    qc.cz(1, 0)
    return qc
'''