A sampling profiler periodically records the current call stack of a running program. Each sample is a pair [timestamp, stack], where stack is a list of frame names ordered from the outermost (root) frame to the innermost (currently executing) frame.
Given a chronologically ordered list of such samples, produce a flat list of trace events. Each event is a tuple of the form (timestamp, action, frame_name) where action is either the string "start" or "end".
Rules for emitting events:
Return the full list of events. If the input is empty, return an empty list.
Write a function stacks_to_trace(samples) that returns this list of event tuples.