Duplicate Uploads in the Asset Bucket
The web team uploads images, scripts and fonts to a shared object bucket, and over the years the same files have been uploaded under different names. The storage team exported a listing of the bucket: for every object it gives the object's path, its size in bytes and a 32-hex-digit checksum of its contents.
Two objects are duplicates of each other exactly when they have the same size and the same checksum. Objects with the same checksum but different sizes, or the same size but different checksums, are not duplicates.
Find every duplicate group: a maximal set of at least two objects that are all duplicates of each other. Inside a group, list the paths in lexicographic order. List the groups in lexicographic order of their smallest path.
The team will keep one copy from every group and delete the rest. Also report how many bytes that
frees: for each group of k objects of size s, that's (k − 1)·s bytes.
Paths are compared character by character by ASCII code, and a path that is a proper prefix of
another comes first. In ASCII, - < . < / < digits < _ < lowercase letters.
Input
The first line contains n (1 ≤ n ≤ 10^5), the number of objects.
Each of the next n lines describes one object as three space-separated fields: the path p, the
size s and the checksum c.
phas 1 to 40 characters, each a lowercase letter, a digit, or one of/,.,_,-. All paths are distinct.sis an integer, 0 ≤ s ≤ 10^12.cis exactly 32 characters, each a digit or a lowercase letter fromatof.
Output
On the first line print g, the number of duplicate groups.
Then print g lines, one per group in the order described above. Each line lists the group's paths
in lexicographic order, separated by single spaces.
On the last line print the total number of bytes freed. It can exceed 2^31, so use a 64-bit integer.
Notes
In the first example, logo.png and img/logo-old.png share size and checksum, and so do the three
copies of app.js. The file img/logo-2x.png has the same checksum as the logo but a different
size, so it's not a duplicate. The freed bytes are 1·4096 + 2·5000000000 = 10000004096.
In the second example every object is different, so there are no groups and nothing is freed.