a=Array.new(10) {|i| i}
while gets
  n,s=$_.split.map(&:to_i)
  cnt=0
  a.permutation(n){|pm|
    b=Array.new(n){|i| i+1}
    cnt+=1 if s==[pm,b].transpose.map{|j| j.inject(:*)}.inject(:+)
  }
  p cnt
end