<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _make_ram_program(program):
 """ Check that this program is a series of quantum gates with terminal MEASURE instructions; pop MEASURE instructions. :param program: The program :return: A new program with MEASURE instructions removed. """

    new_prog = program.copy_everything_except_instructions()
    last_qubit_operation = {}
    times_qubit_measured = defaultdict(lambda: 0)
    ro_size = None
    qubit_to_ram = {}

    for instr in program:
        if isinstance(instr, Pragma):
            new_prog += instr
        elif isinstance(instr, Declare):
            if instr.name == 'ro':
                if instr.memory_type != 'BIT':
                    raise NotRunAndMeasureProgramError("The readout register `ro` "
                                                       "must be of type BIT")
                ro_size = instr.memory_size
            new_prog += instr
        elif isinstance(instr, Gate):
            for qubit in instr.qubits:
                last_qubit_operation[qubit.index] = 'gate'
            new_prog += instr
        elif isinstance(instr, Measurement):
            if instr.classical_reg is None:
                raise NotRunAndMeasureProgramError("No measure-for-effect allowed")
            if instr.classical_reg.name != 'ro':
                raise NotRunAndMeasureProgramError("The readout register must be named `ro`, "
                                                   "not {}".format(instr.classical_reg.name))
            last_qubit_operation[instr.qubit.index] = 'measure'
            times_qubit_measured[instr.qubit.index] += 1
            qubit_to_ram[instr.qubit.index] = instr.classical_reg.offset
        else:
            raise NotRunAndMeasureProgramError(f"Unsupported r_a_m instruction {instr}")

    for q, lqo in last_qubit_operation.items():
        if lqo != 'measure':
            raise NotRunAndMeasureProgramError(f"Qubit {q}'s last operation is a gate")

    for q, tqm in times_qubit_measured.items():
        if tqm > 1:
            raise NotRunAndMeasureProgramError(f"Qubit {q} is measured {tqm} times")

    if ro_size is None:
        raise NotRunAndMeasureProgramError("Please declare a readout register")

    return new_prog, qubit_to_ram, ro_size