from pathlib import Path


def read_polymer(filename: Path) -> tuple[dict, str]:
    """Read polymer structure information from a file

    The polymer is represented by a dict of rules and a polymer structer.

    Args:
        filename (Path): path to the input file.

    Returns:
        dict:   rules
        str:    initial polymer structure

    Examples:
        >>> read_polymer(Path("test_data/day_14.data"))[0]['CH']
        'B'
        >>> read_polymer(Path("test_data/day_14.data"))[1]
        'NNCB'
    """
    with filename.open("r") as file:
        poly_template, rules_raw = file.read().split("\n\n")
    rules = {}
    for line in rules_raw.strip().split("\n"):
        start, end = line.strip().split(" -> ")
        rules[start] = end

    return rules, poly_template