class Calc0170 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @s = args.shift.first end def fact(n) (1..n).to_a.inject(:*) end def run s = @s.split(//) h = s.group_by(&:itself).map { |k, v| v.size } fact(s.size) / h.map { |n| fact(n) }.inject(:*) - 1 end end puts Calc0170.new(STDIN.readlines).run if __FILE__ == $0