'''python
from qiskit import QuantumCircuit

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

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

    # Apply CNOT gates from the first qubit to each of the other qubits in parallel
    for i in range(1, n):
        qc.cx(0, i)

    # Apply Z gate to the first qubit to introduce the phase
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates between the first qubit and each of the other qubits
    for i in range(1, n):
        qc.cx(0, i)

    # Step 3: Apply Z gate to the first qubit to introduce the phase
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    # Step 3: Apply Z gate to the first qubit to introduce the phase
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    # Step 3: Apply Z gate to the first qubit to introduce the phase
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply Z gate to the first qubit to introduce the phase
    qc.z(0)

    # Step 3: Apply a final CNOT gate between the first qubit and all others
    for i in range(1, n):
        qc.cx(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply Z gate to the first qubit to introduce the phase
    qc.z(0)

    # Step 3: Apply a final CNOT gate between the first qubit and all others
    for i in range(1, n-1):
        qc.cx(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 3: Apply a final CNOT gate between the first qubit and all others
    for i in range(1, n):
        qc.cx(0, i)

    # Step 2: Apply Z gate to the first qubit to introduce the phase
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply X gate to all qubits (to prepare for the MCZ)
    for i in range(n):
        qc.x(i)

    # Step 3: Apply a multi-controlled Z (MCZ) gate
    qc.h(n-1)  # Convert Z to X (as multi-controlled X is easier)
    qc.mcx(list(range(n-1)), n-1)  # Apply the multi-controlled X
    qc.h(n-1)  # Convert X back to Z

    # Step 4: Apply X gate again to all qubits
    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:

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

    # Step 2: Apply an X gate to the last qubit to ensure Z gate impacts the correct state
    qc.x(n-1)

    # Step 3: Apply Controlled-Z gate between first qubit and the last one
    qc.cz(0, n-1)

    # Step 4: Apply X gate to revert the last qubit to its original state
    qc.x(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply an n-qubit controlled-Z gate (multi-controlled Z)
    # Convert Z to X (since multi-controlled X is easier to apply)
    qc.h(n-1)
    qc.mcx(list(range(n-1)), n-1)  # Multi-controlled X
    qc.h(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates to entangle the first qubit with all others
    for i in range(1, n):
        qc.cx(0, i)

    # Step 3: Apply a Z gate to introduce the phase of -1
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply controlled-Z gate with depth optimization
    qc.cz(0, n-1)  # This introduces the -1 phase to the |1...1> state

    # Step 3: Apply X gates to qubits 1 to n-2 and then controlled-Z
    for i in range(1, n-1):
        qc.cx(i, n-1)  # Entangles qubits sequentially

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates to entangle the first qubit with all others
    for i in range(1, n):
        qc.cx(0, i)

    # Step 3: Apply a Z gate to introduce the phase of -1
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates in a layered manner
    for i in range(1, n//2):
        qc.cx(0, i)  # First half of CNOTs
    for i in range(n//2, n):
        qc.cx(1, i)  # Second half of CNOTs

    # Step 3: Apply a Z gate to introduce the phase of -1
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates in layers to reduce depth
    # Layer 1
    qc.cx(0, 1)
    qc.cx(0, 2)
    qc.cx(0, 4)
    qc.cx(0, 8)

    # Layer 2
    qc.cx(1, 3)
    qc.cx(1, 5)
    qc.cx(2, 6)
    qc.cx(2, 7)

    # Layer 3
    qc.cx(3, 9)
    qc.cx(4, 10)
    qc.cx(5, 11)
    qc.cx(6, 12)

    # Step 3: Apply a Z gate to introduce the phase of -1
    qc.z(0)

    # Step 3: Apply a Z gate to introduce the phase of -1
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    ## Step 2: Apply CNOT gates in layers to reduce depth
    # Layer 1: Apply CNOT from qubit 0 to qubits 1, 2, 4, 8
    qc.cx(0, 1)
    qc.cx(0, 2)
    qc.cx(0, 4)
    qc.cx(0, 8)

    # Layer 2: Apply CNOTs from qubits 1 to 3, 2 to 5, 4 to 6, 8 to 10
    qc.cx(1, 3)
    qc.cx(2, 5)
    qc.cx(4, 6)
    qc.cx(8, 10)

    # Layer 3: Apply CNOTs from qubits 3 to 7, 5 to 9, 6 to 11, 10 to 12
    qc.cx(3, 7)
    qc.cx(5, 9)
    qc.cx(6, 11)
    qc.cx(10, 12)

    # Layer 4: Apply CNOTs from qubits 7 to 13, 9 to 14
    qc.cx(7, 13)
    qc.cx(9, 14)

    # Step 3: Apply a Z gate to introduce the phase of -1
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    qc.h(0)

    # Step 2: Apply CNOT gates in a more parallelized manner
    step = 1
    while step < n:
        for i in range(0, n, step * 2):
            if i + step < n:
                qc.cx(i, i + step)
        step *= 2

    # Step 3: Apply a Z gate to the first qubit
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    qc.h(0)

    # Step 2: Apply CNOT gates in layers to minimize depth
    # First layer: CNOT from qubit 0 to all qubits that are powers of 2
    for i in range(1, n):
        if i & (i - 1) == 0:  # This condition checks if 'i' is a power of 2
            qc.cx(0, i)

    # Second layer: CNOT from qubits already entangled in the first layer to others
    for i in range(1, n):
        if i & (i - 1) != 0 and i & (n // 2) == 0:  # Skip the powers of 2
            qc.cx(0, i)

    # Step 3: Apply Z gate to introduce the phase
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    qc.h(0)

    # Step 2: Apply CNOT gates in a divide-and-conquer approach
    current_layer = list(range(1, n))

    while len(current_layer) > 1:
        next_layer = []
        for i in range(0, len(current_layer), 2):
            if i + 1 < len(current_layer):
                qc.cx(current_layer[i], current_layer[i+1])
                next_layer.append(current_layer[i+1])
            else:
                next_layer.append(current_layer[i])
        current_layer = next_layer

    # Apply final CNOT gate from qubit 0 to the last qubit in the chain
    qc.cx(0, current_layer[0])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    qc.h(0)

    # Step 2: Apply CNOT gates in parallel layers to reduce depth
    step = 1
    while step < n:
        for i in range(0, n - step, step * 2):
            qc.cx(i, i + step)
        step *= 2

    # Step 3: Apply a final CNOT gate to the last qubit
    if step // 2 < n:
        qc.cx(0, n - 1)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates in layers to maximize parallelism
    step = 2
    while step < n:
        for i in range(step, n, 2 * step):
            qc.cx(0, i)
        step *= 2

    # Step 3: Apply Z gate to introduce the phase
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates in layers to maximize parallelism
    step = 1
    while step < n:
        for i in range(step, n, 2 * step):
            qc.cx(0, i)
        step *= 2

    # Step 3: Apply Z gate to introduce the phase
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates in layers to maximize parallelism
    step = 1
    while step < n:
        for i in range(step, n, 6 * step):
            qc.cx(0, i)
        step *= 2

    # Step 3: Apply Z gate to introduce the phase
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(1,n//4):
        qc.cx(0,i*4)
    for i in range(n//4):
        qc.cx(i*4,i*4+n//8)
    for i in range(n//8):
        qc.cx(2*i,2*i+1)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(n//2,n,n//2):
        qc.cx(0,i)
    for i in range(0,n,n//2):
        qc.cx(i,i+n//4)
    for i in range(0,n,n//4):
        qc.cx(i,i+n//8)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(0,n,n//2):
        if(n//2>0):
            qc.cx(0,i+n//2)
    for i in range(0,n,n//2):
        if(n//4>0):
            qc.cx(i,i+n//4)
    for i in range(0,n,n//4):
        if(n//8>0):
            qc.cx(i,i+n//8)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(0,n,n):
        if(n//2>0):
            qc.cx(i,i+n//2)
    for i in range(0,n,n//2):
        if (n//4>0):
            qc.cx(i,i+n//4)
    for i in range(0,n,n//4):
        if (n//8>0):
            qc.cx(i,i+n//8)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(0,n,n):
        if(n//2>0):
            qc.cx(i,i+n//2)
    for i in range(0,n,n//2):
        if (n//4>0):
            qc.cx(i,i+n//4)
    for i in range(0,n,n//4):
        if (n//8>0):
            qc.cx(i,i+n//8)
    qc.z(n-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    cnt=0
    for i in range(0,n):
        for j in range(2**i):
            if (j+2**i < n):
                qc.cx(j,j+2**i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qbit_list = list(range(1, n, 1))
    done_list = [0]
    is_done = False
    while(True):

        doing_list = []
        for c in done_list:
            if len(qbit_list)==0:
                is_done = True
                break
            target = qbit_list.pop(0)
            qc.cx(c, target)
            doing_list.append(target)

        if is_done:
            break
        done_list.extend(doing_list)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(n//2-1)
    qc.cx(n//2-1,n//2)
    for i in range((n-2)//2+1):
        if 0 <= n//2-2-i < n:
            qc.cx(n//2-1,n//2-2-i)
        if 0 <= n//2+i+1 < n:
            qc.cx(n//2,n//2+i+1)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(n//2-1)
    qc.cx(n//2-1,n//2)
    if n <= 6:
        for i in range((n-2)//2+1):
            if 0 <= n//2-2-i < n:
                qc.cx(n//2-1,n//2-2-i)
            if 0 <= n//2+i+1 < n:
                qc.cx(n//2,n//2+i+1)
    else:
        pass
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(n//2-1)
    qc.cx(n//2-1,n//2)
    if n <= 8:
        for i in range((n-2)//2+1):
            if 0 <= n//2-2-i < n:
                qc.cx(n//2-1,n//2-2-i)
            if 0 <= n//2+i+1 < n:
                qc.cx(n//2,n//2+i+1)
    else:
        pas
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(n//2-1)
    qc.cx(n//2-1,n//2)
    if n <= 8:
        for i in range((n-2)//2+1):
            if 0 <= n//2-2-i < n:
                qc.cx(n//2-1,n//2-2-i)
            if 0 <= n//2+i+1 < n:
                qc.cx(n//2,n//2+i+1)
    else:
        pass
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(n//2-1)
    qc.cx(n//2-1,n//2)
    if n <= 10:
        for i in range((n-2)//2+1):
            if 0 <= n//2-2-i < n:
                qc.cx(n//2-1,n//2-2-i)
            if 0 <= n//2+i+1 < n:
                qc.cx(n//2,n//2+i+1)
    else:
        pass
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(n//2-1)
    qc.cx(n//2-1,n//2)
    if n <= 9:
        for i in range((n-2)//2+1):
            if 0 <= n//2-2-i < n:
                qc.cx(n//2-1,n//2-2-i)
            if 0 <= n//2+i+1 < n:
                qc.cx(n//2,n//2+i+1)
    else:
        pass
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    if n < 10:
        qc.h(n//2-1)
        qc.cx(n//2-1,n//2)
        for i in range((n-2)//2+1):
            if 0 <= n//2-2-i < n:
                qc.cx(n//2-1,n//2-2-i)
            if 0 <= n//2+i+1 < n:
                qc.cx(n//2,n//2+i+1)
    else:
        qc.h(0)

        qc.cx(0,7)

        qc.cx(0,3)
        if n >= 11:
            qc.cx(7,11)

        qc.cx(0,2)
        qc.cx(3,5)
        qc.cx(7,9)
        if n >= 13:
            qc.cx(11,13)

        qc.cx(0,1)
        qc.cx(3,4)
        qc.cx(5,6)
        qc.cx(7,8)
        if n >= 10:
            qc.cx(9,10)
        if n >= 12:
            qc.cx(11,12)
        if n >= 14:
            qc.cx(13,14)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    if n < 10:
        qc.h(n//2-1)
        qc.cx(n//2-1,n//2)
        for i in range((n-2)//2+1):
            if 0 <= n//2-2-i < n:
                qc.cx(n//2-1,n//2-2-i)
            if 0 <= n//2+i+1 < n:
                qc.cx(n//2,n//2+i+1)
    else:
        qc.h(0)

        qc.cx(0,7)

        qc.cx(0,3)
        if n > 11:
            qc.cx(7,11)

        qc.cx(0,2)
        qc.cx(3,5)
        qc.cx(7,9)
        if n > 13:
            qc.cx(11,13)

        qc.cx(0,1)
        qc.cx(3,4)
        qc.cx(5,6)
        qc.cx(7,8)
        if n > 10:
            qc.cx(9,10)
        if n > 12:
            qc.cx(11,12)
        if n > 14:
            qc.cx(13,14)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
        qc.h(0)
    end = 1
    while end < n:
        for left in range(end):
            qc.cx(left, end)
            end += 1
            if end == n:
                break
    qc.z(0)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    l = int(np.ceil(np.log2(n)))

    for m in range(l, 0, -1):
        step = 2 ** m
        half_step = 2 ** (m - 1)
    for k in range(0, n, step):
        if k + half_step < n:
            qc.cx(k, k + half_step)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    l = int(np.ceil(np.log2(n)))

    for m in range(l, 0, -1):
        step = 2 ** m
        half_step = 2 ** (m - 1)
        for k in range(0, n, step):
            if k + half_step < n:
                qc.cx(k, k + half_step)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    l = int(np.ceil(np.log2(n)))

    for m in range(l, 0, -1):
        step = 2 ** m
        half_step = 2 ** (m - 1)
        for k in range(0, n, step):
            if k + half_step < n:
                qc.cx(k, k + half_step)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    cur = 1
    max = 1
    while True:
        for i in reversed(range(max)):
            qc.cx(i, cur)
            print(f'{i}->{cur}')
            cur += 1
            if cur >= n:
                qc.z(0)
                return qc
        max += 1
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    i = 1
    while i < n:
        for j in range(i):
            if i + j < n:
                qc.cx(j, i + j)
        i *= 2

    qc.z(n - 1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(0)
    qc.h(0)
    def rec(l, r):
        if r - l <= 1:
            return
        m = (l + r) // 2
        qc.cx(l, m)
        rec(l, m)
        rec(m, r)
    rec(0, n)
    # for i in range(1, n):
    #     qc.cx(0, i)
    return qc

# if __name__ == "__main__":
#     from qiskit.quantum_info import Statevector
#     import numpy as np
#     n = 15
#     qc = solve(n)
#     sv = Statevector(qc)
#     print(sv)
#     print(qc)
#     print(f"{qc.depth() = }")
# #     sv = Statevector.from_label('+++')
# #     print(sv.evolve(qc))
'''


'''python
from qiskit import QuantumCircuit

import math

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

    qc.h(0)
    circuitEnd = False
    for i in range(1, 5):
        for j in range(i):
            if (j + i >= n):
                circuitEnd = True
                break
            qc.cx(j, j + i)
        if (circuitEnd):
            break

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

import math

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

    qc.h(0)
    circuitEnd = False
    for i in [int(pow(2, x)) for x in range(0, 4)]:

        for j in range(i):
            if (j + i >= n):
                circuitEnd = True
                break
            qc.cx(j, j + i)
        if (circuitEnd):
            break

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    A=[None,0,0,0,0,0,1,1,1,1,2,2,2,3,3,3,4,4,5,6]
    for i in range(1,n):
        qc.cx(A[i],i)
    qc.z(A[n])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    A=[None,0,0,0,0,0,1,1,1,1,2,2,2,3,3,3,4,4,5,7]
    for i in range(1,n):
        qc.cx(A[i],i)
    qc.z(A[n])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    A=[None,0,0,0,0,0,1,1,1,1,2,2,2,3,3,3,4,4,5,6]
    for i in range(1,n):
        qc.cx(A[i],i)
    qc.z(A[n+1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def dnc(qc: QuantumCircuit, l: int, r: int) -> None:
    if l == r:
        return
    m = (l + 1 + r) // 2
    qc.cx(l, m)
    dnc(qc, l, m - 1)
    dnc(qc, m, r)

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

    qc.h(0)
    qc.z(0)
    dnc(qc, 0, n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0, n-1)
    def halve(qc, i, j):
        if i != j:
            half = (i + j) // 2
            if i != half:
                qc.cx(i, half)
            if (half + 1) != j:
                qc.cx(j, half + 1)
            return qc, half
        return qc, None

    qc, half = halve(qc, 0, n - 1)

    qc, half1 = halve(qc, 0, half)
    qc, half2 = halve(qc, half + 1, n - 1)

    qc, _ = halve(qc, 0, half1)
    qc, _ = halve(qc,  half1 +1, half)

    qc, _ = halve(qc, half + 1, half2)
    qc, _ = halve(qc, half2 + 1, n - 1)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0, n-1)
    def halve(qc, i, j):
        if i != j:
            half = (i + j) // 2
            if i != half:
                qc.cx(i, half)
            if (half + 1) != j:
                qc.cx(j, half + 1)
            return qc, half
        return qc, None

    qc, half = halve(qc, 0, n - 1)

    if half:
        qc, half1 = halve(qc, 0, half)
        qc, half2 = halve(qc, half + 1, n - 1)
        if half1:
            qc, _ = halve(qc, 0, half1)
            qc, _ = halve(qc,  half1 +1, half)
        if half2:
            qc, _ = halve(qc, half + 1, half2)
            qc, _ = halve(qc, half2 + 1, n - 1)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    qc.h(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)
    # Write your code here:

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

    for i in range(1, n):
        if i % 2 == 0:
            qc.cx(0, i)
        else:
            qc.cx(1, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    for i in range(1, n):
        if i % 2 == 1:
            qc.cx(0, i)
        else:
            qc.cx(1, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    for i in range(1, n):
        if i % 3 == 1:
            qc.cx(0, i)
        elif i % 3 == 2:
            qc.cx(1, i)
        else:
            qc.cx(2, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(1, n):
        if i % 3 == 1:
            qc.cx(0, i)
        elif i % 3 == 2:
            qc.cx(1, i)
        else:
            qc.cx(2, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(1, n):
        if i % 3 != 0:
            qc.cx(0, i)
        else:
            qc.cx(1, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(1, n):
        if i % 2 != 0:
            qc.cx(0, i)
        else:
            qc.cx(1, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(1, n):
        if i % 4 == 1
            qc.cx(0, i)
        elif i % 4 == 2:
            qc.cx(1, i)
        elif i % 4 == 3:
            qc.cx(2, i)
        else :
            qc.cx(3, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(1, n):
        if i % 4 == 1:
            qc.cx(0, i)
        elif i % 4 == 2:
            qc.cx(1, i)
        elif i % 4 == 3:
            qc.cx(2, i)
        else :
            qc.cx(3, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(0, math.log2(n)):
        for j in range(0, pow(2, i)):
            qc.cx(j, j + i + 1)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(0, (int)math.log2(n)):
        for j in range(0, pow(2, i)):
            qc.cx(j, j + i + 1)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)

    for i in range(0, (i)math.log2(n)):
        for j in range(0, pow(2, i)):
            qc.cx(j, j + i + 1)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import mat

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

    qc.h(0)

    for i in range(0, int(math.log2(n))):
        for j in range(0, pow(2, i)):
            qc.cx(j, j + i + 1)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)

    for i in range(0, int(math.log2(n))):
        for j in range(0, pow(2, i)):
            qc.cx(j, j + i + 1)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)

    for i in range(math.ceil(math.log2(n))):
        for j in range(2 ** i):
            if (j + 2 ** i) > n:
                break
            qc.cx(j, j + 2 ** i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)
    cnt = 0

    for i in range(math.ceil(math.log2(n))):
        for j in range(2 ** i):
            qc.cx(j, j + 2 ** i)
            cnt++

            if cnt == n:
                break
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)
    cnt = 0

    for i in range(math.ceil(math.log2(n))):
        for j in range(2 ** i):
            qc.cx(j, j + 2 ** i)
            cnt+=1

            if cnt == n:
                break
        if cnt == n:
            break
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)
    cnt = 0

    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if cnt == n:
                break
            qc.cx(j, j + 2**i)
            cnt+=1

    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)
    cnt = 0

    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if j + 2**i == n:
                break
            qc.cx(j, j + 2**i)
            cnt+=1

    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    st = list(range(n-1, 0, -1))
    nn = 1
    while st:
        for i in range(nn):
            j = st.pop()
            qc.cx(i, j)
            nn += 1
            if len(st) == 0:
                break
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    qc.h(0)

    # Step 2: Apply Z gate to the first qubit to introduce the phase
    qc.z(0)

    # Step 3: Apply CNOT gates with qubit 0 as the control and the others as targets
    # We apply CNOT gates in parallel where possible
    if n > 1:
        for i in range(1, n):
            qc.cx(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    qc.h(0)

    # Step 2: Apply CNOT gates in a modified manner
    for i in range(1, n):
        qc.cz(0, i)

    # Step 3: Apply a final CNOT gate between the first qubit and all others
    for i in range(1, n):
        qc.cx(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    qc.h(0)

    qc.z(0)

    # Step 3: Apply a final CNOT gate between the first qubit and all others
    for i in range(1, n):
        qc.cx(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    qc.h(0)

    # Step 2: Apply CNOT gates between the first qubit and each of the other qubits
    if n > 1:
        qc.cx(0, 1)  # Depth 2
    if n > 2:
        qc.ccx(0, 1, 2)  # Using Toffoli gate (multi-control XOR) - Depth 3

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    qc.h(0)

    # Step 2: Apply a controlled Z (CZ) gate between all pairs of qubits
    if n > 1:
        qc.cz(0, 1)  # Depth 2
    if n > 2:
        qc.cz(1, 2)  # Depth 2 (since it can be in parallel with the first CZ)
    if n > 3:
        qc.cz(2, 3)  # Depth 3 (this is the final depth)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    kouho = []
    for i in range(n-1):
        target = i + 1
        if kouho:
            a = kouho.pop()
            qc.cx(a, target)
        else:
            qc.cx(0, target)
            for j in range(1, target):
                kouho.append(j)
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.cx(0,1)
    now = 1
    while now<=n-1:
        for i in range(now):
            if now+i+1>=n:
                break
            qc.cx(i+1,i+1+now)
        now *= 2
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    used = [False]*n
    used[0] = True
    ones = [0]
    while True:
        if len(ones) == n:
            break
        nones = []
        for i in ones:
            nones.append(i)
            for j in range(0,n):
                if not used[j]:
                    qc.cx(i,j)
                    used[j] = True
                    nones.append(j)
                    break
        ones = nones[:]
    # Write your code here:
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    qc.h(0)
    for i in range(n):
        if i % 2 == 0:
            if i != 0:
                qc.x(i)
            qc.cx(i, i + 1)
    for i in range(n):
        if i % 2 == 1:
            if i != n - 1:
                qc.x(i)
                qc.cx(i, i + 1)
                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)
    qc.h(0)
    for i in range(n):
        if i % 2 == 0:
            if i != 0:
                qc.x(i)
            if i != n - 1:
                qc.cx(i, i + 1)
    for i in range(n):
        if i % 2 == 1:
            if i != n - 1:
                qc.x(i)
                qc.cx(i, i + 1)
                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)
    qc.h(0)
    max_qubit = 1
    for i in range(4):
        for j in range(2 ** i):
            qc.cx(j, j + 2 ** i)
            max_qubit = max(j + 2 ** i, max_qubit)
            if max_qubit == n - 1:
                break
        if max_qubit == n - 1:
            break
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    qc.h(0)
    for b in [8, 4, 2, 1]:
        for j in range(b, n, b * 2):
            i = j - b
            qc.cx(i, j)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    if n <= 3:
        qc.z(0)
        for i in range(1, n):
            qc.cx(0, i)
    elif n <= 6:
        qc.cx(0, 1)
        qc.cx(1, 2)
        qc.cx(0, 3)
        qc.cx(1, 4)
        qc.cx(2, 5)
        qc.z(0)
    else:
        qc.cx(0, 1)
        qc.cx(1, 2)
        qc.cx(0, 3)
        qc.cx(1, 4)
        qc.cx(2, 5)
        qc.z(0)
        count = 0
        while count+6 < n:
            qc.cx(count, count+6)
            count += 1

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    if n <= 3:
        qc.z(0)
        for i in range(1, n):
            qc.cx(0, i)
    elif n <= 6:
        qc.cx(0, 1)
        qc.cx(1, 2)
        count = 0
        while count+3 < n:
            qc.cx(count, count+3)
            count += 1
        qc.z(0)
    else:
        qc.cx(0, 1)
        qc.cx(1, 2)
        qc.cx(0, 3)
        qc.cx(1, 4)
        qc.cx(2, 5)
        qc.z(0)
        count = 0
        while count+6 < n:
            qc.cx(count, count+6)
            count += 1

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    if n == 3:
        return solve3()
    qc = QuantumCircuit(n)
    qc.h(0)
    ans = [0 for _ in range(n)]
    qc.cx(0, n//2)
    ans[0] = 1
    ans[n//2] = 1
    r = (n//2)//2
    while not all(ans):
        for i in range(n-r):
            if ans[i] == 1 and ans[i+r] == 0:
                qc.cx(i, i+r)
                ans[i+r] = 1
        if r != 1:
            r //= 2
        else:
            break
    qc.z(0)
    return qc

def solve3():
    qc = QuantumCircuit(3)
    # Write your code here:
    qc.h(0)
    for i in range(1, 3):
        qc.cx(0, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    if n == 3:
        return solve3()
    qc = QuantumCircuit(n)
    qc.h(0)
    ans = [0 for _ in range(n)]
    qc.cx(0, n//2)
    ans[0] = 1
    ans[n//2] = 1
    r = (n//2)
    while not all(ans):
        for i in range(n-r):
            if ans[i] == 1 and ans[i+r] == 0:
                qc.cx(i, i+r)
                ans[i+r] = 1
        r //= 2
    qc.z(0)
    return qc

def solve3():
    qc = QuantumCircuit(3)
    # Write your code here:
    qc.h(0)
    for i in range(1, 3):
        qc.cx(0, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    step = 2**ceil(log2(n))
    while step:
        for i in range(0, n, 2 * step):
            if i + step < n:
                qc.cx(i, i + step)
        step //= 2
    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import ceil,log2

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    step = 2**ceil(log2(n))
    while step:
        for i in range(0, n, 2 * step):
            if i + step < n:
                qc.cx(i, i + step)
        step //= 2
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    idx1 = 0
    next1 = 1
    breakF = False
    while not breakF:
        for i, j in enumerate(range(idx1 + 1, idx1 + next1 + 1)):
            if j >= n:
                breakF = True
                break
            qc.cx(i, j)
        if breakF:
            break
        idx1 += next1
        next1 *= 2

    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Entangle all other qubits with the first one
    for i in range(1, n):
        qc.cx(0, i)

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

    # Apply Hadamard gates to all qubits except the first one
    for i in range(1, n):
        qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply CNOT gates to create the desired superposition
    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)

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

    # Apply CNOT gates to create the desired entanglement
    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)

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

  # Apply CNOT gates for efficient entanglement (reduce depth)
  for i in range(1, n):
    for j in range(i):
      qc.cx(j, i)  # Apply CNOT from lower qubits to higher qubits

  return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    a=1
    while a<n:
        for i in range(a):
            if i+a<n:
                qc.cx(i,i+a)
        a*=2
    qc.z(0)
    return qc
'''


'''python
import math

from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.ry(-math.pi, 0)

    log = int(math.log2(n - 1)) + 1

    swapped = set([0])

    for i in range(log - 1, -1, -1):
        done = set()
        for j in range(n):
            if j not in swapped:
                continue

            next_j = j + 2**i
            print(j, next_j)
            if next_j < n and next_j not in swapped:
                done.add(next_j)
                qc.cx(j, next_j)
        swapped |= done

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(1, n):
        mbit = 0
        for j in range(5):
            if i>>j&1: mbit = j
        qc.cx(i, i-(1<<mbit))
    qc.z(n-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(1, n):
        mbit = 0
        for j in range(5):
            if i>>j&1: mbit = j
        qc.cx(i, 1<<mbit)
    qc.z(n-)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(1, n):
        mbit = 0
        for j in range(5):
            if i>>j&1: mbit = j
        qc.cx(i, i-1<<mbit)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(1, n):
        mbit = 0
        for j in range(5):
            if i>>j&1: mbit = j
        qc.cx(i-(1<<mbit), i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    # log depth
    import math

    l = int(math.ceil(math.log2(n)))
    for m in range(l, 0, -1):
        for k in range(0, n, 2**m):
            if k + 2 ** (m - 1) >= n:
                continue
            qc.cx(k, k + 2 ** (m - 1))

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0,1)
    c=0
    if n>2:
        for i in range(n-2):
            if c%2==0:
                qc.cx(0,i+2)
                c=c+1
            else:
                qc.cx(1,i+2)
                c=c+1

    qc.z(1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0,1)
    c=2
    if n>2:
        for i in range(n-2):
            if c%4==0:
                qc.cx(2,i+2)
                c=c+1
            elif c%3==0:
                qc.cx(1,i+2)
                c=c+1
            elif c%2==0:
                qc.cx(0,i+2)
                c=c+1
            else:
                qc.cx(3,i+2)
                c=c+1
    qc.z(1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0,1)
    c=2
    if n>2:
        for i in range(n-2):
            if c%4==0:
                qc.cx(2,i+2)
                c=c+1
            elif c%3==0:
                qc.cx(1,i+2)
                c=c+1
            elif c%2==0:
                qc.cx(0,i+2)
                c=c+1
            elif c%5==0:
                qc.cx(3,i+2)
                c=c+1
            else:
                qc.cx(4,i+2)
                c=c+1
    qc.z(1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    gate = np.array([1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,-1,0])
    ug = UnitaryGate(gate, label = "ug")
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.gate(0,1)
    c=2
    if n>2:
        for i in range(n-2):
            if c%4==0:
                qc.cx(2,i+2)
                c=c+1
            elif c%3==0:
                qc.cx(1,i+2)
                c=c+1
            elif c%2==0:
                qc.cx(0,i+2)
                c=c+1
            elif c%5==0:
                qc.cx(3,i+2)
                c=c+1
            else:
                qc.cx(4,i+2)
                c=c+1
    qc.barrier()
    qc.z(1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0,1)
    c=2
    if n>2:
        for i in range(n-2):
            if c%4==0:
                qc.cx(2,i+2)
                c=c+1
            elif c%3==0:
                qc.cx(1,i+2)
                c=c+1
            elif c%2==0:
                qc.cx(0,i+2)
                c=c+1
            elif c%5==0:
                qc.cx(3,i+2)
                c=c+1
            else:
                qc.cx(4,i+2)
                c=c+1
    qc.barrier()
    qc.z(1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0,1)
    c=2
    if n>2:
        for i in range(n-2):
            if c%4==0:
                qc.cx(2,i+2)
                c=c+1
            elif c%3==0:
                qc.cx(1,i+2)
                c=c+1
            elif c%2==0:
                qc.cx(0,i+2)
                c=c+1
            elif c%5==0:
                qc.cx(3,i+2)
                c=c+1
            else:
                qc.cx(4,i+2)
                c=c+1
    qc.z(1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0,1)
    c=2
    if n>2:
        for i in range(n-2):
            if c%4==0:
                qc.cx(2,i+2)
                c=c+1
            elif c%3==0:
                qc.cx(1,i+2)
                c=c+1
            elif c%2==0:
                qc.cx(0,i+2)
                c=c+1
            elif c%5==0:
                qc.cx(3,i+2)
                c=c+1
            else:
                qc.cx(4,i+2)
                c=c+1
    qc.barrier()
    qc.z(1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0,1)
    c=2
    if n>2:
        for i in range(n-2):
            if c%4==0:
                qc.cx(2,i+2)
                c=c+1
            elif c%3==0:
                qc.cx(1,i+2)
                c=c+1
            elif c%2==0:
                qc.cx(0,i+2)
                c=c+1
            elif c%5==0:
                qc.cx(3,i+2)
                c=c+1
            else:
                qc.cx(4,i+2)
                c=c+1
    if n==14
        qc.z(3)
    else
        qc.z(1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    qc.h(0)
    for b in reversed(range(5)):
        i = 0
        while True:
            if i + (1<<b) >= n:
                break
            qc.cx(i, i + (1<<b))
            i += (1<<(b+1))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2 ** i):
            if 2 ** i + j == n:
                break;
            qc.cx(j, 2 ** i + j)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

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

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)

    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2**i + j == n:
                break
            qc.cx(j, 2**i + j)
    qc.z(0)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    qc.h(0)
    l = int(np.ceil(np.log2(n)))
    for m in range(l, 0, -1):
        for k in range(0, n, 2 ** m):
            if k + 2 ** (m - 1) >= n: continue
            qc.cx(k, k + 2 ** (m - 1))

    return qc
'''


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

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

    qc.h(0)

    def f(x, y):
        if y < n:
            qc.cx(x, y)

    f(0, 1)

    f(0, 2)
    f(1, 3)

    f(0, 4)
    f(1, 5)
    f(2, 6)
    f(3, 7)

    f(0, 8)
    f(1, 9)
    f(2, 10)
    f(3, 11)
    f(4, 12)
    f(5, 13)
    f(6, 14)
    f(7, 15)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.cx(0,1)
    if n>2:
        ent_num=1
        ent_num_tmp=1
        while(True):
            for i in range(ent_num+1):
                qc.cx(i, ent_num+1+i)
                ent_num_tmp+=1

                if ent_num+i+1==n-1:
                    break
            else:
                ent_num=ent_num_tmp
                continue
            break

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    for i in range(1, n):
        qc.cx(i // 2 , i)
    qc.z(1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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


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

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

    l = int(np.ceil(np.log2(n)))
    for m in range(l, 0, -1):
        for k in range(0, n, 2 ** m):
            if k + 2 ** (m - 1) >= n: continue
            qc.cx(k, k + 2 ** (m - 1))
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.z(0)
    m = 1
    while m < n:
        for i in range(m):
            if i + m < n:
                qc.cx(i, i + m)
        m *= 2

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    x=[1]
    for i in range(1,n):
        # print(x)
        y=min(x)
        for j in range(len(x)):
            if y==x[j]:
                break
        qc.cx(j,i)
        x[j]+=1
        x+=x[j],

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    qc.cx(0, 1)

    if n > 2:
        qc.cx(0, 2)
    if n > 3:
        qc.cx(1, 3)

    if n > 4:
        qc.cx(0, 4)
    if n > 5:
        qc.cx(1, 5)
    if n > 6:
        qc.cx(2, 6)
    if n > 7:
        qc.cx(3, 7)

    if n > 8:
        qc.cx(0, 8)
    if n > 9:
        qc.cx(1, 9)
    if n > 10:
        qc.cx(2, 10)
    if n > 11:
        qc.cx(3, 11)
    if n > 12:
        qc.cx(4, 12)
    if n > 13:
        qc.cx(5, 13)
    if n > 14:
        qc.cx(6, 14)

    qc.cz(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    i = 0
    while 2**i < n:
        j = 2**i
        for l in range(j):

            if j+l == n-1:
                break
            qc.cx(l,j+l)

        i = i+1

    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    # finding the mid qubit
    i = 0
    while 2**i < n:
        j = 2**i
        for l in range(j):

            if j+l == n-1:
                break
            qc.cx(l,j+l)

        i = i+1
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    # finding the mid qubit
    i = 0
    while 2**i < n:
        j = 2**i
        for l in range(j):

            if j+l == n-1:
                break
            qc.cx(l,j+l)

        i = i+1

    qc.barrier()
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    qc.h(0)
    # finding the mid qubit
    i = 0
    while 2**i < n:
        j = 2**i
        for l in range(j):

            if j+l == n-1:
                break
            qc.cx(l,j+l)

        i = i+1

    #qc.barrier()
    #qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    # finding the mid qubit
    i = 0
    while 2**i < n:
        j = 2**i
        for l in range(j):

            if j+l == n-1:
                break
            qc.cx(l,j+l)

        i = i+1

    #qc.barrier()
    qc.z(0)
    return qc
'''


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

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

    qc.h(0)

    l = int(np.ceil(np.log2(n)))
    for m in range(l, 0, -1):
        for k in range(0, n, 2 ** m):
            if k + 2 ** (m - 1) >= n: continue
            qc.cx(k, k + 2 ** (m - 1))

    #qc.barrier()
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(n-4):
        if i % 3 == 0:
            qc.cx(0, i+1)
        elif i % 3 == 1:
            qc.cx(1, i+1)
        elif i % 3 == 2:
            qc.cx(2, i+1)

    qc.cx(3, n-3)
    qc.cx(4, n-2)
    qc.cx(5, n-1)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(n-1):
        if i % 15 == 0:
            qc.cx(0, i+1)
        elif i % 15 == 1:
            qc.cx(1, i+1)
        elif i % 15 == 2:
            qc.cx(2, i+1)
        elif i % 15 == 3:
            qc.cx(3, i+1)
        elif i % 15 == 4:
            qc.cx(4, i+1)
        elif i % 15 == 5:
            qc.cx(5, i+1)
        elif i % 15 == 6:
            qc.cx(6, i+1)
        elif i % 15 == 7:
            qc.cx(7, i+1)
        elif i % 15 == 8:
            qc.cx(8, i+1)
        elif i % 15 == 9:
            qc.cx(9, i+1)
        elif i % 15 == 10:
            qc.cx(10, i+1)
        elif i % 15 == 11:
            qc.cx(11, i+1)
        elif i % 15 == 12:
            qc.cx(12, i+1)
        elif i % 15 == 13:
            qc.cx(13, i+1)
        elif i % 15 == 14:
            qc.cx(14, i+1)

    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0,1)
    for i in range(n-2):
        if i % 14 == 0:
            qc.cx(0, i+2)
        elif i % 14 == 1:
            qc.cx(1, i+2)
        elif i % 14 == 2:
            qc.cx(2, i+2)
        elif i % 14 == 3:
            qc.cx(3, i+2)
        elif i % 14 == 4:
            qc.cx(4, i+2)
        elif i % 14 == 5:
            qc.cx(5, i+2)
        elif i % 14 == 6:
            qc.cx(6, i+2)
        elif i % 14 == 7:
            qc.cx(7, i+2)
        elif i % 14 == 8:
            qc.cx(8, i+2)
        elif i % 14 == 9:
            qc.cx(9, i+2)
        elif i % 14 == 10:
            qc.cx(10, i+2)
        elif i % 14 == 11:
            qc.cx(11, i+2)
        elif i % 14 == 12:
            qc.cx(12, i+2)
        elif i % 14 == 13:
            qc.cx(13, i+2)

    qc.z(0)
    return qc
'''


'''python
import math

from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(int(math.log2(n)) + 1):
        for j in range(2**i):
            if 2**i + j == n:
                break
            qc.cx(j, 2**i + j)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    def entangle(idx1, idx2):
        if idx2 > n - 1:
            return
        qc.cx(idx1, idx2)
        entangle(idx2, (idx2 + 1) * 2 - 1)
        entangle(idx2, (idx2 + 1) * 2)
    entangle(0, 1)
    entangle(0, 2)
    qc.z(n- 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for giver in range(math.ceil(math.log2(n))):
        for taker in range(2 ** i):
            if 2**giver + taker == n:
                break
            qc.cx(taker, 2**giver + taker)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for giver in range(math.ceil(math.log2(n))):
        for taker in range(2 ** i):
            if 2**giver + taker == n:
                break
            qc.cx(taker, 2**giver + taker)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for giver in range(math.ceil(math.log2(n))):
        for taker in range(2 ** giver):
            if 2**giver + taker == n:
                break
            qc.cx(taker, 2**giver + taker)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2 ** i):
            if 2 ** i + j == n:
                break
            qc.cx(j, 2 ** i + j)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2 ** i):
            if 2 ** i + j == n:
                break
            qc.cx(j, 2 ** i + j)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def get_min_depth(depth):
    min_val = min(depth.values())
    for (k, v) in depth.items():
        if v == min_val:
            return k

def get_unentangled_qubit(e, n):
    for i in range(n):
        if i not in e:
            return i
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.cx(0, 1)
    entangled_qubits = [0, 1]
    depth = dict()
    for i in range(n):
        depth[i] = 0

    depth[0] = 2
    depth[1] = 2

    while len(entangled_qubits) != n:

        c = get_min_depth(depth)
        t = get_unentangled_qubit(entangled_qubits, n)

        qc.cx(c, t)
        depth[c] = depth[c] + 1
        depth[t] = depth[c]
        entangled_qubits.append(t)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def get_min_depth(depth):
    min_val = min(depth.values())
    for (k, v) in depth.items():
        if v == min_val:
            return k

def get_unentangled_qubit(e, n):
    for i in range(n):
        if i not in e:
            return i
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.cx(0, 1)
    entangled_qubits = [0, 1]
    depth = dict()

    depth[0] = 2
    depth[1] = 2

    while len(entangled_qubits) != n:

        c = get_min_depth(depth)
        t = get_unentangled_qubit(entangled_qubits, n)

        qc.cx(c, t)
        depth[c] = depth[c] + 1
        depth[t] = depth[c]
        entangled_qubits.append(t)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def get_min_depth(depth):
    min_val = min(depth.values())
    for (k, v) in depth.items():
        if v == min_val:
            return k

def get_unentangled_qubit(e, n):
    for i in range(n):
        if i not in e:
            return i
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.cx(0, 1)
    entangled_qubits = [0, 1]
    depth = dict()

    depth[0] = 2
    depth[1] = 2

    while len(entangled_qubits) != n:

        c = get_min_depth(depth)
        t = get_unentangled_qubit(entangled_qubits, n)

        qc.cx(c, t)
        depth[c] = depth[c] + 1
        depth[t] = depth[c]
        entangled_qubits.append(t)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def get_ghz_circuit(n_bits: int) -> QuantumCircuit:
    qc = QuantumCircuit(n_bits)
    qc.h(0)
    m = 0
    while 1 << m < n_bits: m += 1
    for k in range(m):
        d = 1 << k
        for i in range(d):
            if i + d < n_bits: qc.cx(i, i + d)
    return qc

def solve(n: int) -> QuantumCircuit:
    qc = get_ghz_circuit(n)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    for i in range(1, n, 4):
        qc.cx(0, i)
        if i+1 < n:
            qc.cx(i, i+1)
        if i+2 < n:
            qc.cx(i, i+2)
        if i+3 < n:
            qc.cx(i, i+3)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    for i in range(1, n, 5):
        qc.cx(0, i)
        if i+1 < n:
            qc.cx(i, i+1)
        if i+2 < n:
            qc.cx(i, i+2)
        if i+3 < n:
            qc.cx(i, i+3)
        if i+4 < n:
            qc.cx(i, i+4)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    l = 5
    i = 1
    while i < n:
        qc.cx(0, i)
        for j in range(1, l):
            if i+j < n:
                qc.cx(i, i+j)
        i += l
        j -= 1
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    l = 6
    i = 1
    while i < n:
        qc.cx(0, i)
        for j in range(1, l):
            if i+j < n:
                qc.cx(i, i+j)
        i += l
        j -= 1
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    l = 4
    i = 1
    while i < n:
        qc.cx(0, i)
        for j in range(1, l):
            if i+j < n:
                qc.cx(i, i+j)
        i += l
        j -= 1
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    l = 5
    i = 1
    while i < n:
        qc.cx(0, i)
        for j in range(1, l):
            if i+j < n:
                qc.cx(i, i+j)
        i += l
        j = max(j-1, 1)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(n):
        if 2 * i + 1 < n:
            qc.cx(i, 2 * i + 1)
        if 2 * i + 2 < n:
            qc.cx(i, 2 * i + 2)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    depth = [0] * n
    visited = [0] * n
    visited[0] = 1

    for i in range(1, n):
        m = n
        p = 0
        for j in range(i):
            if depth[j] < m:
                m = depth[j]
                p = j
        depth[p] += 1
        depth[i] = depth[p]

        qc.cx(p, i)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    tgt = 1
    for p in range(math.ceil(math.log2(n))):
        for i in range(2**p):
            if tgt < n:
                qc.cx(i,tgt)
                tgt += 1
            else:
                break
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import ceil, log,

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(log2(n)+1):
        for j in range(2**i):
            if 2**i + j = n:
                break
            qc.cx(j,2**i+j)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import ceil, log,

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(int(log2(n)+1)):
        for j in range(2**i):
            if 2**i + j = n:
                break
            qc.cx(j,2**i+j)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import ceil, log,

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(int(log2(n))+1):
        for j in range(2**i):
            if 2**i + j = n:
                break
            qc.cx(j,2**i+j)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import *

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(int(log2(n))+1):
        for j in range(2**i):
            if 2**i + j = n:
                break
            qc.cx(j,2**i+j)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import *

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(int(log2(n))+1):
        for j in range(2**i):
            if 2**i + j == n:
                break
            qc.cx(j,2**i+j)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(int(math.log2(n))+1):
        for j in range(2**i):
            if 2**i + j == n:
                break
            qc.cx(j,2**i+j)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates to entangle the first qubit with the others
    for i in range(1, n):
        qc.cx(0, i)

    # Step 3: Apply a phase shift to the last qubit to create the negative sign
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    i = 0
    while 2**i < n:
        for j in range(2**i):
            if j+2**i < n:
                qc.cx(j, j+2**i)
        i += 1
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n):
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(1,n):
        q =  1 << i.bit_length() -1
        r = i - q
        print(i,q,r)
        qc.cx(r,i)

    qc.cz(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.cx(0,1)
    for i in range(int(math.log2(n-1))):
        for j in range(2**i):
            if (j+2**i) > (n-1): continue
            qc.cx(j,j+2**i)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.cx(0,1)
    for i in range(int(math.log2(n-1))):
        for j in range(2**(i+1)):
            if (j+2**(i+1)) > (n-1): continue
            qc.cx(j,j+2**(i+1))
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    clist = []
    clist.append((0,1))
    clist.append((0,2))
    clist.append((1,3))
    clist.append((1,4))
    clist.append((2,5))
    clist.append((2,6))
    clist.append((3,7))
    clist.append((3,8))
    clist.append((4,9))
    clist.append((4,10))
    clist.append((5,11))
    clist.append((5,12))
    clist.append((6,13))
    clist.append((6,14))

    for c in clist:
        if(c[0] < n and c[1] < n):
        qc.cx(c[0], c[1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    clist = []
    clist.append((0,1))
    clist.append((0,2))
    clist.append((1,3))
    clist.append((1,4))
    clist.append((2,5))
    clist.append((2,6))
    clist.append((3,7))
    clist.append((3,8))
    clist.append((4,9))
    clist.append((4,10))
    clist.append((5,11))
    clist.append((5,12))
    clist.append((6,13))
    clist.append((6,14))

    for c in clist:
        if(c[0] < n and c[1] < n):
            qc.cx(c[0], c[1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    clist = []
    clist.append((0,1))
    clist.append((1,2))
    clist.append((2,3))
    clist.append((3,4))
    clist.append((0,5))
    clist.append((0,8))
    clist.append((0,10))
    clist.append((1,11))
    clist.append((1,12))
    clist.append((2,13))
    clist.append((5,14))

    for c in clist:
        if(c[0] < n and c[1] < n):
            qc.cx(c[0], c[1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    clist = []
    clist.append((0,1))
    clist.append((0,5))
    clist.append((0,8))
    clist.append((0,10))
    clist.append((1,2))
    clist.append((1,11))
    clist.append((1,12))
    clist.append((2,3))
    clist.append((2,13))
    clist.append((3,4))
    clist.append((5,14))

    for c in clist:
        if(c[0] < n and c[1] < n):
            qc.cx(c[0], c[1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    clist = []
    clist.append((0,1))
    clist.append((0,5))
    clist.append((0,8))
    clist.append((0,10))
    clist.append((1,2))
    clist.append((1,11))
    clist.append((1,12))
    clist.append((2,3))
    clist.append((2,13))
    clist.append((3,4))
    clist.append((5,14))
    clist.appned((8,9))

    for c in clist:
        if(c[0] < n and c[1] < n):
            qc.cx(c[0], c[1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    clist = []
    clist.append((0,1))
    clist.append((0,5))
    clist.append((0,8))
    clist.append((0,10))
    clist.append((1,2))
    clist.append((1,11))
    clist.append((1,12))
    clist.append((2,3))
    clist.append((2,13))
    clist.append((3,4))
    clist.append((5,14))
    clist.append((8,9))

    for c in clist:
        if(c[0] < n and c[1] < n):
            qc.cx(c[0], c[1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.z(0)
    clist = []
    clist.append((0,1))
    clist.append((1,2))
    clist.append((2,3))
    clist.append((3,4))
    clist.append((0,5))
    clist.append((5,6))
    clist.append((6,7))
    clist.append((0,8))
    clist.append((8,9))
    clist.append((0,10))
    clist.append((1,11))
    clist.append((1,12))
    clist.append((2,13))
    clist.append((5,14))

    for c in clist:
        if(c[0] < n and c[1] < n):
            qc.cx(c[0], c[1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    qc0 = QuantumCircuit(n-1)
    for i in range(n-1):
        qc0.x(i)
    cxgates = qc0.to_gate().control(1)

    qc.append(cxgates, range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n) -> QuantumCircuit:
	qc = QuantumCircuit(n)
	qc.x(0)
	qc.h(0)
	l = 1
	while l < n:
		r = min(n, 2 * l)
		for i in range(l, r):
			qc.cx(i - l, i)
		l = r
	return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    controls = [0, 0, 1, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7,]

    for i in range(1, n):
        qc.cx(controls[i - 1], i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2 ** i + j == n:
                break
            qc.cx(j,2**i + j)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2 ** i + j == n:
                break
            qc.cx(j,2**i + j)
    qc.barrier()
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2 ** i + j == n:
                break
            qc.cx(j,2**i + j)
    qc.barrier()
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    m = 1
    qc.h(0)
    for i in range(5):
        for l in range(i+1):
            if m >= n:
                break
            qc.cx(l,m)
            m += 1
        if m >= n:
            break
    qc.z(1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    m = 1
    qc.h(0)
    for i in range(5):
        for l in range(2**i):
            if m >= n:
                break
            qc.cx(l,m)
            m += 1
        if m >= n:
            break
    qc.z(1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    t=7*math.pi/2
    qc.ry(t,0)
    li=[0]
    nex=[0]
    while len(li)<n:
        nex=li.copy()
        ma=max(li)+1
        for i in li:

            if ma<n:
                qc.cx(i,ma)
                nex.append(ma)
                ma+=1

        li=nex
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    d = 1
    while d < n:
        for i in range(0, d):
            if i + d < n:
                qc.cx(i, i + d)
                print(i, i + d)
        d *= 2
    qc.z(0)

    return qc

# solve(15).draw('mpl').show()
'''


'''python
from qiskit import QuantumCircuit

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

    if n>=3:
      qc.cx(0, 1)
    if n>=4:
      qc.cx(n-1, n-2)
    if n>=5:
      qc.cx(0, 2)
    if n>=6:
      qc.cx(n-1, n-3)
    if n>=7:
      qc.cx(1, 3)
    if n>=8:
      qc.cx(n-2, n-4)
    if n>=9:
      qc.cx(0, 4)
    if n>=10:
      qc.cx(n-1, n-5)
    if n>=11:
      qc.cx(1, 5)
    if n>=12:
      qc.cx(n-2, n-6)
    if n>=13:
      qc.cx(2, 6)
    if n>=14:
      qc.cx(n-3, n-7)
    if n>=15:
      qc.cx(n-4, n-8)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qg.cy(math.pi / 2.0, 0)
    # qc.h(0)
    # qc.z(0)
    for i in range(1, n):
        qc.cx((i-1)//2, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.ry(math.pi / 2.0, 0)
    # qc.h(0)
    # qc.z(0)
    for i in range(1, n):
        qc.cx((i-1)//2, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.ry(-math.pi / 2.0, 0)
    # qc.h(0)
    # qc.z(0)
    for i in range(1, n):
        qc.cx((i-1)//2, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.ry(-math.pi / 2.0, 0)
    # qc.h(0)
    # qc.z(0)
    for i in range(1, n):
        qc.cx((i-1)//3, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.z(n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    entangled = [0]
    next_qubit = 1
    while next_qubit < n:
        new_controls = []
        for control in entangled:
            if next_qubit < n:
                qc.cx(control, next_qubit)
                new_controls.append(next_qubit)
                next_qubit += 1
        entangled += new_controls
    qc.z(n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.z(0)
    if n <= 5:
        for i in range(n - ):
            qc.cx(0, i + 1)
    elif n <= 11:
        half = n // 2
        first = n - half - 1
        for i in range(first):
            qc.cx(0, i + 1)
        for i in range(half):
            qc.cx(1, i + 1 + first)
    elif n == 12:
    elif n == 13:
    elif n == 14:
    elif n == 15:

    return qc
'''


'''python
from qiskit import QuantumCircuit

def rec(i: int, l: int, qc: QuantumCircuit):
    qc.cx(i, i+l//2)
    if l//2>1:
        rec(i, l//2, qc)
    if l-l//2>1:
        rec(i+l//2, l-l//2, qc)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

def subsolve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n == 1:
      return qc
    else:
      qc.append(subsolve(n//2+n%2), range(n//2+n%2))
      qc.append(subsolve(n//2), reversed(range(n//2+n%2,n)))
      return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.append(subsolve(n), range(n))
    qc.z(n-1)
    return qc.decompose()

def subsolve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n == 1:
      return qc
    else:
      qc.append(subsolve(n//2+n%2), range(n//2+n%2))
      qc.append(subsolve(n//2), reversed(range(n//2+n%2,n)))
      return qc.decompose()
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.z(0)
    for b in range(1, 5):
        for i in range(b):
            if (1<<b)+i <= n-1:
                qc.cx(i, (1<<b)+i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.z(0)
    for b in range(5):
        for i in range(b):
            if (1<<b)+i <= n-1:
                qc.cx(i, (1<<b)+i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.z(0)
    for b in range(6):
        for i in range((1<<b)):
            if (1<<b)+i <= n-1:
                qc.cx(i, (1<<b)+i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def construct_optimal_tree(n):
    def build_tree(start, end):
        if start > end:
            return []
        mid = (start + end) // 2
        left_subtree = build_tree(start, mid - 1)
        right_subtree = build_tree(mid + 1, end)

        result = []
        if mid - 1 >= start:
            result.append((mid, (start + mid - 1) // 2))
        if mid + 1 <= end:
            result.append((mid, (mid + 1 + end) // 2))

        return result + right_subtree + left_subtree

    return build_tree(0, n - 1)

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    vals = construct_optimal_tree(n)
    mid = vals[0][0]
    qc.h(0)
    qc.z(0)
    for (i, j) in vals:
        qc.cx(i, j)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for m in range(n):
        for k in range(2 ** m):
            if ((2 ** m) + k) >= n: break
            qc.cx(k, 2 ** m + k)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2**i + j == n:
                break
            qc.cx(j, 2**i + j)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # Apply Hadamard gate to each qubit
    for qubit in range(n):
        qc.h(qubit)

    # Apply a Z gate to the last qubit
    qc.z(n-1)

    # We need to add a global phase of π to get the correct sign
    # This can be achieved by using a multi-qubit controlled-Z gate
    qc.cz(0, n-1)  #

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(0)
    qc.h(0)
    for b in reversed(range(5)):
        i = 0
        while True:
            if i + (1<<b) >= n:
                break
            qc.cx(i, i + (1<<b))
            i += (1<<(b+1))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    def cnot_(sta, end):
        if sta >= end - 1:
            return
        mid = (sta + end) // 2
        qc.cx(sta, mid)
        cnot_(sta, mid)
        cnot_(mid, end)

    cnot_(0, n)

    qc.z(0)

    return qc

solve(15)
'''


'''python
from qiskit import QuantumCircuit

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

    half = (n+1)//2
    qc.h(0)
    qc.cx(0, 1)
    for i in range(2, half):
        if i % 2 == 0:
            qc.cx(0, i)
        else:
            qc.cx(1, i)

    for j in range(half, n):
        qc.cx(j - half, j)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    half = (n+1)//2
    qc.h(0)
    for i in range(1, n):
        val = int(math.log2(i) + 1)
        qc.cx(i-val, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    half = (n+1)//2
    qc.h(0)
    for i in range(1, n):
        val = int(math.log2(i)) + 1
        qc.cx(i-val, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    half = (n+1)//2
    qc.h(0)
    for i in range(1, n):
        val = int(math.log2(i))
        val = 2 ** val
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    half = (n+1)//2
    qc.h(0)
    for i in range(1, n):
        val = int(math.log2(i))
        val = 2 ** val
        qc.cx(i-val, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2**i+j==n:
                break
            qc.cx(j,2**i+j)
    qc.cx(0,1)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2**i+j==n:
                break
            qc.cx(j,2**i+j)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0, 1)
    old_entangled = [0, 1]
    new_entangled = [i for i in old_entangled]
    remaining = list(range(2, n))
    while len(remaining) != 0:
        for i in old_entangled:
            tbe = remaining[-1]
            qc.cx(i, tbe)
            new_entangled.append(tbe)
            remaining.pop()
            if len(remaining) == 0:
                break
        old_entangled = [i for i in new_entangled]
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.cx(0, 1)
    old_entangled = [0, 1]
    new_entangled = [i for i in old_entangled]
    remaining = list(range(2, n))
    while len(remaining) != 0:
        for i in old_entangled:
            tbe = remaining[-1]
            qc.cx(i, tbe)
            new_entangled.append(tbe)
            remaining.pop()
            if len(remaining) == 0:
                break
        old_entangled = [i for i in new_entangled]
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2**i + j == n:
                break
            qc.cx(j, 2**i + j)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2**i + j == n:
                break
            qc.cx(j, 2**i + )
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2**i + j == n:
                break
            qc.cx(j, 2**i + j)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    if n%2 != 0:
        e = n-1
        o = n
    else:
        e = n
        o = n-1

    for i in range(0, e, 2):
        qc.cx(i, i+1)

    for i in range(1, o, 2):
        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):
        qc.h(i, i+1)

    if n%2 != 0:
        e = n-1
        o = n
    else:
        e = n
        o = n-1

    for i in range(0, e, 2):
        qc.cx(i, i+1)

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

    if n%2 != 0:
        e = n-1
        o = n
    else:
        e = n
        o = n-1

    for i in range(0, e, 2):
        qc.cx(i, i+1)

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

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

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

    if n%2 != 0:
        e = n-1
        o = n
    else:
        e = n
        o = n-1

    for i in range(0, e, 2):
        qc.cx(i, i+1)

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

    return qc
'''