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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    L_binary = format(L, f'0{n}b')
    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)
    qc.rz(theta, range(n))
    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
      if not ((L>>i)&1):
        qc.x(i)
    if n == 1:
      qc.u(0, theta, 0, 0)
    else:
      qc.append(UGate(0, theta, 0).control(n-1),range(n))
    for i in range(n):
      if not ((L>>i)&1):
        qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    #yを|11...1>に変換すべくリトルエンディアンの順序で、0の桁にXゲートで反転させる
    for i in range(n):
        if L&(1<<i) == 0:
            qc.x(i)
    if n == 1:
        qc.p(theta, n-1)
    else:
        qc.mcp(theta, list(range(n-1)), n-1)

    #|11...1>をyに変換すべくリトルエンディアンの順序で、0の桁にXゲートで反転させる
    for i in range(n):
        if L&(1<<i) == 0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    L_bits = format(L, f'0{n}b')

    # Apply X gates to match the state |L>
    for i, bit in enumerate(L_bits):
        if bit == '0':
            qc.x(i)

    # Apply the multi-controlled Z gate with phase shift theta (Rz)
    qc.mcrz(theta, control_qubits=list(range(n)), target_qubit=n-1)

    # Undo the X gates to revert the original state
    for i, bit in enumerate(L_bits):
        if bit == '0':
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    L_bits = format(L, f'0{n}b')

    # Apply X gates to match the state |L>
    for i, bit in enumerate(L_bits):
        if bit == '0':
            qc.x(i)

    # Apply the multi-controlled phase gate
    qc.append(PhaseGate(theta).control(n), range(n))

    # Undo the X gates to revert the original state
    for i, bit in enumerate(L_bits):
        if bit == '0':
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    L_bits = format(L, f'0{n}b')

    # Apply X gates to match the state |L>
    for i, bit in enumerate(L_bits):
        if bit == '0':
            qc.x(i)

    # Apply the multi-controlled phase gate
    qc.append(PhaseGate(theta).control(n-1), range(n))

    # Undo the X gates to revert the original state
    for i, bit in enumerate(L_bits):
        if bit == '0':
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    L_bits = format(L, f'0{n}b')

    bit = L_bits[-1]
    if bit == '0':
        qc.x(n-1)

    # Apply the multi-controlled phase gate
    qc.append(PhaseGate(theta).control(n-1), range(n))

    # Undo the X gates to revert the original state
    if bit == '0':
        qc.x(n-1)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    diag = [1]*(2**n)
    diag[L-1] = np.cos(theta) + 1j * np.sin(theta)

    state = diag / 2 ** n
    qc.initialize(state, range(n))
    # Apply the multi-controlled phase gate

    return qc.decompose().decompose().decompose()
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    diag = [np.sqrt(1/2**n)]*(2**n)
    diag[L-1] = (np.cos(theta) + 1j * np.sin(theta)) / np.sqrt(2**n)

    qc.initialize(diag, list(range(n)))
    # Apply the multi-controlled phase gate

    return qc.decompose().decompose().decompose(
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    diag = [np.sqrt(1/2**n)]*(2**n)
    diag[L-1] = (np.cos(theta) + 1j * np.sin(theta)) / np.sqrt(2**n)

    qc.initialize(diag, list(range(n)))
    # Apply the multi-controlled phase gate

    return qc.decompose().decompose().decompose()
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    diag = [np.sqrt(1/2**n)]*(2**n)
    diag[L-1] = (np.cos(theta) + 1j * np.sin(theta)) / np.sqrt(2**n)
    qc.initialize(diag, list(range(n)))

    return qc.decompose().decompose().decompose().decompose().decompose().decompose()
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if not ((L>>i)&1):
            qc.x(i)

    qc.mcp(theta,[i for i in range(n-1)],n-1)

    for i in range(n):
        if not ((L>>i)&1):
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if not ((L>>i)&1):
            qc.x(i)
    if n==1:
        qc.p(theta,0)

    else :
        qc.mcp(theta,[i for i in range(n-1)],n-1)

    for i in range(n):
        if not ((L>>i)&1):
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if not ((L >> i) & 1):
            qc.x(i)
    if n == 1:
        qc.rz(-2 * theta, 0)
    else:
        qc.mcrz(-2 * theta, list(range(n - 1)), n - 1)
    for i in range(n):
        if not ((L >> i) & 1):
            qc.x(i)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if not ((L >> i) & 1):
            qc.x(i)
    if n == 1:
        qc.append(PhaseGate(theta), [0])
    else:
        qc.append(PhaseGate(theta).control(n - 1), range(n))
    for i in range(n):
        if not ((L >> i) & 1):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if L < 2**n:
        qc.p(theta, L)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in n:
        if not (L>>i & 1):
            qc.x(i)
    if n==1:
        qc.p(theta,0)
    else:
        qc.append(PGate(theta).control(n-1),range(n))
    for i in n:
        if not (L>>i & 1):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in n:
        if not (L>>i & 1):
            qc.x(i)
    if n==1:
        qc.p(theta,0)
    else:
        qc.mcp(theta,range(n-1),n-1)
    for i in n:
        if not (L>>i & 1):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in n:
        if not (L>>i & 1):
            qc.x(i)
    if n==1:
        qc.p(theta,0)
    else:
        qc.mcp(theta,list(range(n-1)),n-1)
    for i in n:
        if not (L>>i & 1):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in n:
        if not ((L>>i) & 1):
            qc.x(i)
    if n==1:
        qc.p(theta,0)
    else:
        qc.mcp(theta,list(range(n-1)),n-1)
    for i in n:
        if not ((L>>i) & 1):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in n:
        if not ((L>>i) & 1):
            qc.x(i)
    if n==1:
        qc.p(theta,n-1)
    else:
        qc.mcp(theta,list(range(n-1)),n-1)
    for i in n:
        if not ((L>>i) & 1):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if not ((L>>i) & 1):
            qc.x(i)
    if n==1:
        qc.p(theta,n-1)
    else:
        qc.mcp(theta,list(range(n-1)),n-1)
    for i in range(n):
        if not ((L>>i) & 1):
            qc.x(i)
    return qc
'''


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

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

    bin_data = format(i, f'0{n}b')
    data_0_bits = [idx for idx, digit in enumerate(reversed(bin_data)) if digit == '0']

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    qc.append(RZGate(-2*theta).control(n-1), range(n))

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    return qc
'''


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

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

    bin_data = format(L, f'0{n}b')
    data_0_bits = [idx for idx, digit in enumerate(reversed(bin_data)) if digit == '0']

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    qc.append(RZGate(-2*theta).control(n-1), range(n))

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    return qc
'''


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

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

    bin_data = format(L, f'0{n}b')
    data_0_bits = [idx for idx, digit in enumerate(bin_data) if digit == '0']

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    qc.append(RZGate(-2*theta).control(n-1), range(n))

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    return qc
'''


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

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

    bin_data = format(i, f'0{n}b')
    data_0_bits = [idx for idx, digit in enumerate(reversed(bin_data)) if digit == '0']

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    qc.append(RZGate(2*theta).control(n-1), range(n))

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    return qc
'''


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

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

    bin_data = format(L, f'0{n}b')
    data_0_bits = [idx for idx, digit in enumerate(reversed(bin_data)) if digit == '0']

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    qc.append(RZGate(2*theta).control(n-1), range(n))

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    return qc
'''


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

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

    bin_data = format(L, f'0{n}b')
    data_0_bits = [idx for idx, digit in enumerate(reversed(bin_data)) if digit == '0']

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    qc.append(CPhaseGate(theta).control(n-1), range(n))

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    return qc
'''


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

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

    bin_data = format(L, f'0{n}b')
    data_0_bits = [idx for idx, digit in enumerate(reversed(bin_data)) if digit == '0']

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    qc.append(PhaseGate(theta).control(n-1), range(n))

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    return qc
'''


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

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

    bin_data = format(L, f'0{n}b')
    data_0_bits = [idx for idx, digit in enumerate(reversed(bin_data)) if digit == '0']

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    if n==1:
        qc.p(theta, 0)
    else:
        qc.append(PhaseGate(theta).control(n-1), range(n))

    if len(data_0_bits) > 0:
        qc.x(data_0_bits)

    return qc
'''


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

def decimalToBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)

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

    L_binary = decimalToBinary(L, n)
    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)

    qc.append(RZ(-2*theta, 0), range(n))

    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)

    return

    return qc
'''


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

def decimalToBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)

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

    L_binary = decimalToBinary(L, n)
    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)

    qc.append(RZ(-2*theta, 0), range(n))

    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)

        return qc
'''


'''python
from qiskit import QuantumCircuit

def decimalToBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)

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

    L_binary = decimalToBinary(L, n)
    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(-2*theta, i)

    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)

        return qc
'''


'''python
from qiskit import QuantumCircuit

def decimalToBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)

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

    qc.rz(theta, L)

        return qc
'''


'''python
from qiskit import QuantumCircuit

def decimalToBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)

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

    qc.rz(theta, L)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)

    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.rz(-2*theta, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)

    qc.rz(-2*theta, L)

   # for i, bit in enumerate(L_binary):
   #     if bit == '1':
  #          qc.rz(-2*theta, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)

    qc.rz(theta, L)

   # for i, bit in enumerate(L_binary):
   #     if bit == '1':
  #          qc.rz(-2*theta, i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)
    theta = theta % (2 * np.pi)

    qc.rz(theta, L)

   # for i, bit in enumerate(L_binary):
   #     if bit == '1':
  #          qc.rz(-2*theta, i)

    return qc
'''


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

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)
    theta = theta % (2 * np.pi)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(-2*theta, i)

    return qc
'''


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

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)
    theta = theta % (2 * np.pi)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(theta, i)

    return qc
'''


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

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

    L_binary = decimalToLittleEndianBinary(L, n)
    theta = theta % (2 * np.pi)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(theta, i)

    return qc
'''


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

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)
    theta = theta % (2 * np.pi)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(-theta, i)

    return qc
'''


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

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(-2*theta, i)

    return qc
'''


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

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(-theta, i)

    return qc
'''


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

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

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

    L_binary = decimalToLittleEndianBinary(L, n)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(theta, i)

    return qc
'''


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

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

    L_binary = decimalToLittleEndianBinary(L, n)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(-2*theta, i)

    return qc
'''


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

def decimalToLittleEndianBinary(n: int, length: int) -> str:
    return bin(n)[2:].zfill(length)[::-1]  # Reverse the string for little-endian

def solve(n: int, L: int, theta: float) -> QuantumCircuit:

    qc = QuantumCircuit(n)

    for i in range(n):
        qc.h(i)
    L_binary = decimalToLittleEndianBinary(L, n)

    for i in range(n):
        if L_binary[i] == '1':
            qc.rz(-2*theta, i)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if ((1 << i) & L) == 0:
            qc.x(i)

    qc.crz(-2 * theta, range(n-1), n-1)

    return qc

# solve(3, 5, 0.5).draw('mpl').show()
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if ((1 << i) & L) == 0:
            qc.x(i)

    qc.cp(-2 * theta, range(n-1), n-1)

    for i in range(n):
        if ((1 << i) & L) == 0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n >= 2:
        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)

        qc.cp(-2 * theta, range(n-1), n-1)

        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)

    else:
        if L == 1:
            qc.rz(-2 * theta, 0)
        else:
            qc.x(0)
            qc.rz(-2 * theta, 0)
            qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n >= 2:
        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)

        qc.cp(-2 * theta, range(n-1), n-1)

        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)

    else:
        if L == 1:
            qc.p(-2 * theta, 0)
        else:
            qc.x(0)
            qc.p(-2 * theta, 0)
            qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n >= 2:
        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)

        qc.cp(theta, range(n-1), n-1)

        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)

    else:
        if L == 1:
            qc.p(theta, 0)
        else:
            qc.x(0)
            qc.p(theta, 0)
            qc.x(0)
            from qiskit.circuit.library import ZGate
            ZGate().control()

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n >= 2:
        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)

        qc.cp(theta, n-1, range(n-1))

        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)
    else:
        if L == 1:
            qc.p(theta, 0)
        else:
            qc.x(0)
            qc.p(theta, 0)
            qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n >= 2:
        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)

        qc.cp(theta, n-1, range(n))

        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)
    else:
        if L == 1:
            qc.p(theta, 0)
        else:
            qc.x(0)
            qc.p(theta, 0)
            qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n >= 2:
        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)

        from qiskit.circuit.library import PhaseGate
        qc.append(PhaseGate(theta).control(n-1), range(n))
        # qc.cp(theta, n-1, range(n))

        for i in range(n):
            if ((1 << i) & L) == 0:
                qc.x(i)
    else:
        if L == 1:
            qc.p(theta, 0)
        else:
            qc.x(0)
            qc.p(theta, 0)
            qc.x(0)

    return qc

solve(3, 5, 0.5).draw('mpl').show()
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
            # check if i-th bit of l is 0 or 1
            if not ((L >> i) & 1):
                qc.x(i)
    if n == 1:
        qc.p(theta, 0)
    else:
        qc.append(PhaseGate(theta).control(n - 1), range(n))

    for i in range(n):
            # check if i-th bit of l is 0 or 1
            if not ((L >> i) & 1):
                qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    binary = bin(L)
    ctrl_state = binary[-1:1:-1]
    ctrl_state = ctrl_state + (2**n - len(ctrl_state))*'0'

    qc.mcp(theta, ctrl_state = ctrl_state)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    binary = bin(L)
    ctrl_state = binary[-1:1:-1]
    ctrl_state = ctrl_state + (2**n - len(ctrl_state)-1)*'0'

    qc.mcp(theta, ctrl_state = ctrl_state, target_qubit = n-1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    binary = bin(L)
    ctrl_state = binary[-1:1:-1]
    ctrl_state = ctrl_state + (2**n - len(ctrl_state)-)*'0'

    qc.mcp(theta, control_qubits= [i for i in range(1, n)] , ctrl_state = L,target_qubit=0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    binary = bin(L)
    ctrl_state = binary[-1:1:-1]
    ctrl_state = ctrl_state + (2**n - len(ctrl_state)-1)*'0'

    qc.mcp(theta, control_qubits= [i for i in range(1, n)] , ctrl_state = L,target_qubit=0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    binary = bin(L)
    ctrl_state = binary[-1:1:-1]
    ctrl_state = ctrl_state + (n - len(ctrl_state)-1)*'0'

    ctrl_state[1:]

    if ctrl_state[0] == 0:
        qc.x(0)
        qc.mcp(theta, control_qubits= [i for i in range(1, n)] , ctrl_state = ctrl_state,target_qubit=0)
        qc.x(0)

    else : qc.mcp(theta, control_qubits= [i for i in range(1, n)] , ctrl_state = ctrl_state,target_qubit=0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    binary = bin(L)
    ctrl_state = binary[-1:1:-1]

    print(ctrl_state)

    ctrl_state = (n - len(ctrl_state))*'0' + ctrl_state
    print(ctrl_state)

    print(ctrl_state[0])

    if ctrl_state[0] == '0':
        ctrl_state = ctrl_state[1:]
        print(ctrl_state)
        qc.x(0)
        qc.mcp(theta, control_qubits= [i for i in range(1, n)] , ctrl_state = ctrl_state,target_qubit=0)
        qc.x(0)

    else :
        ctrl_state = ctrl_state[1:]
        qc.mcp(theta, control_qubits= [i for i in range(1, n)] , ctrl_state = ctrl_state,target_qubit=0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    binary = bin(L)
    ctrl_state = binary[-1:1:-1]

    print(ctrl_state)

    ctrl_state = ctrl_state + (n - len(ctrl_state))*'0'
    print(ctrl_state)

    print(ctrl_state[0])

    if ctrl_state[0] == '0':
        ctrl_state = ctrl_state[-1:0:-1]
        print(ctrl_state)
        qc.x(0)
        qc.mcp(theta, control_qubits= [i for i in range(1,n)] , ctrl_state = ctrl_state,target_qubit= 0)
        qc.x(0)

    else :
        ctrl_state = ctrl_state[-1:0:-1]
        print(ctrl_state)
        qc.mcp(theta, control_qubits= [i for i in range(1,n)] , ctrl_state = ctrl_state,target_qubit= 0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    binary = bin(L)
    ctrl_state = binary[-1:1:-1]

    print(ctrl_state)

    ctrl_state = ctrl_state + (n - len(ctrl_state))*'0'
    print(ctrl_state)

    print(ctrl_state[0])

    if ctrl_state[0] == '0':
        ctrl_state = ctrl_state[-1:0:-1]
        print(ctrl_state)
        qc.x(0)
        qc.mcp(theta, control_qubits= [i for i in range(1,n)] , ctrl_state = ctrl_state,target_qubit= 0)
        qc.x(0)

    else :
        ctrl_state = ctrl_state[-1:0:-1]
        print(ctrl_state)
        qc.mcp(theta, control_qubits= [i for i in range(1,n)] , ctrl_state = ctrl_state,target_qubit= 0)

    #qc.measure_all()

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    binary = bin(L)
    ctrl_state = binary[-1:1:-1]

    print(ctrl_state)

    ctrl_state = ctrl_state + (n - len(ctrl_state))*'0'
    print(ctrl_state)

    print(ctrl_state[0])

    if ctrl_state[0] == '0':
        ctrl_state = ctrl_state[-1:0:-1]
        print(ctrl_state)
        qc.x(0)
        qc.mcp(theta, control_qubits= [i for i in range(1,n)] , ctrl_state = ctrl_state,target_qubit= 0)
        qc.x(0)

    else :
        ctrl_state = ctrl_state[-1:0:-1]
        print(ctrl_state)
        qc.mcp(theta, control_qubits= [i for i in range(1,n)] , ctrl_state = ctrl_state,target_qubit= 0)

    #qc.measure_all()

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    binary = bin(L)
    ctrl_state = binary[-1:1:-1]

    print(ctrl_state)

    ctrl_state = ctrl_state + (n - len(ctrl_state))*'0'
    print(ctrl_state)

    print(ctrl_state[0])

    if n > 1:

        if ctrl_state[0] == '0':
            ctrl_state = ctrl_state[-1:0:-1]
            print(ctrl_state)
            qc.x(0)
            qc.mcp(theta, control_qubits= [i for i in range(1,n)] , ctrl_state = ctrl_state,target_qubit= 0)
            qc.x(0)

        else :
            ctrl_state = ctrl_state[-1:0:-1]
            print(ctrl_state)
            qc.mcp(theta, control_qubits= [i for i in range(1,n)] , ctrl_state = ctrl_state,target_qubit= 0)

    #qc.measure_all()
    else :
        if L == 0:
            qc.x(0)
        qc.p(theta , 0)
        if L == 0:
            qc.x(0)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)
    qc.append(RZGate().control(n - 1), range(n))
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)
    if n==1:
        qc.rz(-theta*2,0)
    else:
        qc.append(RZGate(-theta*2).control(n - 1), range(n))
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)
    qc.mcp(theta, list(range(n - 1)), n - 1)
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)
    if n==1:
        qc.p(theta,0)
    else:
        qc.mcp(theta, list(range(n - 1)), n - 1)
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    #qc.h(range(n))
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)
    if n==1:
        qc.p(theta,0)
    else:
        qc.mcp(theta, list(range(n - 1)), n - 1)
    for i in range(n):
        if (L>>i)&1==0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n, L, theta) -> QuantumCircuit:
	qc = QuantumCircuit(n)
	for i in range(n):
		if ~L >> i & 1:
			qc.x(i)
	qc.mcp(theta, list(range(n - 1)), n - 1)
	for i in range(n):
		if ~L >> i & 1:
			qc.x(i)
	return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n, L, theta) -> QuantumCircuit:
	qc = QuantumCircuit(n)
	for i in range(n):
		if ~L >> i & 1:
			qc.x(i)
	if n == 1:
		qc.p(theta, n - 1)
	else:
		qc.mcp(theta, list(range(n - 1)), n - 1)
	for i in range(n):
		if ~L >> i & 1:
			qc.x(i)
	return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    # Convert L to binary string in little-endian format
    L_bin = format(L, f'0{n}b')[::-1]

    # Create control list for multi-controlled phase gate
    controls = []
    for i in range(n):
        if L_bin[i] == '1':
            controls.append(i)
        else:
            qc.x(i)  # Apply X gate for 0 bits
            controls.append(i)

    # Apply multi-controlled phase gate
    phase_gate = MCPhaseGate(theta, len(controls))
    qc.append(phase_gate, controls)

    # Undo X gates
    for i in range(n):
        if L_bin[i] == '0':
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    # Convert L to binary string in little-endian format
    L_bin = format(L, f'0{n}b')[::-1]

    # Create control list for multi-controlled phase gate
    controls = []
    for i in range(n):
        if L_bin[i] == '1':
            controls.append(i)
        else:
            qc.x(i)  # Apply X gate for 0 bits
            controls.append(i)

    # Apply multi-controlled phase gate
    phase_gate = MCPhaseGate(theta, num_ctrl_qubits=len(controls) - 1)
    qc.append(phase_gate, controls)

    # Undo X gates
    for i in range(n):
        if L_bin[i] == '0':
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    for i in range(n):
        if (1 << i) & L:
            qc.x(i)

    if n == 1:
        qc.p(theta, 0)
    else:
        qc.mcp(theta, list(range(n - 1)), n - 1)

    for i in range(n):
        if (1 << i) & L:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    for i in range(n):
        if not (1 << i) & L:
            qc.x(i)

    if n == 1:
        qc.p(theta, n - 1)
    else:
        qc.mcp(theta, list(range(n - 1)), n - 1)

    for i in range(n):
        if not (1 << i) & L:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if (1 << i) & L == 0:
            qc.x(i)
    if n == 1:
        qc.p(theta, n - 1)
    else:
        qc.mcp(theta, list(range(n - 1)), n - 1)
    for i in range(n):
        if (1 << i) & L == 0:
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # 全部1になっている物を反転
    def reverse(qubits,qc,theta):
        if qubits>1:
            qc.append(RZGate(theta).control(qubits - 1), range(qubits))
        else:
            qc.z(0)

    # ある値をall_1に変更する操作
    def to_calcable(qubits,qc,n):
        for i in range(qubits):
            if not (n&(1<<i)):
                qc.x(i)
    to_calcable(n,qc,L)
    reverse(n,qc,theta*2)
    to_calcable(n,qc,L)

    return qc
'''


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

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

    # 全部1になっている物を反転
    def reverse(qubits,qc,theta):
        if qubits>1:
            qc.append(RZGate(theta).control(qubits - 1), range(qubits))
        else:
            qc.z(0)

    # ある値をall_1に変更する操作
    def to_calcable(qubits,qc,n):
        for i in range(qubits):
            if not (n&(1<<i)):
                qc.x(i)
    to_calcable(n,qc,L)
    reverse(n,qc,theta*2)
    to_calcable(n,qc,L)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n==0 and L==1:
        qc.rz(theta*2,0)
    else:
        raise Exception

    # # 全部1になっている物を反転
    # def reverse(qubits,qc,theta):
    #     if qubits>1:
    #         qc.append(RZGate(theta).control(qubits - 1), range(qubits))
    #     else:
    #         qc.rz(theta,0)

    # # ある値をall_1に変更する操作
    # def to_calcable(qubits,qc,n):
    #     for i in range(qubits):
    #         if not (n&(1<<i)):
    #             qc.x(i)
    # to_calcable(n,qc,L)
    # reverse(n,qc,theta*2)
    # to_calcable(n,qc,L)

    return qc
'''


'''python
def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n==1 and L==1:
        qc.rz(theta*2,0)
    else:
        raise Exception

    # # 全部1になっている物を反転
    # def reverse(qubits,qc,theta):
    #     if qubits>1:
    #         qc.append(RZGate(theta).control(qubits - 1), range(qubits))
    #     else:
    #         qc.rz(theta,0)

    # # ある値をall_1に変更する操作
    # def to_calcable(qubits,qc,n):
    #     for i in range(qubits):
    #         if not (n&(1<<i)):
    #             qc.x(i)
    # to_calcable(n,qc,L)
    # reverse(n,qc,theta*2)
    # to_calcable(n,qc,L)

    return qc
'''


'''python
def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n==1 and L==0:
        qc.x(0)
        qc.rz(theta*2,0)
        qc.x(0)
    else:
        raise Exception

    # # 全部1になっている物を反転
    # def reverse(qubits,qc,theta):
    #     if qubits>1:
    #         qc.append(RZGate(theta).control(qubits - 1), range(qubits))
    #     else:
    #         qc.rz(theta,0)

    # # ある値をall_1に変更する操作
    # def to_calcable(qubits,qc,n):
    #     for i in range(qubits):
    #         if not (n&(1<<i)):
    #             qc.x(i)
    # to_calcable(n,qc,L)
    # reverse(n,qc,theta*2)
    # to_calcable(n,qc,L)

    return qc
'''


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

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

    # # 全部1になっている物を反転
    def reverse(qubits,qc,theta):
        if qubits>1:
            qc.append(RZGate(theta).control(qubits - 1), range(qubits))
        else:
            qc.rz(theta,0)

    # # ある値をall_1に変更する操作
    def to_calcable(qubits,qc,n):
        for i in range(qubits):
            if not (n&(1<<i)):
                qc.x(i)
    to_calcable(n,qc,L)
    reverse(n,qc,-theta*2)
    to_calcable(n,qc,L)

    return qc
'''


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

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

    # # 全部1になっている物を反転
    def reverse(qubits,qc,theta):
        if qubits>1:
            qc.append(RZGate(theta).control(qubits - 1), range(qubits))
        else:
            raise Exception
            qc.rz(theta,0)

    # # ある値をall_1に変更する操作
    def to_calcable(qubits,qc,n):
        for i in range(qubits):
            if not (n&(1<<i)):
                qc.x(i)

    to_calcable(n,qc,L)
    reverse(n,qc,-theta*2)
    to_calcable(n,qc,L)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if L==0:
        qc.x(0)
        qc.rz(-theta*2,0)
        qc.x(0)
    else:
        qc.rz(-theta*2,0)

    # # 全部1になっている物を反転
    # def reverse(qubits,qc,theta):
    #     if qubits>1:
    #         qc.append(RZGate(theta).control(qubits - 1), range(qubits))
    #     else:
    #         qc.rz(theta,0)

    # # # ある値をall_1に変更する操作
    # def to_calcable(qubits,qc,n):
    #     for i in range(qubits):
    #         if not (n&(1<<i)):
    #             qc.x(i)

    # to_calcable(n,qc,L)
    # reverse(n,qc,-theta*2)
    # to_calcable(n,qc,L)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if L==0:
        qc.x(0)
        qc.rz(-theta*2,0)
        qc.x(0)
    else:
        raise Exception
        qc.rz(-theta*2,0)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if L==0 and n==1:
        qc.x(0)
        qc.rz(-theta*2,0)
        qc.x(0)
    else:
        raise Exception
        qc.rz(-theta*2,0)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if L==0 and n==1:
        qc.rz(-theta*2,0)
    else:
        raise Exception
        qc.rz(-theta*2,0)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if L==0 and n==1:
        qc.rz(-theta*2,0)
        qc.x(0)
    else:
        raise Exception
        qc.rz(-theta*2,0)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if L==0 and n==1:
        qc.x(0)
        qc.p(theta*2,0)
        qc.x(0)
    else:
        raise Exception
        qc.rz(-theta*2,0)
    return qc
'''


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

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

    # 全部1になっている物を反転
    def reverse(qubits,qc,theta):
        if qubits>1:
            qc.append(PhaseGate(theta).control(qubits - 1), range(qubits))
        else:
            qc.p(theta,0)

    # ある値をall_1に変更する操作
    def to_calcable(qubits,qc,n):
        for i in range(qubits):
            if not (n&(1<<i)):
                qc.x(i)
    to_calcable(n,qc,L)
    reverse(n,qc,theta)
    to_calcable(n,qc,L)

    return qc
'''


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

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

    # 全部1になっている物を反転
    def reverse(qubits,qc,theta):
        if qubits>1:
            qc.append(PhaseGate(theta).control(qubits - 1), range(qubits))
        else:
            qc.p(theta,0)

    # ある値をall_1に変更する操作
    def to_calcable(qubits,qc,n):
        for i in range(qubits):
            if not (n&(1<<i)):
                qc.x(i)
    to_calcable(n,qc,L)
    reverse(n,qc,theta)
    to_calcable(n,qc,L)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    #qc.x(0)
    mcphase_gate = MCPhaseGate(theta, num_ctrl_qubits=n-1)
    # Write your code here:
    for i in range(n):
        if (L>>i) & 1 == 0:
            qc.x(i)
    qc.append(mcphase_gate, range(0,n))
    for i in range(n):
        if (L>>i) & 1 == 0:
            qc.x(i)

    return qc

qc = solve(4,1,np.pi/4.0)
print(qc)
#print(Statevector(qc)) #こことimportを消す
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    #qc.x(0)
    if n==1:
        if L == 0:
            qc.x(0)
            qc.p(theta,0)
            qc.x(0)
        else:
            qc.p(theta,0)
        return
    mcphase_gate = MCPhaseGate(theta, num_ctrl_qubits=n-1)
    # Write your code here:
    for i in range(n):
        if (L>>i) & 1 == 0:
            qc.x(i)
    qc.append(mcphase_gate, range(0,n))
    for i in range(n):
        if (L>>i) & 1 == 0:
            qc.x(i)

    return qc

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


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    #qc.x(0)
    if n==1:
        if L == 0:
            qc.x(0)
            qc.p(theta,0)
            qc.x(0)
        else:
            qc.p(theta,0)
        return qc
    mcphase_gate = MCPhaseGate(theta, num_ctrl_qubits=n-1)
    # Write your code here:
    for i in range(n):
        if (L>>i) & 1 == 0:
            qc.x(i)
    qc.append(mcphase_gate, range(0,n))
    for i in range(n):
        if (L>>i) & 1 == 0:
            qc.x(i)

    return qc

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


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        # check if i-th bit of l is 0 or 1
        if not ((L >> i) & 1):
            qc.x(i)
    if n == 1:
        qc.p(theta, 0)
    else:
        # apply  gate
        qc.mcp(theta, list(range(n-1)), n-1)
    for i in range(n):
        if not ((L >> i) & 1):
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        # check if i-th bit of l is 0 or 1
        if not ((L >> i) & 1):
            qc.x(n-1-i)
    if n == 1:
        qc.p(theta, 0)
    else:
        # apply  gate
        qc.mcp(theta, list(range(n-1)), n-1)
    for i in range(n):
        if not ((L >> i) & 1):
            qc.x(n-1-i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        # check if i-th bit of l is 0 or 1
        if not ((L >> i) & 1):
            qc.x(n-1-i)
    if n == 1:
        qc.p(theta, 0)
    else:
        # apply  gate
        qc.mcp(theta, list(range(n-1)), n-1)
    for i in range(n):
        if not ((L >> i) & 1):
            qc.x(n-1-i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.reverse_bits()

    for i in range(n):
        # check if i-th bit of l is 0 or 1
        if not ((L >> i) & 1):
            qc.x(i)
    if n == 1:
        qc.p(theta, 0)
    else:
        # apply  gate
        qc.mcp(theta, list(range(n-1)), n-1)
    for i in range(n):
        if not ((L >> i) & 1):
            qc.x(i)

    qc.reverse_bits()
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.x(L)
    qc.rz(2*theta, L)
    qc.x(L)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if not (L >> i) & 1:
            qc.x(i)

    if n == 1:
        qc.p(theta, 0)
    else:
        qc.mcp(theta, list(range(n - 1)), n - 1)
    for i in range(n):
        if not (L >> i) & 1:
            qc.x(i)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if not (L>>i & 1):
            qc.x(i)

    if n==1:
        qc.append(U1Gate(theta), range(1))
    else:
        qc.append(U1Gate(theta).control(n-1), range(n))

    for i in range(n):
        if not (L>>i & 1):
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    x = []
    a = L
    i=n-1
    while a:
        if a%2:
            x.append(i)
        a//=2
        i-=1
    x=x[::-1]
    qc.h(-1)
    qc.mcrx(theta*2,x[:-1],x[-1])
    qc.h(-1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    qc.mcp(theta,[i for i in range(n-1)],n-1)

    L_bin=format(L, '0'+str(n)+'b')
    for i, l in enumerate(L_bin):
        if l=='0':
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    qc.mcp(theta,[i for i in range(n-1)],n-1)

    L_bin=format(L, '0'+str(n)+'b')
    L_bin=L_bin[::-1]
    for i, l in enumerate(L_bin):
        if l=='0':
            qc.x(i)

    return qc
'''


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

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

    bits = []

    i = 0
    while L:
        if L & 1 == 0:
            bits.append(i)
        i += 1
        L >>= 1

    zero = QuantumRegister(1)
    qc.add_bits(zero)

    for idx in bits:
        qc.x(idx)
    qc.append(RZGate(-theta*2).control(n), range(n + 1))
    for idx in bits:
        qc.x(idx)

    return qc
'''


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

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

    bits = []

    for i in range(n):
        if L & (1 << i) == 0:
            bits.append(i)
        i += 1

    zero = QuantumRegister(1)
    qc.add_bits(zero)

    for idx in bits:
        qc.x(idx)
    qc.append(RZGate(-theta*2).control(n), range(n + 1))
    for idx in bits:
        qc.x(idx)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(1)
    # Apply the Rz gate to the qubit
    qc.rz(theta, 0)  # Apply Rz gate with angle theta to qubit 0
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    # Convert L to binary and apply the phase shift
    # L is in little-endian format, so we need to apply the phase to the qubits in reverse order
    binary_representation = format(L, '0' + str(n) + 'b')  # Get binary representation of L with n bits

    # Apply the phase shift only if the state corresponds to L
    # The qubits are in little-endian order, so we need to apply the phase to the qubits in reverse order
    for i in range(n):
        if binary_representation[i] == '1':
            qc.x(i)  # Flip the qubit to |1> if the corresponding bit is 1

    # Apply the phase shift
    qc.rz(theta, 0)  # Apply the phase to the first qubit (which corresponds to |L>)

    # Uncompute the qubits to return to the original state
    for i in range(n):
        if binary_representation[i] == '1':
            qc.x(i)  # Flip back to |0> if it was flipped to |1>

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

"""
You can apply oracle as follows:
qc.compose(o, inplace=True)
"""

def solve(n: int, o: QuantumCircuit) -> QuantumCircuit:
    x, y = QuantumRegister(n), QuantumRegister(1)
    qc = QuantumCircuit(x, y)
    # Write your code here:

    qc.compose(o, inplace=True)
    qc.z(n)
    qc.x(n, n)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    log=[]
    for j,x in enumerate(f"{L:0{n}b}"[::-1]):
        if x=="0":
            log.append(j)
            qc.x(j)

    if n!=1:
        qc.append(PhaseGate(theta).control(n-1), range(n))
        qc.global_phase = theta
    else:
        qc.z(0)
        qc.global_phase = theta

    for j in log:
        qc.x(j)

    return qc
'''


'''python
# B2
from qiskit import QuantumCircuit
from qiskit.circuit.library import PhaseGate

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    log=[]
    for j,x in enumerate(f"{L:0{n}b}"[::-1]):
        if x=="0":
            log.append(j)
            qc.x(j)

    if n!=1:
        qc.append(PhaseGate(theta).control(n-1), range(n))
        qc.global_phase = theta
    else:
        qc.p(0)
        qc.global_phase = theta

    for j in log:
        qc.x(j)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)

    log=[]
    for j,x in enumerate(f"{L:0{n}b}"[::-1]):
        if x=="0":
            log.append(j)
            qc.x(j)

    if n!=1:
        qc.append(PhaseGate(theta).control(n-1), range(n))
        qc.global_phase = theta
    else:
        qc.p(theta,0)
        qc.global_phase = theta

    for j in log:
        qc.x(j)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.x(i)
    for i in range(n):
        if (L >> i & 1):
            qc.p(theta, i)
    for i in range(n):
        qc.x(i)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for l in range(L):
        for i in range(n):
            # check if i-th bit of l is 0 or 1
            if not ((l >> i) & 1):
                qc.x(i)
    if n == 1:
        qc.p(theta)
    else:
        qc.append(qlib.PhaseGate(theta).control(n - 1), range(n))
    for l in range(L):
        for i in range(n):
            # check if i-th bit of l is 0 or 1
            if not ((l >> i) & 1):
                qc.x(i)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for l in range(L):
        for i in range(n):
            # check if i-th bit of l is 0 or 1
            if not ((l >> i) & 1):
                qc.x(i)
    if n == 1:
        qc.p(theta, 0)
    else:
        qc.append(qlib.PhaseGate(theta).control(n - 1), range(n))
    for l in range(L):
        for i in range(n):
            # check if i-th bit of l is 0 or 1
            if not ((l >> i) & 1):
                qc.x(i)
    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        # check if i-th bit of l is 0 or 1
        if not ((L >> i) & 1):
            qc.x(i)
    if n == 1:
        qc.p(theta, 0)
    else:
        qc.append(qlib.PhaseGate(theta).control(n - 1), range(n))
    for i in range(n):
        # check if i-th bit of l is 0 or 1
        if not ((L >> i) & 1):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if ((L >> i) & 1) == 0:
            qc.x(i)
        qc.rz(-2 * theta, i)
        if ((L >> i) & 1) == 0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if ((L >> i) & 1) == 1:
            qc.x(i)
        qc.rz(-2 * theta, i)
        if ((L >> i) & 1) == 1:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # qc.x([0, 2])
    # Write your code here:
    for i in range(n):
        if ((L >> i) & 1) == 0:
            qc.x(i)

    mp = PhaseGate(theta).control(n - 1)
    qc.append(mp, range(n))

    for i in range(n):
        if ((L >> i) & 1) == 0:
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # qc.x([0, 2])
    # Write your code here:
    for i in range(n):
        if ((L >> i) & 1) == 0:
            qc.x(i)

    mp = PhaseGate(theta).control(n - 1)
    qc.append(mp, range(n))

    for i in range(n):
        if ((L >> i) & 1) == 0:
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # qc.x([0, 2])
    # Write your code here:
    for i in range(n):
        if ((L >> i) & 1) == 0:
            qc.x(i)

    if n == 1:
        qc.p(theta, 0)
    else:
        mp = PhaseGate(theta).control(n - 1)
        qc.append(mp, range(n))

    for i in range(n):
        if ((L >> i) & 1) == 0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(0, n):
        if (L >> i) & 1 == 1:
            qc.x(i)

    qc.x(0)
    qc.p(theta, 0)
    qc.x(0)

    for i in range(0, n):
        if (L >> i) & 1 == 1:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    for i in range(0, n):
        if (L >> i) & 1 == 1:
            qc.x(i)

    qc.x(0)
    qc.p(theta, 0)
    qc.x(0)

    for i in range(0, n):
        if (L >> i) & 1 == 1:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    if n == 1:
        qc.p(theta, 0)
    else:
        qc.mcp(theta, list(range(1, n)), 0)

    for i in range(0, n):
        if (L >> i) & 1 == 0:
            qc.x(i)

    return qc
'''


'''python
def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:

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

    for i in range(0, n):
        if (L >> i) & 1 == 0:
            qc.x(i)

    if n == 1:
        qc.p(theta, 0)
    else:
        qc.mcp(theta, list(range(1, n)), 0)

    for i in range(0, n):
        if (L >> i) & 1 == 0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    for i in range(0, n):
        if (L >> i) & 1 == 0:
            qc.x(i)

    if n == 1:
        qc.p(theta, 0)
    elif n == 2:
        qc.cp(theta, 1, 0)
    else:
        qc.mcp(theta, list(range(1, n)), 0)

    for i in range(0, n):
        if (L >> i) & 1 == 0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library.standard_gates import PGate

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    bin_L = bin(L)
    bin_L.zfill(n) # big endian
    bin_L = bin_L[::-1] # little endian

    one_list = []
    zero_list= []
    for i in range(n):
        if bin_L[i] == '1':
            one_list.append(i)
        else:
            zero_list.append(i)

    for i in range(n-1):
        if i in zero_list:
            qc.x(i)
    # ctl_len = len(one_list)-1 if n-1 in one_list else len(one_list)
    # if bin_L[n-1]=='0':
    #     pass
    # else:
    #     qc.
    qc.append(PGate(theta).control(n-1), range(n))

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

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
# from qiskit.circuit.library.standard_gates import PGate

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    bin_L = bin(L)
    bin_L.zfill(n) # big endian
    bin_L = bin_L[::-1] # little endian
    for i in range(n):
        qc.h(i)

    one_list = []
    zero_list= []
    for i in range(n):
        if bin_L[i] == '1':
            one_list.append(i)
        else:
            zero_list.append(i)

    for i in range(n-1):
        if i in zero_list:
            qc.x(i)
    # ctl_len = len(one_list)-1 if n-1 in one_list else len(one_list)
    # if bin_L[n-1]=='0':
    #     pass
    # else:
    #     qc.
    # qc.append(PGate(theta).control(n-1), range(n))
    if n-1 in one_list:
        qc.x(n-1)

    qc.mcx(list(range(n-1)), n-1)
    qc.p(theta, n-1)
    qc.mcx(list(range(n-1)), n-1)

    if n-1 in one_list:
        qc.(n-1)

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

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
# from qiskit.circuit.library.standard_gates import PGate

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    bin_L = bin(L)
    bin_L.zfill(n) # big endian
    bin_L = bin_L[::-1] # little endian
    for i in range(n):
        qc.h(i)

    one_list = []
    zero_list= []
    for i in range(n):
        if bin_L[i] == '1':
            one_list.append(i)
        else:
            zero_list.append(i)

    if n==1:
        if bin_L=='0':
            qc.x(0)
        qc.p(theta, 0)
        if bin_L=='0':
            qc.x(0)
        return qc

    for i in range(n-1):
        if i in zero_list:
            qc.x(i)
    # ctl_len = len(one_list)-1 if n-1 in one_list else len(one_list)
    # if bin_L[n-1]=='0':
    #     pass
    # else:
    #     qc.
    # qc.append(PGate(theta).control(n-1), range(n))
    if n-1 in one_list:
        qc.x(n-1)

    qc.mcx(list(range(n-1)), n-1)
    qc.p(theta, n-1)
    qc.mcx(list(range(n-1)), n-1)

    if n- in one_list:
        qc.(n-1)

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

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
# from qiskit.circuit.library.standard_gates import PGate

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    bin_L = bin(L)
    bin_L.zfill(n) # big endian
    bin_L = bin_L[::-1] # little endian
    for i in range(n):
        qc.h(i)

    one_list = []
    zero_list= []
    for i in range(n):
        if bin_L[i] == '1':
            one_list.append(i)
        else:
            zero_list.append(i)

    if n==1:
        if bin_L=='0':
            qc.x(0)
        qc.p(theta, 0)
        if bin_L=='0':
            qc.x(0)
        return qc

    for i in range(n-1):
        if i in zero_list:
            qc.x(i)
    # ctl_len = len(one_list)-1 if n-1 in one_list else len(one_list)
    # if bin_L[n-1]=='0':
    #     pass
    # else:
    #     qc.
    # qc.append(PGate(theta).control(n-1), range(n))
    if n-1 in one_list:
        qc.x(n-1)

    qc.mcx(list(range(n-1)), n-1)
    qc.p(theta, n-1)
    qc.mcx(list(range(n-1)), n-1)

    if n-1 in one_list:
        qc.x(n-1)

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

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
# from qiskit.circuit.library.standard_gates import PGate

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    bin_L = bin(L)
    bin_L = bin_L[2:]
    bin_L = bin_L.zfill(n) # big endian
    bin_L = bin_L[::-1] # little endian
    print(bin_L)
    for i in range(n):
        qc.h(i)

    one_list = []
    zero_list= []
    for i in range(n):
        if bin_L[i] == '1':
            one_list.append(i)
        else:
            zero_list.append(i)

    if n==1:
        if bin_L=='0':
            qc.x(0)
        qc.p(theta, 0)
        if bin_L=='0':
            qc.x(0)
        return qc

    for i in range(n-1):
        if i in zero_list:
            qc.x(i)
    # ctl_len = len(one_list)-1 if n-1 in one_list else len(one_list)
    # if bin_L[n-1]=='0':
    #     pass
    # else:
    #     qc.
    # qc.append(PGate(theta).control(n-1), range(n))
    if n-1 in one_list:
        qc.x(n-1)

    qc.mcx(list(range(n-1)), n-1)
    qc.p(theta, n-1)
    qc.mcx(list(range(n-1)), n-1)

    if n-1 in one_list:
        qc.x(n-1)

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

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
# from qiskit.circuit.library.standard_gates import PGate

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    bin_L = bin(L)
    bin_L = bin_L[2:]
    bin_L = bin_L.zfill(n) # big endian
    bin_L = bin_L[::-1] # little endian
    print(bin_L)
    for i in range(n):
        qc.h(i)

    one_list = []
    zero_list= []
    for i in range(n):
        if bin_L[i] == '1':
            one_list.append(i)
        else:
            zero_list.append(i)

    if n==1:
        if bin_L=='0':
            qc.x(0)
        qc.p(theta, 0)
        if bin_L=='0':
            qc.x(0)
        return qc

    for i in range(n-1):
        if i in zero_list:
            qc.x(i)
    # ctl_len = len(one_list)-1 if n-1 in one_list else len(one_list)
    # if bin_L[n-1]=='0':
    #     pass
    # else:
    #     qc.
    # qc.append(PGate(theta).control(n-1), range(n))
    if n-1 in zero_list:
        qc.x(n-1)

    qc.mcp(list(range(n-1)), n-1)
    # qc.mcx(list(range(n-1)), n-1)
    # qc.p(theta, n-1)
    # qc.mcx(list(range(n-1)), n-1)

    if n-1 in zero_list:
        qc.x(n-1)

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

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
# from qiskit.circuit.library.standard_gates import PGate

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    bin_L = bin(L)
    bin_L = bin_L[2:]
    bin_L = bin_L.zfill(n) # big endian
    bin_L = bin_L[::-1] # little endian
    print(bin_L)
    for i in range(n):
        qc.h(i)

    one_list = []
    zero_list= []
    for i in range(n):
        if bin_L[i] == '1':
            one_list.append(i)
        else:
            zero_list.append(i)

    if n==1:
        if bin_L=='0':
            qc.x(0)
        qc.p(theta, 0)
        if bin_L=='0':
            qc.x(0)
        return qc

    for i in range(n-1):
        if i in zero_list:
            qc.x(i)
    # ctl_len = len(one_list)-1 if n-1 in one_list else len(one_list)
    # if bin_L[n-1]=='0':
    #     pass
    # else:
    #     qc.
    # qc.append(PGate(theta).control(n-1), range(n))
    if n-1 in zero_list:
        qc.x(n-1)

    qc.mcp(theta, list(range(n-1)), n-1)
    # qc.mcx(list(range(n-1)), n-1)
    # qc.p(theta, n-1)
    # qc.mcx(list(range(n-1)), n-1)

    if n-1 in zero_list:
        qc.x(n-1)

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

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit
# from qiskit.circuit.library.standard_gates import PGate

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    bin_L = bin(L)
    bin_L = bin_L[2:]
    bin_L = bin_L.zfill(n) # big endian
    bin_L = bin_L[::-1] # little endian
    # print(bin_L)
    for i in range(n):
        qc.h(i)

    one_list = []
    zero_list= []
    for i in range(n):
        if bin_L[i] == '1':
            one_list.append(i)
        else:
            zero_list.append(i)

    if n==1:
        if bin_L=='0':
            qc.x(0)
        qc.p(theta, 0)
        if bin_L=='0':
            qc.x(0)
        return qc

    for i in range(n-1):
        if i in zero_list:
            qc.x(i)
    # ctl_len = len(one_list)-1 if n-1 in one_list else len(one_list)
    # if bin_L[n-1]=='0':
    #     pass
    # else:
    #     qc.
    # qc.append(PGate(theta).control(n-1), range(n))
    if n-1 in zero_list:
        qc.x(n-1)

    qc.mcp(theta,list(range(n-1)), n-1)
    # qc.mcx(list(range(n-1)), n-1)
    # qc.p(theta, n-1)
    # qc.mcx(list(range(n-1)), n-1)

    if n-1 in zero_list:
        qc.x(n-1)

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

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.mcp(theta, [ i for i in range(n) ], 0, L)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    ctrl_state = format(L, f'0{n}b')[::-1]

    if n > 1:
        for i in range(n):
            if ctrl_state[i]=='0':
                qc.x(i)

        #Apply MCT phase gate
        qc.mcp(theta, [i for i in range(1,n)],0)

        #Revert X gates
        for i in range(n):
            if ctrl_state[i]=='0':
                qc.x(i)
    else:
        #For single qubit case
        if L==0:
            qc.x(0)
        qc.p(theta,0)
        if L==0:
            qc.x(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    binary = format(L, f'0{n}b')[::-1]
    t_qubit = 0
    c_qubits = list(range(1, n))

    for i in range(n):
      if binary[i] == '0':
        qc.x(i)
    qc.mcp(theta, c_qubits, t_qubit)
    for i in range(n):
      if binary[i] == '0':
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    binary = format(L, f'0{n}b')[::-1]
    t_qubit = 0
    c_qubits = list(range(1, n))

    if n == 1:
      if binary == '0':
        qc.x(0)
        qc.p(theta, 0)
        qc.x(0)
      else:
        qc.p(theta, 0)
    else:
      for i in range(n):
        if binary[i] == '0':
          qc.x(i)
      qc.mcp(theta, c_qubits, t_qubit)
      for i in range(n):
        if binary[i] == '0':
          qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    b=[0]*n
    for i in range(n):
        b[i]=L%2
        L//=2
    for i in range(n):
        if b[i]==0:
            qc.x(i)
    qc.mcp(theta, list(range(n-1)), n-1)
    for i in reversed(range(n)):
        if b[i]==0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    b=[0]*n
    for i in range(n):
        b[i]=L%2
        L//=2
    for i in range(n):
        if b[i]==0:
            qc.x(i)
    if n>1:
        qc.mcp(theta, list(range(n-1)), n-1)
    else:
        qc.p(theta, 0)
    for i in reversed(range(n)):
        if b[i]==0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
    if not (1<<i) & L:
        qc.x(i)
    if n == 1:
        qc.p(theta, n-1)
    else:
        qc.mcp(theta, list(range(n - 1)), n - 1)
    for i in range(n):

        if not(1<<i) & L:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        if not (1<<i) & L:
            qc.x(i)
    if n == 1:
        qc.p(theta, n-1)
    else:
        qc.mcp(theta, list(range(n - 1)), n - 1)
    for i in range(n):

        if not(1<<i) & L:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # Convert L to binary and pad with zeros to match n qubits
    L_binary = bin(L)[2:].zfill(n)

    # Apply phase shift RZ(theta) to the target state
    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)

    # Apply the phase gate to the |L> state
    qc.rz(theta, range(n))

    # Apply the inverse of the previous X gates to return to the original basis
    for i, bit in enumerate(L_binary):
        if bit == '1':
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # Apply a phase shift of θ to the state |L⟩
    for i in range(n):
        if (L >> i) & 1:
            qc.u1(theta, n - 1 - i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    L_bits = [int(b) for b in format(L, f'0{n}b')][::-1]

    for i, bit in enumerate(L_bits):
        if bit == 0:
            qc.x(qr[i])

    qc.mcphase(theta, qr[:-1], qr[-1])

    for i, bit in enumerate(L_bits):
        if bit == 0:
            qc.x(qr[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    L_bits = [int(b) for b in format(L, f'0{n}b')][::-1]

    for i, bit in enumerate(L_bits):
        if bit == 0:
            qc.x(i)

    if n > 1:
        control_qubits = list(range(n-1))
        target_qubit = n-1
        qc.mcphase(theta, control_qubits, target_qubit)
    else:
        qc.p(theta, 0)

    for i, bit in enumerate(L_bits):
        if bit == 0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    L_bits = [int(b) for b in format(L, f'0{n}b')][::-1]

    for i, bit in enumerate(L_bits):
        if bit == 0:
            qc.x(i)

    if n > 1:
        control_qubits = list(range(n-1))
        target_qubit = n-1
        qc.mcp(theta, control_qubits, target_qubit)
    else:
        qc.p(theta, 0)

    for i, bit in enumerate(L_bits):
        if bit == 0:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(0)
    qc.rz(2*theta,0)
    qc.x(0)
    for i in range(n):
        if (L >> i & 1) == 1:
            qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(n):
        if not(L&(1<<i)):
            qc.x(i)
    qc.mcp(theta, list(range(0,n-1)), n-1)
    for i in range(n):
        if not(L&(1<<i)):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n==1:
        if l==0:
            qc.x(0)
            qc.p(theta,0)
            qc.x(0)
        else:
            qc.p(theta,0)
        return qc
    for i in range(n)
        if not(L&(1<<i)):
            qc.x(i)
    qc.mcp(theta, list(range(0,n-1)), n-1)
    for i in range(n):
        if not(L&(1<<i)):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n==1:
        if L==0:
            qc.x(0)
            qc.p(theta,0)
            qc.x(0)
        else:
            qc.p(theta,0)
        return qc
    for i in range(n)
        if not(L&(1<<i)):
            qc.x(i)
    qc.mcp(theta, list(range(0,n-1)), n-1)
    for i in range(n):
        if not(L&(1<<i)):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int, theta: float) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n==1:
        if L==0:
            qc.x(0)
            qc.p(theta,0)
            qc.x(0)
        else:
            qc.p(theta,0)
        return qc
    for i in range(n):
        if not(L&(1<<i)):
            qc.x(i)
    qc.mcp(theta, list(range(0,n-1)), n-1)
    for i in range(n):
        if not(L&(1<<i)):
            qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(1,0)
    qc.cx(0,1)
    qc.cx(1,0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0, 1)
    qc.cx(1, 0)
    qc.cx(0, 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    qc.cx(0, 1)
    qc.cx(1, 0)
    qc.cx(0, 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0,1)
    qc.x(1)
    qc.x(2)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0,1)
    qc.x(1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

  theta = math.pi/2
  qc.rzz(theta, 0, 1)
  qc.ryy(theta, 0, 1)
  qc.rxx(theta, 0, 1)

  #qc.global_phase = theta / 2

  return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

  theta = math.pi/2
  qc.rzz(theta, 0, 1)
  qc.ryy(theta, 0, 1)
  qc.rxx(theta, 0, 1)

  #qc.global_phase = theta / 2

  return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)
    qc.h(1)
    qc.z(1)
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    qc.cx(0, 1)
    qc.cx(1, 0)
    qc.cx(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    qc.cx(0, 1)  # CNOT gate with qubit 0 as control and qubit 1 as target
    qc.cx(1, 0)  # CNOT gate with qubit 1 as control and qubit 0 as target
    qc.cx(0, 1)
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.h(1)

    qc.swap(0,1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.h(1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.h(0)
    qc.h(1)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    qc.cx(1, 0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    qc.cx(1, 0)
    qc.cx(0, 1)
    qc.cx(1, 0)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.swap(0, 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0, 1)
    qc.cx(1, 0)
    qc.cx(0, 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.x(0)  # Flip the first qubit to |1>
    qc.h(1)
    qc.cx(0, 1)  # First CNOT: qubit 0 -> qubit 1
    qc.cx(1, 0)  # Second CNOT: qubit 1 -> qubit 0
    qc.cx(0, 1)  # Third CNOT: qubit 0 -> qubit 1
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Step 1: Apply CNOT from qubit 0 to qubit 1
    qc.cx(0, 1)

    # Step 2: Apply CNOT from qubit 1 to qubit 0
    qc.cx(1, 0)

    # Step 3: Apply CNOT from qubit 0 to qubit 1 again
    qc.cx(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Implement SWAP using 3 CNOT gates
    qc.cx(0, 1)
    qc.cx(1, 0)
    qc.cx(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(1,0)
    qc.cx(0,1)
    qc.cx(1,0)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.quantum_info.operators import Operator

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

    swap = Operator([
        [1, 0, 0, 0],
        [0, 0, 1, 0],
        [0, 1, 0, 0],
        [0, 0, 0, 1]
    ])
    qc.unitary(cswap, [0, 1], label='swap')

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.quantum_info.operators import Operator

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

    sw = Operator([
        [1, 0, 0, 0],
        [0, 0, 1, 0],
        [0, 1, 0, 0],
        [0, 0, 0, 1]
    ])
    qc.unitary(sw, [0, 1], label='sw')

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.quantum_info.operators import Operator

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.quantum_info.operators import Operator

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.reverse_bits()
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(1)
    qc.x(1,0)
    qc.x(1)
    # 2 0 1

    qc.x(0)
    qc.cx(0,1)
    qc.x(0)
    # 0 2 1

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.x(1)
    qc.cx(1,0)
    qc.x(1)
    # 2 0 1

    qc.x(0)
    qc.cx(0,1)
    qc.x(0)
    # 0 2

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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


'''python
from qiskit import QuantumCircuit, AncillaRegister

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    ancilla = AncillaRegister(1)
    qc.add_register(ancilla)
    qc.cx(0, 2)
    qc.cx(1, 2)

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


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    ancilla = QuantumRegister(1)
    qc.add_register(ancilla)
    qc.cx(0, 2)
    qc.cx(1, 2)

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


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    ancilla = QuantumRegisterr(1)
    qc.add_register(ancilla)
    qc.cx(0, 2)
    qc.cx(1, 2)

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

    qc.qregs = qc.qregs[0]
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(1,2)
    qc.cx(2,1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.swap(0,1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # Apply the sequence of CNOT gates to swap the qubit states
    qc.cx(0, 1)  # First CNOT: control qubit 0, target qubit 1
    qc.cx(1, 0)  # Second CNOT: control qubit 1, target qubit 0
    qc.cx(0, 1)  # Third CNOT: control qubit 0, target qubit 1

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.x(1)
    qc.cx(1)
    qc.x(1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(0, 1)
    qc.cx(1, 0)
    qc.cx(0, 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    qc.cx(1, 0)
    qc.cx(0, 1)
    qc.cx(1, 0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


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

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    qc.cx(0, 1)
    qc.cx(1, 0)
    qc.cx(0, 1)
    return qc

# if __name__ == "__main__":
#     from qiskit.quantum_info import Statevector
#     import numpy as np
#     qc = solve(2, 1, math.pi / 2)
#     # sv = Statevector(qc)
#     # print(sv)
#     print(qc)
#     print(f"{qc.depth() = }")
#     sv = Statevector.from_label('++')
#     print(sv.evolve(qc))
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.cx(qubit1, qubit2)
    qc.cx(qubit2, qubit1)
    qc.cx(qubit1, qubit2)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    #a1 a3 swap
    qc.cx(0,1)
    #a1 a2 swap
    qc.cx(1,0)
    #a2 a3 swap
    qc.cx(0,1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(range(2))
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    # qc.h(range(2))
    qc.cx(0,1)
    qc.cx(1,0)
    qc.cx(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    qc.cx(0, 1)
    qc.cx(1, 0)
    qc.cx(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.swap(0, 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    qc.cx(0, 1)
    qc.cx(1, 0)
    qc.cx(0, 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)
    qc.h(1)
    qc.swap(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)
    qc.h(1)
    qc.s(0,1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve() -> QuantumCircuit:
    qc = QuantumCircuit(2)
    # Write your code here:
    qc.h(0)
    qc.h(1)
    # qc.s(0,1)
    # temp = qc(0)
    qc.cx(0,1)
    qc.cx(0,1)
    qc.cx(0,1)
    return qc
'''