Explain the difference between stack and heap memory.
Implement a small memory simulator that models stack values with last-in, first-out behavior and heap values with independently controlled lifetimes. Given valid operations, return the remaining stack values and currently allocated heap values in allocation order.
Function signature: simulate_memory(operations) Each operation is an array such as ["stack_push", id], ["stack_pop"], ["heap_alloc", id], or ["heap_free", id]. Return a dictionary with stack and heap arrays.
def simulate_memory(operations):