from functools import lru_cache @lru_cache(maxsize=None) def check(N): st=set() st.add(0) if N>=2: for bit in range(1,1<