from typing import List
import re


def level_counts(
    prefixes: List[List[str]],
    labels: List[List[re.Pattern]],
) -> List[List[int]]:
    """ generate list of the counts of leaves that sum to each node in the hierarchy

    Arguments:
        prefixes {List[List[str]]} -- location prefixes (one list for each level of hierarchy)
        labels {List[List[re.Pattern]]} -- location regexes (one list for each level of hierarchy)

    Returns:
        List[List[int]] -- list of the counts of leaves that sum to each node, 
            one list for each level in the hierarchy
    """

    prefix_1, prefix_2, prefix_3 = prefixes
    _, zone_labels, state_labels, _, _, _ = labels

    country_cts = [1]
    state_cts = [len(prefix_1)]
    zone_cts = [
        len(list(filter(regex.match, prefix_2))) 
        for regex in state_labels
    ]
    region_cts = [
        len(list(filter(regex.match, prefix_3))) 
        for regex in zone_labels
    ]
    return [country_cts, state_cts, zone_cts, region_cts]