def base41_decode(input):
    """Decode a Base41 string.

    input is the string to decode.

    The decoded data is returned. A TypeError is raised if input
    is not valid (odd number of chars, non-alphabet character present,
    invalid word).
    """
    rslt = bytearray()
    i = 0
    while i + 2 < len(input):
        x = (ord(input[i]) - 41) + 41 * (ord(input[i+1]) - 41) + 1681*(ord(input[i+2]) - 41)
        rslt.extend([x % 256, x // 256])
        i += 3
    if i != len(input):
        raise TypeError("Invalid Base41 string")
    return rslt