def par_insertion(pairs, chars, rules, steps):
    """
    Apply steps of par insertion to the polymer template.
    :param pairs: template pairs
    :param chars: counter of characters
    :param steps: number of required steps
    :return: pairs, chars
    """
    for _ in range(steps):
        for (a, b), value in pairs.copy().items():
            insertion = rules[a + b]
            pairs[a + b] -= value
            pairs[a + insertion] += value
            pairs[insertion + b] += value
            chars[insertion] += value

    return pairs, chars