#K75457. Music Library Operations

    ID: 34423 Type: Default 1000ms 256MiB

Music Library Operations

Music Library Operations

You are given a music library management system that supports the following operations:

  • ADD name popularity: Adds a music record with the given name and an integer popularity (from 1 to 10). If the record already exists, update its popularity.
  • DELETE name: Deletes the record with the given name from the collection. If the record does not exist, ignore this operation.
  • FIND: Returns the record with the highest popularity index. In case of a tie, return the record with the lexicographically smallest name. If the library is empty, print NOT FOUND.
    Formally, if the set of records is \( R = \{(n, p)\} \), then the result is the pair \((n^*, p^*)\) such that \(p^* = \max_{(n, p) \in R} p\) and \(n^* = \min\{n \mid (n, p^*) \in R\}\).
  • PRINT: Prints all records sorted lexicographically by name. Each record is printed in the format name popularity on a new line. If the library is empty, print NOT FOUND.

The input begins with an integer \( Q \) denoting the number of operations, followed by \( Q \) lines of operations. Process the operations in the given order and print the result of each FIND and PRINT operation on a new line.

inputFormat

The first line contains an integer \( Q \) indicating the number of operations. Each of the next \( Q \) lines contains one of the following commands:

  • ADD name popularity
  • DELETE name
  • FIND
  • PRINT

Input is read from standard input (stdin).

outputFormat

For each FIND and PRINT operation, print the appropriate result on a new line. Each result should be printed to standard output (stdout). Note that for the PRINT operation, if there are multiple lines in the result, they should be printed in the same order as described.

## sample
3
ADD rockstar 5
ADD believer 8
FIND
believer 8