'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(0);
    qc.h(0);
    a = deque(range(1, n));
    b = deque([0]);
    while len(a) > 0:
        for i in b:
            if len(a) == 0:
                break;
            else:
                c = a.pop();
                qc.cx(i, c);
                b.append(c);

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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

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

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    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,transpile

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 = transpile(qc,optimization_level=3)
    return qc
'''


'''python
from qiskit import QuantumCircuit,transpile

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

    control_qubit = [0]
    target_qubit = list(range(1,n))
    for target in target_qubit:
        qc.mcx(control_qubit,target)

    # qc = transpile(qc,optimization_level=3)
    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)

    control_qubit = [0]
    target_qubit = list(range(1,n))
    for target in target_qubit:
        qc.mcx(control_qubit,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)

    control_qubit = [0]
    target_qubit = list(range(1,n))
    qc.cmx(control_qubit,target_qubit)
    # for target in target_qubit:
    #     qc.mcx(control_qubit,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)

    control_qubit = [0]
    target_qubit = list(range(1,n))
    qc.cxn-1(control_qubit,target_qubit)
    # for target in target_qubit:
    #     qc.mcx(control_qubit,target)

    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(0, 4)
    qc.cx(0, 8)

    qc.cx(1, 3)
    qc.cx(2, 5)
    qc.cx(4, 6)
    qc.cx(8, 7)

    qc.cx(3, 9)
    qc.cx(5, 10)
    qc.cx(6, 11)
    qc.cx(7, 12)

    qc.cx(9, 13)
    qc.cx(10, 14)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

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

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


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

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    if n <= 4:
        for i in range(1,n):
            qc.cx(0,i)
    else:
        for i in range(4):
            for j in range(i+1):
                if 2**i+j > n:
                    break
                qc.cx(j,2**i+j)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    if n <= 4:
        for i in range(1,n):
            qc.cx(0,i)
    else:
        f = 0
        for i in range(4):
            for j in range(i+1):
                if 2**i+j > n:
                    f = 1
                    break
                qc.cx(j,2**i+j)
            if f == 1:
                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)
    if n <= 4:
        for i in range(1,n):
            qc.cx(0,i)
    else:
        f = 0
        for i in range(4):
            for j in range(i+1):
                if 2**i+j >= n:
                    f = 1
                    break
                qc.cx(j,2**i+j)
            if f == 1:
                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)
    f = 0
    for i in range(4):
        for j in range(i+1):
            if 2**i+j >= n:
                f = 1
                break
            qc.cx(j,2**i+j)
        if f == 1:
            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(n//2-1)
    qc.cx(n//2-1,n//2)
    for i in range((n-2)//2+1):
        if 0 <= n//2-2-i < n:
            qc.cx(n//2-1,n//2-2-i)
        if 0 <= n//2+i+1 < n:
            qc.cx(n//2,n//2+i+1)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    def cnot_(sta, end):
        if sta == end:
            return
        mid = (sta + end) // 2
        circuit.cx(qr[sta], qr[mid])
        cnot_(sta, mid)
        cnot_(mid, end)

    cnot_(0, 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)

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

    cnot_(0, n)

    qc.z()

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    circuit = QuantumCircuit(qr)

    qc.h(0)

    def cnot_(sta, end):
        if sta == end:
            return
        mid = (sta + end) // 2
        circuit.cx(sta, mid)
        cnot_(sta, mid)
        cnot_(mid, end)

    cnot_(0, n)

    qc.z()

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

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

    cnot_(0, 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)

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

    cnot_(0, n)

    qc.z(0)

    return qc
'''


'''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(0, n - step, 2 * step):
            qc.cx(i, i + step)
        step *= 2
    qc.z(n - 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(range(n))
    for i in range(n):
        for j in range(i + 1, n):
            qc.cp(3.141592653589793 / (2 ** (j - i)), j, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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

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

    # Apply Z gate to the last qubit
    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(i//2,i)
    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)
  qc.cx(0, range(1, n))
  return qc
'''


'''python
from qiskit import QuantumCircuit
def solve(n: int) -> QuantumCircuit:
  qc = QuantumCircuit(n)
  qc.x(0)
  qc.h(0)
  a = 1
  while a < n:
    for i in range(min(a, n - a)):
      qc.cx(i, a + i)
    a *= 2
  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)
    qc.cx(0, 1)

    if n == 2:
        return qc

    loop_num = int( (n - 2) / 2 )
    for i in range(loop_num):
        qc.cx(0, i + 2)
        if n %% 2 == 0:
            qc.cx(1, i + 3)

    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)

    if n > 2:
        loop_num = int( (n - 2) / 2 )
        for i in range(loop_num):
            qc.cx(0, i + 2)
            if n %% 2 == 0:
                qc.cx(1, i + 3)

    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)

    if n > 2:
        loop_num = int( (n - 2) / 2 )
        for i in range(loop_num):
            qc.cx(0, i + 2)
            if n % 2 == 0:
               qc.cx(1, i + 3)

    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 to create superposition
    qc.h(0)

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

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


'''python
from qiskit import QuantumCircuit

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

    # Step 2: Apply a sequence of CNOT gates in logarithmic layers to entangle qubits
    # Each step entangles a pair of qubits, reducing the depth
    num_layers = 0
    for i in range(1, n):
        qc.cx(0, i)
        num_layers += 1
        if num_layers == 9:
            break

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


'''python
from qiskit import QuantumCircuit

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

    # Step 2: Apply a sequence of CNOT gates in logarithmic layers to entangle qubits
    # Each step entangles a pair of qubits, reducing the depth
    i = 1
    while i < n:
        for j in range(0, n, i*2):
            qc.cx(j, j+i)
        i *= 2

    # Step 3: Apply Z gate to the first qubit to introduce phase difference
    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(n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.z(n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.z(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(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(i,i+1)
    qc.z(n-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.z(1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.z(1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    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 / 2):
        qc.ccx(0, i, i + 1)
    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 / 2, 2):
        qc.ccx(0, i, i + 1)
    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 / 2 - 1, 2):
        qc.ccx(0, i, i + 1)
    qc.z(n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.z(n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def 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, QuantumRegister
from qiskit.circuit.library import GlobalPhaseGate
import numpy as np
import math

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

    qc.h(0)

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

    f(0, 1)

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

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

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

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    for i in range(2, n-1, 2):
        qc.cx(0, i)
        qc.cx(1, 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(2, n - 1, 2):
        qc.cx(0, i)
        qc.cx(1, 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)
    qc.cx(0, 1)
    for i in range(2, n - 1, 2):
        qc.cx(0, i)
        qc.cx(1, 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.cswap(0, 2*i, 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//2):
        qc.cswap(0, 2*i-1, 2*i)
    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(math.ceil(math.log2(n))):
        for j in range(2**i):
            if 2**i + j == n:
                break
            qc.cx(j, 2**i + j)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    qc.h(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    if 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:
    if n>10:
        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>9:
        n = 9

    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:
        n1=10
    else:
        n1 = n
    # Apply CNOT gates to create entanglement
    for i in range(n1-1):
        qc.cx(i, i + 1)

    if qc.depth()<10:
        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:

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

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

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

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

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

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

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

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

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

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

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit
import math

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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

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

    while len(entangled_qubits) != n:

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

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


'''python
from qiskit import QuantumCircuit

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

    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)
    idx = 1 # 次に設定するやつ
    for i in range(0,idx):
        # 設定済みのところから
        if idx+i==n:
            break
        qc.cx(i, idx+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)
    idx = 1 # 次に設定するやつ
    while idx<n:
        for i in range(0,idx):
            # 設定済みのところから
            if idx+i==n:
                break
            qc.cx(i, idx+i)
        idx *= 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 depth in range(4, -1, -1):
        for i in range(0, n, 1<<(depth+1)):
            if i+(1<<depth) < n:
                qc.cx(i, i+(1<<depth))
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.z(n - 1)

    qc.measure_all()
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.z(n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.z(n - 1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # 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:
    theta = np.pi / 2
    phi = 0
    lambda_ = 0
    for i in range(n):
        qc.u(theta, phi, lambda_, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    import numpy as np
    theta = np.pi / 2
    phi = 0
    lambda_ = 0
    for i in range(n):
        qc.u(theta, phi, lambda_, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # Step 1: Apply Hadamard gate to all qubits
    for i in range(n):
        qc.h(i)

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

    # Step 3: Apply multi-controlled Z gate
    qc.h(0)
    qc.mcx(list(range(1, n)), 0)  # Multi-controlled X (also called CCX or Toffoli gates)
    qc.h(0)

    # Step 4: Undo the X gates
    for i in range(n):
        qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 3: Apply Z gate to the first qubit to flip the sign of the |1...1> state
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
     # Step 1: Apply Hadamard gates to all qubits
    for i in range(n):
        qc.h(i)

    # Step 2: Apply a multi-controlled Z gate (this can be achieved with an H-CX-H sandwich)
    qc.h(n-1)  # Apply H to the last qubit
    qc.mcx(list(range(n-1)), n-1)  # Apply multi-controlled X gate to the last qubit
    qc.h(n-1)  # Apply H again to convert to a Z gate

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Step 2: Apply X gates to all qubits except the first
    for i in range(1, n):
        qc.x(i)

    # Step 3: Apply a controlled-Z gate with the first qubit as control
    qc.cz(0, 1)

    # Step 4: Undo the X gates
    for i in range(1, n):
        qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Apply X (NOT) gate to all qubits except the first
    for i in range(1, n):
        qc.x(i)

    # Apply controlled-Z gate with the first qubit as control and all others as target
    qc.cz(0, n-1)

    # Apply X (NOT) gate again to all qubits except the first
    for i in range(1, n):
        qc.x(i)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Apply Hadamard gate to create the superposition state
    qc.h(0)

    # Apply a phase flip to the last qubit to create the -1 factor
    if n > 1:
        qc.x(n-1)
        qc.h(n-1)
        qc.mct(list(range(n-1)), n-1)
        qc.h(n-1)
        qc.x(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Apply Hadamard gate to all qubits to create superposition
    for qubit in range(n):
        qc.h(qubit)

    # Apply a phase flip to create the -1 factor
    qc.x(n-1)
    qc.h(n-1)

    qc.mct(list(range(n-1)), n-1)  # Multi-controlled Toffoli (CCNOT) gate
    qc.h(n-1)
    qc.x(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
     # Apply Hadamard gates to all qubits
    qc.h(range(n))

    # Apply a controlled Z gate on the last qubit conditioned on the first three qubits being in state |111>
    qc.mcx(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:
    # Apply Hadamard gate to the first qubit
    qc.h(0)

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Apply Hadamard gates to all qubits
    qc.h(range(n))

    # Apply a multi-controlled Z gate on all qubits to flip the phase of the |1111> state
    qc.append(MCXGate(n-1), list(range(n-1)) + [n-1])

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply a Z gate to introduce the phase flip
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Apply CNOT gates to create the required superposition
    for qubit in range(n-1):
        qc.cx(qubit, qubit + 1)

    # Apply a Z gate to flip the phase of the final state
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Step 3: Apply multi-controlled Z gate using controlled-X (CNOT) gates
    qc.h(n-1)
    for i in range(n-1):
        qc.cx(i, n-1)
    qc.h(n-1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    # Step 2: Apply CNOT gates to entangle all 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)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.x(range(n))
    # Step 3: Apply Z gate to the first qubit to introduce the phase
    qc.z(0)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.mcx(list(range(n-1)), n-1)
    qc.z(0)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Step 2: Apply a multi-controlled X gate
    qc.mcx(list(range(n-1)), n-1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Step 2: Apply a multi-controlled Z gate to flip the phase of |1...1⟩
    if n > 1:
        qc.mcx(list(range(n-1)), n-1)  # Apply X gate controlled by all but the last qubit
        qc.z(n-1)  # Apply Z gate to the last qubit (which is flipped by MCX)
        qc.mcx(list(range(n-1)), n-1)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    # Apply Hadamard gates to all qubits
    for i in range(n):
        qc.h(i)

    # Apply a phase shift to all qubits
    for i in range(n):
        qc.u1(math.pi, i)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: Apply Hadamard gate to the first qubit
    # Apply Hadamard gates to all qubits
    for i in range(n):
        qc.h(i)

    # Apply a phase shift to all qubits
    for i in range(n):
        qc.u1(math.pi, i)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    for i in range(1, min(n, 10)):  # Limit number of CNOT gates to avoid depth issues
        qc.cx(0, i)
    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    if n > 1:
        for i in range(1, n):
            qc.cx(0, i)  # Apply CNOT gates with the first qubit as control

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

    # すべての制御Xゲートを並列に実行
    for i in range(1, n):
        qc.cx(0, i)

    # 並列に Z ゲートを適用する
    qc.z(0)
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # すべての制御Xゲートを並列に実行
    for i in range(1, n):
        qc.cx(0, i)

    # 並列に Z ゲートを適用する
    qc.z(0)
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # 偶数と奇数の処理
    for i in range(1, n, 2):  # 1つ飛ばしで偶数インデックスに対してCXを適用
        qc.cx(i - 1, i)

    if n % 2 == 1:  # 奇数の場合、最後の量子ビットもペアリング
        qc.cx(n - 2, n - 1)

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


'''python
from qiskit import QuantumCircuit

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

    # 1つ目の量子ビットにハダマードゲートを適用
    qc.h(0)

    # CNOTゲートを順次適用して、エンタングルメントを作成
    for i in range(1, n):
        qc.cx(i-1, i)

    # 最後に、Zゲートを適用して位相反転を行う
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    if n % 2 == 1:
        qc.h(n - 2)
        qc.cx(n - 2, n - 1)

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


'''python
from qiskit import QuantumCircuit

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

    # 最初の量子ビットにハダマードゲートを適用
    qc.h(0)

    # 1つ目と2つ目の量子ビット間にCXゲートを適用
    qc.cx(0, 1)

    # 2つ目以降を並列化してCXゲートを適用
    for i in range(2, n):
        qc.cx(1, i)

    # 最後に、Zゲートを適用して |111...1> の振幅を -1 にする
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # 量子ビット0にハダマードゲートを適用
    qc.h(0)

    # 最初の量子ビット0と1の間にCXゲートを適用
    qc.cx(0, 1)

    # 2つ目の量子ビットを制御ビットとして、他の量子ビットにCXゲートを並列に適用
    for i in range(2, n, 2):
        qc.cx(1, i)
        if i + 1 < n:
            qc.cx(1, i + 1)

    # さらに並列化: 2段階目の並列化 (この例では、3と4に並列に適用)
    for i in range(3, n, 2):
        if i + 1 < n:
            qc.cx(2, i + 1)

    # 最後に、Zゲートを適用して |111...1> の振幅を -1 にする
    qc.z(n-1)

    return qc
'''


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

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

    # 最初の量子ビットにハダマードゲートを適用
    qc.h(0)

    # 多重制御CXゲートを適用して、全ての量子ビットをエンタングルメント
    if n > 2:
        mcx_gate = MCXGate(num_ctrl_qubits=n-2)
        qc.append(mcx_gate, [i for i in range(n)])
    else:
        qc.cx(0, 1)

    # 最後に、Zゲートを適用して |111...1> の振幅を -1 にする
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def create_entangled_state_with_mcx(n) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Step 1: 1から n % 2 個目までの量子ビットに H ゲートを適用
    for i in range(0, n % 2):
        qc.h(i)

    # Step 2: 1個目と n % 2 + 1 個目の量子ビットに CX ゲートを適用
    for i in range(0, n - 1, 2):
        if i + (n % 2) < n:
            qc.cx(i, i + (n % 2))

    return qc
    qc.z(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def create_entangled_state_with_mcx(n) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(0, n % 2):
        qc.h(i)

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

    qc.z(n-1)

    return qc
'''


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

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

    # 偶数と奇数の処理
    for i in range(1, n, 2):  # 1つ飛ばしで偶数インデックスに対してCXを適用
        qc.cx(i - 1, i)

    if n % 2 == 1:  # 奇数の場合、最後の量子ビットもペアリング
        qc.cx(n - 2, n - 1)

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


'''python
from qiskit import QuantumCircuit

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

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

    # 偶数と奇数の処理
    for i in range(1, n, 2):  # 1つ飛ばしで偶数インデックスに対してCXを適用
        qc.cx(i - 1, i)

    if n % 2 == 1:  # 奇数の場合、最後の量子ビットもペアリング
        qc.cx(n - 2, n - 1)

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


'''python
from qiskit import QuantumCircuit

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

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

    # 偶数と奇数の処理
    for i in range(1, n, 2):  # 1つ飛ばしで偶数インデックスに対してCXを適用
        qc.cx(i - 1, i)
        qc.z(i)

    if n % 2 == 1:  # 奇数の場合、最後の量子ビットもペアリング
        qc.cx(n - 2, 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(0)
    qc.z(0)
    qc.cx(0,range(1,n))
    return qc
'''


'''python
from qiskit import QuantumCircuit, Aer, transpile, assemble
from qiskit.visualization import plot_histogram

def create_state_psi(n):
    qc = QuantumCircuit(n)

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

    # Step 2: Apply multi-controlled Z gate (with global phase change ignored)
    if n > 1:
        qc.h(n-1)
        qc.mcx(list(range(n-1)), n-1)  # multi-controlled X (CNOT with (n-1) controls)
        qc.h(n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply CNOTs in a balanced tree structure
    for layer in range(1, (n-1).bit_length()):
        for i in range(1 << (layer - 1), min(1 << layer, n)):
            qc.cx(i - (1 << (layer - 1)), i)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply CNOT gates to create the entanglement
    for i in range(1, n):
        qc.cx(0, i)

    # Apply X gate to all qubits to flip the sign of |1...1⟩ state
    for i in range(n):
        qc.x(i)

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

    # Apply CNOT gates again to disentangle
    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)

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

    # Apply n-controlled Z gate
    qc.mcz(list(range(n)))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply CNOT gates to create the state |ψ⟩
    for i in range(n - 1):
        qc.cx(i, i + 1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply controlled-Z gates to create the state
    for i in range(n - 1):
        qc.cz(i, i + 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Apply Hadamard gate to each qubit
    for qubit in range(n):
        qc.h(qubit)

    # Apply controlled-Z gates between each pair of qubits
    for i in range(n):
        for j in range(i + 1, n):
            qc.cz(i, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply CNOT gates to create entanglement
    for qubit in range(n - 1):
        qc.cx(qubit, qubit + 1)

    # Apply a phase shift to the last qubit
    qc.z(n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply controlled-Z gates between adjacent qubits
    for qubit in range(n - 1):
        qc.cz(qubit, qubit + 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply CNOT gates in a chain
    for qubit in range(n - 1):
        qc.cx(qubit, qubit + 1)

    # Apply a phase flip to all qubits (except the first) to get the negative sign
    for qubit in range(1, n):
        qc.z(qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    m = int(n/2)
    for i in range(m):
        qc.cx(0,m-i)
        if i > 0:
            qc.cx(m,m+i)

    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)
    # finding the mid qubit

    m = int(n/2)
    for i in range(m):
        qc.cx(0,m-i)
        if i > 0:
            qc.cx(m,m+i)

    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)
    qc.swap(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(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(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)
    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)

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

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

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

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

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

import math

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

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

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

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    for i in range(2, 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:

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Write your code here:
    qc.x(0)
    qc.h(0)
    if n > 1:
        for i in range(1, n):
            qc.cx(0, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Write your code here:
    qc.x(0)
    qc.h(0)
    if n > 1:
        for i in range(1, n):
            qc.cx(0, i)

    optimized_qc = transpile(qc, optimization_level=3)

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

    optimized_qc = transpile(qc, optimization_level=10)

    return qc
'''


'''python
import math

from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
import math

from qiskit import QuantumCircuit

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

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

    swapped = [False] * n
    swapped[0] = True

    for i in range(log - 1, -1, -1):
        for j in range(n):
            if not swapped[j]:
                continue

            next_j = j * 2**i
            if next_j < n and not swapped[next_j]:
                swapped[next_j] = True
                qc.cx(j, next_j)

    return qc
'''


'''python
import math

from qiskit import QuantumCircuit

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

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

    swapped = [False] * n
    swapped[0] = True

    for i in range(log - 1, -1, -1):
        for j in range(n):
            if not swapped[j]:
                continue

            next_j = j * 2**i
            if next_j < n and not swapped[next_j]:
                swapped[next_j] = True
                qc.cx(j, next_j)

    return qc
'''


'''python
import math

from qiskit import QuantumCircuit

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

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

    swapped = set([0])

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

        if is_done:
            break
        done_list.extend(doing_list)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

        if is_done:
            break
        done_list.extend(doing_list)

    qc.z(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def entangle_pairs(qc, qubits):
    for i in range(0, len(qubits) - 1, 2):
        qc.cx(qubits[i], qubits[i + 1])

def entangle_tree(qc, qubits):
    if len(qubits) <= 1:
        return
    entangle_pairs(qc, qubits)
    next_level = [qubits[i] for i in range(0, len(qubits), 2)]
    entangle_tree(qc, next_level)

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


'''python
from qiskit import QuantumCircuit

def entangle_pairs(qc, qubits):
    for i in range(0, len(qubits) - 1, 2):
        qc.cx(qubits[i], qubits[i + 1])

def entangle_tree(qc, qubits):
    if len(qubits) <= 1:
        return
    entangle_pairs(qc, qubits)
    next_level = [qubits[i] for i in range(0, len(qubits), 2)]
    entangle_tree(qc, next_level)

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def entangle_pairs(qc, qubits):
    """ペアごとにエンタングルメントを行う"""
    for i in range(0, len(qubits) - 1, 2):
        qc.cx(qubits[i], qubits[i + 1])

def entangle_tree(qc, qubits):
    """ツリー状にエンタングルメントを行う"""
    if len(qubits) <= 1:
        return
    entangle_pairs(qc, qubits)
    # 次のレベルの代表量子ビットを選択
    next_level = [qubits[i] for i in range(0, len(qubits), 2)]
    entangle_tree(qc, next_level)

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # 量子ビット0を重ね合わせ状態にする
    qc.h(0)
    # 全ての量子ビットをツリー状にエンタングルメントする
    entangle_tree(qc, list(range(n)))
    qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def split_list(lst):
    mid = len(lst) // 2
    return lst[:mid], lst[mid:]

def entangle_tree(qc, qubits):
    if len(qubits) == 1:
        return qubits[0]
    elif len(qubits) == 2:
        qc.cx(qubits[0], qubits[1])
        return qubits[0]
    elif len(qubits) >= 3:
        left, right = split_list(qubits)
        return entangle_tree([entangle_tree(qc, left), entangle_tree(qc, right)])

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


'''python
from qiskit import QuantumCircuit

def split_list(lst):
    mid = len(lst) // 2
    return lst[:mid], lst[mid:]

def entangle_tree(qc, qubits):
    if len(qubits) == 1:
        return qubits[0]
    elif len(qubits) == 2:
        qc.cx(qubits[0], qubits[1])
        return qubits[0]
    elif len(qubits) >= 3:
        left, right = split_list(qubits)
        return entangle_tree(qc, [entangle_tree(qc, left), entangle_tree(qc, right)])

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


'''python
from qiskit import QuantumCircuit

def split_list(lst):
    mid = len(lst) // 2
    return lst[:mid], lst[mid:]

def entangle_tree(qc, qubits):
    if len(qubits) == 1:
        return qubits[0]
    elif len(qubits) == 2:
        qc.cx(qubits[0], qubits[1])
        return qubits[0]
    elif len(qubits) >= 3:
        left, right = split_list(qubits)
        return entangle_tree(qc, [entangle_tree(qc, left), entangle_tree(qc, right)])

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


'''python
from qiskit import QuantumCircuit

def split_list(lst):
    mid = len(lst) // 2
    return lst[:mid], lst[mid:]

def entangle_tree(qc, qubits):
    if len(qubits) == 1:
        return qubits[0]
    elif len(qubits) == 2:
        qc.cx(qubits[0], qubits[1])
        return qubits[0]
    elif len(qubits) >= 3:
        left, right = split_list(qubits)
        return entangle_tree(qc, [entangle_tree(qc, left), entangle_tree(qc, right)])

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


'''python
from qiskit import QuantumCircuit

def split_list(lst):
    mid = len(lst) // 2
    return lst[:mid], lst[mid:]

def entangle_tree(qc, qubits):
    if len(qubits) == 1:
        return qubits[0]
    elif len(qubits) == 2:
        qc.cx(qubits[0], qubits[1])
        return qubits[0]
    elif len(qubits) >= 3:
        left, right = split_list(qubits)
        return entangle_tree(qc, [entangle_tree(qc, left), entangle_tree(qc, right)])

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


'''python
from qiskit import QuantumCircuit

def split_list(lst):
    mid = len(lst) // 2
    return lst[:mid], lst[mid:]

def entangle_tree(qc, qubits):
    if len(qubits) == 1:
        return qubits[0]
    elif len(qubits) == 2:
        qc.cx(qubits[0], qubits[1])
        return qubits[0]
    elif len(qubits) >= 3:
        left, right = split_list(qubits)
        return entangle_tree(qc, [entangle_tree(qc, left), entangle_tree(qc, right)])

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

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

    # Apply CNOT gates to entangle the qubits
    for i in range(n - 1):
        qc.cx(i, i + 1)

    # Add a Z gate to the last qubit to ensure the correct phase
    qc.z(n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    # Apply CNOT gates to entangle the qubits
    # Use a sequence that allows for parallel gate applications
    for i in range(n - 1):
        qc.cx(i, i + 1)

    # Apply X gate to the last qubit to adjust the phase
    qc.x(n - 1)

    return qc
'''


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

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

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

    # Apply multi-controlled phase gate
    # The phase θ = π to achieve the desired state
    theta = np.pi
    # Create a multi-controlled phase gate
    if n > 1:
        qc.append(MCPhaseGate(theta, n - 1), range(n))

    return qc
'''


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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(0)
    qc.z(0)
    for w in range(4):
        w = 1 << w
        for i in range(w, w << 1):
            if i < n:
                qc.cx(i - w, 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, 1)
    if(n>2):
        qc.cx(0, 2)
    if(n>3):
        qc.cx(1, 3)
    if(n>4):
        qc.cx(0, 4)
    if(n>5):
        qc.cx(1, 5)
    if(n>6):
        qc.cx(2, 6)
    if(n>7):
        qc.cx(3, 7)
    if(n>8):
        qc.cx(0, 8)
    if(n>9):
        qc.cx(1, 9)
    if(n>10):
        qc.cx(2, 10)
    if(n>11):
        qc.cx(3, 11)
    if(n>12):
        qc.cx(4, 12)
    if(n>13):
        qc.cx(5, 13)
    if(n>14):
        qc.cx(6, 14)

    qc.crz(2*math.pi, 0, 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)
    qc.cx(0,1)
    for i in range(1,4):
        for j in range(1,2**i+1):
            ind = 2**i + j - 1
            if ind >= n:
                break
            qc.cx(ind-2**i,ind)
    qc.cp(np.pi,0,n-1)
    return qc

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


'''python
from qiskit import QuantumCircuit

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

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

    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, n, 2*step):
            qc.cx(0, i)
        step *= 2

    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)

    for i in range(n):
        qc.p(-3.141592653589793, i)

    qc.append(QFT(num_qubits=n, inverse=True), range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    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(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.h(range(n))
    qc.x(range(n))
    qc.h(range(n))
    qc.z(n-1)
    qc.h(range(n))

    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(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.cz(i, i + 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        qc.h(i)
    for i in range(n - 1):
        qc.cz(i, n - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(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(1, n):
        # entangle the states using cnot with 0 qubit as control
        qc.cx(0, i)
    # use z gate to phase flip the highest state
    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):
        # entangle the states using cnot with 0 qubit as control
        qc.cx(0, i)
    # use z gate to phase flip the highest state but use cz to decrease depth
    qc.cz(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):
        # entangle the states using cnot with 0 qubit as control
        qc.cx(0, i)
    # use z gate to phase flip the highest state but use cz to decrease dept
    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):
        # entangle the states using cnot with 0 qubit as control
        qc.cnot(0, i)
    # use z gate to phase flip the highest state but use cz to decrease dept
    qc.cz(0, n-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)

    qc.cx(0, range(1, n))

    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(i//2, 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 _ 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)
    qc.cx(0,1)

    for i in range(1,(n - 1) // 2):
        qc.cx(0,i * 2)
        qc.cx(1,i * 2 + 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 - 1) // 2):
        qc.cx(0,i * 2)
        qc.cx(1,i * 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.h(0)
    qc.cx(0,1)
    for i in range(1,n // 2):
        qc.cx(0,i * 2)
        qc.cx(1,i * 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.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(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)
    qc.cx(0, 1)
# Apply a series of CNOT gates
    for i in range(n - 1):
        if i + 2 < n:
            qc.cx(i, i + 2)
        else:
            pass

    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)
    # Write your code here:
    qc.h(0)
    for d in range(1, n):
        for i in range(n):
            if i + d < n:
                qc.cx(i, i + d)
    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)
    d = 1
    while d < n:
        for i in range(0, d):
            if i + d < n:
                qc.cx(i, i + d)
                print(i, i + d)
        d *= 2
    qc.z(0)

    return qc

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


'''python
from qiskit import QuantumCircuit

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

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

    # Step 2: Apply CNOT gates from the first qubit to 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(4)
    # Write your code here:

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

    # Step 2: Apply CNOT gates from the first qubit to each of the other qubits
    for i in range(1, 4):
        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(3)
    # Write your code here:

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

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

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

    return qc
'''