Implement pagination with the ability to navigate forward and backward, keeping track of the indices of the first and last records on the current page.
Implement paginate(records, page_size, actions). Return the initial page followed by a snapshot after each action. Each snapshot contains records, first_index, and last_index; use null indices when records is empty. Actions are the strings "next" and "prev", and navigation must remain within the available pages.
def paginate(records, page_size, actions):