def fact(x);(1..x).inject(:*);end s=gets.chars.to_a.sort! a=[1] s.inject(){|m,e| if m==e a[-1]+=1 else a+=[1] end e } n=fact(s.size) a.each{|e|n/=fact(e)} p n-1