import base64, sys

def try_all(data):
    """Return list of (name, decoded_bytes) for each codec that plausibly decodes."""
    outs = []
    for name, fn in (('b64', base64.b64decode),
                     ('b85', base64.b85decode),
                     ('a85', base64.a85decode)):
        try:
            d = fn(data)
            if d:
                outs.append((name, d))
        except Exception:
            pass
    return outs

def unwrap(data, depth=5, path=()):
    """DFS through nested encodings exactly `depth` layers; return (path, text)."""
    if depth == 0:
        try:
            t = data.decode('utf-8')
        except UnicodeDecodeError:
            return None
        return (path, t)
    for name, d in try_all(data):
        r = unwrap(d, depth - 1, path + (name,))
        if r:
            return r
    return None

if __name__ == '__main__':
    raw = sys.argv[1].strip().encode()
    for depth in (5, 4, 3, 2, 1):
        r = unwrap(raw, depth)
        if r:
            print(f'layers({depth}) = {" -> ".join(r[0])}')
            print(r[1])
            break
    else:
        print('no decode found')
