import re


def merge_pair(pair: tuple, voc_in: dict) -> dict:
    """
    Merge the most frequent pair
    :param pair: one character pair, e.g., the most frequent character pair
    :param voc_in: Input vocabulary
    :return voc_out: Output vocabulary after merge
    """
    voc_out = {}
    bigram = re.escape(' '.join(pair))
    p = re.compile(r'(?<!\S)' + bigram + r'(?!\S)')
    for word in voc_in:
        w_out = p.sub(''.join(pair), word)
        voc_out[w_out] = voc_in[word]
    return voc_out