def f(x): if T[x]!=None: return T[x] for j in range(N): if x&(1<>=1 S[a]=x T=[None]*(1<