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

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

        qc.append(ZGate().control(n - 1), range(n))

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

    return qc
'''


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

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

        qc.append(ZGate().control(n - 1), range(n))

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

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n == 1:
        if L <= 1:
            qc.x(0)
            qc.z(0)
            qc.x(0)
        if L <= 2:
            qc.z(0)

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

        qc.append(ZGate().control(n - 1), range(n))

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

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n == 1:
        if L <= 1:
            qc.x(0)
            qc.z(0)
            qc.x(0)
        if L <= 2:
            qc.z(0)
        return qc

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

        qc.append(ZGate().control(n - 1), range(n))

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

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n == 1:
        if L >= 1:
            qc.x(0)
            qc.z(0)
            qc.x(0)
        if L >= 2:
            qc.z(0)
        return qc

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

        qc.append(ZGate().control(n - 1), range(n))

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    from qiskit.circuit.library import ZGate

    for  i in range(L):
        for j in range(n):
            if(not ((i>>j)&1)):
                qc.x(j)
        qc.append(ZGate().control(n-1),range(n))
        for i in range(n):
            if not ((j >> i) & 1):
                qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    from qiskit.circuit.library import ZGate

    for  i in range(L):
        for j in range(n):
            if(not ((i>>j)&1)):
                qc.x(j)
        qc.append(ZGate().control(n-1),range(n))
        for i in range(n):
            if not ((j >> i) & 1):
                qc.x(j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    from qiskit.circuit.library import ZGate

    for  i in range(L):
        for j in range(n):
            if(not ((i>>j)&1)):
                qc.x(j)
        if(n==1):
            qc.z(0)
        else:
            qc.append(ZGate().control(n-1),range(n))
        for i in range(n):
            if not ((j >> i) & 1):
                qc.x(j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    from qiskit.circuit.library import ZGate

    for  i in range(L):
        for j in range(n):
            if(not ((i>>j)&1)):
                qc.x(j)
        if(n==1):
            qc.z(0)
        else:
            qc.append(ZGate().control(n-1),range(n))
        for i in range(n):
            if not ((i >> j) & 1):
                qc.x(j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    from qiskit.circuit.library import ZGate

    for  i in range(L):
        for j in range(n):
            if(not ((i>>j)&1)):
                qc.x(j)
        if(n==1):
            qc.z(0)
        else:
            qc.append(ZGate().control(n-1),range(n))
        for j in range(n):
            if not ((i >> j) & 1):
                qc.x(j)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(n-1)
    for i in range(L):
        cs=str(format(i, '0'+str(n-1)+'b'))[0:n-1]
        if i<2**(n-1):
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
        else:
            print(i, cs)
            qc.x(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.x(n-1)
    qc.h(n-1)

    return qc
'''


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

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

    qc.h(n-1)
    for i in range(L):
        cs=str(format(i, '0'+str(n-1)+'b'))[0:n-1]
        if i<2**(n-1):
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
        else:
            print(i, cs)
            qc.x(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.x(n-1)
    qc.h(n-1)

    return qc
'''


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

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

    qc.h(n-1)
    for i in range(L):
        cs=str(format(i, '0'+str(n-1)+'b'))[0:n-1]
        if i<2**(n-1):
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
        else:
            qc.x(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.x(n-1)
    qc.h(n-1)

    return qc
'''


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

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

    qc.h(n-1)
    for i in range(L):
        cs=str(format(i, '0'+str(n-1)+'b'))[-(n-1):]
        if i<2**(n-1):
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
        else:
            qc.x(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.x(n-1)
    qc.h(n-1)

    return qc
'''


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

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

    qc.h(n-1)
    for i in range(L):
        cs=str(format(i, '0'+str(n-1)+'b'))[-(n-1):]
        if i<2**(n-1):
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
        else:
            qc.x(n-1)
            qc.h(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.h(n-1)
            qc.x(n-1)
    qc.h(n-1)

    return qc
'''


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

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

    for i in range(L):
        cs=str(format(i, '0'+str(n-1)+'b'))[-(n-1):]
        if i<2**(n-1):
            qc.h(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.h(n-1)
        else:
            qc.x(n-1)
            qc.h(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.h(n-1)
            qc.x(n-1)

    return qc
'''


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

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

    for i in range(L):
        cs=str(format(i, '0'+str(n-1)+'b'))[-(n-1):]
        if i<2**(n-1):
            qc.x(n-1)
            qc.h(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.h(n-1)
            qc.x(n-1)
        else:
            qc.h(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.h(n-1)

    return qc
'''


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

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

    if n==1:
        if L=1:
            qc.x(0)
            qc.z(0)
            qc.x(0)
        else:
            qc.z(0)
        return qc

    for i in range(L):
        cs=str(format(i, '0'+str(n-1)+'b'))[-(n-1):]
        if i<2**(n-1):
            qc.x(n-1)
            qc.h(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.h(n-1)
            qc.x(n-1)
        else:
            qc.h(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.h(n-1)

    return qc
'''


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

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

    if n==1:
        qc.x(0)
        qc.z(0)
        qc.x(0)
        if L==2:
            qc.z(0)
        return qc

    for i in range(L):
        cs=str(format(i, '0'+str(n-1)+'b'))[-(n-1):]
        if i<2**(n-1):
            qc.x(n-1)
            qc.h(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.h(n-1)
            qc.x(n-1)
        else:
            qc.h(n-1)
            qc.append(MCXGate(n-1, ctrl_state=cs), range(n))
            qc.h(n-1)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for l in range(L):
        for i in range(n):
            if (l >> i) & 1 == 0:
                qc.x(i)
        if n == 1:
            qc.z(0)
        else:
            qc.append(ZGate().control(n - 1), range(n))
        for i in range(n):
            if (l >> i) & 1 == 0:
                qc.x(i)
        qc.barrier()

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for l in range(L):
        for i in range(n):
            if (l >> i) & 1 == 0:
                qc.x(i)
        if n == 1:
            qc.z(0)
        else:
            qc.append(ZGate().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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if (L>>(n-1))%2==0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)
    for i in range(n-2,-1,-1):
        if (L>>i)%2==0:
            qc.x(i)
        else:
            qc.x(i)
            qc.mcp(math.pi, range(i+1,n), i)
            qc.x(i)
    for i in range(n):
        if (L>>i)%2==0:
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if (L>>(n-1))%2==0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)
    for i in range(n-2,-1,-1):
        if (L>>i)%2==0:
            qc.x(i)
        else:
            qc.x(i)
            %qc.mcp(math.pi, range(i+1,n), i)
            qc.x(i)
    for i in range(n):
        if (L>>i)%2==0:
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if (L>>(n-1))%2==0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)
    for i in range(n-2,-1,-1):
        if (L>>i)%2==0:
            qc.x(i)
        else:
            qc.x(i)
            #qc.mcp(math.pi, range(i+1,n), i)
            qc.x(i)
    for i in range(n):
        if (L>>i)%2==0:
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if (L>>(n-1))%2==0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)
    for i in range(n-2,-1,-1):
        if (L>>i)%2==0:
            qc.x(i)
        else:
            qc.x(i)
            qc.append(MCPhaseGate(math.pi).control(i), range(i+1,n))
            qc.x(i)
    for i in range(n):
        if (L>>i)%2==0:
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if (L>>(n-1))%2==0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)
    for i in range(n-2,-1,-1):
        if (L>>i)%2==0:
            qc.x(i)
        else:
            qc.x(i)
            qc.append(MCPhaseGate(math.pi).control(n-i+1), range(n,i-1,-1))
            qc.x(i)
    for i in range(n):
        if (L>>i)%2==0:
            qc.x(i)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if (L>>(n-1))%2==0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)
    for i in range(n-2,-1,-1):
        if (L>>i)%2==0:
            qc.x(i)
        else:
            qc.x(i)
            qc.append(PhaseGate(theta = math.pi).control(num_ctrl_qubits = n-i+1), qargs = range(n,i-1,-1))
            qc.x(i)
    for i in range(n):
        if (L>>i)%2==0:
            qc.x(i)

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

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

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if (L>>(n-1))%2==0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)
    for i in range(n-2,-1,-1):
        if (L>>i)%2==0:
            qc.x(i)
        else:
            qc.x(i)
            qc.mcp(math.pi, list(range(i+1,n)), i)
            qc.x(i)
    for i in range(n):
        if (L>>i)%2==0:
            qc.x(i)

    return qc
'''


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

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

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

    qc.append(ZGate().control(n - 1), range(L))

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

    return qc
'''


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

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

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

    qc.append(XGate().control(n - 1), range(L - 1))

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

    return qc
'''


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

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

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

    qc.append(ZGate().control(n - 1), range(L - 1))

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

    return qc
'''


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

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

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

    qc.append(ZGate().control(n - 1), range(2))

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

    return qc
'''


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

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

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

    if n == 2:
        qc.append(ZGate().control(n - 1), range(L - 1))
    elif n == 3:
        qc.append(ZGate().control(n - 1), range(int((L - 1) // 2) - 1))
    elif n == 4:
        qc.append(ZGate().control(n - 1), range(int((L - 1) // 4)))
    elif n == 5:
        qc.append(ZGate().control(n - 1), range(int((L - 1) // 8) - 1))

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

    return qc
'''


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

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

    # qc.append(ZGate().control(n - 1), range(n))
    for i in range(n):
        qc.h(i)
        qc.z(i)

    if n == 2:
        qc.append(ZGate().control(n - 1), range(L - 1))
    elif n == 3:
        qc.append(ZGate().control(n - 1), range(int((L // 2) - 1)))
    elif n == 4:
        qc.append(ZGate().control(n - 1), range(int((L // 4) - 1)))
    elif n == 5:
        qc.append(ZGate().control(n - 1), range(int((L // 8) - 1)))

    return qc
'''


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

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

    # qc.append(ZGate().control(n - 1), range(n))
    # for i in range(n):
    # qc.h(i)
    # qc.z(i)

    if n == 2:
        qc.append(ZGate().control(n - 1), range(L - 1))
    elif n == 3:
        qc.append(ZGate().control(n - 1), range(int((L // 2) - 1)))
    elif n == 4:
        qc.append(ZGate().control(n - 1), range(int((L // 4) - 1)))
    elif n == 5:
        qc.append(ZGate().control(n - 1), range(int((L // 8) - 1)))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        qc.h(i)
    for j in range((1 << n) - L):
        for i in range(n):
            if((j >> i) & 1):
                qc.x(i)
        qc.mcp(math.pi, qc.qregs[0][:n-1], qc.qregs[0][n-1])
        for i in range(n):
            if((j >> i) & 1):
                qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for j in range((1 << n) - L):
        for i in range(n):
            if((j >> i) & 1):
                qc.x(i)
        qc.mcp(math.pi, qc.qregs[0][:n-1], qc.qregs[0][n-1])
        for i in range(n):
            if((j >> i) & 1):
                qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n == 1:
        if L == 1:
            qc.p(math.pi, 0)
    else:
        for j in range((1 << n) - L):
            for i in range(n):
                if((j >> i) & 1):
                    qc.x(i)
            qc.mcp(math.pi, qc.qregs[0][:n-1], qc.qregs[0][n-1])
            for i in range(n):
                if((j >> i) & 1):
                    qc.x(i)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.append(ZGate().control(n - 1), range(n))

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    qc.append(ZGate().control(n - 1), range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    # L未満の状態に-1の位相を加えるための回路を構築
    for i in range(L):
        # リトルエンディアンで整数をエンコードするためのビットパターンを生成
        bit_pattern = '{:0{}b}'.format(i, n)

        # ビットパターンに合わせてXゲートを適用
        for qubit, bit in enumerate(reversed(bit_pattern)):
            if bit == '0':
                qc.x(qubit)

        # 制御Zゲートを適用
        if n > 1:
            qc.h(n-1)
            qc.mcx(list(range(n-1)), n-1)
            qc.h(n-1)
        else:
            qc.z(0)

        # Xゲートを元に戻す
        for qubit, bit in enumerate(reversed(bit_pattern)):
            if bit == '0':
                qc.x(qubit)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    #L = 2^m + a となる最大のmを求めて
    m = int(L/2);
    a = L - 2**m;
    #m-1キュビットまでは、mキュビット以上をX=>Z でOK
    for i in range(m,n):
        qc.x(i);
        qc.z(i);
        qc.x(i);
    #で,a分だけはCNOTで場合分けしながら,
    for i in range(a+1):

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    #L = 2^m + a となる最大のmを求めて
    m = int(L/2);
    a = L - 2**m;
    #m-1キュビットまでは、mキュビット以上をX=>Z でOK
    for i in range(m,n):
        qc.x(i);
        qc.z(i);
        qc.x(i);
    #で,a分だけはCNOTで場合分けしながら,

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    #最善はL が2^nより大きいか小さいかで場合分けするのがいちばんいい。
    #L = 2^m + a となる最大のmを求めて
    m = int(L/2);
    a = L - 2**m;
    #m-1キュビットまでは、mキュビット以上をX=>Z でOK
    for i in range(m,n):
        qc.x(i);
        qc.z(i);
        qc.x(i);
    #で,a分だけはCNOTで場合分けしながら,
    #iに応じて、各0~m-1キュビットまでにXつけるかどうか.
    #その後にCCCCCZをかましたい.
    for i in range(a+1):
        qc.append(Gate().control())

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


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

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


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

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


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for l in range(L):
        for i in range(n):
            if not(l & (1 << i)):
                qc.x(i)
        if n == 1:
            qc.z(0)
        else:
            qc.append(ZGate().control(n - 1), range(n))
        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) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1<<n-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        qc.cz(0, range(1, n))
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1<<n-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        qc.cz(range(0, n-1), n-1)
        qc.x(xlis)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1<<n-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        qc.cz(range(0, n-1), n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        qc.cz(range(0, n-1), n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        for j in range(n-1):
            qc.cz(j, n-1)
        if n%2 == 1:
            qc.z(0)
            qc.x(0)
            qx.z(0)
            qx.x(0)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        if n%2 == 1:
            qc.z(0)
            qc.x(0)
            qx.z(0)
            qx.x(0)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        #qc.x(xlist)
        for j in range(n-1):
            qc.cz(j, n-1)
        if n%2 == 1:
            qc.z(0)
            qc.x(0)
            qx.z(0)
            qx.x(0)
        #qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        #for j in range(n-1):
        #    qc.cz(j, n-1)
        #if n%2 == 1:
        #    qc.z(0)
        #    qc.x(0)
        #    qx.z(0)
        #    qx.x(0)
        #qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        for j in range(n-1):
            qc.cz(j, n-1)
        #if n%2 == 1:
        #    qc.z(0)
        #    qc.x(0)
        #    qx.z(0)
        #    qx.x(0)
        #qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        for j in range(n-1):
            qc.cz(j, n-1)
        if n%2 == 1:
            qc.z(0)
            qc.x(0)
            qx.z(0)
            qx.x(0)
        #qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        for j in range(n-1):
            qc.cz(j, n-1)
        #if n%2 == 1:
        #    qc.z(0)
        #    qc.x(0)
        #    qx.z(0)
        #    qx.x(0)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        for j in range(n-1):
            qc.cz(j, n-1)
        if n%2 == 1:
            qc.z(0)
            qc.x(0)
            qc.z(0)
            qc.x(0)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        if n > 1:
            qc.cz(range(0, n-1), n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        if n > 1:
            qc.cz(range(0, n-1), n-1)
        else:
            qx.z(n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = []
        for j in range(n):
            if ((i>>j)&1) == 0:
                xlist.append(j)
        qc.x(xlist)
        if n > 1:
            qc.cz(range(0, n-1), n-1)
        else:
            qc.z(n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        qc.x(xlist)
        if n > 1:
            qc.cz(range(0, n-1), n-1)
        else:
            qc.z(n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(range(n))
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        qc.x(xlist)
        if n > 1:
            qc.cz(range(0, n-1), n-1)
        else:
            qc.z(n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        qc.x(xlist)
        if n > 1:
            qc.cz(range(0, n), n-1)
        else:
            qc.z(n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)-1):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        qc.x(xlist)
        if n > 1:
            qc.cz(range(1, n), 0)
        else:
            qc.z(n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        qc.x(xlist)
        if n > 1:
            qc.cz(range(1, n), 0)
        else:
            qc.z(n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range((1<<n)):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        if len(xlist) == 0:
            continue
        qc.x(xlist)
        if n > 1:
            qc.cz(range(1, n), 0)
        else:
            qc.z(n-1)
        qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(range(n))
    qc.x(0)
    qx.z(range(n))
    qc.x(0)
    if n > 1:
        qc.cz(range(1, n), 0)
    else:
        qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    #qc.z(range(n))
    qc.x(0)
    #qx.z(range(n))
    qc.x(0)
    if n > 1:
        qc.cz(range(1, n), 0)
    else:
        qc.z(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    if n > 1:
        qc.cz(range(1, n), 0)
    else:
        qc.z(0)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    if n > 1:
        qc.append(Z().control(range(1, n)), 0)
    else:
        qc.z(0)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    if n > 1:
        qc.append(ZGate().control(range(1, n)), 0)
    else:
        qc.z(0)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    if n > 1:
        qc.append(ZGate().control(0)), range(1, n))
    else:
        qc.z(0)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    if n > 1:
        qc.append(ZGate().control(0), range(1, n))
    else:
        qc.z(0)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1<<n-1):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        qc.x(xlist)
        if n > 1:
            qc.cz(range(0, n-1), n-1)
        else:
            qc.z(0)
        qc.x(xlist)
    return qc
'''


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

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


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1<<n-1):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        qc.x(xlist)
        if n > 1:
            qc.cz([j for j in range(n) if j != i], i)
        else:
            qc.z(0)
        qc.x(xlist)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1<<n-1):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        qc.x(xlist)
        if n > 1:
            qc.cz([j for j in range(n) if 1<<j != i], i)
        else:
            qc.z(0)
        qc.x(xlist)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1<<n):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        if len(xlist) != 0:
            qc.x(xlist)
        if n > 1:
            qc.cz([j for j in range(n) if 1<j != i], i)
        else:
            qc.z(0)
        if len(xlist) != 0:
            qc.x(xlist)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(1<<n):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        if len(xlist) != 0:
            qc.x(xlist)
        if n > 1:
            qc.cz(range(0, n-1), n-1)
        else:
            qc.z(0)
        if len(xlist) != 0:
            qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        xlist = [j for j in range(n) if ((i>>j)&1) == 0]
        if len(xlist) != 0:
            qc.x(xlist)
        if n > 1:
            qc.cz(range(0, n-1), n-1)
        else:
            qc.z(0)
        if len(xlist) != 0:
            qc.x(xlist)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        [qc.x(j) for j in range(n) if ((i>>j)&1) == 0]
        if n > 1:
            qc.cz(range(0, n-1), n-1)
        else:
            qc.z(0)
        [qc.x(j) for j in range(n) if ((i>>j)&1) == 0]
    return qc
'''


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

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


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    now = n - 1
    tmp0 = []

    while(now >= 0):
        if(now == n - 1):
            if((L & (1 << now))):
                qc.rz(math.pi * 2, now)
                #qc.z(now)
            else:
                qc.rz(math.pi * 2, now)
                qc.z(now)
                tmp0.append(now)
                qc.x(now)
        else:
            if((L & (1 << now))):
                #qc.crz(math.pi * 2, range(now + 1, n), now)
                qc.cz(range(now + 1, n), now)
            else:
                qc.crz(math.pi * 2, range(now + 1, n), now)
                qc.cz(range(now + 1, n), now)

                tmp0.append(now)
                qc.x(now)

        now -= 1

    for x in tmp0:
        qc.x(x)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    now = n - 1
    tmp0 = []

    while(now >= 0):
        if(now == n - 1):
            if((L & (1 << now))):
                qc.rz(math.pi * 2, now)
                #qc.z(now)
            else:
                qc.rz(math.pi * 2, now)
                qc.z(now)
                tmp0.append(now)
                qc.x(now)
        else:
            if((L & (1 << now))):
                #qc.crz(math.pi * 2, range(now + 1, n), now)
                qc.cz(range(now + 1, n), now)
            else:
                qc.crz(math.pi * 2, range(now + 1, n), now)
                qc.cz(range(now + 1, n), now)

                tmp0.append(now)
                qc.x(now)

        now -= 1

    for x in tmp0:
        qc.x(x)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import mat

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    now = n - 1
    tmp0 = []

    while(now >= 0):
        if(now == n - 1):
            if((L & (1 << now))):
                qc.rz(math.pi * 2, now)
                #qc.z(now)
            else:
                qc.rz(math.pi * 2, now)
                qc.z(now)
                tmp0.append(now)
                qc.x(now)
        else:
            if((L & (1 << now))):
                qc.crz(math.pi * 2, range(now + 1, n), now)
                qc.cz(range(now + 1, n), now)
            else:
                qc.crz(math.pi * 2, range(now + 1, n), now)
                qc.cz(range(now + 1, n), now)

                tmp0.append(now)
                qc.x(now)

        now -= 1

    for x in tmp0:
        qc.x(x)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    now = n - 1
    tmp0 = []

    while(now >= 0):
        if(now == n - 1):
            if((L & (1 << now))):
                qc.rz(math.pi * 2, now)
                #qc.z(now)
            else:
                qc.rz(math.pi * 2, now)
                qc.z(now)
                tmp0.append(now)
                qc.x(now)
        else:
            if((L & (1 << now))):
                qc.crz(math.pi * 2, range(now + 1, n), now)
                qc.cz(range(now + 1, n), now)
            else:
                qc.crz(math.pi * 2, range(now + 1, n), now)
                qc.cz(range(now + 1, n), now)

                tmp0.append(now)
                qc.x(now)

        now -= 1

    for x in tmp0:
        qc.x(x)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    now = n - 1
    tmp0 = []

    while(now >= 0):
        if(now == n - 1):
            if((L & (1 << now))):
                qc.rz(math.pi * 2, now)
                #qc.z(now)
            else:
                qc.rz(math.pi * 2, now)
                qc.z(now)
                tmp0.append(now)
                qc.x(now)
        else:
            if((L & (1 << now))):
                qc.crz(math.pi * 2, range(now + 1, n), now)
                #qc.cz(range(now + 1, n), now)
            else:
                qc.crz(math.pi * 2, range(now + 1, n), now)
                qc.cz(range(now + 1, n), now)

                tmp0.append(now)
                qc.x(now)

        now -= 1

    for x in tmp0:
        qc.x(x)

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    now = n - 1
    tmp0 = []

    while(now >= 0):
        if(now == n - 1):
            if((L & (1 << now))):
                qc.rz(math.pi * 2, now)
                #qc.z(now)
            else:
                qc.rz(math.pi * 2, now)
                qc.z(now)
                tmp0.append(now)
                qc.x(now)
        else:
            if((L & (1 << now))):
                #qc.cz(range(now + 1, n), now)
                tmp = [i for i in range(now + 1, n)]
                tmp += [now]
                qc.append(ZGate().control(n - 1 - now), tmp)

                tmp0.append(now)
                qc.x(now)

        now -= 1

    for x in tmp0:
        qc.x(x)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    now = n - 1
    tmp0 = []

    while(now >= 0):
        if(now == n - 1):
            if((L & (1 << now))):
                qc.rz(math.pi * 2, now)
                #qc.z(now)
            else:
                qc.rz(math.pi * 2, now)
                qc.z(now)
                tmp0.append(now)
                qc.x(now)
        else:
            if((L & (1 << now))):
                #qc.cz(range(now + 1, n), now)
                tmp = [i for i in range(now + 1, n)]
                tmp += [now]
                qc.append(ZGate().control(n - 1 - now), tmp)

                tmp0.append(now)
                qc.x(now)

        now -= 1

    for x in tmp0:
        qc.x(x)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    now = n - 1
    tmp0 = []

    while(now >= 0):
        if(now == n - 1):
            if((L & (1 << now))):
                qc.rz(math.pi * 2, now)
                #qc.z(now)
            else:
                qc.rz(math.pi * 2, now)
                qc.z(now)
                tmp0.append(now)
                qc.x(now)
        else:
            if((L & (1 << now))):
                #qc.cz(range(now + 1, n), now)
                tmp = [i for i in range(now + 1, n)]
                tmp += [now]
                qc.append(ZGate().control(n - 1 - now), tmp)

                tmp0.append(now)
                qc.x(now)
            else:
                tmp = [i for i in range(now + 1, n)]
                tmp += [now]
                qc.append(ZGate().control(n - 1 - now), tmp)

        now -= 1

    for x in tmp0:
        qc.x(x)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(n):
        controlled_gate = Gate('cz', 2, [])
        for j in range(n-1):
            controlled_gate = controlled_gate.control()
        qc.append(controlled_gate, [i] + list(range(n, n+L)))
    return qc
'''


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

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

    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << (n - 1 - j)) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << (n - 1 - j)) == 0:
                qc.x(qr[j])

    return qc

if __name__ == "__main__":
    c = solve(2, 3)
    print(c)
'''


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

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

    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << (n - 1 - j)) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << (n - 1 - j)) == 0:
                qc.x(qr[j])

    return qc

if __name__ == "__main__":
    c = solve(2, 3)
    print(c)
'''


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

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

    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << (n - 1 - j)) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << (n - 1 - j)) == 0:
                qc.x(qr[j])

    return qc
'''


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

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

    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])

    return qc
'''


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

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

    qr = qc.qregs[0]
    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])

    return qc
'''


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

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

    return qc
'''


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

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

    qr = qc.qregs[0]
    for i in range(L - 1):
        gate = ZGate()
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])

    return qc
'''


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

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

    qr = qc.qregs[0]
    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << (n - 1 - j)) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << (n - 1 - j)) == 0:
                qc.x(qr[j])

    return qc
'''


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

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

    qr = qc.qregs[0]
    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])
        # qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])

    return qc
'''


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

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

    if n == 1:
        if L == 1:
            return qc.cz(0, 1)
        else:
            assert L == 2
            return qc

    qr = qc.qregs[0]
    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])

    return qc
'''


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

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

    if n == 1:
        return qc
        if L == 1:
            return qc.cz(0, 1)
        else:
            assert L == 2
            return qc

    qr = qc.qregs[0]
    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])

    return qc
'''


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

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

    if n == 1:
        if L == 1:
            qc.z(0)
        else:
            assert L == 2
        return qc

    qr = qc.qregs[0]
    for i in range(L):
        gate = ZGate()
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])
        qc.append(ZGate().control(n - 1), qr)
        for j in range(n):
            if i & (1 << j) == 0:
                qc.x(qr[j])

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.append(XGate().control(n-1),range(L))
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.append(XGate().control(n-1),range(n))
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.append(ZGate.control(n-1), range(n))
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.append(ZGate.control(L-1), range(L))
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    qc.append(RXGate(2*math.pi).control(n-1), range(n))
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    qc.append(RXGate(2*math.pi).control(n-1), range(L))
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    qc.append(RXGate(2*math.pi).control(L-1), range(L))
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.h(range(n))
    qc.append(RXGate(2*math.pi).control(L-1), range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.h(range(n))
    qc.mcx(qc.qregs[0][:(n-1)],qc.qregs[0][n-1])
    qc.h(range(n))
    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    qc.append(ZGate().control(n - 1), range(n))

    # Write your code here:

    return qc
'''


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

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

    qc.append(ZGate().control(n - 1), range(n))

    # Write your code here:

    return qc
'''


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

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

    qc.append(ZGate().control(n - 1), range(n))

    # Write your code here:

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(L, 2**n):
      stri = bin(i)
      stri = stri[2:]
      while len(stri) < n:
         stri = '0'  + stri
      print(stri)
      for j in range(len(stri)):
         if stri[j] == '0':
            qc.x(n-j-1)
      qc.append(ZGate().control(n - 1), range(n))
      for j in range(len(stri)):
         if stri[j] == '0':
            qc.x(n-j-1)

    # Write your code here:

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n != 1:
      for i in range(L, 2**n):
         stri = bin(i)
         stri = stri[2:]
         while len(stri) < n:
            stri = '0'  + stri
         print(stri)
         for j in range(len(stri)):
            if stri[j] == '0':
               qc.x(n-j-1)
         qc.append(ZGate().control(n - 1), range(n))
         for j in range(len(stri)):
            if stri[j] == '0':
               qc.x(n-j-1)
    else:
       if L == 1:
          qc.z(1)

    # Write your code here:

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n != 1:
      for i in range(L, 2**n):
         stri = bin(i)
         stri = stri[2:]
         while len(stri) < n:
            stri = '0'  + stri
         for j in range(len(stri)):
            if stri[j] == '0':
               qc.x(n-j-1)
         qc.append(ZGate().control(n - 1), range(n))
         for j in range(len(stri)):
            if stri[j] == '0':
               qc.x(n-j-1)
    else:
       if L == :
          qc.z(1)

    # Write your code here:

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n != 1:
      for i in range(L, 2**n):
         stri = bin(i)
         stri = stri[2:]
         while len(stri) < n:
            stri = '0'  + stri
         for j in range(len(stri)):
            if stri[j] == '0':
               qc.x(n-j-1)
         qc.append(ZGate().control(n - 1), range(n))
         for j in range(len(stri)):
            if stri[j] == '0':
               qc.x(n-j-1)
    else:
       if L == 1:
          qc.z(1)

    # Write your code here:

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n != 1:
      for i in range(L, 2**n):
         stri = bin(i)
         stri = stri[2:]
         while len(stri) < n:
            stri = '0'  + stri
         for j in range(len(stri)):
            if stri[j] == '0':
               qc.x(n-j-1)
         qc.append(ZGate().control(n - 1), range(n))
         for j in range(len(stri)):
            if stri[j] == '0':
               qc.x(n-j-1)
    else:
       if L == 1:
          qc.z(0)

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit

# from qiskit.quantum_info import Statevector

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

    # Write your code here:
    v = 0
    for i in range(n-1, -1, -1):
        if (L>>i)&1:
            for j in range(n-1, i-1, -1):
                if ((v>>j)&1)==0:
                    qc.x(j)
            if i==n-1:
                qc.z(i)
            else:
                qc.h(i)
                qc.mcx(list(range(i+1, n)), i)
                qc.h(i)
            for j in range(n-1, i-1, -1):
                if ((v>>j)&1)==0:
                    qc.x(j)
            v ^= (1<<i)
    # print(qc.depth())
    return qc

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


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

def solve(n: int, L: int) -> 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.z(0)
        else:
            # apply multiple controlled Z gate
            qc.append(ZGate().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
from qiskit.circuit.library import ZGate

def solve(n: int, L: int) -> 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.z(0)
        else:
            # apply multiple controlled Z gate
            qc.append(ZGate().control(n - 1), range(n))

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

    return qc
'''


'''python
from qiskit.quantum_info.operators import Operator, Pauli
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import *
import math
def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    # if L == (1 << n):
    #   qc.append(GlobalPhaseGate(math.pi))
    #   return qc
    # qc.append(ZGate().control(n - 1), range(n))
    # for i in range(L):
    #   ..
    # for i in range(n - 1, -1, -1):
    #   //
    s = range(n)
    f = ZGate().control(n - 1)
    for i in range(L):
      for j in range(n):
        if (i >> j) & 1:
          continue
        else:
          qc.x(j)
      qc.append(f, s)
      for j in range(n):
        if (i >> j) & 1:
          continue
        else:
          qc.x(j)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
import math
def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    s = range(n)
    f = ZGate().control(n - 1)
    for i in range(L):
      for j in range(n):
        if (i >> j) & 1:
          continue
        else:
          qc.x(j)
      qc.append(f, s)
      for j in range(n):
        if (i >> j) & 1:
          continue
        else:
          qc.x(j)
    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate
import math
def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n == 1:
      if L == 2:
        qc.z(0)
      qc.x(0)
      qc.z(0)
      qc.x(0)
      return qc

    s = range(n)
    f = ZGate().control(n - 1)
    for i in range(L):
      for j in range(n):
        if (i >> j) & 1:
          continue
        else:
          qc.x(j)
      qc.append(f, s)
      for j in range(n):
        if (i >> j) & 1:
          continue
        else:
          qc.x(j)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if 2 ** (n - 1) > L > 1:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = bin(i)[2:].split(" ")
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.x(eff_n)
            qc.append(ZGate().control(n - 1), range(n))
            qc.x(eff_n)
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    elif 2 ** (n - 1) < L:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = bin(i)[2:].split(" ")
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.append(ZGate().control(n - 1), range(n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    else:
        pass
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if 2 ** (n - 1) > L > 1:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = bin(i)[2:].split(" ")
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.x(eff_n)
            qc.append(ZGate().control(n - 1), range(n))
            qc.x(eff_n)
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    elif 2 ** (n - 1) < L:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = bin(i)[2:].split(" ")
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.append(ZGate().control(n - 1), range(n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    else:
        pass
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if 2 ** (n - 1) > L > 1:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = bin(i)[2:].zfill(eff_n).split(" ")
            # print(bit_i)
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.x(eff_n)
            qc.append(ZGate().control(n - 1), range(n))
            qc.x(eff_n)
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    elif 2 ** (n - 1) < L:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = bin(i)[2:].zfill(eff_n).split(" ")
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.append(ZGate().control(n - 1), range(n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    else:
        pass
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if 2 ** (n - 1) > L > 1:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = bin(i)[2:].zfill(eff_n).split(" ")[::-1]
            # print(bit_i)
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.x(eff_n)
            qc.append(ZGate().control(n - 1), range(n))
            qc.x(eff_n)
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    elif 2 ** (n - 1) < L:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = bin(i)[2:].zfill(eff_n).split(" ")[::-1]
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.append(ZGate().control(n - 1), range(n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    else:
        pass
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if 2 ** (n - 1) > L > 1:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = list(bin(i)[2:].zfill(eff_n))
            # print(bit_i)
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.x(eff_n)
            qc.append(ZGate().control(n - 1), range(n))
            qc.x(eff_n)
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    elif 2 ** (n - 1) < L:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = list(bin(i)[2:].zfill(eff_n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.append(ZGate().control(n - 1), range(n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    else:
        pass
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if 2 ** (n - 1) > L > 1:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = list(bin(i)[2:].zfill(eff_n))
            # print(bit_i)
            for j, b in enumerate(bit_i):
                if b == "0":
                    qc.x(j)
            qc.x(eff_n)
            qc.append(ZGate().control(n - 1), range(n))
            qc.x(eff_n)
            for j, b in enumerate(bit_i):
                if b == "0":
                    qc.x(j)
    elif 2 ** (n - 1) < L:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = list(bin(i)[2:].zfill(eff_n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.append(ZGate().control(n - 1), range(n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    else:
        pass
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if 2 ** (n - 1) > L > 1:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = list(bin(i)[2:].zfill(eff_n))
            # print(bit_i)
            for j, b in enumerate(bit_i):
                if b == "0":
                    qc.x(j)
            qc.x(eff_n + 1)
            qc.append(ZGate().control(n - 1), range(n))
            qc.x(eff_n + 1)
            for j, b in enumerate(bit_i):
                if b == "0":
                    qc.x(j)
    elif 2 ** (n - 1) < L:
        eff_n = int(math.log2(L - 1)) + 1
        for i in range(L):
            bit_i = list(bin(i)[2:].zfill(eff_n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
            qc.append(ZGate().control(n - 1), range(n))
            for j, b in enumerate(bit_i):
                if j == "0":
                    qc.x(j)
    else:
        pass
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        bit_i = list(bin(i)[2:].zfill(eff_n))
        for j, b in enumerate(bit_i):
            if b == "1"
            qc.x(j)
        qc.append(ZGate().control(n - 1), range(n))
        for j, b in enumerate(bit_i):
            if b == "1"
            qc.x(j)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        bit_i = list(bin(i)[2:].zfill(n))
        for j, b in enumerate(bit_i):
            if b == "1":
                qc.x(j)
        qc.append(ZGate().control(n - 1), range(n))
        for j, b in enumerate(bit_i):
            if b == "1":
                qc.x(j)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        bit_i = list(bin(i)[2:].zfill(n))[::-1]
        for j, b in enumerate(bit_i):
            if b == "1":
                qc.x(j)
        qc.append(ZGate().control(n - 1), range(n))
        for j, b in enumerate(bit_i):
            if b == "1":
                qc.x(j)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        bit_i = list(bin(i)[2:].zfill(n))[::-1]
        for j, b in enumerate(bit_i):
            if b == "0":
                qc.x(j)
        qc.append(ZGate().control(n - 1), range(n))
        for j, b in enumerate(bit_i):
            if b == "0":
                qc.x(j)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    if n > 1:
        for i in range(L):
            bit_i = list(bin(i)[2:].zfill(n))[::-1]
            for j, b in enumerate(bit_i):
                if b == "0":
                    qc.x(j)
            qc.append(ZGate().control(n - 1), range(n))
            for j, b in enumerate(bit_i):
                if b == "0":
                    qc.x(j)
    else:
        if L % 2 == 1:
            qc.z(n - 1)
    return qc
'''


'''python
from qiskit import QuantumCircuit

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


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if i>>j==0:
                qc.x[j]
        qc.append(ZGate().control(n - 1), range(n))
        for j in range(n):
            if i>>j==0:
                qc.x[j]

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if i>>j==0:
                qc.x[j]
        qc.mcp(nath.pi,range(n-1),n-1)
        for j in range(n):
            if i>>j==0:
                qc.x[j]

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if i>>j==0:
                qc.x[j]
        qc.mcp(math.pi,range(n-1),n-)
        for j in range(n):
            if i>>j==0:
                qc.x[j]

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if i>>j==0:
                qc.x[j]
        qc.mcp(math.pi,range(n-1),n-1)
        for j in range(n):
            if i>>j==0:
                qc.x[j]

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if i>>j==0:
                qc.x[j]
        qc.mcp(math.pi,range(n),n-1)
        for j in range(n):
            if i>>j==0:
                qc.x[j]

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if i>>j==0:
                qc.x[j]
        qc.append(Gate(Z).control(n - 1), range(n))
        for j in range(n):
            if i>>j==0:
                qc.x[j]

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if i>>j==0:
                qc.x[j]
        qc.mcp(math.pi,range(n))
        for j in range(n):
            if i>>j==0:
                qc.x[j]

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if i>>j==0:
                qc.x[j]
        qc.mcp(math.pi,range(n))
        for j in range(n):
            if i>>j==0:
                qc.x[j]

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(math.ceil(math.log2(L))):
            if i>>j==0:
                qc.x[j]
        qc.mcp(math.pi,range(n))
        for j in range(n):
            if i>>j==0:
                qc.x[j]

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    bits = [int(x) for x in f"{L:0{n}b}"]
    bits.reverse()
    for i in reversed(range(n)):
        if bits[i] == 0:
            continue
        for j in range(i + 1, n):
            if bits[j]:
                qc.x(j)
        qc.x(i)
        if i == n - 1:
            qc.z(i)
        else:
            qc.cz(range(i + 1, n), i)
        qc.x(i)
        for j in range(i + 1, n):
            if bits[j]:
                qc.x(j)
    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    bits = [int(x) for x in f"{L:0{n}b}"]
    bits.reverse()
    for i in reversed(range(n)):
        if bits[i] == 0:
            continue
        for j in range(i + 1, n):
            if bits[j] == 0:
                qc.x(j)
        qc.x(i)
        if i == n - 1:
            qc.z(i)
        else:
            qc.cz(range(i + 1, n), i)
        qc.x(i)
        for j in range(i + 1, n):
            if bits[j] == 0:
                qc.x(j)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    bits = [int(x) for x in f"{L:0{n}b}"]
    bits.reverse()
    for i in reversed(range(n)):
        if bits[i] == 0:
            continue
        for j in range(i + 1, n):
            if bits[j] == 0:
                qc.x(j)
        qc.x(i)
        if i == n - 1:
            qc.z(i)
        else:
            qc.append(ZGate().control(n - i - 1), range(i, n))
        qc.x(i)
        for j in range(i + 1, n):
            if bits[j] == 0:
                qc.x(j)
    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    qc.append(ZGate().control(n-1),range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
import math

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

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

    if (L & (1 << (n-1))) == 0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)

    for i in range(n-2, -1,-1):
        b = (L & (1  << i))
        if b == 0:
            qc.x(i)
        else:
            data = []
            for t in range(n-1,i,-1):
                data.append(t)
            qc.x(i)
            qc.mcp(lam=math.pi,control_qubits=data, target_qubit=i)
            qc.x(i)

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


'''python
from qiskit import QuantumCircuit
import mat

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

    if (L & (1 << (n-1))) == 0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)

    for i in range(n-2, -1,-1):
        b = (L & (1  << i))
        if b == 0:
            qc.x(i)
        else:
            data = []
            for t in range(n-1,i,-1):
                data.append(t)
            qc.x(i)
            qc.mcp(lam=math.pi,control_qubits=data, target_qubit=i)
            qc.x(i)

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


'''python
from qiskit import QuantumCircuit
import mat

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

    if (L & (1 << (n-1))) == 0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)

    for i in range(n-2, -1,-1):
        b = (L & (1  << i))
        if b == 0:
            qc.x(i)
        else:
            data = []
            for t in range(n-1,i,-1):
                data.append(t)
            qc.x(i)
            qc.x(i)

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


'''python
from qiskit import QuantumCircuit
import math

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

    if (L & (1 << (n-1))) == 0:
        qc.x(n-1)
    else:
        qc.x(n-1)
        qc.z(n-1)
        qc.x(n-1)

    for i in range(n-2, -1,-1):
        b = (L & (1  << i))
        if b == 0:
            qc.x(i)
        else:
            data = []
            for t in range(n-1,i,-1):
                data.append(t)
            qc.x(i)
            qc.mcp(lam=math.pi,control_qubits=data, target_qubit=i)
            qc.x(i)

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


'''python
from qiskit import QuantumCircuit
from qiskit.extensions import ZGate
from qiskit.circuit.library import CU1Gate
from math import pi
from qiskit.quantum_info.operators.operator import Operator
import numpy as np

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

    unitary = [[0 for _ in range(2**n)] for _ in range(2**n)]

    for i in range(2**n):
        if i < L:
            unitary[i][i] = -1
        else:
            unitary[i][i] = 1

    oeprator = Operator(unitary)

    qc.append(oeprator, range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
from math import pi
from qiskit.quantum_info.operators.operator import Operator
import numpy as np

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

    unitary = [[0 for _ in range(2**n)] for _ in range(2**n)]

    for i in range(2**n):
        if i < L:
            unitary[i][i] = -1
        else:
            unitary[i][i] = 1

    oeprator = Operator(unitary)

    qc.append(oeprator, range(n))

    return qc
'''


'''python
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZGate, CZGate
from math import pi
import numpy as np

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

    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    dp = [-1 for _ in range(2**n)]
    for i in range(2**n):
        if i >= L:
            if dp[i] == -1:
                array = []
                for j in range(n):
                    if i & (1 << j) != 0:
                        array.append(j)
                qc.append(ZGate().control(len(array) - 1), array)

                for j in range(n):
                    if i & (1 << j) == 0:
                        dp[i ^ (1 << j)] *= -1

    #qc.append(ZGate(), [1])
    #qc.append(ZGate().control(1), [0, 1])

    return qc
'''


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

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

    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    dp = [-1 for _ in range(2**n)]
    for i in range(2**n):
        if i >= L:
            if dp[i] == -1:
                array = []
                for j in range(n):
                    if i & (1 << j) != 0:
                        array.append(j)
                qc.append(ZGate().control(len(array) - 1), array)

                for j in range(n):
                    if i & (1 << j) == 0:
                        dp[i ^ (1 << j)] *= -1

    #qc.append(ZGate(), [1])
    #qc.append(ZGate().control(1), [0, 1])

    return qc
'''


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

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

    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    dp = [-1 for _ in range(2**n)]
    for i in range(2**n):
        if i >= L:
            if dp[i] == -1:
                array = []
                for j in range(n):
                    if i & (1 << j) != 0:
                        array.append(j)
                if len(array) == 1:
                    qc.z(array[0])
                else:
                    qc.append(ZGate().control(len(array) - 1), array)

                for j in range(n):
                    if i & (1 << j) == 0:
                        dp[i ^ (1 << j)] *= -1

    #qc.append(ZGate(), [1])
    #qc.append(ZGate().control(1), [0, 1])

    return qc
'''


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

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

    qc.z(0)
    qc.x(0)
    qc.z(0)
    qc.x(0)
    dp = [-1 for _ in range(2**n)]
    for i in range(2**n):
        if i >= L:
            if dp[i] == -1:
                array = []
                for j in range(n):
                    if i & (1 << j) != 0:
                        array.append(j)
                if len(array) == 1:
                    qc.z(array[0])
                else:
                    qc.append(ZGate().control(len(array) - 1), array)
                for j in range(2**n):
                    if j > i:
                        ok = True
                        for k in range(n):
                            if ((i & (1 << k)) != 0) and ((j & (1 << k)) == 0):
                                ok = False
                        if ok:
                            dp[j] *= -1

    #qc.append(ZGate(), [1])
    #qc.append(ZGate().control(1), [0, 1])

    return qc
'''


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

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

    for i in range(L):
        for j in range(n):
            if ((1 << j) & i) == 0:
                qc.cx(j)
        qc.append(XGate().control(n-1), range(n-1))

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

    return qc
'''


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

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

    if n == 1:
    	if L == 2:
    		qc.x(0)
    		qc.z(0)
    		qc.x(0)
    		qc.z(0)
    	else:
    		qc.x(0)
    		qc.z(0)
    		qc.x(0)
    else:
	    for i in range(L):
	        for j in range(n):
	            if ((1 << j) & i) == 0:
	                qc.x(j)
	        qc.append(ZGate().control(n-1), range(n))

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

    return qc

solve(2, 1)
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if (i/(2**j)) % 2 == 0:
                qc.x(j)
        qc.cx(range(n),0)
        for j in range(n):
            if (i/(2**j)) % 2== 0:
                qc.x(j)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if (i//(2**j)) % 2 == 0:
                qc.x(j)
        qc.append(ZGate().control(n-1),range(n))
        for j in range(n):
            if (i//(2**j)) % 2== 0:
                qc.x(j)

    return qc
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n == 1:
        return qc
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if (i//(2**j)) % 2 == 0:
                qc.x(j)
        qc.append(ZGate().control(n-1),range(n))
        for j in range(n):
            if (i//(2**j)) % 2== 0:
                qc.x(j)

    return qc

# for n in range(5):
#     for l in range(2**(n+1)):
#         print(f"{n+1} {l+1}")
#         solve(n+1,l+1)
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    if n == 1:
        if L==1:
            qc.z(0)

        return qc
    # Write your code here:
    for i in range(L):
        for j in range(n):
            if (i//(2**j)) % 2 == 0:
                qc.x(j)
        qc.append(ZGate().control(n-1),range(n))
        for j in range(n):
            if (i//(2**j)) % 2== 0:
                qc.x(j)

    return qc

# for n in range(5):
#     for l in range(2**(n+1)):
#         print(f"{n+1} {l+1}")
#         solve(n+1,l+1)
'''


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

def solve(n: int, L: int) -> QuantumCircuit:
    qc = QuantumCircuit(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)
        if n == 1:
            qc.z(0)
        else:
            # apply multiple controlled Z gate
            qc.append(ZGate().control(n - 1), range(n))
        for i in range(n):
            if not ((l >> i) & 1):
                qc.x(i)
    return qc
'''