#K91747. Playlist Management

    ID: 38044 Type: Default 1000ms 256MiB

Playlist Management

Playlist Management

This problem simulates a music streaming service's playlist. The playlist supports four operations:

  • add x: Append song ID x to the end of the playlist.
  • remove x: Remove the first occurrence of song ID x from the playlist (if it exists).
  • find x: Return the 1-indexed position of the first occurrence of song ID x in the playlist. If the song is not found, return -1.
  • query x: Return the song ID at the 1-indexed position x in the playlist. If the position is out of range, return -1.

All positions are 1-indexed. Your task is to process all operations sequentially and print the results of the find and query operations one per line.

Note: If a song to be removed is not present, do nothing.

The mathematical formulation for the position is given by: \[ \text{position} = \begin{cases} \text{index of } x + 1, & \text{if } x \text{ exists in the list}\\ -1, & \text{otherwise} \end{cases} \]

inputFormat

The input is read from stdin and consists of:

  1. An integer q denoting the number of queries.
  2. q lines each containing a query of the form:
  • add x
  • remove x
  • find x
  • query x

Here, x is an integer.

outputFormat

For each find or query operation, output the answer on a separate line to stdout.

## sample
5
add 101
add 203
find 101
query 2
remove 101
1

203

</p>