#C2944. Group Files by Content

    ID: 46316 Type: Default 1000ms 256MiB

Group Files by Content

Group Files by Content

You are given an integer \( n \) representing the number of files, followed by \( n \) lines. Each line contains a file identifier and a string representing the file content. Your task is to group files that have exactly the same content.

The groups should be output according to the following rules:

  • Groups with more files should come first.
  • If two groups have the same number of files, they should be ordered by the lexicographical order of their file content (i.e. the content string).
  • Within each group, the file identifiers should be sorted in increasing order and printed on one line separated by a single space.

Example: For input

5
101 abcd
102 efgh
103 abcd
104 ijkl
105 efgh
The duplicate file groups are:

  • "abcd" appears in files 101 and 103.
  • "efgh" appears in files 102 and 105.
  • "ijkl" appears only once.

Sorted by the rules, the output is:

101 103
102 105
104

inputFormat

The first line contains an integer \( n \) (\( 1 \leq n \leq 10^5 \)), representing the number of files.

The next \( n \) lines each contain a file ID (a positive integer) and a file content (a non-empty string without spaces), separated by a space.

outputFormat

Output the groups of file IDs (one group per line). Within each group, the file IDs must be in increasing order and separated by a single space. The groups should be printed in order: first by descending group size, and if the sizes are equal, by the lexicographical order of the file content.

## sample
5
101 abcd
102 efgh
103 abcd
104 ijkl
105 efgh
101 103

102 105 104

</p>