#K68037. Average Rating Calculator

    ID: 32775 Type: Default 1000ms 256MiB

Average Rating Calculator

Average Rating Calculator

You are given a list of ratings for various items. Each rating consists of an item identifier and an integer rating. Your task is to compute the average rating for each item using the formula \(\text{average} = \frac{\text{total rating}}{\text{number of ratings}}\) rounded to two decimal places.

After computing the average ratings, output each unique item along with its average rating. The output must be sorted by the average rating in descending order. In case of a tie, sort the items in ascending lexicographical order based on the item identifier.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer \(n\), which represents the number of ratings.
  • The next \(n\) lines each contain a string and an integer separated by space. The string is the item identifier and the integer is its rating.

outputFormat

Output to standard output (stdout) all unique items, each on its own line, in the following format:

item_identifier average_rating

The average rating must be rounded to two decimal places. The items must be sorted in descending order by average rating. If two items have the same average rating, they should appear in ascending lexicographical order.

## sample
5
item1 4
item1 5
item2 3
item3 5
item2 2
item3 5.00

item1 4.50 item2 2.50

</p>