import java.util.*;
import java.io.*;

public class MultiAnagram {
    public static void main(String[] args) {
        int minGroupSize = Integer.parseInt(args[1]);

        //Read words from file and put into a simulated multimap
        MultiMap<String,String> m = new MultiMap<String,String>();
       
        try {
            //peut lever FileNotFoundException
            Scanner s = new Scanner(new File(args[0]));
            String word;
            while(s.hasNext()) {
                word = s.next();
                String alpha = alphabetize(word);
                m.put(alpha,word);
            }
            s.close(); // ne lève pas d'exception
        } catch(IOException e) {
            System.err.println(e);
            System.exit(1);
        }

        //Print all permutation groups above size threshold
        for (String key : m.keySet()) {
            if (m.get(key).size() >= minGroupSize)
                System.out.println(m.get(key).size() + ": " + m.get(key));
        }
    }

    private static String alphabetize(String s) {
        char[] tab = s.toCharArray();
        Arrays.sort(tab);  
        return new String(tab);
    }
}
