#num = "2***9*2*6*1199*"
#as = [0,1 ,2 ,3, 4, 6, 7, 8, 9]

def isum(ns)
	Enumerator.new {|y|
		ns.each.each_with_index {|n,idx|
			if idx.odd?
				y << (n*2).to_s.chars.map{|c|c.to_i}.inject(:+)
			else
				y<< n
			end
		}
	}.inject(:+)
end

def holes(str)
	a = 0
	e = 0
	str.chars.each_with_index {|n,idx|
		if n == "*"
			a+=1
			if idx.odd?
				e+=1
			end
		end
	}
	[a,e]
end

def factrial(n)
	(1..n).inject(:*)
end

def count_perm(arr)
	h = Hash.new(0)
	l = arr.length
	arr.each {|x|
		h[x]+=1
	}
	ret = factrial(l)
	h.values.each {|x|
		ret /= factrial(x)
	}
	ret
end
gets
num = gets.chomp
gets
as = gets.chomp.split(" ").map(&:to_i)

all,even = holes num
sum = isum num.chars.map(&:to_i)
#p sum,all,even
p as.repeated_combination(all-even).map {|arr|
	as.repeated_combination(even).map {|arr2|
		s1 = arr.inject(:+)
		s2 = arr2.map {|x|
			if 2*x >= 10
				(2*x/10) + (2*x%10)
			else
				2*x
			end
		}.inject(:+)
		if (sum+s1+s2) % 10 == 0
			count_perm(arr)*count_perm(arr2)
		else
			0
		end
	}
}.flatten.inject(:+)