def count_typos(s1, s2, flags1, flags2, typo_table):
    """
    Check unmatched characters in strings 's1' and 's2' for typos.

    The typos (or known phonetic or character recognition errors) are
    defined in the 'typo_table' argument, which defines the mapping between
    similar characters, and a score to assign to each. [See the
    typo_tables.py module].

    The function returns the total typo score, and updates the 'field2' bit
    array to mark which characters were adjudged similar.
    """
    assert 0 in flags1
    typo_score = 0
    for i, flag1 in enumerate(flags1):
        if flag1:
            continue
        row = s1[i]
        if row not in typo_table:
            continue
        typo_row = typo_table[row]
        for j, flag2 in enumerate(flags2):
            if flag2:
                continue
            col = s2[j]
            if col not in typo_row:
                continue
            typo_score += typo_row[col]
            flags2[j] = 2
            break
    return typo_score, flags2
