#C3591. Product Usage Tracker

    ID: 47035 Type: Default 1000ms 256MiB

Product Usage Tracker

Product Usage Tracker

You are given a list of product usage logs. Your task is to count the number of times each product appears in the list. More formally, for any product ( p ), its usage count is defined as:

[ \text{count}(p) = \sum_{i=1}^{N} [\text{logs}_i = p]
]

where ([\text{condition}]) is 1 if the condition holds true and 0 otherwise.

After counting, print each product along with its frequency sorted in lexicographical order. Each line of the output should contain a product and its count separated by a space.

inputFormat

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

  • The first line contains an integer ( N ) representing the number of log entries.
  • Each of the next ( N ) lines contains a single product name (a non-empty string).

outputFormat

Print to standard output (stdout) the usage count for each product. The products must be sorted in lexicographical order. For each product, output a line with the product name and its count separated by a space. If there are no log entries (i.e. ( N = 0 )), do not print anything.## sample

3
keyboard
keyboard
keyboard
keyboard 3

</p>