from collections import deque def count_possible_strings(S): visited = set() queue = deque([S]) visited.add(S) n = len(S) while queue: current = queue.popleft() # Precompute the number of 0s and 1s for all possible substrings # This is a 2D array where prefix[i][j] is the count of 0s from index i to j inclusive prefix = [[0]*(n) for _ in range(n)] for i in range(n): count0 = 0 for j in range(i, n): if current[j] == '0': count0 += 1 prefix[i][j] = count0 # Iterate over all possible t and u pairs for Lt in range(n): for Rt in range(Lt, n): t0 = prefix[Lt][Rt] t1 = (Rt - Lt + 1) - t0 # Now find u after Rt for Lu in range(Rt+1, n): for Ru in range(Lu, n): u0 = prefix[Lu][Ru] u1 = (Ru - Lu + 1) - u0 if t0 == u0 and t1 == u1: # Swap t and u new_str = current[:Lt] + current[Lu:Ru+1] + current[Rt+1:Lu] + current[Lt:Rt+1] + current[Ru+1:] if new_str not in visited: visited.add(new_str) queue.append(new_str) return len(visited) S = input().strip() print(count_possible_strings(S))