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

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

    for k in range(n):
        j = n-1-k
        # qc.h(j)
        qc.h(k)

        for i in range(j-1):
        # for i in reversed(range(j-1)):
            qc.cp(2*np.pi/2**(j-i), i, j-1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(math.pi/(1<<(j-i)), 0, 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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


'''python
from qiskit import QuantumCircuit
import math

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


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n-1, -1, -1):
        qc.h(i)
        for j in range(i-1, -1, -1):
            qc.cp(math.pi/(1<<(i-j)), i, j)
    for i in range(n//2):
        qc.swap(i, n-i-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

        # Apply controlled phase gates
        for k in range(j+1, n):
            qc.cp(2 * np.pi / (2 ** (k - j + 1)), k, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # Implement QFT for little-endian notation
    for j in range(n):
        # Apply Hadamard gate to the (n-1-j)-th qubit
        qc.h(n-1-j)

        # Apply controlled phase gates
        for k in range(j+1, n):
            qc.cp(2 * np.pi / (2 ** (k - j)), n-1-k, n-1-j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # Implement QFT for little-endian notation
     for j in range(n):
        # Apply Hadamard gate to the j-th qubit (no reversal needed for little-endian)
        qc.h(j)

        # Apply controlled phase gates
        for k in range(j+1, n):
            qc.cp(2 * np.pi / (2 ** (k - j + 1)), j, k)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    if not 1 <= n <= 10:
        raise ValueError("n must be between 1 and 10")

    qc = QuantumCircuit(n)

    for j in range(n):
        qc.h(j)
        for k in range(j+1, n):
            qc.cp(2 * pi / (2 ** (k - j + 1)), j, k)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for j in range(n):
        qc.h(j)
        for k in range(j+1, n):
            qc.cp(3.14159265358979 / (2 ** (k - j)), j, k)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def qft(n):
    qc = QuantumCircuit(n)
    # Apply QFT
    for qubit in range(n):
        qc.h(qubit)
        for other_qubit in range(qubit + 1, n):
            qc.cp(pi / 2**(other_qubit - qubit), other_qubit, qubit)
    # Swap qubits to reverse the order
    for qubit in range(n // 2):
        qc.swap(qubit, n - qubit - 1)
    return qc

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def r(qc: QuantumCircuit, control: int, target: int, l: int):
    qc.cp(2*math.pi/(1<<l), control, target)

def qft(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n//2):
        qc.cx(i, n-i-1)
        qc.cx(n-i-1, i)
        qc.cx(i, n-i-1)
    for i in range(0, n):
        qc.h(i)
        for j in range(1, n-i):
            r(qc, i+j, i, j+1)
    return qc

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(q[2])
    qc.cu1(math.pi/2.0, q[1], q[2])
    qc.cu1(math.pi/4.0, q[0], q[2])
    qc.h(q[1])
    qc.cu1(math.pi/2.0, q[0], q[1])
    qc.h(q[0])
    qc.swap(q[0],q[2])
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(2)
    qc.cu1(math.pi/2.0, 1, 2)
    qc.cu1(math.pi/4.0, 0, 2)
    qc.h(1)
    qc.cu1(math.pi/2.0, 0, 1)
    qc.h(0)
    qc.swap(0,2)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for l in range(2**n-1):
        for i in range(n):
            if not (l>>i)&1:
                qc.x(i)
            theta= math.exp(2*math.pi*l*i*1j/2**n)
            if n==1:
                qc.p(theta,n-1)
            qc.mcp(theta,list(n-1),n-1)
            if not (l>>i)&1:
                qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        if not (l>>i)&1:
            qc.x(i)
            theta= 2*math.pi*l*i/2**n
        if n==1:
            qc.p(theta,0)
        qc.mcp(theta,list(range(n-1)),n-1)
        if not (l>>i)&1:
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            qc.cp(np.pi / 2**(j - i), j, i)
    for i in range(n // 2):
        qc.swap(i, n - i - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            qc.cp(np.pi / 2**(j - i), j, i)
    #for i in range(n // 2):
    #    qc.swap(i, n - i - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n - 1, -1, -1):
        qc.h(i)
        for j in range(i - 1, -1, -1):
            qc.cp(np.pi / 2**(i - j), i, j)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n - 1, -1, -1):
        qc.h(i)
        for j in range(i - 1, -1, -1):
            qc.cp(np.pi / 2**(i - j), i, j)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n - 1, -1, -1):
        qc.h(i)
        for j in range(i - 1, -1, -1):
            qc.cp(np.pi / 2**(i - j), i, j)

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

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n - 1, -1, -1):
        qc.h(i)
        for j in range(i - 1, -1, -1):
            qc.cp(np.pi / 2**(i - j), i, j)

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

    return qc
'''


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

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

    thetas = []
    for k in range(0, 1+n):
        thetas.append(2 * math.pi / (2**k))

    for idx in range(0, n):
        qc.h(idx)
        for jdx in range(idx+1, n):
            thetaidx = jdx - idx + 1
            qc.cp(thetas[thetaidx], jdx, idx)

    return qc

def solve(n: int) -> QuantumCircuit:
    return qft(n)
'''


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

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

    thetas = []
    for k in range(0, 1+n):
        thetas.append(2 * math.pi / (2**k))

    for idx in range(0, n):
        qc.h(idx)
        for jdx in range(idx+1, n):
            thetaidx = jdx - idx + 1
            qc.cp(thetas[thetaidx], jdx, idx)

    qc = qc.reverse_bits()
    return qc

def solve(n: int) -> QuantumCircuit:
    return qft(n)
'''


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

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

    thetas = []
    for k in range(0, 1+n):
        thetas.append(2 * math.pi / (2**k))

    for idx in range(0, n):
        qc.h(n-1-idx)
        for jdx in range(idx+1, n):
            thetaidx = jdx - idx + 1
            qc.cp(thetas[thetaidx], n-1-jdx, n-1-idx)

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

    return qc

def solve(n: int) -> QuantumCircuit:
    return qft(n)
'''


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

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


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

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


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

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


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(0,n):
        qc.p(pi*(2**i)/(2**(n-1)),i)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.rz(2*pi/2**(j-i+1), j)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(n-1-i)
        for j in range(i+1, n):
            qc.rz(2*pi/2**(j-i+1), n-1-j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for j in range(n):
        # Apply the Hadamard gate
        qc.h(j)

        # Apply the controlled phase rotation gates
        for k in range(j + 1, n):
            qc.cp(np.pi / 2**(k - j), k, j)

    # Swap qubits to reverse their order
    for i in range(n // 2):
        qc.cx(i, n - i - 1)
        qc.cx(n - i - 1, i)
        qc.cx(i, n - i - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

# from qiskit.quantum_info import Statevector

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # qc.initialize([0,1,0,0])

    # Write your code here:
    for i in range(n-1, -1, -1):
        qc.h(i)
        for j in range(0, i):
            qc.cp(2*math.pi/(2**(i-j+1)), j, i)
    i = 0
    while i<n-i-1:
        qc.swap(i, n-i-1)
        i += 1
    return qc

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


'''python
from qiskit import QuantumCircuit
import math

# from qiskit.quantum_info import Statevector

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # qc.initialize([0,1,0,0])

    # Write your code here:
    for i in range(n-1, -1, -1):
        qc.h(i)
        for j in range(i-1, -1, -1):
            qc.cp(2*math.pi/(2**(i-j+1)), j, i)

    # print(qc.depth())
    i = 0
    while i<n-i-1:
        qc.swap(i, n-i-1)
        i += 1

    return qc

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


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n-1):
        qc.h(i)
        k = 2
        for j in range(i+1, n):
            theta = 2 * math.pi / 2 ^ k
            qc.cp(theta, j, i)
            k += 1
    for i in range(n // 2):
        qc.cx(i, n-i)
        qc.cx(n-i, i)
        qc.cx(i, n-i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n-1):
        # qc.h(i)
        k = 2
        for j in range(i+1, n):
            theta = 2 * math.pi / 2 ^ k
            qc.cp(theta, j, i)
            k += 1
    for i in range(n // 2):
        qc.cx(i, n-i)
        qc.cx(n-i, i)
        qc.cx(i, n-i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n-1):
        qc.h(i)
        k = 2
        for j in range(i+1, n):
            theta = 2 * math.pi / 2 ^ k
            qc.cp(theta, j, i)
            k += 1
    # for i in range(n // 2):
    #     qc.cx(i, n-i)
    #     qc.cx(n-i, i)
    #     qc.cx(i, n-i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        for i in range(n // 2):
            qc.cx(i, n-i)
            qc.cx(n-i, i)
            qc.cx(i, n-i)
    else:
        qc.h(i)
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            # qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        for i in range(n // 2):
            qc.cx(i, n-i)
            qc.cx(n-i, i)
            qc.cx(i, n-i)
    else:
        # qc.h(i)
        qc.p(2 * math.pi / 2,)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        for i in range(n // 2):
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)
    else:
        qc.p(2 * math.pi / 2,)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        for i in range(n // 2):
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n--i)
    else:
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        for i in range(n // 2):
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n--i)
    else:
        qc.h(0)
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        for i in range(n // 2):
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)
    else:
        qc.h(0)
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        # for i in range(n // 2):
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)
    else:
        qc.h(0)
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, i, j)
                k += 1
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(n)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(n-1)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                # qc.cp(theta, j, i)
                k += 1
        qc.h(n-)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)
        qc.p(2 * math.pi / 2)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(n-)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(n-1)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(n-1)
        for i in range(n // 2):
            # qc.swap(i, n-1-i)
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            for j in range(i-1, 1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        for i in range(n // 2):
            # qc.swap(i, n-1-i)
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            for j in range(i-1, 1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        # for i in range(n // 2):
        #     # qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,-1,-1):
            qc.h(i)
            k = 2
            for j in range(i-1, 1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        # for i in range(n // 2):
        #     # qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,-1,-1):
            qc.h(i)
            k = 2
            for j in range(i-1, 0, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        # for i in range(n // 2):
        #     # qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0,-1):
            qc.h(i)
            k = 2
            for j in range(i-1, -1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        # for i in range(n // 2):
        #     # qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0,-1):
            qc.h(i)
            k = 2
            for j in range(i-1, -1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            for j in range(i-1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            for j in range(i-1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        # for i in range(n // 2):
        #     qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(0, n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        # for i in range(n // 2):
        #     qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(0, n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(n-1)
        # for i in range(n // 2):
        #     qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(0, n-1):
            qc.h(i)
            k = 2
            for j in range(i+1, n):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(n-1)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            for j in range(i-1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        for i in range(n // 2):
            # qc.swap(i, n-1-i)
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            for j in range(i-1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        for i in range(n):
            # qc.swap(i, n-1-i)
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0,-1):
            qc.h(i)
            k = 2
            for j in range(i-1, -1,-1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        for i in range(n // 2):
            # qc.swap(i, n-1-i)
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        # for i in range(n-1,0):
        for i in range(n-1):
            ii = n-1-i
            qc.h(i)
            k = 2
            # for j in range(i-1, -1):
            for j in range(ii):
                jj = n-2-j
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, jj, ii)
                k += 1
        qc.h(0)
        for i in range(n // 2):
            # qc.swap(i, n-1-i)
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        # for i in range(n-1,0):
        for i in range(n-1):
            ii = n-1-i
            qc.h(ii)
            k = 2
            # for j in range(i-1, -1):
            for j in range(ii):
                jj = n-2-j
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, jj, ii)
                k += 1
        qc.h(0)
        for i in range(n // 2):
            # qc.swap(i, n-1-i)
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        # for i in range(n-1,0):
        for i in range(n-1):
            ii = n-1-i
            qc.h(ii)
            k = 2
            # for j in range(i-1, -1):
            for j in range(ii):
                jj = ii-1-j
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, jj, ii)
                k += 1
        qc.h(0)
        for i in range(n // 2):
            # qc.swap(i, n-1-i)
            qc.cx(i, n-1-i)
            qc.cx(n-1-i, i)
            qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            for j in range(i-1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        # for i in range(n // 2):
        #     # qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0,-1):
            qc.h(i)
            k = 2
            for j in range(i-1, -1,-1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        qc.h(0)
        # for i in range(n // 2):
        #     # qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            # for j in range(i-1, -1):
            j = i -1
            while j >= 0:
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
                j -= 1
        qc.h(0)
        # for i in range(n // 2):
        #     # qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        # for i in range(n-1,0):
        i = n - 1
        while i >= 1:
            qc.h(i)
            k = 2
            # for j in range(i-1, -1):
            j = i - 1
            while j >= 0:
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
                j -= 1
        qc.h(0)
        # for i in range(n // 2):
        #     # qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        # for i in range(n-1,0):
        i = n - 1
        while i >= 1:
            qc.h(i)
            k = 2
            # for j in range(i-1, -1):
            j = i - 1
            while j >= 0:
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
                j -= 1
            i -= 1
        qc.h(0)
        # for i in range(n // 2):
        #     # qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        # for i in range(n-1,0):
        i = n - 1
        while i >= 1:
            qc.h(i)
            k = 2
            # for j in range(i-1, -1):
            j = i - 1
            while j >= 0:
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
                j -= 1
            i -= 1
        qc.h(0)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        # for i in range(n-1,0):
        i = n - 1
        while i > 0:
            qc.h(i)
            k = 2
            # for j in range(i-1, -1):
            j = i - 1
            while j >= 0:
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
                j -= 1
            i -= 1
        qc.h(0)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        # for i in range(n-1,0):
        i = n - 1
        while i > 0:
            qc.h(i)
            k = 2
            # for j in range(i-1, -1):
            j = i - 1
            while j >= 0:
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
                j -= 1
            i = i - 1
        qc.h(0)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            # for j in range(i-1, -1):
            j = i - 1
            while j >= 0:
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
                j -= 1
        qc.h(0)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,0):
            qc.h(i)
            k = 2
            for j in range(i-1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
                j -= 1
        qc.h(0)
        for i in range(n // 2):
            qc.swap(i, n-1-i)
        #     qc.cx(i, n-1-i)
        #     qc.cx(n-1-i, i)
        #     qc.cx(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,-1):
            qc.h(i)
            k = 2
            for j in range(i-1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
                j -= 1
        for i in range(n // 2):
            qc.swap(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(n-1,-1):
            qc.h(i)
            k = 2
            for j in range(i-1, -1):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        for i in range(n // 2):
            qc.swap(i, n-1-i)

    else:
        qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
        for i in range(n-1, -1, -1):
            qc.h(i)
            k = 2
            for j in range(i-1, -1, -):
                theta = 2 * math.pi / 2 ^ k
                qc.cp(theta, j, i)
                k += 1
        for i in range(n // 2):
            qc.swap(i, n-1-i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n-1, -1, -1):
        qc.h(i)
        k = 2
        for j in range(i-1, -1, -1):
            theta = 2 * math.pi / 2 ** k
            qc.cp(theta, j, i)
            k += 1
    for i in range(n // 2):
        qc.swap(i, n-1-i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for qubit in range(n):
        qc.h(qubit)
        for k in range(qubit + 1, n):
            qc.cp(2 * np.pi / (2 ** (k - qubit + 1)), k, qubit)
    for qubit in range(n // 2):
        qc.swap(qubit, n - qubit - 1)

    return qc
'''


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

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

    for qubit in range(n):
        qc.h(qubit)
        for k in range(qubit + 1, n):
            qc.cp(2 * np.pi / (2 ** (k - qubit + 1)), k, qubit)
    for qubit in range(n // 2):
        q.swap(qubit, n - qubit - 1)

    return qc
'''


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

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

    for qubit in range(0,n):
        qc.h(qubit)
        for k in range(qubit + 1, n):
            qc.cp(2 * np.pi / (2 ** (k - qubit + 1)), k, qubit)
    for qubit in range(0, n // 2):
        q.swap(qubit, n - qubit - 1)

    return qc
'''


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

def qft(circuit, n):
    for qubit in range(n):
        circuit.h(qubit)
        for k in range(qubit + 1, n):
            circuit.cp(2 * np.pi / (2 ** (k - qubit + 1)), k, qubit)
    for qubit in range(n // 2):
        circuit.swap(qubit, n - qubit - 1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc += QFT(num_qubits=n, approximation_degree=0, do_swaps=True, inverse=False, insert_barriers=False, name='qft')
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc += QFT(num_qubits=n, approximation_degree=0, do_swaps=True, inverse=False, insert_barriers=False, name='qft')
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    def swap_registers(circuit, n):
        for qubit in range(n//2):
            circuit.swap(qubit, n-qubit-1)
        return circuit

    def qft(circuit, n):
        """QFT on the first n qubits in circuit"""
        qft_rotations(circuit, n)
        swap_registers(circuit, n)
        return circuit

    def qft_rotations(circuit, n):
        """Performs qft on the first n qubits in circuit (without swaps)"""
        if n == 0:
            return circuit
        n -= 1
        circuit.h(n)
        for qubit in range(n):
            circuit.cp(pi/2**(n-qubit), qubit, n)
        # At the end of our function, we call the same function again on
        # the next qubits (we reduced n by one earlier in the function)
        qft_rotations(circuit, n)
    # Let's see how it looks:
    qft(qc,n)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    def swap_registers(circuit, n):
        for qubit in range(n//2):
            circuit.swap(qubit, n-qubit-1)
        return circuit

    def qft(circuit, n):
        """QFT on the first n qubits in circuit"""
        qft_rotations(circuit, n)
        swap_registers(circuit, n)
        return circuit

    def qft_rotations(circuit, n):
        """Performs qft on the first n qubits in circuit (without swaps)"""
        if n == 0:
            return circuit
        n -= 1
        circuit.h(n)
        for qubit in range(n):
            circuit.cp(pi/2**(n-qubit), qubit, n)
        # At the end of our function, we call the same function again on
        # the next qubits (we reduced n by one earlier in the function)
        qft_rotations(circuit, n)
    # Let's see how it looks:
    qft(qc,n)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi
def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    def swap_registers(circuit, n):
        for qubit in range(n//2):
            circuit.swap(qubit, n-qubit-1)
        return circuit

    def qft(circuit, n):
        """QFT on the first n qubits in circuit"""
        qft_rotations(circuit, n)
        swap_registers(circuit, n)
        return circuit

    def qft_rotations(circuit, n):
        """Performs qft on the first n qubits in circuit (without swaps)"""
        if n == 0:
            return circuit
        n -= 1
        circuit.h(n)
        for qubit in range(n):
            circuit.cp(pi/2**(n-qubit), qubit, n)
        # At the end of our function, we call the same function again on
        # the next qubits (we reduced n by one earlier in the function)
        qft_rotations(circuit, n)
    # Let's see how it looks:
    qft(qc,n)

    return qc
'''


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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(2 * np.pi / 2**(j-i+1), j, i)
    for i in range(n//2):
        qc.cx(i, n-i-1)
        qc.cx(n-i-1, i)
        qc.cx(i, n-i-1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(2 * np.pi / 2**(j-i+1), j, i)
    for i in range(n//2):
        qc.cx(i, n-i-1)
        qc.cx(n-i-1, i)
        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:
    for i in reversed(range(n)):
        for j in reversed(range(i))
            qc.cp(math.pi / (2 ** (i - j)), j, i)
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in reversed(range(n)):
        qc.h(i)
        for j in reversed(range(i))
            qc.cp(math.pi / (2 ** (i - j)), j, i)
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in reversed(range(n)):
        qc.h(i)
        for j in reversed(range(i)):
            qc.cp(math.pi / (2 ** (i - j)), j, i)
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1,n):
            qc.cp(np.pi/(2.0 ** (j-(i+1)+1)), j, i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # for i in range(n):
    #     qc.h(i)
    #     for j in range(i+1,n):
    #         qc.cp(np.pi/(2.0 ** (j-(i+1)+1)), j, i)

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

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # for i in range(n):
    #     qc.h(i)
    #     for j in range(i+1,n):
    #         qc.cp(np.pi/(2.0 ** (j-(i+1)+1)), j, i)

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

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # for i in range(n):
    #     qc.h(i)
    #     for j in range(i+1,n):
    #         qc.cp(np.pi/(2.0 ** (j-(i+1)+1)), j, i)

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

    for i in range(n):
        if i < n-1-i:
            qc.swap(i,n-1-i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for qubit in range(n):
        qc.h(qubit)
        for j in range(qubit):
            qc.cp(pi / 2**(qubit - j), j, qubit)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

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


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

def qft_rotations(circuit, n):
    """Performs the QFT on the first n qubits in the circuit."""
    if n == 0:
        return circuit
    n -= 1
    circuit.h(n)
    for qubit in range(n):
        circuit.cp(np.pi / 2**(n - qubit), qubit, n)
    qft_rotations(circuit, n)

def swap_registers(circuit, n):
    """Swaps the qubits to correct the ordering after QFT."""
    for qubit in range(n // 2):
        circuit.swap(qubit, n - qubit - 1)
    return circuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Apply the QFT
    qft_rotations(qc, n)
    # Swap the qubits to correct the ordering
    swap_registers(qc, n)
    return qc
'''


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

def qft_rotations_optimized(circuit, n):
    """Performs the QFT on the first n qubits in the circuit."""
    for i in range(n):
        circuit.h(i)
        for j in range(i + 1, n):
            circuit.cp(np.pi / 2**(j - i), j, i)

def swap_registers(circuit, n):
    """Swaps the qubits to correct the ordering after QFT."""
    for qubit in range(n // 2):
        circuit.swap(qubit, n - qubit - 1)
    return circuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Apply the optimized QFT
    qft_rotations_optimized(qc, n)
    # Swap the qubits to correct the ordering
    swap_registers(qc, n)
    return qc
'''


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

def qft_rotations(circuit, n):
    """Performs the QFT on the first n qubits in the circuit."""
    for j in range(n):
        circuit.h(j)
        for k in range(j + 1, n):
            circuit.cp(np.pi / 2**(k - j), k, j)

def swap_registers(circuit, n):
    """Swaps the qubits to correct the ordering after QFT."""
    for qubit in range(n // 2):
        circuit.swap(qubit, n - qubit - 1)
    return circuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Apply the QFT
    qft_rotations(qc, n)
    # Swap the qubits to correct the ordering
    swap_registers(qc, n)
    return qc
'''


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

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

    for j in range(n):
        for k in range(j):
            qc.cp(np.pi / 2**(j - k), n - 1 - j, n - 1 - k)
        qc.h(n - 1 - j)

    return qc

def solve(n: int) -> QuantumCircuit:
    return optimized_qft(n)
'''


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

def qft_rotations(circuit, n):
    """Performs the QFT on the first n qubits in the circuit."""
    if n == 0:
        return circuit
    n -= 1
    circuit.h(n)
    for qubit in range(n):
        circuit.cp(np.pi / 2**(n - qubit), qubit, n)
    qft_rotations(circuit, n)

def swap_registers(circuit, n):
    """Swaps the qubits to correct the ordering after QFT."""
    for qubit in range(n // 2):
        circuit.swap(qubit, n - qubit - 1)
    return circuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Apply the QFT
    qft_rotations(qc, n)
    return qc
'''


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

def qft(n):
    qc = QuantumCircuit(n)
    for i in range(n):
        # Apply Hadamard gate
        qc.h(i)
        # Apply controlled phase rotation gates
        for j in range(i + 1, n):
            qc.cp(pi / 2**(j - i), j, i)
    # Reverse the order of qubits
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    return qc

def solve(n: int) -> QuantumCircuit:
    return qft(n)

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


'''python
from qiskit import QuantumCircuit
from numpy import pi

def qft(n):
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            qc.cp(pi / 2**(j - i), j, i)
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    return qc

def solve(n: int) -> QuantumCircuit:
    return qft(n)
'''


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

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


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n//2):
        qc.swap(i, n-i-1)
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.append(U1Gate(pi/2**(j-i)).control(j), [j, i])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n//2):
        qc.swap(i, n-i-1)
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.append(U1Gate(pi/2**(j-i)).control(1), [j, i])
    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            theta = 2 * pi / (2 ** j)
            qc.cp(theta, j, i)

    for i in range(n):
        j = n - 1 - i
        if i >= j:
            break
        qc.swap(i, j)

    return qc
'''


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

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

    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            theta = 2 * pi / (2 ** (j + 1))
            qc.cp(theta, j, i)

    for i in range(n):
        j = n - 1 - i
        if i >= j:
            break
        qc.swap(i, j)

    return qc
'''


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

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

    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            theta = 2 * pi / (2 ** (j + 1 - i))
            qc.cp(theta, j, i)

    for i in range(n):
        j = n - 1 - i
        if i >= j:
            break
        qc.swap(i, j)

    return qc
'''


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

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

    for i in range(n):
        qc.h(i)
        print("start", i + 1)
        for j in range(i + 1, n):
            theta = 2 * pi / (2 ** (j + 1 - i))
            print(j + 1 - i)
            qc.cp(theta, j, i)

    return qc
'''


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

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

    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            qc.cp(2 * math.pi / pow(2, j + 1) , j, i)

    return qc
'''


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

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

    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            qc.cp(2 * math.pi / pow(2, j + 1) , j, i)

    for i in range(n):
        j = (n - 1 - i)
        if i < j:
            qc.swap(i, j)

    return qc
'''


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

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

    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            qc.cp(2 * math.pi / pow(2, j - i + 1) , j, i)

    for i in range(n):
        j = (n - 1 - i)
        if i < j:
            qc.swap(i, j)

    return qc
'''


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

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

    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            qc.cp(2 * math.pi / pow(2, j - i + 1) , j, i)

    return qc
'''


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

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

    for i in range(n - 1, -1, -1):
        qc.h(i)
        for j in range(0, i):
            qc.cp(2 * math.pi / pow(2, i - j + 1) , j, i)

    return qc
'''


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

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

    for i in range(n - 1, -1, -1):
        qc.h(i)
        for j in range(i - 1, -1, -1):
            qc.cp(2 * math.pi / pow(2, i - j + 1) , j, i)

    return qc
'''


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

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

    for i in range(n - 1, -1, -1):
        qc.h(i)
        for j in range(i - 1, -1, -1):
            qc.cp(2 * math.pi / pow(2, i - j + 1) , j, i)

    for i in range(n):
        j = (n - 1 - i)
        if i < j:
            qc.swap(i, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates  import PhaseGate
import math
def solve(n: int) -> QuantumCircuit:
  qc = QuantumCircuit(n)
  for i in range(n - 1, -1, -1):
    qc.h(i)
    for j in range(i):
      qc.append(PhaseGate(math.pi * 2 * math.pow(2, j - 1 - i)).control(1), [i, j])
  for i in range(n // 2):
    qc.cx(i, n - 1 - i)
    qc.cx(n - 1 - i, i)
    qc.cx(i, n - 1 - i)
  return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates  import PhaseGate
import math
def solve(n: int) -> QuantumCircuit:
  qc = QuantumCircuit(n)
  for i in range(n - 1, -1, -1):
    for j in range(n - 1, i + 1, -1):
      qc.append(PhaseGate(math.pi * 2 * math.pow(2, i - 1 - j)).control(1), [i, j])
    qc.h(i)
  for i in range(n // 2):
    qc.cx(i, n - 1 - i)
    qc.cx(n - 1 - i, i)
    qc.cx(i, n - 1 - i)
  return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates  import PhaseGate
import math
def solve(n: int) -> QuantumCircuit:
  qc = QuantumCircuit(n)
  for i in range(n - 1, -1, -1):
    for j in range(n - 1, i, -1):
      qc.append(PhaseGate(math.pi * 2 * math.pow(2, i - 1 - j)).control(1), [i, j])
    qc.h(i)
  for i in range(n // 2):
    qc.cx(i, n - 1 - i)
    qc.cx(n - 1 - i, i)
    qc.cx(i, n - 1 - i)
  return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        # Apply Hadamard gate to the i-th qubit
        qc.h(i)

        # Apply controlled phase gates
        for j in range(i + 1, n):
            angle = np.pi / (2 ** (j - i))
            qc.cp(angle, j, i)

    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        # Apply Hadamard gate to the i-th qubit
        qc.h(i)

        # Apply controlled phase gates
        for j in range(i + 1, n):
            angle = np.pi / (2 ** (j - i))
            qc.cp(angle, j, i)  # Controlled Phase gate (CPhase)

    # Reverse the qubits order to match little-endian format
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

import numpy as np

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

    # Apply QFT
    for i in range(n):
        # Apply Hadamard gate to the i-th qubit
        qc.h(i)

        # Apply controlled phase gates
        for j in range(i + 1, n):
            angle = np.pi / (2 ** (j - i))
            qc.cp(angle, j, i)  # Controlled Phase gate (CPhase)

    # Reverse the qubits order to match little-endian format
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    # Write your code here:

    return qc
'''


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

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

    for i in range(n):
        # Apply Hadamard gate to the i-th qubit
        qc.h(i)

        # Apply controlled phase gates
        for j in range(i + 1, n):
            angle = np.pi / (2 ** (j - i))
            qc.cp(angle, j, i)  # Controlled Phase gate (CPhase)

    # Reverse the qubits order to match little-endian format
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    # Write your code here:

    return qc
'''


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

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

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

    # Apply controlled phase shifts
    for i in range(n):
        for j in range(i+1, n):
            qc.cp(2 * math.pi / (2 ** (j - i)), i, j)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

    # Apply controlled phase shifts
    for i in range(n):
        for j in range(i+1, n):
            qc.cp(2 * math.pi / (2 ** (j - i)), i, j)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

    # Apply controlled phase shifts
    for i in range(n):
        for j in range(i+1, n):
            qc.cp(2 * math.pi / (2 ** (j - i + 1)), j, i)

    # Swap qubits to get the correct order
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

import numpy as np

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

    # Apply QFT
    for i in range(n):
        # Apply Hadamard gate to the i-th qubit
        qc.h(i)

        # Apply controlled phase gates
        for j in range(i + 1, n):
            angle = np.pi / (2 ** (j - i))
            qc.cp(angle, j, i)  # Controlled Phase gate (CPhase)

    # Reverse the qubit order to match little-endian format
    for i in range(n // 2):
        qc.swap(i, n - i - 1)

    return qc

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

import numpy as np

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

    # Apply QFT
    for i in range(n):
        # Apply Hadamard gate to the i-th qubit
        qc.h(i)

        # Apply controlled phase gates
        for j in range(i + 1, n):
            angle = np.pi / (2 ** (j - i))
            qc.cp(angle, j, i)  # Controlled Phase gate (CPhase)

    # Reverse the qubit order to match little-endian format
    for i in range(n // 2):
        qc.swap(i, n - i - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    # Quantum Fourier Transform
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(math.pi / (2**(j-i)), j, i)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    """
    量子フーリエ変換の量子回路を生成する関数

    Args:
        n: 量子ビット数

    Returns:
        QuantumCircuit: 量子フーリエ変換の量子回路
    """

    qc = QuantumCircuit(n)

    # 量子フーリエ変換の回路を構築
    for i in range(n):
        # Hadamardゲートを適用
        qc.h(i)
        # Controlled-phaseゲートを適用
        for j in range(i):
            qc.cp(np.pi / 2**(i-j), j, i)

    # 量子ビットの順番を逆転
    for qubit in range(n//2):
        qc.swap(qubit, n-qubit-1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    #state_vector = [0, 0, 1, 0] #2量子系において初期状態を与える
    #qc.initialize(state_vector, [0, 1]) #量子系の初期状態を変更

    # QFTの実装（リトルエンディアン）
    cnt = list(range(0,n,1))
    prev = list(range(0,n,1))
    for i in range(n):
        cnt[i]=0

    for i in range(25):
        for j in range(n-1,-1,-1):
            if prev[j]!=0:
                continue
            if cnt[j]==0:
                qc.h(j)
                cnt[j]+=1
            elif cnt[j]+j>=n:
                continue
            else:
                k = cnt[j]+1
                qc.cp(2*np.pi/(2**k),j+k-1,j)
                cnt[j]+=1
                prev[j+k-1]-=1

    return qc

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


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # state_vector = [0, 1, 0, 0] #2量子系において初期状態を与える
    # qc.initialize(state_vector, [0, 1]) #量子系の初期状態を変更

    # QFTの実装（リトルエンディアン）
    cnt = list(range(0,n,1))
    prev = list(range(0,n,1))
    for i in range(n):
        cnt[i]=0

    for i in range(n):
        x = i
        y = n-1-i
        if x>=y :
            break
        qc.swap(x,y)

    for i in range(25):
        for j in range(n-1,-1,-1):
            if prev[j]!=0:
                continue
            if cnt[j]==0:
                qc.h(j)
                cnt[j]+=1
            elif cnt[j]+j>=n:
                continue
            else:
                k = cnt[j]+1
                qc.cp(2*np.pi/(2**k),j+k-1,j)
                cnt[j]+=1
                prev[j+k-1]-=1

    return qc

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


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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for j in range(0, n):
        qc.h(0)
        for i in range(j+1, n):
            qc.cu(1/2**(i-j)*math.pi, 0, 0, 0, i, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for j in range(0, n):
        qc.h(0)
        for i in range(j+1, n):
            qc.cp(1/2**(i-j)*math.pi, i, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for j in range(0, n):
        qc.h(j)
        for i in range(j+1, n):
            qc.cp(1/2**(i-j)*math.pi, i, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for j in reversed(range(0, n)):
        qc.h(j)
        num_entanglements = max(
            0, j - max(0, 0 - (n - j - 1)))
        for k in reversed(range(j-num_entanglements, j)):
            lam = math.pi * (2.0 ** (k - j))
            qc.cp(lam, j, k)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for j in reversed(range(0, n)):
        qc.h(j)
        for k in reversed(range(0, j)):
            lam = math.pi * (2.0 ** (k - j))
            qc.cp(lam, j, k)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for j in reversed(range(0, n)):
        qc.h(j)
        for k in reversed(range(0, j)):
            lam = math.pi * (2.0 ** (k - j))
            qc.cp(lam, j, k)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
from np import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    angles = [np.pi / 2**(i) for i in range(1, n)]
    for j in range(n):
        qc.h(j)
        for i, angle in enumerate(angles):
            qc.cp(angle, j + i + 1, j)
            if j + i + 1 >= n - 1:
                break

    # ビットの順序を逆にする
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    angles = [np.pi / 2**(i) for i in range(1, n)]
    for j in range(n):
        qc.h(j)
        for i, angle in enumerate(angles):
            qc.cp(angle, j + i + 1, j)
            if j + i + 1 >= n - 1:
                break

    # ビットの順序を逆にする
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1,n):
            qc.cp(pi/2**(j-i),j,i)

    # ビットの順序を逆にする
    for i in range(n // 2):
        qc.swap(i, n - i - 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for j in range(n):
        qc.h(q[j])
        for k in range(j+1,n):
            qc.cu1(math.pi/float(2**(k-j)), q[k], q[j])
        qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for j in range(n):
        qc.h(q[j])
        for k in range(j+1,n):
            qc.cu1(pi/float(2**(k-j)), q[k], q[j])
        qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for j in range(n):
        qc.h(j)
        for k in range(j+1,n):
            qc.cu1(pi/float(2**(k-j)), k, j)
        qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(np.pi/float(2**(j-i)), j, i)

    # ビットリバース
    for i in range(n//2):
        qc.swap(i, n-i-1)

    qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cu1(np.pi/float(2**(j-i)), j, i)
    for i in range(n//2):
        qc.swap(i, n-i-1)
    qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

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


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(np.pi / float(2**(j-i)), i)
    for i in range(n//2):
        qc.swap(i, n-i-1)
    qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(np.pi/float(2**(j-i)),i)
    for i in range(n//2):
        qc.swap(i, n-i-1)
    qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
from numpy import pi

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cu1(np.pi/float(2**(j-i)),i)
    for i in range(n//2):
        qc.swap(i, n-i-1)
    qc.barrier()
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range (n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2^(b)), b, a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n=1
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2^(b)), b, a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n=5
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2^(b)), b, a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n=3
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2^(b)), b, a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n=2
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2^(b)), b, a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n=2
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(b)), b, a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(b)), b, a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        k=2
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(k)), b, a)
            k++
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        k=2
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(k)), b, a)
            k = k+1
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(b-a+1)), b, a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(b-a+)), b, a)
    swaps=int(n/2)
    for a in range(swaps):
        qc.swap(a,n-1-a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(b-a+)), b, a)
    swaps=int(n/2)
    for a in range(swaps):
        qc.swap(a, n-a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(b-a+1)), b, a)
    swaps=int(n/2)
    for a in range(swaps):
        qc.swap(a, n-a-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(b-a+1)), b, a)
    swaps=int(n//2)
    for a in range(swaps):
        qc.swap(a, n-a-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(2*math.pi/(2**(b-a)), b, a)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for a in range(n):
        qc.h(a)
        for b in range(a+1, n):
            qc.cp(math.pi/(2**(b-a)), b, a)

    return qc
'''


'''python
import math

from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n -= 1
    qc.h(n)
    for qubit in range(n):
        qc.cp(math.pi/2**(n-qubit), qubit, n)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(n-i-1)[::-1]:
            print(n-j-1, i)
            qc.cp(2*pi/(2**(n-j-i)), n-j-1, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n)[::-1]:
        qc.h(i)
        for j in range(n-i-1):
            print(n-j-1, i)
            qc.cp(2*pi/(2**(n-j-i)), n-j-1, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(n-i-1)[::-1]:
            qc.cp(2*pi/(2**(n-j-i)), n-j-1, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n)[::-1]:
        qc.h(i)
        for j in range(i):
            qc.cp(2*pi/(2**(i)), i, i-j-1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n)[::-1]:
        qc.h(i)
        for j in range(i):
            qc.cp(2*pi/(2**(i)), i, i-j-1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(n-i-1)[::-1]:
            qc.cp(2*pi/(2**(n-j-i)), n-j-1, i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n)[::-1]:
        qc.h(i)
        for j in range(i):
            qc.cp(2*pi/(2**(j+2)), i, i - j - 1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(n-i-1)[::-1]:
            qc.cp(2*pi/(2**(n-j-i)), i, n-j-1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(n-i-1):
            qc.cp(2*pi/(2**(j+2)), i, n-j-1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(n-i-1):
            qc.cp(2*pi/(2**(j+2)), n-j-1, i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(n-i-1)[::-1]:
            qc.cp(2*pi/(2**(n-j-i)), n-j-1, i)
    qc.swap(0,4)
    qc.swap(1,3)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(n-i-1)[::-1]:
            qc.cp(2*pi/(2**(n-j-i)), n-j-1, i)
    for i in range(n//2):
        qc.swap(i,n-i)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(n-i-1)[::-1]:
            qc.cp(2*pi/(2**(n-j-i)), i, n-j-1)
    for i in range(n//2):
        qc.swap(i,n-i)
    return qc
'''


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

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


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

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


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(n-1-i)
        for j in range(n-i-1):
            qc.cp(2*math.pi/(2**(n-i-j)),j , n-1-i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(n-1-i)
        for j in range(n-i-1):
            qc.cp(2*math.pi/(2**(n-i-j)),j , n-1-i)
    for i in range(int((n)/2)):
        qc.swap(i,n-1-i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
      for j in range(n-i):
        if j == 0:
          qc.h(i)
        else:
          qc.cp(2*np.pi/2**(j+1), j+i, i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
      for j in range(n-i):
        if j == 0:
          qc.h(i)
        else:
          qc.cp(2*np.pi/2**(j+1), j+i, i)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
      for j in range(n-i):
        if j == 0:
          qc.h(i)
        else:
          qc.cp(2*np.pi/2**(j+1), j+i, i)

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

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # for i in range(n):
    #   for j in range(n-i):
    #     if j == 0:
    #       qc.h(i)
    #     else:
    #       qc.cp(2*np.pi/2**(j+1), i+j, i)
    for i in range(n):
      qc.h(-1-i)
      for j in range(i+1,n):
          qc.cp(2 * np.pi / 2**(j+1-i), -1-j, -1-i)

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

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
      qc.h(-1-i)
      for j in range(i+1,n):
          qc.cp(2 * np.pi / 2**(j+1-i), -1-j, -1-i)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in reversed(range(n)):
        qc.h(i)
        for j in reversed(range(i)):
            qc.cp(2*math.pi*(i-j),j,i)
    for i in range(n//2):
        qc.swap(i, n-i-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in reversed(range(n)):
        qc.h(i)
        for j in reversed(range(i)):
            qc.cp(math.pi/2**(i-j),j,i)
    for i in range(n//2):
        qc.swap(i, n-i-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit, math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    def swap_gate(qc, i, j):
        qc.cx(i,j)
        qc.cx(j,i)
        qc.cx(i,j)
        return qc
    def qft_layer(qc, i):
        qc.h(i)
        for l in range(i):
            k = i - 1 - l
            theta = 2 * math.pi / 2 ** (i - k + 1)
            qc.cp(theta, k, i)
        return qc
    for j in range(n):
        qc = qft_layer(qc, n - 1 - j)
    half = n//2
    for i in range(half):
        qc = swap_gate(qc, i, n - 1 - i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    def swap_gate(qc, i, j):
        qc.cx(i,j)
        qc.cx(j,i)
        qc.cx(i,j)
        return qc
    def qft_layer(qc, i):
        qc.h(i)
        for l in range(i):
            k = i - 1 - l
            theta = 2 * math.pi / 2 ** (i - k + 1)
            qc.cp(theta, k, i)
        return qc
    for j in range(n):
        qc = qft_layer(qc, n - 1 - j)
    half = n//2
    for i in range(half):
        qc = swap_gate(qc, i, n - 1 - i)
    return qc
'''


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

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

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

    # Reverse the qubit order
    for i in range(n // 2):
        qc.swap(i, n - i - 1)

    return qc
'''


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

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

     # Implement the QFT in little-endian order
    for i in range(n):
        # Apply Hadamard gate to qubit i
        qc.h(i)

        # Apply the controlled phase rotations
        for j in range(i+1, n):
            qc.cp(pi / (2 ** (j - i)), j, i)

    # Reverse the qubit order
    for i in range(n // 2):
        qc.swap(i, n - i - 1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    n = 2
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(pi / (2 ** (j - i)), j, i)
    for i in range(n // 2):
        qc.swap(i, n - i - 1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    n = 2
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(pi / (2 ** (j - i)), j, i)
    for i in range(n // 2):
        qc.swap(i, n - i - 1)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Apply the QFT
    for qubit in range(n):
        # Apply the Hadamard gate
        qc.h(qubit)
        # Apply the controlled phase shift gates
        for k in range(2, n - qubit + 1):
            qc.cp(np.pi / (2 ** (k-1)), qubit, qubit + k - 1)

    # Swap qubits to reverse the bit order
    for i in range(n // 2):
        qc.swap(i, n - i - 1)

    return qc
'''


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

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

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

    # Apply controlled rotation gates
    for i in range(n):
        for j in range(i):
            k = i - j + 1
            qc.cp(2 * pi / 2**k, j, i)

    # Swap qubits to correct the order (little-endian)
    for i in range(n // 2):
        qc.swap(i, n - 1 - i)

    return qc
'''


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

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

    # Implement QFT
    for i in range(n):
        qc.h(i)
        for j in range(i + 1, n):
            qc.cp(pi / 2**(j - i), j, i)

    return qc
'''


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

def qft_rotations(qc, n):
    """Apply the QFT to the first n qubits in the quantum circuit qc."""
    if n == 0:
        return qc
    n -= 1
    qc.h(n)
    for qubit in range(n):
        qc.cp(np.pi / 2**(n-qubit), qubit, n)
    qft_rotations(qc, n)

def swap_registers(qc, n):
    """Swap the qubits to reverse their order."""
    for qubit in range(n//2):
        qc.swap(qubit, n-qubit-1)

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

    # Apply the QFT
    qft_rotations(qc, n)

    # Reverse the order of qubits by swapping them
    swap_registers(qc, n)

    return qc
'''


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

def qft_rotations_optimized(qc, n):
    """Apply the QFT to the first n qubits in the quantum circuit qc."""
    for j in range(n):
        qc.h(j)
        for k in range(j+1, n):
            qc.cp(np.pi / 2**(k-j), k, j)

def swap_registers_optimized(qc, n):
    """Swap the qubits to reverse their order."""
    for qubit in range(n//2):
        qc.swap(qubit, n-qubit-1)

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

    # Apply the optimized QFT rotations
    qft_rotations_optimized(qc, n)

    # Reverse the order of qubits by swapping them
    swap_registers_optimized(qc, n)

    return qc
'''


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

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

    # Apply the QFT
    for i in range(n):
        qc.h(i)
        for j in range(i+1, n):
            qc.cp(np.pi / 2**(j-i), j, i)

    # Reverse the order of qubits by swapping them
    for i in range(n // 2):
        qc.swap(i, n-i-1)

    return qc
'''