import string


def decode(digits, base):
    """Decode given digits in given base to number in base 10.
    digits: str -- string representation of number (in given base)
    base: int -- base of given number
    return: int -- integer representation of number (in base 10)"""
    # Handle up to base 36 [0-9a-z]
    assert 2 <= base <= 36, 'base is out of range: {}'.format(base)

    result = 0
    power = len(digits)-1
    for i in range(len(digits)):
        if digits[i] in string.ascii_lowercase:
            digit = ord(digits[i]) - 87
        elif digits[i] in string.ascii_uppercase:
            digit = ord(digits[i]) - 55
        else:
            digit = int(digits[i])
        
        num = (base**power) * digit
        result += num
        power -= 1
    return result