/*
 * I. 489.
 * Mócsy Mátyás, 10.
 * Szent István Gimnázium, Budapest
 */

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class i489 {

    public static final String[] family = new String[]{"En", "Apa", "Anya", "Mama", "Papa", "Ocsi", "Hugi"};
    public static String[] places;
    public static String[] dates;
    public static String[][] people;
    public static ArrayList<String> friends;
    public static ArrayList<String> everyone;
    public static int kepCount = 0;

    public static void main(String[] args) throws Exception, Error {
        RandomAccessFile raf = new RandomAccessFile("kepszem.txt", "r");
        raf.seek(0);
        kepCount = Integer.parseInt(raf.readLine());
        StringTokenizer st;
        places = new String[kepCount];
        dates = new String[kepCount];
        people = new String[kepCount][];
        for (int i = 0; i < kepCount; i++) {
            st = new StringTokenizer(raf.readLine());
            places[i] = st.nextToken();
            dates[i] = st.nextToken();
            people[i] = new String[st.countTokens()];
            for (int j = 0; j < people[i].length; j++) {
                people[i][j] = st.nextToken();
            }
        }
        //input kész
        System.out.println("1. feladat:");
        int friends = getAllFriends();
        System.out.println("Tamasnak " + friends + " ismerose szerepel a kepeken.");
        //1. kész
        System.out.println("2. feladat:");
        System.out.println(noDateAndPlaceCount() + " kep keszitesenek ideje es helye ismeretlen.");
        //2.kész
        System.out.println("3. feladat:");
        System.out.println(getMostPeopleCount() + " embernel nincs több egy kepen sem.");
        //3. kész
        System.out.println("4. feladat:");
        String[] s = everyone.toArray(new String[]{});
        Arrays.sort(s);
        System.out.println("A kepeken szerepel: " + toString(s) + ".");
        //4. kész
        System.out.println("5. feladat: ");
        System.out.print("Kerem adj meg egy szereplot: ");
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String name = reader.readLine();
        String both = getWith(name);
        System.out.println(both);
        //5. kész
        System.out.println("6. feladat: ");
        System.out.println("Csaladi tablo");
        printTablo();
    }

    public static void printTablo() {
        for (int i = 0; i < kepCount; i++) {
            printTabloLine(i);
        }
    }

    public static void printTabloLine(int i) {
        String en = "En";
        int c = 0;
        for (String s : people[i]) {
            if (!s.equals(en) && isFamily(s)) {
                c++;
            }
        }
        if (c >= 2) {
            String place = to16(places[i]);
            String date = to16(dates[i]);
            String[] p = people[i];
            Arrays.sort(p);
            String peeps = toTabloString(p);
            System.out.println(place + date + peeps);
        }
    }

    public static String to16(String s) {
        while (s.length() < 16) {
            s += " ";
        }
        return s;
    }

    public static String getWith(String name) {
        String en = "En";
        String string = "Tamas es " + name + " kozos idopontjai: ";
        for (int i = 0; i < kepCount; i++) {
            String[] s = people[i];
            boolean hasEn = false;
            boolean hasName = false;
            for (String st : s) {
                if (st.equals(en)) {
                    hasEn = true;
                }
                if (st.equals(name)) {
                    hasName = true;
                }
            }
            if (hasEn && hasName && !dates[i].equals("-")) {
                string += dates[i] + " ";
            }
        }
        if (string.equals("Tamas es " + name + " kozos idopontjai: ")) {
            string = "Tamas es " + name + " nem szerepel kozosen ismert idopontban keszitett kepen.";
        } else {
            string = string.trim();
        }
        return string;
    }

    public static String toTabloString(String[] str) {
        String s = "";
        for (String st : str) {
            if (isFamily(st)) {
                s += st + " ";
            }
        }
        if (!s.equals("")) {
            s = s.substring(0, s.length() - 1);
        }
        return s;
    }

    public static String toString(String[] str) {
        String s = "";
        for (String st : str) {

            s += st + ", ";
        }
        if (!s.equals("")) {
            s = s.substring(0, s.length() - 2);
        }
        return s;
    }

    public static int getMostPeopleCount() {
        int max = 0;
        for (int i = 0; i < people.length; i++) {
            if (people[i].length > max) {
                max = people[i].length;
            }
        }
        return max;
    }

    public static int noDateAndPlaceCount() {
        int count = 0;
        for (int i = 0; i < kepCount; i++) {
            if (dates[i].equals("-") && places[i].equals("-")) {
                count++;
            }
        }
        return count;
    }

    public static int getAllFriends() {//friends lista feltöltése
        friends = new ArrayList<String>();
        everyone = new ArrayList<String>();
        for (int i = 0; i < people.length; i++) {
            for (String s : people[i]) {
                if (!friends.contains(s)) {
                    if (!everyone.contains(s)) {
                        everyone.add(s);
                    }
                    if (!isFamily(s)) {
                        friends.add(s);
                    }
                }
            }
        }
        return friends.size();
    }

    public static boolean isFamily(String s) {
        for (String s1 : family) {
            if (s1.equals(s)) {
                return true;
            }
        }
        return false;
    }    
}
