def count_chars(template: str, instructions: dict[str, str], n: int) -> int:
    """
    Counts the characters in the would-be string after `n` steps and
    returns the highest count (most common) - lowest count (least common).

    Args:
        template (str): The polymer template e.g. "NNCB"
        instructions (dict[str, str]): The pair instructions as a dictionary
            e.g. {"CH": "B"} etc.
        n (int): Number of steps.

    Returns:
        int: Most common count - Least common count
    """
    # We don't actually care about the string, just the quantity of pairs
    # if we see a pair, we inject a new letter into the middle according
    # to the instructions, therefore every one of those 2 character pairs becomes 3 characters
    # and 2 new pairs are created
    # e.g. if we see 'CH' and the instruction is CH -> B
    # we create the 3 character sequence: 'CBH'
    # and 2 new pairs: 'CB' and 'BH'

    pair_counts = {pair: template.count(pair) for pair in instructions}
    char_counts = {char: template.count(char) for char in instructions.values()}

    for i in range(n):
        # Take a copy to prevent modifying while iterating
        for pair, value in pair_counts.copy().items():
            # Found the pair e.g. 'CH' which we're going to replace
            # with whatever the instruction says so this pair now occurs
            # 'value' less times (because we replace them all)
            pair_counts[pair] -= value

            # Form the new pair based on the first character of the old
            # and whatever the instructions tell us to put next
            # and increase their count
            pair_counts[pair[0] + instructions[pair]] += value

            # Same for the new pair formed by the now middle
            # replacement character and the last character of the old pair
            pair_counts[instructions[pair] + pair[1]] += value

            # Bump the character counts
            char_counts[instructions[pair]] += value

    answer = max(char_counts.values()) - min(char_counts.values())
    return answer