import base64


def decode(s):
    """
    Base64 decode.

    :param s:
    :return: str
    """
    if isinstance(s, str):
        if len(s) % 4 > 0:
            s = s + '=' * (4 - len(s) % 4)
        s = s.encode('utf-8')

    # URL Safe
    s = s.translate(bytes.maketrans(b'-_', b'+/'))

    try:
        return base64.b64decode(s).decode('utf-8')
    except UnicodeDecodeError:
        return base64.b64decode(s)