s = gets.chomp @h = {} def f(s, t) n = s.size if n == 1 @h[t + s[0]] = 1 else f(s[1, n - 1], t + s[0]) f(s[0, n - 1], t + s[-1]) end end f(s, '') puts @h.size