A forward-only stream cannot revisit old elements unless they are buffered. You are given a finite list `stream` representing the values that would arrive from such a stream, plus operations on a stream-backed recoverable iterator. Supported operations are `('hasNext',)`, `('next',)`, `('save',)`, `('restore', token)`, and `('release', token)`. `save()` returns a token for the current logical position. `restore(token)` moves the cursor back to that position. `release(token)` means that snapshot will never be used again. The iterator should keep only the minimum data needed for future restores: after each operation, it may discard every buffered element whose position is strictly before `min(current_cursor, all_unreleased_snapshot_positions)`; if there are no unreleased snapshots, use `current_cursor`. Return both the operation results and the maximum retained buffer size. Assume cleanup happens immediately after each operation, so `max_buffer_size` is measured after that cleanup.
Examples
Input: ([10, 20, 30], [('save',), ('next',), ('next',), ('save',), ('restore', 0), ('next',), ('release', 0), ('next',), ('release', 1)])
Expected Output: ([0, 10, 20, 1, None, 10, None, 20, None], 2)
Explanation: Because snapshot 0 points to the beginning, the first two values must stay buffered until that snapshot is released.
Input: ([], [('hasNext',), ('next',), ('save',), ('restore', 0), ('release', 0)])
Expected Output: ([False, None, 0, None, None], 0)
Explanation: An empty stream never stores any buffered data.
Input: ([5, 6], [('next',), ('hasNext',), ('next',), ('hasNext',)])
Expected Output: ([5, True, 6, False], 0)
Explanation: With no saved states, each consumed stream element can be discarded immediately, so the retained buffer size stays 0.
Input: ([1], [('save',), ('next',), ('save',), ('restore', 0), ('next',), ('restore', 1), ('hasNext',), ('release', 0), ('release', 1)])
Expected Output: ([0, 1, 1, None, 1, None, False, None, None], 1)
Explanation: The first snapshot forces the single streamed value to stay buffered until token 0 is released; token 1 represents the end state.