#K8526. Error Log Frequency Analysis

    ID: 36602 Type: Default 1000ms 256MiB

Error Log Frequency Analysis

Error Log Frequency Analysis

You are given a list of error logs recorded in a day. Each error log is a string in the format timestamp error_code where timestamp is a string representing the time stamp and error_code is an alphanumeric error code.

Your task is to determine the most frequent and least frequent error codes. In case there are ties, output the lexicographically smallest error code among those tied.

Let \(f(c)\) denote the frequency of the error code \(c\). You are to find error codes \(c_m\) and \(c_l\) such that:

  • \(c_m = \min\{ c \mid f(c) = \max_{d} f(d) \}\)
  • \(c_l = \min\{ c \mid f(c) = \min_{d} f(d) \}\)

Print both error codes separated by a space.

inputFormat

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

n
log1
log2
...
logn

Where the first line contains an integer \(n\) representing the number of error logs. The next \(n\) lines each contain an error log in the format "timestamp error_code".

outputFormat

Output to stdout a single line containing two error codes separated by a space. The first is the most frequent error code and the second is the least frequent error code (with lexicographical order tie-breaking).

## sample
6
2021-10-15 08:23:45 E001
2021-10-15 09:47:21 E001
2021-10-15 10:15:00 E002
2021-10-15 11:05:34 E003
2021-10-15 14:31:12 E002
2021-10-15 16:18:40 E003
E001 E001

</p>