from sys import setrecursionlimit setrecursionlimit(10**6) def operator1(C): M = len(C) cnt = 0 for b in range(1,1<<16): cnt += len(bin(b)) - 2 if cnt == M: return b, M, len(bin(b)) - 2 def operator2(C, M): Run = [] cnt = 1 for i in range(1,M): if C[i] == '0': cnt += 1 else: Run.append(cnt) cnt = 1 Run.append(cnt) return Run def operator3(N): Num = [[] for _ in range(N+1)] for i in range(1,N+1): B = bin(i)[2:] cnt = 1 for b in B[1:]: if b == '0': cnt += 1 else: Num[i].append(cnt) cnt = 1 Num[i].append(cnt) return Num def operator4(Num, N): Len = [[] for _ in range(30)] for i in range(1,N+1): Len[len(Num[i])].append(i) return Len def operator5(Run, Num, N, M): G = [[] for _ in range(N+1)] for i in range(1,N+1): L = len(Num[i]) for j in range(M-L+1): if Num[i] == Run[j:j+L]: G[i].append(j) return G def dfs(x, y): global Run, Num, Len, G, ans, Flg if len(Len[x]) == y: x -= 1 while not len(Len[x]) and x: x -= 1 y = 0 if x == 0: Answer() c = Len[x][y] L = len(Num[c]) for i in G[c]: Flg2 = 0 for k in range(L): if Flg[i+k]: Flg2 = 1 break if Flg2: continue ans[c] = i for k in range(L): Flg[i+k] = 1 dfs(x, y+1) for k in range(L): Flg[i+k] = 0 def Answer(): global ans for i in range(N+1): ans[i] = [ans[i], i] ans = ans[1:] ans.sort() for i in range(N): ans[i] = ans[i][1] print(*ans) exit() C = input() N,M,B = operator1(C) Run = operator2(C, M) M = len(Run) Num = operator3(N) Len = operator4(Num, N) G = operator5(Run, Num, N, M) ans = [0] * (N+1) Flg = [0] * M dfs(20, 0)