import java.util.*;

class DinesmanMultipleDwelling {

    private static void generatePermutations(String[] apartmentDwellers, Set<String> set, String curPermutation) {
        for (String s : apartmentDwellers) {
            if (!curPermutation.contains(s)) {
                String nextPermutation = curPermutation + s;
                if (nextPermutation.length() == apartmentDwellers.length) {
                    set.add(nextPermutation);
                } else {
                    generatePermutations(apartmentDwellers, set, nextPermutation);
                }
            }
        }
    }

    private static boolean topFloor(String permutation, String person) {