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

public class TextReader {
    static boolean testText(String text) {
        for (int i = 0; i < text.length(); i++) {
            char c = text.charAt(i);
            if (!(
                c >= 'a' && c <= 'z' ||
                c >= 'A' && c <= 'Z' ||
                c == ' ' ||
                c == '.' ||
                c == ',' ||
                c == '-' ||
                c == '?' ||
                c == '!' ||
                c == ':' ||
                c == ';' ||
                c == '\'' ||
                c == '"' 
            )) {
                System.out.println(c);
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader textR = new BufferedReader(new FileReader(args[0]));
        StringBuilder text = new StringBuilder();
        String line;
        ArrayList<String> lines = new ArrayList<String>();
        while ((line = textR.readLine()) != null) {
            text.append(line);
            lines.add(line);
        }
        if (text.length() > 10000) {
            System.out.println("Text is too long");
        }

        String txt = text.toString();
        if (!testText(txt)) {
            System.out.println("The text contains some illegal symbols");
        }
        HashSet<String> words = new HashSet<String>();
        StringTokenizer st = new StringTokenizer(txt, " .,:;!?-'\"");
        while (st.hasMoreTokens()) {
            words.add(st.nextToken());
        }


        if (args[2].equals("-EXTRA")) {
            words.add("heptaparaparsinokh");
        } else if (args[2].equals("-LACK")) {
            Iterator<String> it = words.iterator();
            String fw = it.next();
            words.remove(fw);
        }
        if (words.size() > 1000) {
            System.out.println("The number of words exceed 1000");
        }

        PrintWriter out = new PrintWriter(args[1]);
        out.println(words.size() + " " + lines.size());
        for (String word : words) {
            out.println(word.toLowerCase());
        }
        for (String ln : lines) {
            out.println(ln);
        }
        out.close();
    }
}