long (List<List<String>> nested) { long count = 0L; for (List<String> names : nested) { Set<String> uniqueValues = new HashSet<>(); for (String name : names) { if (uniqueValues.add(name)) { count++; } } } return count; }