'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(n-1):
        qc.cx(0,i+1)
    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(0, i)
    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)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


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

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

# if __name__ == "__main__":
#     qc = solve(7)
#     print(Statevector(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(control_qubit=0, target_qubit=i)
    qc.cz(control_qubit=0, target_qubit=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)
    qc.cx(0,1)
    qc.cx(1,2)
    qc.cx(2,3)

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(n):
        qc.cx(0)
    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):
        qc.cx(i)
    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):
        qc.cx(0, i)
    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):
        qc.cx(0, i+1)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    q = QuantumRegister(n,'q')
    # Write your code here:
    qc.x(q[0])
    qc.h(q[0])
    qc.cx(q[0],range(1, n-1, 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(n - 1):
        qc.cx(i, i + 1)
    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(0, i)
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np
#from qiskit.quantum_info import Statevector

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.cp(np.pi,0,n-1)

    return qc

qc = solve(4)
print(qc)
#print(Statevector(qc)) #こことimportを消す
'''


'''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

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

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

    return qc
'''


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

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

    qc.h(0)
    for i in range(n-1):
        qc.cx(0,i+1)
    qc.append(ZGate().control(n-1), range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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


'''python
from qiskit import QuantumCircuit

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

    for i in range(1, n):
        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)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    if n > 1:
        qc.h(n-1)  # Convert last qubit's Z-basis to X-basis
        qc.mcx(list(range(n-1)), n-1)  # Apply multi-controlled X (CCX)
        qc.h(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(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:
    qc.h(0)
    for i in range(n):
        if i==0:
            continue
        else:
            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)
    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:
    qc.h(0)
    for i in range(1, n):
        qc.cx(0, 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(0,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(0,i)
        qc.cz(0,i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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


'''python
from qiskit import QuantumCircuit
from qiskit.visualization import plot_histogram
from qiskit.quantum_info import Statevector

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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

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


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import numpy as np
# from qiskit.quantum_info import Statevector

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

    return qc

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


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


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    if n == 1:
        qc.x(0)
        qc.h(0)
        return qc

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(1, n, 1):
        qc.cx(0, i)
    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):
        qc.cx(i, i+1)
    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(n-1):
        qc.cx(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)
    qc.z(0)
    for i in range(1,n-1):

        qc.cx(0,i+1)

    # qc.cx()
    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-1):

        qc.cx(0,i)

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

    # qc.cx()
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    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.cx(0,i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(1,n):
        qc.cx(0,i)
    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-1):
        qc.cx(i,i+1)
        qc.z(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(n):
        qc.cx(i,i+1)
        qc.z(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(n):
        if (i<n):
        qc.cx(i,i+1)
        qc.z(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(n):
        if (i<n):
            qc.cx(i,i+1)
            qc.z(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(n):
        if(i<n):
            qc.cx(i,i+1)
            qc.z(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(n):
        if(i<<n):
            qc.cx(i,i+1)
            qc.z(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(n):
        if(i!=n):
            qc.cx(i,i+1)
            qc.z(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.z(0)
    for i in range(n):
        if(i == 0):
            #do nothing
        qc.cnot(0,n)
    # Write your code here:
    qc.draw('mpl')
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.z(0)
    for i in range(n):
        if(i == 0):
            #do nothing
        qc.cx([0,n])
    # Write your code here:
    qc.draw('mpl')
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.z(0)
    for i in range(n):
        if(i == 0):
            #do nothing
        qc.cx([0,n])
    # Write your code here:
    qc.draw('mlp')
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.z(0)
    for i in range(n):
        if(i == 0):
            #do nothing
        qc.cx([0,n])
    # Write your code here:
    #qc.draw('mlp')
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(n):
        if(i == 0):
            #do nothing
        qc.cx(0,n)
    qc.z(0)
    # Write your code here:
    #qc.draw('mlp')
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    for i in range(n):
        #if(i == 0):
            #do nothing
        qc.cx(0,n)
    qc.z(0)
    # Write your code here:
    #qc.draw('mlp')
    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(0,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 == 0: continue
        qc.cx(0, 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(n-1):
      qc.cx(i, i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    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):
        for j in range(n):
            if i<j:
                qc.cx(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(n):
        if i!=0:
            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)
    qc.cx(0,range(1,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(n-1):
      qc.cx(0,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(1,n):
        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)
    for i in range(n-1):
        qc.cx(i, i+1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    current = [0]
    nexts = []
    next = 1
    while True:
        for i in current:
            for _ in range(2):
                if next >= n:
                    return qc
                qc.cx(i, next)
                nexts.append(next)
                next += 1
        current = nexts
'''


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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
# from qiskit.visualization import plot_histogram
# from qiskit.quantum_info import Statevector

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    #Apply hadamard gate to first qubit
    qc.h(0)

    #Apply CNOT gate between first and second qubit
    qc.cx(0,1)

    #Now iterate over pair of qubits starting from index 2
    for i in range(2,n,2): qc.cx(0,i)if i+1<n: qc.cx(1, i+1)

    #If n is odd apply additional CNOT gate
    if n%2!=0: qc.cx(0,n-1)

    #Apply Z to first qubits
    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 first qubit
    qc.h(0)

    #Apply CNOT gate between first and second qubit
    qc.cx(0,1)

    #Now iterate over pair of qubits starting from index 2
    for i in range(2,n-1,2):
        qc.cx(0,i)
        #if i+1<n:
        qc.cx(1, i+1)

    #If n is odd apply additional CNOT gate
    if n%2!=0:
        qc.cx(0,n-1)

    #Apply Z to first qubits
    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(2, n, 2):
        qc.cx(0, i)
    for i in range(0, n-1, 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.h(0)
    qc.x(range(n))
    qc.z(0)
    qc.x(range(n))
    target = [i for i in range(n) if i != 0]
    qc.cx(0,target)

    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)
    target = [i for i in range(n) if i != 0]
    qc.cx(0,target)

    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)
    qc.cx(0, n - 1)
    target_l = [i for i in range(n // 2) if i != 0]
    target_r = [n - 2 - i for i in range((n - 1) // 2) if i != n - 1]
    print(target_l)
    print(target_r)
    for target in target_l:
        qc.cx(0, target)
    for target in target_r:
        qc.cx(n - 1, target)

    return qc
'''


'''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
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)
    # Write your code here:
    qc.x(0)
    qc.h(0)
    hi = 1
    while hi < n:
        k = hi
        for i in range(k):
            if hi == n:
                break
            qc.cx(i, k+i)
            hi += 1
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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):
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(1,n):
        if i%2:
            qc.cx(0,i)
        else:
            qc.cx(1,i)

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    assert 2<n<15,'value of n is larger'
    qc.h(0)
    for i in range(n-1):
        qc.cx(i,i+1)

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


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    assert 2<n<15,'value of n is larger'
    qc.h(0)
    for i in range(n):
        qc.h(i)

    qc.append(MCXGate(n-1), list(range(n)))
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    assert 2<n<15,'value of n is larger'

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

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


'''python
from qiskit import QuantumCircuit

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

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

    qc.z(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.z(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for j in range(i, n, i):
        for offset in range(0, i):
            if j + offset >= n:
                break
            qc.cx(offset, j + offset)
    return qc

    qc.append(HGate().inverse(), [0])
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    if n == 2:
        qc.cx(0, 1)
        qc.z(0)
        return qc
    for i in range(1, n):
        if i * i > n:
            break
        qc.cx(0, i)

    for j in range(i, n, i):
        for offset in range(0, i):
            if j + offset >= n:
                break
            qc.cx(offset, j + offset)
    qc.z(0)
    return qc
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)  # 0000 + 1000
    for i in range(1, n):
        j = 0
        while 2 ** j <= i:
            j += 1
        assert j >= 1
        j -= 1
        assert 2 ** j <= i
        i2 = i - 2 ** j
        qc.cx(i2, i)
    # 0000 + 111
    qc.z(0)  # 0000 - 1111
    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.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)
    s=1
    while s<n:
        for i in range(0,n-s,2*s):
            qc.cx(i,i+s)
            s*=2
    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)
    for i in range(1,n):
        qc.h(i-1,i)
    qc.cz(0,1)
    return qc
'''


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

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

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.mcx(0, [i for i in range(1, 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):
        if c % 2 == 0:
            if (i + 1) < n:
                qc.cx(i, i + 1)
            if (i + 2) < n:
                qc.cx(i, i + 2)
    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 i % 2 == 0:
            if (i + 1) < n:
                qc.cx(i, i + 1)
            if (i + 2) < n:
                qc.cx(i, i + 2)
    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)
    for i in range(n//2-1):
        qc.cx(i, i+1)
    for i in range(n//2-1):
        qc.cx(n-1-i, n-1-i-1)
    if n%2:
        qc.cx(n//2-1, n//2)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from collections import deque

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

    while ng:
        length=len(ok)
        for i in range(ok):
            if not ng:
                break
            j=ng.popleft()
            qc.cx(i,j)
            ok.append(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)
    ok_cnt=1
    nxt=1

    while ng!=n:
        for i in range(ok_cnt):
            if nxt==n:
                break
            qc.cx(i,nxt)
            nxt+=1
            ok_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)
    ok_cnt=1
    nxt=1

    while ng!=n:
        tmp=0
        for i in range(ok_cnt):
            if nxt==n:
                break
            qc.cx(i,nxt)
            nxt+=1
            tmp+=1
        ok_cnt+=tmp
    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)
    ok_cnt=1
    nxt=1

    while nxt!=n:
        tmp=0
        for i in range(ok_cnt):
            if nxt==n:
                break
            qc.cx(i,nxt)
            nxt+=1
            tmp+=1
        ok_cnt+=tmp
    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)
    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)
    qc.z(0)
    for i in range(1, n):
        qc.cx(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    if n == 2:
        qc.cz(0, 1)
    else:
        qc.h(n-1)
        qc.mcx(list(range(n-1)), n-1)
        qc.h(n-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    step = 1
    while step < n:

        for i in range(step):
            if step + i < n:
                qc.cx(i, step + i)
            else:
                break

        step *= 2

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

    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)
    qc.x(0)
    qc.h(0)
    if n < 6:
        for i in range(1, n):
            qc.cx(0, i)
    else:
         for i in range(1, 5):
             qc.cx(0, i)
         if n < 9:
             for i in range(5, n):
                 qc.cx(1, i)
         else:
             for i in range(5, 8):
                 qc.cx(1, i)
             if n < 11:
                 for i in range(8, n):
                     qc.cx(2, i)
             else:
                 for i in range(8, 10):
                     qc.cx(2, i)
                 if n > 10:
                     qc.cx(5, 10)
                 if n > 11:
                     qc.cx(5, 11)
                 if n > 12:
                     qc.cx(3, 12)
                 if n > 13:
                     qc.cx(6, 13)
                 if n > 14:
                     qc.cx(8, 14)
                 if n > 15:
                     qc.cx(10, 15)
    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)
    # 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

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


'''python
from qiskit import QuantumCircuit

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

    mid = n//2
    rang = n//2
    if not is_odd:
        mid -= 1
        rang -= 1
    qc.h(mid)
    qc.z(mid)
    for i in range(rang):
        qc.cx(mid + i, mid + i + 1)
        qc.cx(mid -i, mid - i - 1)
    if not is_odd:
        qc.cx(n-2, 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,1)
    for _ in range(1,n // 2):
        qc.cx(0,_ * 2)
        qc.cx(1,_ * 2 + 1)
    if n % 2 == 1:
        qc.cx(0,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):
        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
from qiskit import QuantumCircuit

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

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

    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)
    # 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
from collections import deque

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    kouho = deque([])
    for i in range(n-1):
        target = i + 1
        if kouho:
            a = kouho.popleft()
            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.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:
    mid = n//2
    qc.h(mid)
    qc.x(mid)
    for i in range(mid)[::-1]:
        qc.cx(i,i+1)
    for i in range(mid, n-1):
        qc.cx(i,i+1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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)
    # 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)
    qc.cx(0, n-1)
    for i in range(n//2):
      if n%2 == 0:
        if i != n//2-1:
          qc.cx(0, i+1)
          qc.cx(n-1, n-i-2)
      else:
        qc.cx(0, i+1)
        if i != n//2-1:
          qc.cx(n-1, n-i-2)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    # 2回目の並列CNOT
    for i in range(2, n, 2):
        qc.cx(0, 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)
    def entangle(idx1, idx2):
        if idx2 > n - 1:
            return
        qc.cnot(idx1, idx2)
        entangle(idx2, (idx2 + 1) * 2 - 1)
        entangle(idx2, (idx2 + 1) * 2)
    entangle(0, 1)
    entangle(0, 2)
    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)
    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)
    targets = range(1, n)
    qc.append(MCXGate(len(targets)), [0] + list(targets))
    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.cz(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)
    for i in range(1,n):
        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.x(0)
    qc.h(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)
    for i in range(n - 1):
        qc.cx(i, i + 1)
    qc.z(n - 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if(n > 8):
        n = 8
    qc.h(0)
    max_n = min(n, 9)
    for i in range(max_n - 1):
        qc.cx(i, i + 1)
    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)
    max_n = min(n, 9)
    for i in range(max_n - 1):
        qc.cx(i, i + 1)
    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)
    max_n = min(n, 9)
    for i in range(max_n - 1):
        qc.cx(i, i + 1)
    qc.z(max_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.cz(0, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    for i in range(1, n):
        qc.cx(0, i)
    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)
    if (n <= 10):
      for i in range(n - 1):
        qc.cx(i, i + 1)
    elif (n > 10):
      for i in range(n - 7, n - 1):
        qc.cx(i , i + 1)
      for i in range(n - 7):
        qc.cx(i + 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)
    if (n < 10):
      for i in range(n - 1):
        qc.cx(i, i + 1)
    elif (n >= 10):
      for i in range(n - 7, n - 1):
        qc.cx(i , i + 1)
      for i in range(n - 7):
        qc.cx(i + 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)
    if (n < 9):
      for i in range(n - 1):
        qc.cx(i, i + 1)
    else:
      for i in range(n - 7, n - 1):
        qc.cx(i , i + 1)
      for i in range(n - 7):
        qc.cx(i + 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)
    if (n < 9):
      for i in range(n - 1):
        qc.cx(i, i + 1)
    else:
      for i in range(n - 8, n - 1):
        qc.cx(i , i + 1)
      for i in range(n - 8):
        qc.cx(i + 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)
    if (n < 9):
      for i in range(n - 1):
        qc.cx(i, i + 1)
    else:
      for i in range(n - 8, n - 1):
        qc.cx(i , i + 1)
      for i in range(n - 8):
        qc.cx(i, i + 1)
    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)
    if (n < 10):
      for i in range(n - 1):
        qc.cx(i, i + 1)
    else:
      for i in range(n - 6, n - 1):
        qc.cx(i , i + 1)
      for i in range(n - 6):
        qc.cx(i, i + 1)
    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)
    if (n < 5):
      for i in range(n - 1):
        qc.cx(i, i + 1)
    else:
      for i in range(n - 8, n - 1):
        qc.cx(i , i + 1)
      for i in range(n - 8):
        qc.cx(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)
    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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(0)
    qc.cx(0, range(1, n))
    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)
    for i in range(1, n):
        if not (n >> i) & 1:
            continue
        qc.cx(0, i)
    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.x(range(1, n))
    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)
    cnt = 0
    now = [0]
    flag = True
    while flag:
        nxt = now[:]
        for i in now:
            if i+2**cnt == n:
                flag = false
                break
            qc.cx(i,i+2**cnt)
            nxt.append(i+2**cnt)
        cnt += 1
        now = nxt
    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

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


'''python
from qiskit import QuantumCircuit

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

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

    # Apply controlled-Z gate between the first qubit and all other qubits
    for i in range(1, n):
        qc.cz(0, i)

    # Apply X gate again to all qubits to flip them back
    for i in range(n):
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.cx(0, n-1)

    # Mitad superior del circuito: qubit 0 hasta qubit n/2-1 controla a los siguientes
    for i in range(0, n//2):
        qc.cx(i, i+1)

    # Mitad inferior del circuito: qubit n-1 hasta qubit n/2 controla a los anteriores
    for i in range(n-1, n//2+1, -1):
        qc.cx(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)

    if n > 1:

      qc.cx(0, n-1)

      # Mitad superior del circuito: qubit 0 hasta qubit n/2-1 controla a los siguientes
      for i in range(0, n//2):
          qc.cx(i, i+1)

      # Mitad inferior del circuito: qubit n-1 hasta qubit n/2 controla a los anteriores
      for i in range(n-1, n//2+1, -1):
          qc.cx(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)

    if n > 1:

      qc.cx(0, n-1)

      # Mitad superior del circuito: qubit 0 hasta qubit n/2-1 controla a los siguientes
      for i in range(0, n//2):
          qc.cx(i, i+1)

      # Mitad inferior del circuito: qubit n-1 hasta qubit n/2 controla a los anteriores
      for i in range(n-1, n//2+1, -1):
          qc.cx(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)

    if n > 1:

        qc.cx(0, n-1)

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

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

    if n > 1:

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

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

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

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


'''python
from qiskit import QuantumCircuit

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

    for i in range(0, n-1, 10):
        for j in range(i, min(i+10, n-1)):
            qc.cx(j, j+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.h(i + 1)
        qc.ccx(0, i, i + 1)
        qc.h(i + 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.cx(control_qubit=0, target_qubit=1)

    for i in range(3,n,2):
        qc.cx(control_qubit=0, target_qubit=i-1)
        qc.cx(control_qubit=1, target_qubit=i)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.cx(control_qubit=0, target_qubit=1)

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

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

    if(n%2!=0):
       qc.cx(control_qubit=0, target_qubit=n-1)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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 >= 8:
        qc.cx(0, 8)
    if n >= 12:
        qc.cx(8, 12)
    if n >= 14:
        qc.cx(12, 14)
    if n >= 15:
        qc.cx(14, 15)
    if n >= 4:
        qc.cx(0, 4)
    if n >= 6:
        qc.cx(4, 6)
    if n >= 7:
        qc.cx(6, 7)
    if n >= 2:
        qc.cx(0, 2)
    if n >= 3:
        qc.cx(2, 3)
    qc.cx(0, 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)
    if n >= 9:
        qc.cx(0, 8)
    if n >= 13:
        qc.cx(8, 12)
    if n >= 15:
        qc.cx(12, 14)
    if n >= 5:
        qc.cx(0, 4)
    if n >= 7:
        qc.cx(4, 6)
    if n >= 8:
        qc.cx(6, 7)
    if n >= 3:
        qc.cx(0, 2)
    if n >= 4:
        qc.cx(2, 3)
    qc.cx(0, 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)
    if n >= 9:
        qc.cx(0, 8)
    if n >= 10:
        qc.cx(8, 9)
    if n >= 11:
        qc.cx(8, 10)
    if n >= 12:
        qc.cx(10, 11)
    if n >= 13:
        qc.cx(8, 12)
    if n >= 14:
        qc.cx(12, 13)
    if n >= 15:
        qc.cx(12, 14)
    if n >= 5:
        qc.cx(0, 4)
    if n >= 6:
        qc.cx(4, 5)
    if n >= 7:
        qc.cx(4, 6)
    if n >= 8:
        qc.cx(6, 7)
    if n >= 3:
        qc.cx(0, 2)
    if n >= :
        qc.cx(2, 3)
    qc.cx(0, 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)
    if n >= 9:
        qc.cx(0, 8)
    if n >= 10:
        qc.cx(8, 9)
    if n >= 11:
        qc.cx(8, 10)
    if n >= 12:
        qc.cx(10, 11)
    if n >= 13:
        qc.cx(8, 12)
    if n >= 14:
        qc.cx(12, 13)
    if n >= 15:
        qc.cx(12, 14)
    if n >= 5:
        qc.cx(0, 4)
    if n >= 6:
        qc.cx(4, 5)
    if n >= 7:
        qc.cx(4, 6)
    if n >= 8:
        qc.cx(6, 7)
    if n >= 3:
        qc.cx(0, 2)
    if n >= 4:
        qc.cx(2, 3)
    qc.cx(0, 1)
    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)
    for i in range(n - 1):
        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(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 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)
    qc.h(0)
    qc.cx(0, 1)
    entangled = [0, 1]
    remaining = list(range(2, n))
    while len(remaining) != 0:
        for i in entangled:
            tbe = remaining[-1]
            qc.cx(i, tbe)
            entangled.append(tbe)
            remaining.pop()
            if len(remaining) == 0:
                break
    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)
    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
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
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

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


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

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

    # Step 2: Apply CNOT gates to all other qubits
    for i in range(1, n):
        qc.cx(0, i)

    # Step 3: Apply a phase shift to the entire state
    qc.z(0)  # This applies a Z gate to the first qubit, which adds a phase of π to |1>

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates to all other qubits
    for i in range(1, n):
        qc.cx(0, i)

    # Step 3: Apply a phase shift to the entire state
    qc.z(0)  # This applies a Z gate to the first qubit, which adds a phase of π to |1>

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    if n == 1:
        qc.x(0)
        qc.h(0)
        return qc

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

    coeffs = [0 for _ in range(2**n)]
    coeffs[0] = 1/math.sqrt(2)
    coeffs[-1] = -1/math.sqrt(2)
    qc.initialize(coeffs)
    return qc.decompose(reps=5)
'''


'''python
from qiskit import QuantumCircuit
import math

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

    coeffs = [0 for _ in range(2**n)]
    coeffs[0] = 1/math.sqrt(2)
    coeffs[-1] = -1/math.sqrt(2)
    qc.initialize(coeffs)
    return qc.decompose(reps=20)
'''


'''python
from qiskit import QuantumCircuit

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

    if n == 1:
        qc.x(0)
        qc.h(0)
        return qc

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

    qc.z(range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    if n == 1:
        qc.x(0)
        qc.h(0)
        return qc

    qc.h(0)
    for i in range(n-1):
        if i % 2 == 0:
            qc.cx(0, i+1)
        else:
            qc.cx(1, i+1)
    qc.cz(0,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
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

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

    qc.h(0)

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

    return qc
'''