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

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

    def gao(l, r):
        if r - l == 1:
            return
        m = (l + r) // 2
        qc.swap(l, m)
        gao(l, m)
        gao(m, r)

    gao(0, n + 1)
    return qc.inverse()

# p = [i for i in range(9)]
# def gao(l, r):
#     if r - l == 1:
#         return
#     m = (l + r) // 2
#     p[l], p[m] = p[m], p[l]
#     gao(l, m)
#     gao(m, r)
# gao(0, len(p))
# print(p)
# exit(0)
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    for i in range((n + 1) // 2):
        qc.swap(2 * i, 2 * i + 1)
    for i in range((n + 1)// 4):
        qc.swap(4 * i, 4 * i + 2)
    if (n == 10):
        qc.swap(8, 10)
    for i in range((n + 1) // 8):
        qc.swap(8 * i, 8 * i + 4)

    if (n >= 8):
        qc.swap(0, 8)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    for i in range((n + 1) // 2):
        qc.swap(2 * i, 2 * i + 1)
    for i in range((n + 1) // 4):
        qc.swap(4 * i, 4 * i + 2)
    #if (n == 10):
        #qc.swap(8, 10)
    for i in range((n + 1) // 8):
        qc.swap(8 * i, 8 * i + 4)

    if (n >= 8):
        qc.swap(0, 8)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    i = 0
    while(2 * i + 1 >= n):
        qc.swap(2 * i, 2 * i + 1)
    i = 0
    while(4 * i + 2 >= n):
        qc.swap(4 * i, 4 * i + 2)
    while(8 * i + 4 >= n):
        qc.swap(8 * i, 8 * i + 4)

    if (n >= 8):
        qc.swap(0, 8)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    i = 0
    while(2 * i + 1 < n):
        qc.swap(2 * i, 2 * i + 1)
    i = 0
    while(4 * i + 2 < n):
        qc.swap(4 * i, 4 * i + 2)
    while(8 * i + 4 < n):
        qc.swap(8 * i, 8 * i + 4)

    if (n >= 8):
        qc.swap(0, 8)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    i = 0
    while(2 * i + 1 < n):
        qc.swap(2 * i, 2 * i + 1)
        i++
    i = 0
    while(4 * i + 2 < n):
        qc.swap(4 * i, 4 * i + 2)
        i++
    while(8 * i + 4 < n):
        qc.swap(8 * i, 8 * i + 4)
        i++
    if (n >= 8):
        qc.swap(0, 8)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    i = 0
    while(2 * i + 1 < n):
        qc.swap(2 * i, 2 * i + 1)
        i += 1
    i = 0
    while(4 * i + 2 < n):
        qc.swap(4 * i, 4 * i + 2)
        i += 1
    i = 0
    while(8 * i + 4 < n):
        qc.swap(8 * i, 8 * i + 4)
        i += 1
    if (n >= 8):
        qc.swap(0, 8)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    i = 0
    while(2 * i + 1 < n):
        qc.swap(2 * i, 2 * i + 1)
        i += 1
    i = 0
    while(4 * i + 2 < n):
        qc.swap(4 * i, 4 * i + 2)
        i += 1
    i = 0
    while(8 * i + 4 < n):
        qc.swap(8 * i, 8 * i + 4)
        i += 1
    if (n % 2 == 0):
        qc.swap(0, n)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    i = 0
    while(2 * i + 1 <= n):
        qc.swap(2 * i, 2 * i + 1)
        i += 1
    i = 0
    while(4 * i + 2 <= n):
        qc.swap(4 * i, 4 * i + 2)
        i += 1
    i = 0
    while(8 * i + 4 <= n):
        qc.swap(8 * i, 8 * i + 4)
        i += 1
    if (n % 2 == 0):
        qc.swap(0, n)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    i = 0
    while(2 * i + 1 <= n):
        qc.swap(2 * i, 2 * i + 1)
        i += 1
    i = 0
    while(4 * i + 2 <= n):
        qc.swap(4 * i, 4 * i + 2)
        i += 1
    i = 0
    while(8 * i + 4 <= n):
        qc.swap(8 * i, 8 * i + 4)
        i += 1
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    i = 0
    while(2 * i + 1 <= n):
        qc.swap(2 * i, 2 * i + 1)
        i += 1
    i = 0
    while(4 * i + 2 <= n):
        qc.swap(4 * i, 4 * i + 2)
        i += 1
    i = 0
    while(8 * i + 4 <= n):
        qc.swap(8 * i, 8 * i + 4)
        i += 1
    i = 0
    while(16 * i + 8 <= n):
        qc.swap(16 * i, 16 * i + 8)
        i += 1
    i = 0

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from math import pi
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import HGate

def sw(qc: QuantumCircuit, arr):
    narr = []
    if len(arr) % 2 == 0:
        for i in range(0, len(arr), 2):
            qc.swap(arr[i], arr[i + 1])
            narr.append(arr[i])
    else:
        narr.append(arr[0])
        for i in range(1, len(arr), 2):
            qc.swap(arr[i], arr[i + 1])
            narr.append(arr[i])
    return narr

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(n + 1)

    arr = list(range(n + 1))
    while len(arr) > 1:
        arr = sw(qc, arr)
        print(arr)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
# from qiskit.quantum_info import Statevector
from qiskit.circuit.library.standard_gates import XGate

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

    # qc.x(0)

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

    return qc

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


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

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

    # qc.x(0)

    for i in reversed(range(n)):
        qc.swap(i,i+1)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(2)
#     print(Statevector(qc))
'''


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

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

    # qc.x(0)

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

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(2)
#     print(Statevector(qc))
'''


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

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

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

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(2)
#     print(Statevector(qc))
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    if (n + 1) % 2 == 1:
        qc.swap(0, n)

    return qc

def main():
    print(solve(1))
    print(solve(2))
    print(solve(7))
    print(solve(8))
    print(solve(9))

if __name__ == "__main__":
    main()
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.swap(0, n)

    return qc

def main():
    print(solve(1))
    print(solve(2))
    print(solve(7))
    print(solve(8))
    print(solve(9))

if __name__ == "__main__":
    main()
'''


'''python
from qiskit import QuantumCircuit

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

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

    # qc.swap(0, n)

    return qc

def main():
    for n in range(1, 11):
        print(n)
        print(solve(n))

if __name__ == "__main__":
    main()
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    num_swaps = (n+1) // 2
    for i in range(num_swaps):
        qc.swap(i, n - i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    num_swaps = (n+1) // 2
    for i in range(num_swaps):
        qc.cx(i, n - i)
        qc.cx(n - i, i)
        qc.cx(i, n - i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    num_swaps = (n+1) // 2
    for i in range(num_swaps):
        qc.swap(i, n-i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    qc.swap(0, n)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    # twos complement, flip all, plus one
    for i in range(n):
        qc.x(i)

    # from 004 - A5 editorial
    for i in reversed(range(1, n)):
        qc.mcx(list(range(i)), i)
    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n-1, 0, -1):
        mx = XGate().control(i)
        qubit = list(range(i+1))
        # print(i, qubit)
        qc.append(mx, qubit)

    qc.x(0)

    return qc
'''


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

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

    for i in range(n-1, 0, -1):
        mx = XGate().control(i)
        qubit = list(range(i+1))
        # print(i, qubit)
        qc.append(mx, qubit)

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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

    qc.x(0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    qc.x(0)

    return qc
'''


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

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

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

    # increment
    for i in reversed(range(n)):
        if i:
            qc.append(XGate().control(i), list(range(i + 1)))
        else:
            qc.x(i)

    return qc
'''


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

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

    # qc.x(0)

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

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

    qc.x(0)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(2)
#     print(Statevector(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(pi / 2 ** (i - j), j, i)
    for i in range(n):
        for j in range(i):
            qc.cp(pi / 2 ** (i - j), j, i)  # 角度の符号を反転
        qc.h(i)

    return qc
'''


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

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(pi / 2 ** (i - j), j, i)
    for i in range(n):
        for j in range(i):
            qc.cp(pi / 2 ** (i - j), j, i)  # 角度の符号を反転
        qc.h(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    for i in range(n):
        qc.p(2 * np.pi / (2**(n - i)), i)

    for i in range(n):
        for j in range(i):
            qc.cp(-np.pi / (2**(i - j)), j, i)
        qc.h(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.x(i)

    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)), j, i)

    for i in range(n):
        qc.p(2 * np.pi / (2**(n - i)), i)

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

    return qc
'''


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

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

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

    qc.x(0)

    return qc

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

    for i in range(n):
        qc.x(i)
    qc.append(add1(n), range(n))
    return qc
'''


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

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

    qc.x(range(n))

    for i in reversed(range(1, n)):
        num_controls = i
        mcx_gate = XGate().control(num_controls)
        qubits_to_apply = list(range(i + 1))
        qc.append(mcx_gate, qubits_to_apply)

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate

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

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

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

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

    return qc

def solve(n) -> QuantumCircuit:

    qc = QuantumCircuit(n)
    qc.compose(qft(n), inplace=True)
    qc.compose(qft(n), inplace=True)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate

def solve(n) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(range(n))

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)
    # インクリメント（Ripple carry加算器の最小構成）
    for i in range(n):
        qc.x(i)
        if i == 0:
            break
        for j in reversed(range(1, i+1)):
            qc.ccx(j-1, j, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n+1)
    for i in range(n):
        qc.x(i)
    # +1のインクリメント（nビットRipple Carry）
    for i in range(n):
        # 1桁目はXだけ
        if i == 0:
            qc.x(0)
        else:
            # それ以降は、下位がすべて1のとき反転 (全て1かどうかの多重制御X)
            controls = [j for j in range(i)]
            qc.mcx(controls, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n+1)
    for i in range(n):
        qc.x(i)
    # +1のインクリメント（nビットRipple Carry）
    for i in range(n):
        # 1桁目はXだけ
        if i == 0:
            qc.x(0)
        else:
            # それ以降は、下位がすべて1のとき反転 (全て1かどうかの多重制御X)
            controls = [j for j in range(i)]
            qc.mcx(controls, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n+1)
    for i in range(n):
        # i=0: 最下位ビットは必ず反転
        if i == 0:
            qc.x(0)
        else:
            # それまでのビットが全て1なら反転
            qc.mcx(list(range(i)), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n+1)
    # (1) すべてのビットを反転（Xゲート）
    for i in range(n):
        qc.x(i)
    # (2) +1 のインクリメント（LSBからMSBへのキャリー伝播）
    for i in range(n):
        if i == 0:
            qc.x(0)
        else:
            qc.mcx(list(range(i)), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # (1) すべてのビットを反転（Xゲート）
    for i in range(n):
        qc.x(i)
    # (2) +1 のインクリメント（LSBからMSBへのキャリー伝播）
    for i in range(n):
        if i == 0:
            qc.x(0)
        else:
            qc.mcx(list(range(i)), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # すべてのビットを反転
    for i in range(n):
        qc.x(i)
    # +1（インクリメント）
    for i in range(n):
        if i == 0:
            qc.x(0)
        else:
            qc.mcx(list(range(i)), i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # (1) 全ビット反転
    for i in range(n):
        qc.x(i)
    # (2) +1加算
    # ここは「位ごとの多重制御X（キャリー）」でリトルエンディアン
    for i in range(n):
        if i == 0:
            qc.x(0)
        else:
            qc.mcx(list(range(i)), i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        if i == 0:
            qc.x(i)
        else:
            # Create carry chain
            controls = list(range(i))
            qc.mcx(controls, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(range(n))

    for i in range(n - 1, 0, -1):
        control_qubits = list(range(i))
        qc.mcx(control_qubits, qc.qubits[i])

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        if i == 0:
            qc.x(0)  # flip bit thấp nhất luôn luôn
        else:
            qc.mcx(list(range(i)), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def add1(qc: QuantumCircuit, n: int) -> QuantumCircuit:
    for i in reversed(range(1, n)):
        qc.mcx(list(range(i)), i)
    qc.x(0)

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.x(range(n))
    add1(qc, n)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

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

    qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc

def main():
    print(solve(1))
    print(solve(2))
    print(solve(3))
    print(solve(4))

if __name__ == "__main__":
    main()
'''


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

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

    qc.x(range(i, n))

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

    return qc
'''


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

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

    qc.x(range(i, n))

    for i in range(n-1):
        qc.x(i)
        qc.append(XGate().control(i - 1), in range(i))
        qc.x(i)

    return qc
'''


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

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

    qc.x(range(i, n))

    for i in range(n-1):
        qc.x(i)
        qc.append(XGate().control(i - 1), range(i))
        qc.x(i)

    return qc
'''


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

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

    qc.x(range(1, n))

    for i in range(n-1):
        #qc.barrier()
        qc.x(i)
        qc.append(XGate().control(i+1), range(i + 2))
        qc.x(i)

    return qc
'''


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

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

    if(n == 1):
        return qc

    qc.x(range(1, n))

    for i in range(n-1):
        #qc.barrier()
        qc.x(i)
        qc.append(XGate().control(i+1), range(i + 2))
        qc.x(i)

    return qc
'''


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

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

    if(n == 1):
        return qc

    qc.x(range(1, n))

    for i in range(n-1):
        #qc.barrier()
        qc.x(range(i + 1))
        qc.append(XGate().control(i + 1), range(i + 2))
        qc.x(range(i + 1))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


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

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

    return qc
'''


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

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

    qc.x(range(n))

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


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

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.append(PhaseGate(2 * pi / (1 << n) * k_const), [i])
        k_const *= 2
        k_const %= (1 << n)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    w = np.pi / (2**n)

    for i in range(n):
        qc.p(w * (k_const - 1) ** (2**i), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    w = np.pi / (2**n)

    for i in range(n):
        qc.p(w * (k_const - 1) * (2**i), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    w = 2 * np.pi / (2**n)

    for i in range(n):
        qc.p(w * (k_const - 1) * (2**i), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    w = np.exp(1j * np.pi / (2**n))

    for i in range(n):
        qc.p(np.angle(w ** ((k_const - 1) * (2**i))), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    w = np.exp(1j * np.pi / (2**n))

    for i in range(n):
        qc.p(np.angle(w ** (k_const * (2**i))), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    w = np.exp(2j * np.pi / (2**n))

    for i in range(n):
        qc.p(np.angle(w ** (k_const * (2**i))), i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    wconst = 2 * math.pi * k_const / (2 ** n)

    for i in range(n):
        theta = wconst ** (1 << i)
        qc.p(theta, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    wconst = 2 * math.pi * k_const / (2 ** n)

    for i in range(n):
        theta = wconst * (1 << i)
        qc.p(theta, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    I=[]
    for i in range(n):
        I.append(k_const%2)
        k_const//=2
    for i in range(n):
        if I[i]:
            qc.x(i)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    I=[]
    for i in range(n):
        I.append(k_const%2)
        k_const//=2
    for i in range(n):
        if I[i]:
            theta = 2*math.pi/2**n
            qc.p(theta, i)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    I=[]
    for i in range(n):
        I.append(k_const%2)
        k_const//=2
    for i in range(n):
        if I[i]:
            theta = 2*math.pi/2**n
            qc.p(theta, i)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for i in range(n):
        theta = k_const*2*math.pi/2**n
        qc.p(theta*(2**i), i)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for s in range(n):
        qc.p(pi*2 * 2**(s-n) * k_const, s)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for i in range(n):
        angle = 2 * math.pi / (2**n) * k_const * (2**i)
        qc.p(angle, i)

    return qc
'''


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

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

    for j in range(n):
        lambda_j = (2 * np.pi * k_const) / (2**(n - j))

        if lambda_j != 0:
            qc.p(lambda_j, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    omega_angle = 2 * np.pi * k_const / (2**n)
    for j in range(n):
        angle = (2 ** j) * omega_angle
        qc.rz(angle, j)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    omega_angle = 2 * np.pi * k_const / (2**n)
    for j in range(n):
        angle = (2 ** j) * omega_angle
        qc.u1(angle, j)
    return qc
'''


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

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


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

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.p(2 * pi * k_const / 2**n, i)
    return qc
'''


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

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        qc.p(2 * pi * int(bin(k_const)[:-1-i]) / 2**n, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    k_const_bits = []
    temp = k_const
    for i in range(n):
        k_const_bits.append(temp % 2)
        temp //= 2

    for j in range(n):
        if k_const_bits[j] == 1:
            angle = 2 * math.pi / (2**(n-j))
            qc.p(angle, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for j in range(n):
        angle = 0
        for i in range(n):
            if (k_const >> i) & 1:
                if i <= j:
                    angle += math.pi / (2**(j - i))

        if angle != 0:
            qc.p(2 * angle, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    for j in range(n):
        phase_accumulator = 0.0
        for i in range(n):
            if (k_const >> i) & 1:
                if i <= j:
                    phase_accumulator += 1.0 / (2.0 ** (j - i + 1))

        if phase_accumulator > 0:
            angle = 2.0 * math.pi * phase_accumulator
            qc.p(angle, j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        theta = 2 * math.pi * k_const / (2 ** (i + 1))
        qc.p(theta, i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        theta = 2 * math.pi * k_const / (2 ** (n - i))
        qc.p(theta, i)
    return qc
'''


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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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


'''python
from qiskit import QuantumCircuit
import mat

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


'''python
from qiskit import QuantumCircuit
import mat

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


'''python
from qiskit import QuantumCircuit
import math

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


'''python
from qiskit import QuantumCircuit
from math import tau

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        theta = tau * k_const * (1 << i) / (1 << n)
        qc.p(theta, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        phase_angle = 2 * 3.141592653589793 * k_const / (2 ** (n - i))
        qc.p(phase_angle, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

    return qc

def main():
    print(solve(4, 1))
    print(solve(4, 2))

if __name__ == "__main__":
    main()
'''


'''python
from qiskit import QuantumCircuit
import math

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


'''python
from qiskit import QuantumCircuit
import math

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


'''python
from qiskit import QuantumCircuit
import math

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


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
# from qiskit.quantum_info import Statevector
from qiskit.circuit.library.standard_gates import XGate

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

    for i in range(n):
        rot=2*np.pi/2**n*k_const*(2**i)
        # print(rot)
        qc.p(rot,i)

    return qc

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


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, k_const: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    S = [k_const * (2 ** i) for i in range(n)]
    for i in range(n):
        theta = 2 * math.pi * S[i] / 2**n
        qc.p(theta, i)

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

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

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.append(qft(n),range(1,n+1))

    for j in range(n):
        ang=2*np.pi*k_left/(2**(j+1))
        qc.p(ang,j+1)
        qc.cp(-2*ang,0,j+1)

    qc.append(qft(n).inverse(),range(1,n+1))

    if m_left:
        qc.x(0)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(3,3,3)
#     print(Statevector(qc))
'''


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

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

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

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.append(qft(n),range(1,n+1))

    # for j in range(n):
    #     ang=2*np.pi*k_left/(2**(j+1))
    #     qc.p(ang,j+1)
    #     qc.cp(-2*ang,0,j+1)

    # qc.append(qft(n).inverse(),range(1,n+1))

    if m_left:
        qc.x(0)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(3,3,3)
#     print(Statevector(qc))
'''


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

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

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

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.append(qft(n),range(1,n+1))

    # for j in range(n):
    #     ang=2*np.pi*k_left/(2**(j+1))
    #     qc.p(ang,j+1)
    #     qc.cp(-2*ang,0,j+1)

    # qc.append(qft(n).inverse(),range(1,n+1))

    if m_left:
        qc.x(0)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(3,3,3)
#     print(Statevector(qc))
'''


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

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

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

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

#     return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    # qc.append(qft(n),range(1,n+1))

    # for j in range(n):
    #     ang=2*np.pi*k_left/(2**(j+1))
    #     qc.p(ang,j+1)
    #     qc.cp(-2*ang,0,j+1)

    # qc.append(qft(n).inverse(),range(1,n+1))

    if m_left:
        qc.x(0)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(3,3,3)
#     print(Statevector(qc))
'''


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

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

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

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.append(qft(n),range(1,n+1))

    # for j in range(n):
    #     ang=2*np.pi*k_left/(2**(j+1))
    #     qc.p(ang,j+1)
    #     qc.cp(-2*ang,0,j+1)

    # qc.append(qft(n).inverse(),range(1,n+1))

    if m_left:
        qc.x(0)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(3,3,3)
#     print(Statevector(qc))
'''


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

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

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

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.compose(qft(n),range(1,n+1),inplace=True)

    for j in range(n):
        ang=2*np.pi*k_left/(2**(j+1))
        qc.p(ang,j+1)
        qc.cp(-2*ang,0,j+1)

    qc.compose(qft(n).inverse(),range(1,n+1),inplace=True)

    if m_left:
        qc.x(0)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(3,3,3)
#     print(Statevector(qc))
'''


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

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

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

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.compose(qft(n),range(1,n+1),inplace=True)

    for j in range(n):
        ang=2*np.pi*k_left/(2**(j+1))
        qc.p(ang,j+1)
        qc.cp(-2*ang,0,j+1)

    qc.compose(qft(n).inverse(),range(1,n+1),inplace=True)

    if m_left:
        qc.x(0)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(3,3,3)
#     print(Statevector(qc))
'''


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

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

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

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.compose(qft(n),range(1,n+1),inplace=True)

    for j in range(n):
        ang=2*np.pi*k_left/(2**(j+1))
        qc.p(ang,j+1)
        qc.cp(-2*ang,0,j+1)

    qc.compose(qft(n).inverse(),range(1,n+1),inplace=True)

    if m_left:
        qc.x(0)

    return qc

# from qiskit.quantum_info import Statevector
# if __name__ == "__main__":
#     qc = solve(3,0,1)
#     print(Statevector(qc))
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.x(range(2,n+1))
    qc.mcz(range(n),n)
    qc.x(range(2,n+1))

    if m_left%2 == 1: qc.x(0)
    for i in range(k_left):
        qc.rz(2 * pi * 2**(k_left*i - n + 1))

    if m_left%2 == 1:
        qc.x(range(2,n+1))
        qc.mcx(range(2,n),0)
        qc.x(range(2,n+1))

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.x(range(2,n+1))
    qc.mcz(range(n),n)
    qc.x(range(2,n+1))

    if m_left%2 == 1: qc.x(0)
    for i in range(n-1):
        qc.rz(2 * pi * 2**(k_left*i - n + 1), i+2)

    if m_left%2 == 1:
        qc.x(range(2,n+1))
        qc.mcx(range(2,n),0)
        qc.x(range(2,n+1))

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    qc.x(range(2,n+1))
    qc.append(ZGate().control(n), range(n+1))
    #qc.mcz(range(n),n)
    qc.x(range(2,n+1))

    if m_left%2 == 1: qc.x(0)
    for i in range(n-1):
        qc.rz(2 * pi * 2**(k_left*i - n + 1), i+2)

    if m_left%2 == 1:
        qc.x(range(2,n+1))
        qc.mcx(list(range(2,n)),0)
        qc.x(range(2,n+1))

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    qc.x(range(2,n+1))
    qc.append(ZGate().control(n), range(n+1))
    #qc.mcz(range(n),n)
    qc.x(range(2,n+1))

    if m_left%2 == 1: qc.x(0)
    for i in range(n-1):
        qc.rz(2 * pi * 2**(k_left*i - n + 1), i+2)

    if m_left%2 == 1:
        qc.x(range(2,n+1))
        qc.mcx(list(range(2,n)),0)
        qc.x(range(2,n+1))

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    qc.x(range(2,n+1))
    qc.append(ZGate().control(n), range(n+1))
    #qc.mcz(range(n),n)
    qc.x(range(2,n+1))

    if m_left%2 == 1: qc.x(0)
    for i in range(n-1):
        qc.rz(2 * pi * 2**(k_left*i - n + 1), i+2)

    if m_left%2 == 1:
        qc.x(range(2,n+1))
        qc.mcx(list(range(2,n+1)),0)
        qc.x(range(2,n+1))

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    if m_left%2 == 1: qc.x(0)
    if k_left%2 == 1: qc.x(1)
    qc.x(range(2,n+1))
    qc.append(ZGate().control(n), range(n+1))
    #qc.mcz(range(n),n)
    qc.x(range(2,n+1))
    if m_left%2 == 1: qc.x(0)
    if k_left%2 == 1: qc.x(1)

    if m_left%2 == 1: qc.x(0)
    for i in range(n-1):
        qc.rz(2 * pi * 2**(k_left*i - n + 1), i+2)

    if m_left%2 == 1:
        qc.x(range(2,n+1))
        qc.mcx(list(range(2,n+1)),0)
        qc.x(range(2,n+1))

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    qc.x(range(2,n+1))
    if m_left%2 == 1 and k_left%2 == 1:
        qc.append(ZGate().control(n), range(n+1))
    elif m_left%2 == 1 and k_left%2 == 0:
        qc.append(ZGate().control(n-1), [0] + list(range(2,n+1)))
    elif m_left%2 == 0 and k_left%2 == 1:
        qc.append(ZGate().control(n-1), range(1, n+1))
    else:
        qc.append(ZGate().control(n-2), range(2, n+1))
    #qc.mcz(range(n),n)
    qc.x(range(2,n+1))

    if m_left%2 == 1: qc.x(0)
    for i in range(n-1):
        qc.rz(2 * pi * 2**(k_left*i - n + 1), i+2)

    if m_left%2 == 1:
        qc.x(range(2,n+1))
        qc.mcx(list(range(2,n+1)),0)
        qc.x(range(2,n+1))

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    qc.x(range(2,n+1))
    if m_left%2 == 1 and k_left%2 == 1:
        qc.append(ZGate().control(n), range(n+1))
    elif m_left%2 == 1 and k_left%2 == 0:
        qc.append(ZGate().control(n-1), [0] + list(range(2,n+1)))
    elif m_left%2 == 0 and k_left%2 == 1:
        qc.append(ZGate().control(n-1), range(1, n+1))
    else:
        qc.append(ZGate().control(n-2), range(2, n+1))
    #qc.mcz(range(n),n)
    qc.x(range(2,n+1))

    if m_left%2 == 1: qc.x(0)
    for i in range(n-1):
        qc.rz(2 * pi * 2**(k_left*i - n + 1), i+2)

    #if m_left%2 == 1:
    #    qc.x(range(2,n+1))
    #    qc.mcx(list(range(2,n+1)),0)
    #    qc.x(range(2,n+1))

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    ctrl = [2+s for s in range(n-1)]

    # c に比例する位相回転 ( R^{ck_l} )
    for s in range(n-1):
        qc.cp(pi*2 * 2**(s-n+1) * k_left, 2+s, 0)
    # X^{m_l}
    if m_left % 2 == 1:
        qc.x(0)
        # c=0 に対して x をキャンセル
        qc.x(ctrl)
        qc.mcx(ctrl, 0)
        qc.x(ctrl)

    # c=0 に対して，|a>|b> -> (-1)^{a m_l + b k_l} |a>|b>
    qc.x(ctrl)
    if m_left % 2 == 1:
        qc.mcrz(pi, ctrl, 0)
    if k_left % 2 == 1:
        qc.mcrz(pi, ctrl, 1)
    qc.x(ctrl)

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    ctrl = [2+s for s in range(n-1)]
    # c=0 に対して，|a>|b> -> (-1)^{a m_l + b k_l} |a>|b>
    qc.x(ctrl)
    if m_left % 2 == 1:
        qc.mcrz(pi, ctrl, 0)
    if k_left % 2 == 1:
        qc.mcrz(pi, ctrl, 1)
    qc.x(ctrl)

    # c に比例する位相回転 ( R^{ck_l} )
    for s in range(n-1):
        qc.cp(pi*2 * 2**(s-n+1) * k_left, 2+s, 0)
    # X^{m_l}
    if m_left % 2 == 1:
        qc.x(0)
        # c=0 に対して x をキャンセル
        #qc.x(ctrl)
        #qc.mcx(ctrl, 0)
        #qc.x(ctrl)

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    ctrl = [2+s for s in range(n-1)]

    # c=0 に対して，|a>|b> -> (-1)^{a m_l + b k_l} |a>|b>
    qc.x(ctrl)
    if m_left % 2 == 1:
        # qc.mcrz(pi, ctrl, 0)
        qc.compose(ZGate().control(n-1), ctrl+[0], inplace=True)
    if k_left % 2 == 1:
        #qc.mcrz(pi, ctrl, 1)
        qc.compose(ZGate().control(n-1), ctrl+[1], inplace=True)
    qc.x(ctrl)

    # c に比例する位相回転 ( R^{ck_l} )
    for s in range(n-1):
        qc.cp(pi*2 * 2**(s-n+1) * k_left, 2+s, 0)
    # X^{m_l}
    if m_left % 2 == 1:
        qc.x(0)
        # c=0 に対して x をキャンセル
        #qc.x(ctrl)
        #qc.mcx(ctrl, 0)
        #qc.x(ctrl)

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    ctrl = [2+s for s in range(n-1)]

    # c=0 に対して，|a>|b> -> (-1)^{a m_l + b k_l} |a>|b>
    qc.x(ctrl)
    if m_left % 2 == 1:
        # qc.mcrz(pi, ctrl, 0)
        qc.compose(ZGate().control(n-1), ctrl+[0], inplace=True)
    if k_left % 2 == 1:
        #qc.mcrz(pi, ctrl, 1)
        qc.compose(ZGate().control(n-1), ctrl+[1], inplace=True)
    qc.x(ctrl)

    # c に比例する位相回転 ( R^{ck_l} )
    for s in range(n-1):
        qc.cp(pi*2 * 2**(s-n+1) * k_left, 2+s, 0)
    # X^{m_l}
    if m_left % 2 == 1:
        qc.x(0)
        # c=0 に対して x をキャンセル
        qc.x(ctrl)
        qc.mcx(ctrl, 0)
        qc.x(ctrl)

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    ctrl = [2+s for s in range(n-1)]

    # c=0 に対して，|a>|b> -> (-1)^{a m_l + b k_l} |a>|b>
    qc.x(ctrl)
    if m_left % 2 == 1:
        # qc.mcrz(pi, ctrl, 0)
        qc.compose(ZGate().control(n-1), ctrl+[0], inplace=True)
    if k_left % 2 == 1:
        #qc.mcrz(pi, ctrl, 1)
        qc.compose(ZGate().control(n-1), ctrl+[1], inplace=True)
    qc.x(ctrl)

    # c に比例する位相回転 ( R^{ck_l} )
    for s in range(n-1):
        #qc.cp(pi*2 * 2**(s-n+1) * k_left, 2+s, 0)
        qc.rz(pi*2 * 2**(s-n+1) * k_left, 2+s, 0)
    # X^{m_l}
    if m_left % 2 == 1:
        qc.x(0)
        # c=0 に対して x をキャンセル
        qc.x(ctrl)
        qc.mcx(ctrl, 0)
        qc.x(ctrl)

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    ctrl = [2+s for s in range(n-1)]

    # c=0 に対して，|a>|b> -> (-1)^{a m_l + b k_l} |a>|b>
    qc.x(ctrl)
    if m_left % 2 == 1:
        # qc.mcrz(pi, ctrl, 0)
        qc.compose(ZGate().control(n-1), ctrl+[0], inplace=True)
    if k_left % 2 == 1:
        #qc.mcrz(pi, ctrl, 1)
        qc.compose(ZGate().control(n-1), ctrl+[1], inplace=True)
    qc.x(ctrl)

    # c に比例する位相回転 ( R^{ck_l} )
    for s in range(n-1):
        #qc.cp(pi*2 * 2**(s-n+1) * k_left, 2+s, 0)
        qc.crz(pi*2 * 2**(s-n+1) * k_left, 2+s, 0)
    # X^{m_l}
    if m_left % 2 == 1:
        qc.x(0)
        # c=0 に対して x をキャンセル
        qc.x(ctrl)
        qc.mcx(ctrl, 0)
        qc.x(ctrl)

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    if m_left == 1:
        z0 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z0, list(range(2, n + 1)) + [0])
    if k_left % 2 == 1:
        z1 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z1, list(range(2, n + 1)) + [1])

    for i in range(n - 1):
        theta = 2 * math.pi / (2.0 ** (n - 1 - i)) * k_left
        qc.p(theta, 2 + i)

    if m_left == 1:
        qc.x(0)

    return qc
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    if m_left == 1:
        z0 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z0, list(range(2, n + 1)) + [0])
    if k_left % 2 == 1:
        z1 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z1, list(range(2, n + 1)) + [1])

    for i in range(n - 1):
        theta = 2 * math.pi / (2.0 ** (n - 1 - i)) * k_left
        qc.crz(theta, 2 + i, 0)

    x0h = XGate().control(n - 1, ctrl_state=0)
    qc.append(x0h, list(range(2, n + 1)) + [0])
    qc.x(0)

    return qc

def main():
    print(solve(4, 1, 1))
    # print(solve(4, 2))

if __name__ == "__main__":
    main()
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    if m_left == 1:
        z0 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z0, list(range(2, n + 1)) + [0])
    if k_left % 2 == 1:
        z1 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z1, list(range(2, n + 1)) + [1])

    for i in range(n - 1):
        theta = 2 * math.pi / (2.0 ** (n - 1 - i)) * k_left
        qc.crz(theta, 2 + i, 0, ctrl_state=0)

    x0h = XGate().control(n - 1, ctrl_state=0)
    qc.append(x0h, list(range(2, n + 1)) + [0])
    qc.x(0)

    return qc

def main():
    print(solve(4, 1, 1))
    # print(solve(4, 2))

if __name__ == "__main__":
    main()
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    if m_left == 1:
        z0 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z0, list(range(2, n + 1)) + [0])
    if k_left % 2 == 1:
        z1 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z1, list(range(2, n + 1)) + [1])

    qc.x(range(2, n + 1))
    for i in range(n - 1):
        theta = 2 * math.pi / (2.0 ** (n - 1 - i)) * k_left
        qc.crz(theta, 2 + i, 0)

    x0h = XGate().control(n - 1, ctrl_state=0)
    qc.append(x0h, list(range(2, n + 1)) + [0])
    qc.x(0)

    return qc

def main():
    print(solve(4, 1, 1))
    # print(solve(4, 2))

if __name__ == "__main__":
    main()
'''


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

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    if m_left == 1:
        z0 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z0, list(range(2, n + 1)) + [0])
    if k_left % 2 == 1:
        z1 = ZGate().control(n - 1, ctrl_state=0)
        qc.append(z1, list(range(2, n + 1)) + [1])

    for i in range(n - 1):
        theta = 2 * math.pi / (2.0 ** (n - 1 - i)) * k_left
        qc.crz(theta, control_qubit=2 + i, target_qubit=0)

    if m_left == 1:
        x0h = XGate().control(n - 1, ctrl_state=0)
        qc.append(x0h, list(range(2, n + 1)) + [0])
        qc.x(0)

    return qc

def main():
    print(solve(4, 1, 1))
    # print(solve(4, 2))

if __name__ == "__main__":
    main()
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    k_bits = list()

    for i in range(n):
        k_bits.append(k_left % 2)
        k_left >>= 1

    if (m_left == 1):
        qc.x(0)

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

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

    qc.x(0)
    for i in range(1, n + 1):
        theta = 2 * math.pi * k_bits(i - 1) * (2 ** (i - 1)) / 2 ** n
        qc.cp(theta, 0, i)

    qc.x(0)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    k_bits = list()

    for i in range(n):
        k_bits.append(k_left % 2)
        k_left = k_left // 2

    if (m_left == 1):
        qc.x(0)

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

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

    qc.x(0)
    for i in range(1, n + 1):
        theta = 2 * math.pi * k_bits(i - 1) * (2 ** (i - 1)) / 2 ** n
        qc.cp(theta, 0, i)

    qc.x(0)

    QFT(qc, list(range(1, n + 1)), inversed=True)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    k_bits = list()

    for i in range(n):
        k_bits.append(k_left % 2)
        k_left = k_left //

    if (m_left == 1):
        qc.x(0)

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

    for i in range(1, n + 1):
        theta = 2 * math.pi * k_bits[i - 1] * (2 ** (i - 1)) / 2 ** n
        qc.cp(-theta, 0, i)

    qc.x(0)
    for i in range(1, n + 1):
        theta = 2 * math.pi * k_bits[i - 1] * (2 ** (i - 1)) / 2 ** n
        qc.cp(theta, 0, i)

    qc.x(0)

    QFT(qc, list(range(1, n + 1)), inversed=True)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    k_bits = list()

    for i in range(n):
        k_bits.append(k_left % 2)
        k_left = k_left // 2

    if (m_left == 1):
        qc.x(0)

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

    for i in range(1, n + 1):
        theta = 2 * math.pi * k_bits[i - 1] * (2 ** (i - 1)) / 2 ** n
        qc.cp(-theta, 0, i)

    qc.x(0)
    for i in range(1, n + 1):
        theta = 2 * math.pi * k_bits[i - 1] * (2 ** (i - 1)) / 2 ** n
        qc.cp(theta, 0, i)

    qc.x(0)

    QFT(qc, list(range(1, n + 1)), inversed=True)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    k_bits = list()

    for i in range(n):
        k_bits.append(k_left % 2)
        k_left = k_left //

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

    for i in range(1, n + 1):
        theta = 2 * math.pi * k_bits[i - 1] * (2 ** (i - 1)) / 2 ** n
        qc.p(theta, 0, i)

    for i in range(1, n + 1):
        theta = -4 * math.pi * k_bits[i - 1] * (2 ** (i - 1)) / 2 ** n
        qc.cp(theta, 0, i)

    if (m_left == 1):
        qc.x(0)

    QFT(qc, list(range(1, n + 1)), inversed=True)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    k_bits = list()

    for i in range(n):
        k_bits.append(k_left % 2)
        k_left = k_left // 2

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

    for i in range(1, n + 1):
        theta = 2 * math.pi * k_bits[i - 1] * (2 ** (i - 1)) / 2 ** n
        qc.p(theta, i)

    for i in range(1, n + 1):
        theta = -4 * math.pi * k_bits[i - 1] * (2 ** (i - 1)) / 2 ** n
        qc.cp(theta, 0, i)

    if (m_left == 1):
        qc.x(0)

    QFT(qc, list(range(1, n + 1)), inversed=True)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

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

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

    for i in range(1, n + 1):
        theta = -4 * math.pi * k_left * (2 ** (i - 1)) / 2 ** n
        qc.cp(theta, 0, i)

    if (m_left == 1):
        qc.x(0)

    QFT(qc, list(range(1, n + 1)), inversed=True)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    QFT(qc, list(range(1, n + 1)))

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

    for i in range(1, n + 1):
        theta = -4 * math.pi * k_left * (2 ** (i - 1)) / 2 ** n
        qc.cp(theta, 0, i)

    if (m_left == 1):
        qc.x(0)

    QFT(qc, list(range(1, n + 1)), inversed=True)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    QFT(qc, list(range(1, n + 1)))

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

    for i in range(1, n + 1):
        theta = -4 * math.pi * k_left * (2 ** (i - 1)) / 2 ** n
        qc.cp(theta, 0, i)

    QFT(qc, list(range(1, n + 1)), inversed=True)

    if (m_left == 1):
        qc.x(0)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.rz(2 * math.pi * k_left / (2 **(n - 1)), 0)

    if (m_left == 1):
        qc.x(0)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.rz(2 * math.pi * k_left / (2 **(n)), 0)

    if (m_left == 1):
        qc.x(0)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.rz(2 * math.pi * k_left / (2 **(n - 1)), 0)

    if (m_left == 1):
        qc.z(0)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    for i in range(2, n + 1):
        qc.x(i)
    qc.mcp(math.pi * m_left, list(range(2, n + 1)), 0)
    qc.mcp(math.pi * k_left, list(range(2, n + 1)), 1)
    qc.mcrz(-2 * math.pi * k_left / (2 ** (n - 1)), list(range(2, n + 1)), 0)

    qc.rz(2 * math.pi * k_left / (2 **(n - 1)), 0)

    if (m_left == 1):
        qc.mcz(list(range(2, n+1)), 0)
        qc.z(0)

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    for i in range(2, n + 1):
        qc.x(i)
    qc.mcp(math.pi * m_left, list(range(2, n + 1)), 0)
    qc.mcp(math.pi * k_left, list(range(2, n + 1)), 1)
    qc.mcrz(-2 * math.pi * k_left / (2 ** (n - 1)), list(range(2, n + 1)), 0)

    qc.rz(2 * math.pi * k_left / (2 **(n - 1)), 0)

    if (m_left == 1):
        qc.mcp(math.pi, list(range(2, n+1)), 0)

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

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    for i in range(2, n + 1):
        qc.x(i)
    qc.mcp(math.pi * m_left, list(range(2, n + 1)), 0)
    qc.mcp(math.pi * k_left, list(range(2, n + 1)), 1)
    qc.mcrz(-2 * math.pi * k_left / (2 ** (n - 1)), list(range(2, n + 1)), 0)

    qc.rz(2 * math.pi * k_left / (2 **(n - 1)), 0)

    if (m_left == 1):
        qc.mcp(2 *  math.pi,list(range(2, n+1)), 0)

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

    return qc
'''


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

def QFT(qc : QuantumCircuit, idx : list[int], inversed : bool = False) -> QuantumCircuit:
    n = len(idx)
    for i in range(n // 2):
        qc.swap(idx[i], idx[n - i - 1])
    for j in range(n):
        qc.h(idx[j])
        for k in range(j+1, n):
            theta = math.pi / (2 ** (k - j))
            if (inversed):
                theta *= -1
            qc.cp(theta, idx[k], idx[j])

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

    return qc

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    for i in range(2, n + 1):
        qc.x(i)
    qc.mcp(math.pi * m_left, list(range(2, n + 1)), 0)
    qc.mcp(math.pi * k_left, list(range(2, n + 1)), 1)
    qc.mcrz(-2 * math.pi * k_left / (2 ** (n - 1)), list(range(2, n + 1)), 0)

    qc.rz(2 * math.pi * k_left / (2 **(n - 1)), 0)

    if (m_left == 1):
        qc.z(0)
        qc.mcp(2 *  math.pi,list(range(2, n+1)), 0)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import XGate, RZGate
from math import pi

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.x(range(2, n + 1))

    S = [k_left * (2 ** i) for i in range(n)]
    for i in range(n):
        theta = 2 * pi * S[i] / 2**n
        qc.p(theta, i)
    if m_left == 1:
      qc.x(0)
    if m_left == 1:
      qc.append(XGate().control(n - 1), list(range(2, n + 1)) + [0])
    qc.x(range(2, n + 1))
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import XGate, RZGate
from math import pi

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.x(range(2, n + 1))

    S = [k_left * (2 ** i) for i in range(n - 1)]
    for i in range(n - 1):
        theta = 2 * pi * S[i] / 2**n
        qc.cp(theta, i + 2, 0)

    if m_left == 1:
      qc.x(0)
    if m_left == 1:
      qc.append(XGate().control(n - 1), list(range(2, n + 1)) + [0])

    qc.x(range(2, n + 1))
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import XGate, RZGate
from math import pi

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.x(range(2, n + 1))

    S = [k_left * (2 ** i) for i in range(n - 1)]
    for i in range(n - 1):
        theta = 2 * pi * S[i] / 2**n
        qc.crz(theta, i + 2, 0)

    if m_left == 1:
      qc.x(0)
    if m_left == 1:
      qc.append(XGate().control(n - 1), list(range(2, n + 1)) + [0])

    qc.x(range(2, n + 1))
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import XGate, RZGate
from math import pi

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.x(range(2, n + 1))

    S = [k_left * (2 ** i) for i in range(n - 1)]
    for i in range(n - 1):
        theta = 2 * pi * S[i] / 2**(n - 1)
        qc.crz(theta, i + 2, 0)

    if m_left == 1:
      qc.x(0)
    if m_left == 1:
      qc.append(XGate().control(n - 1), list(range(2, n + 1)) + [0])

    qc.x(range(2, n + 1))
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import XGate, RZGate
from math import pi

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    S = [k_left * (2 ** i) for i in range(n - 1)]
    for i in range(n - 1):
        theta = 2 * pi * S[i] / 2**(n - 1)
        qc.crz(theta, i + 2, 0)

    qc.x(range(2, n + 1))

    if m_left == 1:
      qc.x(0)
    if m_left == 1:
      qc.append(XGate().control(n - 1), list(range(2, n + 1)) + [0])

    qc.x(range(2, n + 1))
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import XGate, ZGate
from math import pi

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:

    qc.x(range(2, n + 1))
    if m_left == 1:
      qc.append(ZGate().control(n - 1), list(range(2, n + 1)) + [0])
    if k_left%2 == 1:
      qc.append(ZGate().control(n - 1), list(range(2, n + 1)) + [1])

    S = [k_left * (2 ** i) for i in range(n - 1)]
    for i in range(n - 1):
        theta = 2 * pi * S[i] / 2**(n - 1)
        qc.crz(theta, i + 2, 0)

    if m_left == 1:
      qc.x(0)
    if m_left == 1:
      qc.append(XGate().control(n - 1), list(range(2, n + 1)) + [0])

    qc.x(range(2, n + 1))
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate, XXPlusYYGate, RZZGate

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    a, b, c, anc = (
        QuantumRegister(1),
        QuantumRegister(1),
        QuantumRegister(n - 1),
        QuantumRegister(1),
    )

    qc = QuantumCircuit(a, b, c, anc)
    zangle = 2 * np.pi / 2 ** (n - 1)

    qc.x(anc)
    qc.mcx(c, anc)

    if m_left == 0:
        for i in range(n - 1):
            qc.mcrz(zangle * (2**i), anc, c[i])

    qc.mcx(c, anc)
    qc.x(anc)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate, XXPlusYYGate, RZZGate

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    a, b, c, anc = (
        QuantumRegister(1),
        QuantumRegister(1),
        QuantumRegister(n - 1),
        QuantumRegister(1),
    )

    qc = QuantumCircuit(a, b, c, anc)
    zangle = 2 * np.pi / 2 ** (n - 1)

    qc.x(anc)
    qc.mcx(c, anc)

    if m_left == 0:
        for i in range(n - 1):
            qc.mcrz(zangle * k_left * (2**i), anc, c[i])

    qc.mcx(c, anc)
    qc.x(anc)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate, XXPlusYYGate, RZZGate

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    a, b, c = (
        QuantumRegister(1),
        QuantumRegister(1),
        QuantumRegister(n - 1),
    )

    qc = QuantumCircuit(a, b, c)
    zangle = 2 * np.pi / (2 ** (n - 1))

    if m_left == 0:
        for i in range(n - 1):
            qc.rz(zangle * k_left * (2**i), c[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate, XXPlusYYGate, RZZGate

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    a, b, c, anc = (
        QuantumRegister(1),
        QuantumRegister(1),
        QuantumRegister(n - 1),
        QuantumRegister(1),
    )

    qc = QuantumCircuit(a, b, c)
    zangle = 2 * np.pi / (2 ** (n - 1))

    qc.x(anc)
    qc.mcx(c, anc)

    if m_left == 0:
        for i in range(n - 1):
            qc.crz(zangle * k_left * (2**i), anc, a)

    qc.mcx(c, anc)
    qc.x(anc)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate, XXPlusYYGate, RZZGate

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    a, b, c, anc = (
        QuantumRegister(1),
        QuantumRegister(1),
        QuantumRegister(n - 1),
        QuantumRegister(1),
    )

    qc = QuantumCircuit(a, b, c, anc)
    zangle = 2 * np.pi / (2 ** (n - 1))

    qc.x(anc)
    qc.mcx(c, anc)

    if m_left == 0:
        for i in range(n - 1):
            qc.crz(zangle * k_left * (2**i), anc, a)

    qc.mcx(c, anc)
    qc.x(anc)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate, XXPlusYYGate, RZZGate

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    a, b, c = (
        QuantumRegister(1),
        QuantumRegister(1),
        QuantumRegister(n - 1),
    )

    qc = QuantumCircuit(a, b, c)
    zangle = 2 * np.pi / (2 ** (n - 1))

    if m_left == 0:
        for i in range(n - 1):
            qc.crz(zangle * k_left * (2**i), c[i], a)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import numpy as np
from qiskit.circuit.library.standard_gates import HGate, XGate, XXPlusYYGate, RZZGate

def solve(n: int, m_left: int, k_left: int) -> QuantumCircuit:
    a, b, c, anc = (
        QuantumRegister(1),
        QuantumRegister(1),
        QuantumRegister(n - 1),
        QuantumRegister(1),
    )

    qc = QuantumCircuit(a, b, c, anc)
    zangle = 2 * np.pi / (2 ** (n - 1))

    qc.x(c)
    qc.x(anc)
    qc.mcx(c, anc)
    qc.x(c)

    if m_left == 0:
        for i in range(n - 1):
            qc.crz(zangle * k_left * (2**i), c[i], a)

    else:
        for i in range(n - 1):
            qc.crz(zangle * k_left * (2**i), c[i], a)

        qc.cx(anc, a)

    qc.x(c)
    qc.mcx(c, anc)
    qc.x(anc)
    qc.x(c)

    return qc
'''