The framework of Grover’s algorithm is shown in Figure from Qiskit.

But I didn’t understand the tutorial’s construction rules for U_f. If there are four qubits, labeled 0001, 0010, 1001, and 1110, how to design U_f? If there are 5 bits, labeled 00101, 01010, 10101, and 11110, how to design U_f? Can you summarize in code how Uf imposes CZ gates?