from collections import deque def count_reachable_strings(s): visited = set() queue = deque() visited.add(s) queue.append(s) n = len(s) while queue: current = queue.popleft() # Generate all possible pairs of non-overlapping substrings t and u for t_start in range(n): for t_end in range(t_start, n): # Get t's composition t = current[t_start:t_end+1] t0 = t.count('0') t1 = t.count('1') # Iterate over possible u_start after t_end for u_start in range(t_end + 1, n): for u_end in range(u_start, n): # Get u's composition u = current[u_start:u_end+1] u0 = u.count('0') u1 = u.count('1') if t0 == u0 and t1 == u1: # Swap t and u new_str = ( current[:t_start] + u + current[t_end+1:u_start] + t + current[u_end+1:] ) if new_str not in visited: visited.add(new_str) queue.append(new_str) return len(visited) s = input().strip() print(count_reachable_strings(s))