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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(XGate().control(n), list(k) + [m[0]])
    qc.append(HGate().control(n), list(k) + [m[0]])
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(n), list(k) + [m[0]])
    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    aux = QuantumRegister(1, 'aux')
    qc.add_register(aux)

    qc.x(aux[0])

    for i in range(n):
        qc.cx(k[i], aux[0])

    qc.ch(aux[0], m[0])

    for i in range(n):
        qc.cx(k[i], aux[0])
    qc.x(aux[0])

    return qc
'''


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

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

    controlled_h = HGate().control(n, ctrl_state='0' * n)
    qc.append(controlled_h, k[:] + [m[0]])

    controlled_z = ZGate().control(n, ctrl_state='0' * n)
    qc.append(controlled_z, k[:] + [m[0]])

    return qc
'''


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

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

    controlled_h = HGate().control(n, ctrl_state='0' * n)
    qc.append(controlled_h, k[:] + [m[0]])

    return qc
'''


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

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

    c0h = HGate().control(n, ctrl_state=0)
    qc.append(c0h, list(range(1, n + 1)) + [0])

    return qc

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

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


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.ch(k, m)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.ch(k, m)
    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(len(k)), range(len(k),-1,-1))
    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.compose(HGate().control(len(k)), [*k, m[0]], inplace=True)
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(len(k)), range(len(k),-1,-1))
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(n), list(range(1, n+1))+[0])
    qc.x(k)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    # Flip k so that controls are on '0'
    for i in range(n):
        qc.x(k[i])

    # Multi-controlled Hadamard is hard; instead, we:
    # Put state |m> through H, and then Z conditioned on m and all k==0
    qc.h(m[0])
    if n == 0:
        # No controls, always act
        qc.z(m[0])
    else:
        qc.mcz([m[0]] + [k[i] for i in range(n)], m[0])
    # But Qiskit mcz does not allow target as part of controls!
    # Instead, do controlled-Z on m[0], controlled by all k==0

    if n > 0:
        qc.mcz([k[i] for i in range(n)], m[0])

    # Unflip k
    for i in range(n):
        qc.x(k[i])
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    # Invert all k qubits (check if they're in |0⟩)
    for i in range(n):
        qc.x(k[i])

    # Apply multi-controlled Toffoli to m (using no ancilla)
    if n == 1:
        qc.cx(k[0], m[0])
    elif n == 2:
        qc.ccx(k[0], k[1], m[0])
    else:
        qc.mct(k[:], m[0], mode='noancilla')  # n ≥ 3

    # Apply Z then H to m[0]
    qc.z(m[0])
    qc.h(m[0])

    # Undo the Toffoli
    if n == 1:
        qc.cx(k[0], m[0])
    elif n == 2:
        qc.ccx(k[0], k[1], m[0])
    else:
        qc.mct(k[:], m[0], mode='noancilla')  # n ≥ 3

    # Undo the X gates
    for i in range(n):
        qc.x(k[i])
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    # Apply X gates to flip m if needed (controlled by k=0 condition)
    # Use multi-controlled X gate to check if k == 0
    qc.x(k)  # Flip all k qubits to test the inverse
    qc.mcx(k, m)  # Multi-controlled X gate with k controlling m
    qc.x(k)  # Flip back k qubits
    # Apply Hadamard to m to get the superposition
    qc.h(m)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    # Use an ancillary qubit approach to detect k = 0 and apply phase
    qc.h(m)  # Start with Hadamard to get superposition
    # Apply multi-controlled Z gate to introduce phase when k != 0
    qc.mcx(k, m)  # Control on k qubits, target m (flips when k != 0)
    qc.x(m)  # Correct the phase by flipping m
    qc.h(m)  # Reapply Hadamard to adjust superposition
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
# Apply transformation only when k = 0
    qc.x(k)  # Flip k qubits to test k = 0 (all 1s means original k = 0)
    qc.mcx(k, m)  # Multi-controlled X when k = 0
    qc.h(m)  # Apply Hadamard to get superposition
    qc.x(k)  # Restore k qubits
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    # Add an ancillary qubit to handle the control
    anc = QuantumRegister(1, 'anc')
    qc.add_register(anc)
    # Initialize anc to |0>
    qc.x(anc)  # anc = |1> for control inversion
    # Check if k = 0 using multi-controlled X
    qc.mcx(k, anc)  # anc flips to |0> only if k = 0
    # Apply controlled Hadamard with phase
    qc.ch(m, anc)  # Controlled Hadamard when anc = |1> (k != 0 does nothing)
    qc.cz(m, anc)  # Apply phase based on m when anc = |1>
    qc.x(anc)  # Reset anc
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    # Apply X gates to invert k for k = 0 condition
    qc.x(k)  # Flip all k qubits (k = 0 becomes all |1>)
    # Use multi-controlled Hadamard with phase
    qc.mch(k, m)  # Multi-controlled Hadamard (approximates superposition)
    qc.mcx(k, m)  # Apply controlled X to adjust phase
    qc.x(k)  # Restore k qubits
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
# Apply transformation only when k = 0
    # Invert k to check k = 0 (all |1> means original k = 0)
    for i in range(n):
        qc.x(k[i])  # Flip each k qubit
    # Apply controlled operation
    qc.h(m)  # Start with Hadamard
    for i in range(n):
        qc.cx(k[i], m)  # Use CNOT to build control (approximates multi-control)
    qc.h(m)  # Refine superposition
    for i in range(n):
        qc.x(k[i])  # Restore k qubits
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
# Apply transformation only when k = 0
    qc.x(k)  # Invert k (k = 0 becomes all |1>)
    qc.mct(k, m)  # Multi-controlled Toffoli when k = 0
    qc.h(m)  # Apply Hadamard to get superposition
    qc.mct(k, m)  # Undo the control to adjust phase
    qc.x(k)  # Restore k
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
# Conditionally apply transformation when k = 0
    for i in range(n):
        qc.x(k[i])  # Invert k (k = 0 becomes all |1>)
    # Use controlled operations to apply transformation
    qc.h(m)  # Apply Hadamard
    for i in range(n-1, -1, -1):  # Iterate backwards for control
        qc.cx(k[i], m)  # Control on each k[i]
    qc.h(m)  # Refine superposition
    for i in range(n):
        qc.x(k[i])  # Restore k
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    # Invert k to check k = 0 (all |1> means original k = 0)
    for i in range(n):
        qc.x(k[i])
    # Apply controlled Hadamard and phase
    qc.h(m)  # Initial Hadamard
    for i in range(n-1, -1, -1):  # Control chain
        qc.cx(k[i], m)
    # Apply phase based on m
    qc.cz(m, m)  # Self-controlled Z to introduce (-1)^m phase
    for i in range(n-1, -1, -1):  # Undo control chain
        qc.cx(k[i], m)
    qc.h(m)  # Final Hadamard to complete transformation
    for i in range(n):
        qc.x(k[i])  # Restore k
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Invert k to check k = 0 (all |1> means original k = 0)
    for i in range(n):
        qc.x(k[i])
    # Apply controlled Hadamard and phase
    qc.h(m)  # Initial Hadamard
    # Build control chain
    for i in range(n-1, -1, -1):
        qc.cx(k[i], m)
    # Apply Z gate for phase (-1)^m, controlled by the chain
    qc.z(m)  # Apply Z to introduce phase
    for i in range(n-1, -1, -1):
        qc.cx(k[i], m)  # Undo control chain
    qc.h(m)  # Final Hadamard to complete transformation
    for i in range(n):
        qc.x(k[i])  # Restore k
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
# Invert k to check k = 0 (all |1> means original k = 0)
    for i in range(n):
        qc.x(k[i])
    # Apply controlled Hadamard and phase
    qc.h(m)  # Initial Hadamard
    qc.mcx(k, m)  # Multi-controlled X when k = 0
    qc.z(m)  # Apply Z gate for (-1)^m phase
    qc.mcx(k, m)  # Undo the control to apply conditionally
    qc.h(m)  # Final Hadamard to complete transformation
    for i in range(n):
        qc.x(k[i])  # Restore k
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Invert k to check k = 0 (all |1> means original k = 0)
    for i in range(n):
        qc.x(k[i])
    # Apply controlled transformation
    qc.mcx(k, m)  # Control on k, target m
    qc.h(m)  # Hadamard within control
    qc.z(m)  # Phase flip
    qc.h(m)  # Complete the transformation
    qc.mcx(k, m)  # Undo the control
    for i in range(n):
        qc.x(k[i])  # Restore k
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    if k==0:
        qc.h(0)
    else:
        pass

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    if k==0 and m==0:
        qc.x(0)
        qc.h(0)

    elif k==0 and m==1:
        qc.h(0)

    else:
        pass

    return qc
'''


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

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

    qc.ry(np.pi / 4, m[0])
    qc.x(k)

    qc.h(m[0])
    qc.mcx([*k], m[0])
    qc.h(m[0])

    qc.x(k)

    qc.ry(-np.pi / 4, m[0])
    return qc
'''


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

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

    h_gate = HGate()
    multi_controlled_h_gate = h_gate.control(num_ctrl_qubits=n, ctrl_state='0' * n)
    qc.append(multi_controlled_h_gate, [*k, m[0]])

    return qc
'''


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

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

    h_gate = HGate()
    multi_controlled_h_gate = h_gate.control(num_ctrl_qubits=n, ctrl_state='0' * n)
    qc.append(multi_controlled_h_gate, [*k, m[0]])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.h(m)
    qc.cz(k, m)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.ch(k, m)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.append(HGate().control(n - 1), range(n))
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import HGate
from qiskit.quantum_info import Statevector

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.append(HGate().control(n - 1), range(1, n + 1))
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.append(HGate().control(n - 1), range(1, n + 1))
    return qc
'''


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

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

    qc.x(k)
    qc.append(HGate().control(n), range(1, n + 1))
    qc.x(k)

    return qc
'''


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

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

    qc.x(k)
    qc.append(HGate().control(n), range(n + 1))
    qc.x(k)

    return qc
'''


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

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


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.append(HGate().control(n), k[:] + m[:])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    target = range()
    qc.append(HGate().control(n), range(n+1))
    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(n), range(n+1))
    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(n), list(range(1, n + 1)) + [0])
    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(n), k[:] + m[:])
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(n), k[:] + m[:])
    qc.x(k)

    return qc
'''


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

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

    for i in range(1, n + 1):
        qc.x(i)
    qc.append(HGate().control(n), list(range(1, n + 1)) + [0])
    for i in range(1, n + 1):
        qc.x(i)

    return qc
'''


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

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


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.append(HGate().control(n),[n,range(n)])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.x(k)
    # Write your code here:
    qc.append(HGate().control(n),k+m)
    qc.x(k)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.x(k)
    # Write your code here:
    qc.append(HGate().control(n),k[:]+m[:])
    qc.x(k)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.h(m)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(1,n+1):
        qc.x(i)
    qc.swap(0,n)
    qc.append(ZGate().control(n-1), range(n))
    qc.swap(0,n)
    for i in range(1,n+1):
        qc.x(i)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(1,n+1):
        qc.x(i)
    qc.swap(0,n)
    qc.append(HGate().control(n), range(n+1))
    qc.swap(0,n)
    for i in range(1,n+1):
        qc.x(i)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])
    mcH = HGate().control(n)
    qc.append(mcH, [*k, m[0]])
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    ch = HGATE().control(n)
    qc.append(ch,k[:]+m[:])
    qc.x(k)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    ch = HGATE().control(n)
    qc.append(ch,k[:]+m[:])
    qc.x(k)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    ch = HGATE().control(n)
    qc.append(ch,k[:]+m[:])
    qc.x(k)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    h_circ.h(0)
    h_gate = h_circ.to_gate()
    ch_gate = h_gate.control(n)
    qc.x(k)
    qc.append(ch_gate,k[:]+m[:])
    qc.x(k)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    h_circ = quantumCircuit(1)
    h_circ.h(0)
    h_gate = h_circ.to_gate()
    ch_gate = h_gate.control(n)
    qc.x(k)
    qc.append(ch_gate,k[:]+m[:])
    qc.x(k)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.x(k)

    qc.append(HGate().control(n), [k, m], inplace=True)

    qc.x(k)

    return qc
'''


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

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

    for i in range(n):
        qc.x(k[i])

    qc.append(ZGate().control(n), [q for q in k] + [m[0]])
    qc.h(m[0])
    for i in range(n):
        qc.x(k[i])

    return qc
'''


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

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

    for i in range(n):
        qc.x(k[i])

    qc.append(ZGate().control(n), [q for q in k] + [m[0]])
    qc.h(m[0])
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    if n == 1:
        qc.x(k[0])
        qc.ch(k[0], m[0])
        qc.x(k[0])
    else:
        for i in range(n):
            qc.x(k[i])

        control_qubits = [k[i] for i in range(n)]
        qc.mch(control_qubits, m[0])
        for i in range(n):
            qc.x(k[i])

    return qc
'''


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

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

    for i in range(n):
        qc.x(k[i])

    if n == 1:
        qc.ch(k[0], m[0])
    elif n == 2:
        qc.ccx(k[0], k[1], m[0])
        qc.h(m[0])
        qc.ccx(k[0], k[1], m[0])
        qc.h(m[0])
    else:
        control_qubits = [k[i] for i in range(n)]
        qc.mcx(control_qubits, m[0])
        qc.h(m[0])
        qc.mcx(control_qubits, m[0])
        qc.h(m[0])

    for i in range(n):
        qc.x(k[i])

    return qc
'''


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

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

    if n == 1:
        qc.x(k[0])
        qc.ch(k[0], m[0])
        qc.x(k[0])
    else:
        h_gate = HGate()
        controlled_h = h_gate.control(num_ctrl_qubits=n, ctrl_state='0'*n)
        qubits = [k[i] for i in range(n)] + [m[0]]
        qc.append(controlled_h, qubits)

    return qc
'''


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

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

    if n == 0:
        qc.h(m[0])
    else:
        qc.append(HGate().control(n - 1), range(n))

    return qc
'''


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

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

    if n == 0:
        qc.h(m[0])
    else:
        qc.append(HGate().control(n - 1), k[:n-1] + [m[0]])

    return qc
'''


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

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

    if n == 0:
        qc.h(m[0])
    else:
        for i in range(n):
            qc.x(k[i])
        qc.append(HGate().control(n), list(k) + [m[0]])
        for i in range(n):
            qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from math

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

    qc.h(n)

    if n == 1:
        qc.cz(0, n)
    else:
        qc.mcp(math.pi(), list(range(n)), n)
    qc.h(n)
    for i in range(n):
        qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from math

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])
    # m にHadamard
    qc.h(m[0])
    # k=|1...1> のときに m に制御Z
    if n == 1:
        qc.cz(k[0], m[0])
    else:
        qc.mcp(math.pi, [k[i] for i in range(n)], m[0])
    # m にHadamard
    qc.h(m[0])
    # k を元に戻す
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from math

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])

    qc.h(m[0])

    if n == 0:
        qc.z(m[0])  # kビットが無い場合
    elif n == 1:
        qc.cz(k[0], m[0])
    else:
        qc.mcp(math.pi, [k[i] for i in range(n)], m[0])

    # mにHを作用
    qc.h(m[0])

    # kを元に戻す
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from math

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])

    # 制御付きHadamard
    if n == 1:
        qc.ch(k[0], m[0])
    elif n >= 2:
        qc.h(m[0])
        qc.mcx([k[i] for i in range(n)], m[0])
        qc.h(m[0])
    else:  # n==0の場合はmにHのみ
        qc.h(m[0])

    # kを元に戻す
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
from math

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])

    # 制御付きHadamard
    if n == 1:
        qc.ch(k[0], m[0])
    elif n >= 2:
        # n>=2の多重制御Hは分解が必要（補助ビット無しなら mcu1 + H などで近似）
        # 例として、mビットに対して多重制御Xをはさむ
        # ここでは簡単にmビットにHadamard+多重制御X+Hadamard
        qc.mcx([k[i] for i in range(n)], m[0])
        qc.x(0)
        qc.h(m[0])
    else:  # n==0の場合はmにHのみ
        qc.h(m[0])

    # kを元に戻す
    for i in range(n):
        qc.x(k[i])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])

    # 制御付き（k=0のときだけ）H→Z→H
    # H
    qc.h(m[0])
    # 多重制御Z（符号反転、Z = P(π) = Rz(π)）
    qc.mcz([k[i] for i in range(n)], m[0])
    # H
    qc.h(m[0])

    # kを元に戻す
    for i in range(n):
        qc.x(k[i])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])

    # Hでmを±に分解
    qc.h(m[0])
    # 多重制御Xで |k=111...1⟩をmに制御X
    if n > 0:
        qc.mcx([k[i] for i in range(n)], m[0])
    # Hで基底を戻す
    qc.h(m[0])

    # kを元に戻す
    for i in range(n):
        qc.x(k[i])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if n == 1:
        # k[0]==1の時のみ
        qc.ch(k[0], m[0])
    else:
        # n>=2: k[0]~k[n-1]すべて1の時だけm[0]にH
        # Hadamardを2回で挟んだmcx（Toffoli拡張）でX型の符号調整も可能
        qc.h(m[0])  # 変換
        qc.mcx([k[i] for i in range(n)], m[0])
        qc.h(m[0])  # 戻す
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if n == 1:
        # k[0]==1の時のみ
        qc.ch(k[0], m[0])
    else:
        # n>=2: k[0]~k[n-1]すべて1の時だけm[0]にH
        # Hadamardを2回で挟んだmcx（Toffoli拡張）でX型の符号調整も可能
        qc.h(m[0])  # 変換
        qc.mcx([k[i] for i in range(n)], m[0])
        qc.h(m[0])  # 戻す
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

from qiskit.circuit.library import ZGate

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if n == 1:
        # k[0]==1の時のみ
        qc.ch(k[0], m[0])
    else:
        # n>=2: k[0]~k[n-1]すべて1の時だけm[0]にH
        # Hadamardを2回で挟んだmcx（Toffoli拡張）でX型の符号調整も可能
        qc.h(m[0])  # 変換
        qc.mcx([k[i] for i in range(n)], m[0])
        qc.h(m[0])  # 戻す
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

from qiskit.circuit.library import ZGate

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])

    # 制御付きHadamard
    if n == 1:
        qc.ch(k[0], m[0])
    elif n >= 2:
        # Hadamardで重ね合わせ
        qc.h(m[0])
        # 多重制御Z（符号反転）、HでX-Z-X変換して多重制御XでもOK
        qc.mcx([k[i] for i in range(n)], m[0])
        qc.h(m[0])

    # kを元に戻す
    for i in range(n):
        qc.x(k[i])
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

from qiskit.circuit.library import ZGate

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])

    # 2. 多重制御Hゲート（mに対してk全部が1のときだけ作用）
    if n == 0:
        qc.h(m[0])  # kレジスタが無い場合
    elif n == 1:
        qc.ch(k[0], m[0])
    else:
        # HadamardでH→mcx→Hで多重制御Hを合成
        qc.h(m[0])
        qc.mcx([k[i] for i in range(n)], m[0])
        qc.h(m[0])

    # 3. kを元に戻す
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

from qiskit.circuit.library import ZGate

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    for i in range(n):
        qc.x(k[i])

    # 2. 多重制御Hゲート（mに対してk全部が1のときだけ作用）
    if n == 0:
        qc.h(m[0])  # kレジスタが無い場合
    elif n == 1:
        qc.ch(k[0], m[0])
    else:
        # HadamardでH→mcx→Hで多重制御Hを合成

        qc.mcx([k[i] for i in range(n)], m[0])
        qc.x(0)
        qc.h(m[0])

    # 3. kを元に戻す
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

from qiskit.circuit.library import ZGate

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    anc = QuantumRegister(1, 'anc')
    qc = QuantumCircuit(m, k, anc)

    # ancillaビットに「kがすべて0の時のみ1になる」ような多重制御X
    if n == 1:
        qc.x(k[0])
        qc.cx(k[0], anc[0])
        qc.x(k[0])
    else:
        for i in range(n):
            qc.x(k[i])
        qc.mcx([k[i] for i in range(n)], anc[0])
        for i in range(n):
            qc.x(k[i])

    # ancilla=1の時のみ、mビットにHadamard
    qc.ch(anc[0], m[0])

    # ancillaを元に戻す
    if n == 1:
        qc.x(k[0])
        qc.cx(k[0], anc[0])
        qc.x(k[0])
    else:
        for i in range(n):
            qc.x(k[i])
        qc.mcx([k[i] for i in range(n)], anc[0])
        for i in range(n):
            qc.x(k[i])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.x(k)
    qc.append(HGate().control(n - 1), range(n))
    qc.x(k)
    # Write your code here:

    return qc
'''


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

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

    qc.append(HGate().control(n), range(n+1))
    qc.x(k)
    # Write your code here:

    return qc
'''


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

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

    qc.append(HGate().control(n), list(range(1,n+1))+[0])
    qc.x(k)
    # Write your code here:

    return qc
'''


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

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

    qc.append(HGate().control(n), reversed(range(n + 1)))

    return qc
'''


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

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

    for i in range(n):
        qc.x(k[i])
    qc.append(HGate().control(n), reversed(range(n + 1)))
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.x(k)

    qc.append(ZGate().control(n + 1), list(k) + [m[0]] + [m[0]])
    qc.append(HGate().control(n), list(k) + [m[0]])

    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.x(k)

    qc.append(ZGate().control(n), list(k) + [m[0]])
    qc.append(HGate().control(n), list(k) + [m[0]])

    qc.x(k)
    return qc
'''


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

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

    qc.x(k)
    qc.append(ZGate().control(n), list(k) + [m[0]])
    qc.append(HGate().control(n), list(k) + [m[0]])
    qc.x(k)

    return qc
'''


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

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

    qc.x(k)

    qc.append(ZGate().control(n), list(k) + [m[0]])
    qc.append(HGate().control(n), list(k) + [m[0]])

    qc.x(k)

    return qc
'''


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

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

     qc.x(k)
    qc.append(HGate().control(n), list(k) + [m[0]])
    qc.x(k)

    return qc
'''


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

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

    qc.x(k)  # flip k to detect zero state
    qc.append(HGate().control(n), list(k) + [m[0]])  # apply H to m if k==0
    qc.x(k)  # unflip

    return qc
'''


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

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

    # qc.x(0)

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

    qc.mcx(control_qubits=[i for i in range(1,n+1)], target_qubit=0)

    qc.h(0)

    qc.mcx(control_qubits=[i for i in range(1,n+1)], target_qubit=0)

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

    return qc

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


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

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

    # qc.x(0)

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

    qc.mcx(control_qubits=[i for i in range(1,n+1)], target_qubit=0)

    qc.h(0)
    qc.z(0)

    # qc.mcx(control_qubits=[i for i in range(1,n+1)], target_qubit=0)

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

    return qc

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


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

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

    # qc.x(0)

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

    L=[i for i in range(1,n+1)]
    L.append(0)
    qc.append(HGate().control(n),L)

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

    return qc

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


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.x(k)

    qc.mch(k, 0)
    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.h(0)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.append(HGate().control(num_ctrl_qubits=n), range(1, n+1))

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.append(HGate().control(n), k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.append(HGate().control(n-1), k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.append(HGate().control(n+1),)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.append(HGate().control(n+1))

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.append(HGate().control(k+m))

    return qc
'''


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

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

    qc.append(HGate().control(k+m))

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.append(qiskit.circuit.library.HGate().control(k+m))

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.append(qiskit.circuit.library.HGate().control(n+1))

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    h_gate = qiskit.circuit.library.standard_gates.h.HGate()
    ch_gate = h_gate.control(num_ctrl_qubits=n)

    qc.append(chgate, [*k, m[0]])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    h_gate = qiskit.circuit.library.standard_gates.h.HGate()
    ch_gate = h_gate.control(num_ctrl_qubits=n)

    qc.append(ch_gate, [*k, m[0]])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister
import qiskit

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

    h_gate = qiskit.circuit.library.standard_gates.h.HGate()
    ch_gate = h_gate.control(num_ctrl_qubits=n)

    qc.append(ch_gate, [*k, m[0]])

    return qc
'''


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

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

    h_gate = qiskit.circuit.library.standard_gates.h.HGate()
    ch_gate = h_gate.control(num_ctrl_qubits=n)

    qc.append(ch_gate, [*k, m[0]])

    return qc
'''


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

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

    h_gate = qiskit.circuit.library.standard_gates.h.HGate()
    ch_gate = h_gate.control(num_ctrl_qubits=n)

    qc.append(HGate().control(n), [*k, m[0]])

    return qc
'''


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

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

    qc.append(HGate().control(n), [*k, m[0]])

    return qc
'''


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

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

    qc.x(k)
    qc.append(HGate().control(n), [*k, m[0]])
    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(0)
    qc.compose(HGate().control(n),[*k, *m])
    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(0)
    qc.compose(HGate().control(n),[*k, m[0]], inplace=True)
    qc.x(0)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.compose(HGate().control(len(k)),[*k, m[0]], inplace=True)
    qc.x(k)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.compose(HGate().control(len(k)),[*k, m[0]], inplace=True)
    qc.x(k)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.mh(k, m)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.swap(0, n)
    qc.append(HGate.control(n), range(n + 1))
    qc.swap(n, 0)
    return qc
'''


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

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

    qc.append(HGate().control(n), list(range(1, n+1)) + [0])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here
    for i in range(1, n + 1):
        qc.x[i]
    qc.append(HGate().control(n), list(range(1, n+1)) + [0])

    for i in range(1, n + 1):
        qc.x[i]
    return qc
'''


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

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

    qc.append(HGate().control(n), list(range(1, n+1)) + [0])

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


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if k == 0:
        qc.h(m)
        if m == 1:
            qc.z(k)
        else:
            qc.i(k)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if k == 0:
        qc.h(m)
        if m == 1:
            qc.z(k)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if k == 0:
        qc.h(m)
        qc.append(ZGate().control(n - 1), range(n))
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if k == 0:
        qc.h(m)
        qc.append(ZGate().control(m), range(n))
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if k == 0:
        qc.h(m)
        qc.append(ZGate().control(m), range(k))
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if k == 0:
        qc.h(m)
    return qc
'''


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

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


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    if k == 0:
        qc.h(0)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    return qc
'''


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

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


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

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


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(m)
    qc.x(k)
    qc.compose(HGate().control(len(k)),[*k, *m])
    qc.x(k)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(m)
    qc.x(k)
    qc.compose(XGate().control(len(k)),[*k, *m])
    qc.x(k)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(m)
    qc.x(k)
    qc.compose(XGate().control(len(k)),[*k, m[0]], inplace=True)
    qc.x(k)
    return qc
'''


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

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

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

    return qc
'''


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

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

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

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(i for i in k)
    qc.x(m[0])
    qc.append(XGate().control(n), list(k) + [m[0]])
    qc.x(i for i in k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(XGate().control(n), list(range(1, n+1))+[0])
    qc.x(k)
    qc.x(0)
    return qc
'''


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

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

    for i in range(1, n):
        if k[i] == 0:
            qc.x(k[i])
    control = [i+1 for i in range(n)]
    qc.append(XGate().control(n), [*control, 0])
    for i in range(1, n):
        if k[i] == 0:
            qc.x(k[i])

    return qc
'''


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

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

    control = [i+1 for i in range(n)]
    qc.append(XGate().control(n), [*control, 0])

    return qc
'''


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

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

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

    return qc

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

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


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

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

    if n == 1:
        qc.cx(k[0], m[0])
    elif n == 2:
        qc.cx(k[0], m[0])
        qc.cx(k[1], m[0])
        qc.ccx(k[0], k[1], m[0])
    else:
        for i in range(n):
            qc.x(k[i])

        mcx_gate = MCXGate(num_ctrl_qubits=n)
        qc.append(mcx_gate, [k[i] for i in range(n)] + [m[0]])
        for i in range(n):
            qc.x(k[i])

        qc.x(m[0])

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(XGate().control(n), k[:] + [m[0]])
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(m[0])
    qc.x(k)
    qc.append(XGate().control(n), k[:] + [m[0]])
    qc.x(k)

    return qc
'''


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

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

    if n == 0:
        pass
    else:
       for i in range(n):
            qc.x(k[i])

        if n == 1:
            qc.cx(k[0], m[0])
        else:
            qc.append(HGate().control(n), list(k) + [m[0]])
        for i in range(n):
            qc.x(k[i])
        qc.x(m[0])
    return qc
'''


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

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

    if n == 0:
        pass
    else:
       for i in range(n):
            qc.x(k[i])

        if n == 1:
            qc.cx(k[0], m[0])
        else:
            qc.append(XGate().control(n), list(k) + [m[0]])
        for i in range(n):
            qc.x(k[i])
        qc.x(m[0])
    return qc
'''


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

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

    if n == 0:
        pass
    else:
       for i in range(n):
            qc.x(k[i])

        if n == 1:
            qc.cx(k[0], m[0])
        else:
            qc.append(XGate().control(n), list(k) + [m[0]])
        for i in range(n):
            qc.x(k[i])
        qc.x(m[0])
    return qc
'''


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

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

    if n == 0:
        pass
    else:
       for i in range(n):
            qc.x(k[i])
        if n == 1:
            qc.cx(k[0], m[0])
        else:
            qc.append(XGate().control(n), list(k) + [m[0]])
        for i in range(n):
            qc.x(k[i])
        qc.x(m[0])
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(m[0])

    if n == 0:
        qc.x(m[0])
    else:
        controlled_x_gate = XGate().control(num_ctrl_qubits=n, ctrl_state='0'*n)
        qc.append(controlled_x_gate, list(k) + [m[0]])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.x(k)
    qc.(XGate().append.control(n), list(k) + [m[0]])
    qc.x(k)
    return qc
'''


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

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

    qc.x(k)
    qc.(XGate().append.control(n), list(k) + [m[0]])
    qc.x(k)
    return qc
'''


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

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

    qc.x(k)
    qc.append(XGate().control(n), list(k) + [m[0]])
    qc.x(k)
    return qc
'''


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

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

    for i in range(1, n + 1):
        qc.x(i)
    qc.append(XGate().control(n), list(range(1, n + 1)) + [0])
    for i in range(1, n + 1):
        qc.x(i)

    return qc
'''


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

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

    qc.x(0)
    for i in range(1, n + 1):
        qc.x(i)
    qc.append(XGate().control(n), list(range(1, n + 1)) + [0])
    for i in range(1, n + 1):
        qc.x(i)

    return qc
'''


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

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

    qc.x(m)
    qc.x(k)
    qc.append(XGate().control(n), reversed(range(0, n + 1)))
    qc.x(k)

    return qc
'''


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

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

    for i in range(n):
        qc.x(k[i])
    qc.append(XGate().control(n), reversed(range(n + 1)))
    for i in range(n):
        qc.x(k[i])

    return qc
'''


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

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

    for i in range(n):
        qc.x(k[i])
    qc.append(XGate().control(n), reversed(range(n + 1)))
    for i in range(n):
        qc.x(k[i])
    qc.x(m[0])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    for i in range(n + 1):
        qc.x(i)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

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


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

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

    qc.x(0)

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

    L=[i for i in range(1,n+1)]
    L.append(0)
    qc.append(XGate().control(n),L)

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

    return qc

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


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

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

    qc.append(XGate().control(n), list(range(1,n+1))+[0])
    qc.x(k)
    # Write your code here:

    return qc
'''


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

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

    qc.append(XGate().control(n), list(range(1,n+1))+[0])
    qc.x(k)

    # Write your code here:

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.mcx(k,m)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.mcx(k,m)
    qc.x(k)
    qc.x(m)

    return qc
'''


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

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

    qc.x(k)
    qc.append(XGate().control(n), list(k) + [m[0]])
    qc.x(k)

    return qc
'''


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

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

    qc.x(k)
    qc.mcx(list(k), m[0])
    qc.x(k)

    return qc
'''


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

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

    qc.x(k)
    qc.append(XGate().control(n), list(k) + [m[0]])
    qc.x(k)
    qc.x(m[0])

    return qc
'''


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

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

    qc.x(k)
    qc.append(XGate().control(n), list(k) + [m[0]])
    qc.x(k)
    # qc.x(m[0])

    return qc
'''


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

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

    qc.x(m[0])
    qc.x(k)
    qc.mcx(k, m[0])
    qc.x(k)

    return qc
'''


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

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

    for i in range(n):
        qc.cx(k[i], m[0])

    return qc
'''


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

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

    qc.x(m[0])

    qc.x(k)

    qc.mcx(k, m[0])

    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m = QuantumRegister(1, 'm')
    k = QuantumRegister(n, 'k')
    qc = QuantumCircuit(k, m)
=
    for i in range(n):
        qc.x(k[i])

    qc.h(m[0])
    qc.append(ZGate().control(n), [k[i] for i in range(n)] + [m[0]])
    qc.h(m[0])

    for i in range(n):
        qc.x(k[i])

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m = QuantumRegister(1, 'm')
    k = QuantumRegister(n, 'k')
    qc = QuantumCircuit(k, m)
=
    for i in range(n):
        qc.x(k[i])

    qc.h(m[0])
    qc.append(ZGate().control(n), [k[i] for i in range(n)] + [m[0]])
    qc.h(m[0])

    for i in range(n):
        qc.x(k[i])

    return qc
'''


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

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

    for i in range(n):
        qc.x(k[i])

    qc.h(m[0])
    qc.append(ZGate().control(n), [k[i] for i in range(n)] + [m[0]])
    qc.h(m[0])

    for i in range(n):
        qc.x(k[i])

    return qc
'''


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

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

    qc.x(m)
    qc.x(k)
    qc.append(XGate().control(n), [*k, *m])
    qc.x(k)

    return qc
'''


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

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

    mc_h = XGate().control(n)

    qubits = list(range(n, 0, -1)) + [0]
    qc.append(mc_h, qubits)

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

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.x(m[0])
    qc.x(k)
    qc.mcx(k, m[0])
    qc.x(k)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    if n == 1:
        qc.cx(k[0], m[0])
    else:
        # NOT(k)を作って、全ビット0のとき以外反転
        for i in range(n):
            qc.x(k[i])
        qc.x(m[0]).c_if(qc.cregs[0], 0)  # 古典条件付きではなく下でANDで
        qc.mcx([k[i] for i in range(n)], m[0])  # 多重制御X
        for i in range(n):
            qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    for i in range(n):
        qc.x(k[i])

    # 多重制御X（kが全て1→m反転、つまり元のkが全て0以外）
    qc.mcx([k[i] for i in range(n)], m[0])

    # kを元に戻す
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    if n > 2:
        anc = QuantumRegister(n-2, 'anc')
        qc = QuantumCircuit(m, k, anc)
        # k[0]~k[n-1]がすべて1のとき m[0] にX
        qc.mcx([k[i] for i in range(n)], m[0], ancilla_qubits=anc, mode='v-chain')
    else:
        qc = QuantumCircuit(m, k)
        qc.mcx([k[i] for i in range(n)], m[0])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    qc.x(m[0])

    # k全てにXをかけて「全て1」を「全て0」に写す
    for i in range(n):
        qc.x(k[i])

    # 多重制御X（kが全て1→m反転、つまり元のkが全て0以外）
    qc.mcx([k[i] for i in range(n)], m[0])

    # kを元に戻す
    for i in range(n):
        qc.x(k[i])

    return qc
'''


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

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

    # qc.x(k)
    # qc.x(m)

    qc.x(k)
    qc.append(HGate().control(n), k[:] + m[:])
    qc.x(k)
    qc.z(m)
    qc.x(k)
    qc.append(HGate().control(n), k[:] + m[:])
    qc.x(k)
    qc.x(m)

    return qc
'''


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

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

    # qc.x(k)
    # qc.x(m)

    qc.x(k)
    qc.append(HGate().control(n), k[:] + m[:])
    qc.z(m)
    qc.append(HGate().control(n), k[:] + m[:])
    qc.x(k)
    qc.x(m)

    return qc
'''


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

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

    qc.append(RYGate(-pi / 2).control(n), k[:] + m[:])
    qc.z(m)
    qc.append(RYGate(-pi / 2).control(n), k[:] + m[:])
    qc.x(m)

    return qc
'''


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

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

    qc.append(HGate().control(n, ctrl_state="0"*n), k[:] + m[:])
    qc.z(m)
    qc.append(HGate().control(n, ctrl_state="0"*n), k[:] + m[:])
    qc.x(m)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(m[0])
    for i in range(n):
        qc.x(k[i])
    qc.mcx([*k], m[0])
    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(range(n + 1))
    qc.mcx(k, m)
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.x(k)
    # Write your code here:
    qc.append(CXGate().control(n),k[:]+m[:])
    qc.x(k)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.x(k)
    # Write your code here:
    qc.append(XGate().control(n),k[:]+m[:])
    qc.x(k)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.x(k)
    # Write your code here:
    qc.append(XGate().control(n),k[:]+m[:])
    qc.x(k)
    qc.x(m)
    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.x(k)
    # Write your code here:
    qc.append(XGate().control(n),k[:]+m[:])
    qc.x(k)
    qc.x(m)
    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(n), k[:] + m[:])
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(n), k[:] + m[:])
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(HGate().control(n), list(range(1, n + 1)) + [0])
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(XGate().control(n), list(range(1, n + 1)) + [0])
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(XGate().control(n), list(range(1, n + 1)) + [0])
    qc.x(k)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.append(XGate().control(n), list(range(1, n + 1)) + [0])

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(XGate().control(n), m[:], k[:])
    qc.x(k)
    qc.x(m)
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(XGate().control(n), k[:] + m[:])
    qc.x(k)
    qc.x(m)
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    # Write your code here:
    qc.x(k)
    qc.append(XGate().control(n), k[:] + m[:])
    qc.x(range(n+1))

    return qc
'''


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

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

    for i in range(n):
        controlled_cx = CXGate().control(n, ctrl_state='0' * n)
        qc.append(controlled_cx, k[:] + [m[0]] + [k[i]])

    return qc
'''


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

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

    for i in range(1,n+1):
        qc.x(i)
    # k/n = 1の場合（すべてのkビットが1）にmを反転
    if n == 1:
        qc.cx(k[0], m[0])
    else:
        qc.mcx(k[:], m[0])
    for i in range(1,n+1):
        qc.x(i)

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    for i in range(n):
        qc.x(k[i])

    qc.mcx(k, m[0])

    for i in range(n):
        qc.x(k[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

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

    for i in range(n):
        qc.x(k[i])

    qc.mcx(k, m[0])

    for i in range(n):
        qc.x(k[i])

    qc.x(m[0])

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    qc.append(XGate(), [m[0]])
    qc.append(XGate().control(n, ctrl_state='0'*n), k[:] + [m[0]])
    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    memo = list(range(n + 1))
    while len(memo) >= 2:
        memo2 = []
        while len(memo) >= 2:
            i = memo.pop(0)
            j = memo.pop(0)
            qc.swap(i, j)
            memo2.append(i)
        memo2 += memo
        memo = memo2

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1, name=f"Controlled Increment(n={n})")

    k_qubits = list(range(n))
    m_qubit = n

    qc.append(QFT(n, do_swaps=True, little_endian=True), k_qubits)

    for i in range(n):
        angle = np.pi / (2**i)
        qc.cp(angle, m_qubit, k_qubits[n-1-i])

    qc.append(QFT(n, do_swaps=True, little_endian=True).inverse(), k_qubits)

    return qc
'''


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

def solve(n: int) -> QuantumCircuit:
    qft_builder_qc = QuantumCircuit(n, name='QFT')
    for i in range(n - 1, -1, -1):
        qft_builder_qc.h(i)
        for j in range(i - 1, -1, -1):
            angle = np.pi / (2**(i - j))
            qft_builder_qc.cp(angle, j, i)
    for i in range(n // 2):
        qft_builder_qc.swap(i, n - 1 - i)

    qft_gate = qft_builder_qc.to_gate(label='QFT')
    iqft_gate = qft_gate.inverse()
    iqft_gate.label = 'IQFT'

    qc = QuantumCircuit(n + 1)
    k_qubits = list(range(n))
    m_qubit = n

    qc.append(qft_gate, k_qubits)

    for i in range(n):
        angle = 2 * np.pi / (2**(i + 1))
        qc.cp(angle, m_qubit, k_qubits[i])

    qc.append(iqft_gate, k_qubits)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    if n == 1:
        qc.swap(0, 1)
    elif n == 2:
        qc.swap(2, 1)
        qc.swap(1, 0)
    elif n == 3:
        qc.swap(3, 2)
        qc.swap(2, 1)
        qc.swap(1, 0)
    elif n == 4:
        qc.swap(4, 3)
        qc.swap(3, 2)
        qc.swap(2, 1)
        qc.swap(1, 0)
    else:
        for i in range(n):
            qc.swap(n - i, n - i - 1)

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

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


'''python
from qiskit import QuantumCircuit

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

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

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

    for i in range(0, n - 3, 8):
        qc.swap(i, i + 4)

    for i in range(0, n - 7, 16):
        qc.swap(i, i + 8)
    return qc
'''


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

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

    def shift_r(l: int, r: int) -> None:
        if r - l == 1:
            return
        m = (l + r) >> 1
        qc.swap(m - 1, r - 1)
        shift_r(l, m)
        shift_r(m, r)
    shift_r(0, n)

    return qc
'''


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

def swap(a: int, b: int, n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    qc.cx(a,b)
    qc.cx(b,a)
    qc.cx(a,b)
    return qc

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


'''python
from qiskit import QuantumCircuit

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

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


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

def solve(n) -> QuantumCircuit:
    input, anc = QuantumRegister(n + 1), QuantumRegister(n + 1)
    qc = QuantumCircuit(input, anc)

    def d2swap(x, y):
        qc.append(XXPlusYYGate(np.pi), [x, y])
        qc.append(RZZGate(np.pi / 2), [x, y])

    for i in range(n + 1):
        d2swap(input[i], anc[i])

    d2swap(anc[0], input[-1])
    for i in range(n):
        d2swap(input[i], anc[i + 1])

    return qc
'''


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

def solve(n) -> QuantumCircuit:
    input, anc = QuantumRegister(n + 1), QuantumRegister(n + 1)
    qc = QuantumCircuit(input, anc)

    def d2swap(x, y):
        qc.append(XXPlusYYGate(np.pi), [x, y])
        qc.append(RZZGate(np.pi / 2), [x, y])

    for i in range(n + 1):
        d2swap(input[i], anc[i])

    d2swap(anc[-1], input[0])
    for i in range(n):
        d2swap(input[i - 1], anc[i])

    return qc
'''


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

def solve(n) -> QuantumCircuit:
    input, anc = QuantumRegister(n + 1), QuantumRegister(n + 1)
    qc = QuantumCircuit(input, anc)

    def d2swap(x, y):
        qc.append(XXPlusYYGate(np.pi), [x, y])
        qc.append(RZZGate(np.pi / 2), [x, y])

    for i in range(n + 1):
        d2swap(input[i], anc[i])

    d2swap(anc[-1], input[0])
    for i in range(n):
        d2swap(input[i + 1], anc[i])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    # Write your code here:
    if n > 0:
        qc.swap(k[0], m[0])

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    # Write your code here:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    if n > 0:
        qc.swap(k[0], m[0])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    # Write your code here:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    if n > 0:
        qc.swap(k[0], m[0])

    return qc
'''


'''python
from qiskit import QuantumCircuit, QuantumRegister

def solve(n: int) -> QuantumCircuit:
    # Write your code here:
    m, k = QuantumRegister(1), QuantumRegister(n)
    qc = QuantumCircuit(m, k)
    if n > 0:
       for i in range(n):
        qc.swap(k[i], m[0])

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    for i in range(n):
        qc.swap(i, n)  # n番目のビットが |m⟩

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

      qc.x(range(n + 1))  # 全ビットを反転
    qc.mcz(list(range(n)), n)  #
    qc.x(range(n + 1))  # 元に戻す

    return qc
'''


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

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

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n)
    for i in range(4):
        for j in range(0, n - 2**i, 2 * 2**i):
            qc.swap(j,j+2**i)

    return qc
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    n=n+1
    qc = QuantumCircuit(n)
    for i in range(4):
        for j in range(0, n - 2**i, 2 * 2**i):
            qc.swap(j,j+2**i)

    return qc
s
'''


'''python
from qiskit import QuantumCircuit

def solve(n: int) -> QuantumCircuit:
    qc = QuantumCircuit(n + 1)
    n+=1
    for i in range(4):
        for j in range(0, n - 2**i, 2 * 2**i):
            qc.swap(j,j+2**i)

    return qc
'''


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

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

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

    gao(0, n + 1)
    return qc

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