#C7462. Compress Consecutive Log Entries

    ID: 51336 Type: Default 1000ms 256MiB

Compress Consecutive Log Entries

Compress Consecutive Log Entries

You are given a series of log entries. Each entry is a string provided in the order they occur. Your task is to compress the log entries by replacing consecutive identical entries with a single instance of that entry followed by the number of repetitions, but only if the number of repetitions is greater than one (i.e. when \(k>1\)). Otherwise, if an entry appears only once consecutively, output the entry as it is.

For example, if the input log entries are:

INFO
INFO
WARN
ERROR
ERROR
ERROR

Then, the compressed output is:

INFO2 WARN ERROR3

Implement a solution that reads input from stdin and outputs the result to stdout in one line with each compressed log entry separated by a single space.

inputFormat

The input is read from standard input.

  • The first line contains an integer \(n\) representing the number of log entries.
  • The following \(n\) lines each contain one log entry (a non-empty string).

outputFormat

Output the compressed log entries on one line. Consecutive identical entries are compressed into a single entry followed immediately by the count if the count is greater than one. Entries are separated by a single space.

## sample
6
INFO
INFO
WARN
ERROR
ERROR
ERROR
INFO2 WARN ERROR3