/************************************************
Grundlegende Algorithmen mit Java,
http://algorithmen-und-problemloesungen.de/
Copyright @2007-2008 by Doina Logofatu
************************************************/

import java.io.*;
import java.util.*;

public class P12Compactation {
    private static final String FileInputName = "tests.in";
    private static final String FileOutputName = "tests.out";
    
    private static boolean compatibleChars(char c1, char c2){
        return c1 == c2   || c1 == 'X' ||  c2 == 'X';
    }
    
    private static boolean compatibleLines(String str1, String str2) {
        int len = str1.length();
        if (len != str2.length()) return false;
        for(int i = 0;i<len;i++) 
            if(!compatibleChars(str1.charAt(i), str2.charAt(i)))
                return false;
        return true;               
    }

    private static char mergeChars(char c1, char c2) {
        return compatibleChars(c1, c2)?('X' == c1 ? c2 : c1) : '*';                  
    } 

    private static String mergeLines(String str1, String str2) {
        int len = str1.length();
        if (len != str2.length())  return null;
        char chars[] = new char[len];
        for (int i = 0; i < len; i++) {
            chars[i] = mergeChars(str1.charAt(i), str2.charAt(i));
        }
        return new String(chars);
    } 
    
    private static void recExactCompact(List<String> v, List<String> vRet) {
        List<String> vCopy  = new ArrayList<String>(v);
        boolean compact = true;
        for (int i = 0; i < vCopy.size() - 1; i++)
            for (int j = i + 1; j < vCopy.size(); j++)
                if (compatibleLines(vCopy.get(i), vCopy.get(j))) {
                    compact = false;
                    String str = mergeLines(vCopy.get(i), vCopy.get(j));
                    vCopy.remove(i);
                    vCopy.remove(j - 1);
                    vCopy.add(str);
                    recExactCompact(vCopy, vRet);
                }

        if (compact) {
            if (vRet.size() > vCopy.size()) {
                vRet.clear();
                for (int i = 0; i < vCopy.size(); i++)
                    vRet.add(vCopy.get(i));
            }
            return;
        }
    } 
    
    private static double doRecExactCompact
        (List<String> v, List<String> vRet, PrintStream out) {
        recExactCompact(v, vRet);
        out.print(v.size()); out.print(' ');
        out.println(v.get(0).length()); 
        out.print(vRet.size()); out.print(' ');
        out.print(vRet.size()*100.0/v.size());
        out.println('%');
        out.println();        
        for (String s : vRet) {
            out.println(s);
        }        
        return vRet.size()*100.0/v.size();
    }
    
    public static void main(String[] args) throws IOException {
        Scanner sc = null;
        PrintStream out = null;
        try {
            out = new PrintStream(new File(FileOutputName));
            sc = new Scanner(new File(FileInputName));
            List<String> v = new ArrayList<String>();
            while(sc.hasNext()) {
                v.add(sc.next());
            }
            List<String> vRet = new ArrayList<String>(v);
            doRecExactCompact(v, vRet,out);
        }
        finally {
            if (sc != null) {
                sc.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
}



