from typing import Counter


def wordle_judge(input_word: str, answer_word: str)-> int:
    """
    Judge input word based on the wordle rule
    
    We assume input_word and answer_word are of the same length (but no check is conducted)

    Judge results are defined as a sequence of {0, 1, 2}, where
      2: exact, 1: partial, 0: none
    Return value is the base-10 integer value that represents this result interpreted as an integer of base 3.

    e.g. 22001 --> 2 * 3^4 + 2 * 3*3 + 0 * 3^2 + 0 * 3^2 + 1 * 3^0 = 181
    """
    
    exactmatch = [a==b for a, b in zip(input_word, answer_word)]
    lettercount = Counter(b for b, m in zip(answer_word, exactmatch) if not m)
    partialmatch = [False] * len(input_word)
    for i, (a, m) in enumerate(zip(input_word, exactmatch)):
        if m: continue
        if lettercount.get(a, 0) > 0:
            lettercount[a] -= 1
            partialmatch[i] = True
    out = 0
    power = 1
    for x, y in zip(reversed(exactmatch), reversed(partialmatch)):
        if x:
            out += power*2
        elif y:
            out += power
        power *= 3
    return out