H = {} def fill_hash(cs, str) if cs.size <= 0 then H[str] = true return end cs_dup = cs.dup str_dup = str.dup str_dup << cs_dup.pop fill_hash(cs_dup, str_dup) str << cs.shift fill_hash(cs, str) end CS = gets.chomp.chars fill_hash(CS, "") puts H.size