class Calc0052 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @s = args.shift.first end def run return 1 if @s.size == 1 ops = [[:shift, :pop]] * @s.size ops.first.product(*ops[1..-1]).map { |op| s = @s.split(//) op.inject('') { |t, o| t + s.send(o) } }.uniq.size end end puts Calc0052.new(STDIN.readlines).run if __FILE__ == $0