from typing import Union
from pathlib import Path
from typing import List
from typing import Counter


def second(filename: Union[str, Path]) -> int:
    """
    For each group of letters (separated by a double newline), count the
    number of letters that appear on all the lines in the group. Then
    return the total number of such letters. (Letters do not need to
    be distinct _between_ groups, only within groups.)
    """
    with open(filename, "rt") as infile:
        groups: List[str] = infile.read().strip().split("\n\n")

    split_groups: List[List[str]] = [group.split("\n") for group in groups]

    return sum(
        sum(val == len(group) for val in Counter("".join(group)).values())
        for group in split_groups
    )