from typing import List
from typing import Counter
from typing import Dict


def count_lanternfish(contents: List[str], days: int = 80) -> int:
    """Count number of lanternfish after certain days given initial population.

    Args:
        contents (List[str]): the file contents
        days (int, optional): number of days to count generation

    Returns:
        int: number of lanternfish

    """
    population = [int(fish) for fish in contents[0].split(',')]
    count = dict(Counter(population))
    for _ in range(days):
        new_count: Dict[int, int] = {}
        for fish_day in range(8, 0, -1):
            if fish_day not in count:
                continue
            new_count[fish_day - 1] = count[fish_day]

        if 0 in count:
            new_count[6] = count[0] + new_count.get(6, 0)
            new_count[8] = count[0] + new_count.get(8, 0)
        count = new_count

    return sum(count.values())